void UBDesktopAnnotationController::updateMask(bool bTransparent) { if(bTransparent) { // Here we have to generate a new mask This method is certainly resource // consuming but for the moment this is the only solution that I found. mMask = QPixmap(mTransparentDrawingView->width(), mTransparentDrawingView->height()); QPainter p; p.begin(&mMask); p.setPen(Qt::red); p.setBrush(QBrush(Qt::red)); // Here we draw the widget mask if(mDesktopPalette->isVisible()) { p.drawRect(mDesktopPalette->geometry().x(), mDesktopPalette->geometry().y(), mDesktopPalette->width(), mDesktopPalette->height()); } if(UBApplication::boardController->paletteManager()->mKeyboardPalette->isVisible()) { p.drawRect(UBApplication::boardController->paletteManager()->mKeyboardPalette->geometry().x(), UBApplication::boardController->paletteManager()->mKeyboardPalette->geometry().y(), UBApplication::boardController->paletteManager()->mKeyboardPalette->width(), UBApplication::boardController->paletteManager()->mKeyboardPalette->height()); } if(UBApplication::boardController->paletteManager()->leftPalette()->isVisible()) { QRect leftPalette(UBApplication::boardController->paletteManager()->leftPalette()->geometry().x(), UBApplication::boardController->paletteManager()->leftPalette()->geometry().y(), UBApplication::boardController->paletteManager()->leftPalette()->width(), UBApplication::boardController->paletteManager()->leftPalette()->height()); QRect tabsPalette(UBApplication::boardController->paletteManager()->leftPalette()->getTabPaletteRect()); p.drawRect(leftPalette); p.drawRect(tabsPalette); } if(UBApplication::boardController->paletteManager()->rightPalette()->isVisible()) { QRect rightPalette(UBApplication::boardController->paletteManager()->rightPalette()->geometry().x(), UBApplication::boardController->paletteManager()->rightPalette()->geometry().y(), UBApplication::boardController->paletteManager()->rightPalette()->width(), UBApplication::boardController->paletteManager()->rightPalette()->height()); QRect tabsPalette(UBApplication::boardController->paletteManager()->rightPalette()->getTabPaletteRect()); p.drawRect(rightPalette); p.drawRect(tabsPalette); } p.end(); // Then we add the annotations. We create another painter because we need to // apply transformations on it for coordinates matching QPainter annotationPainter; QTransform trans; trans.translate(mTransparentDrawingView->width()/2, mTransparentDrawingView->height()/2); annotationPainter.begin(&mMask); annotationPainter.setPen(Qt::red); annotationPainter.setBrush(Qt::red); annotationPainter.setTransform(trans); QList<QGraphicsItem*> allItems = mTransparentDrawingScene->items(); for(int i = 0; i < allItems.size(); i++) { QGraphicsItem* pCrntItem = allItems.at(i); if(pCrntItem->isVisible()) { QPainterPath crntPath = pCrntItem->shape(); QRectF rect = crntPath.boundingRect(); annotationPainter.drawRect(rect); } } annotationPainter.end(); mTransparentDrawingView->setMask(mMask.createMaskFromColor(Qt::black)); } else { // Remove the mask QPixmap noMask(mTransparentDrawingView->width(), mTransparentDrawingView->height()); mTransparentDrawingView->setMask(noMask.mask()); } }