Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Masking in Desktop mode #895

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/core/UB.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@

#define UB_MAX_ZOOM 9

#if defined(Q_OS_LINUX) || (defined(Q_OS_OSX) && (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)))
#define UB_REQUIRES_MASK_UPDATE 1
#endif

struct UBMimeType
{
enum Enum
Expand Down
174 changes: 20 additions & 154 deletions src/desktop/UBDesktopAnnotationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent, UB
{
connect( UBApplication::boardController->paletteManager()->mKeyboardPalette, SIGNAL(keyboardActivated(bool)),
mTransparentDrawingView, SLOT(virtualKeyboardActivated(bool)));

#ifdef UB_REQUIRES_MASK_UPDATE
connect(UBApplication::boardController->paletteManager()->mKeyboardPalette, SIGNAL(moved(QPoint)), this, SLOT(refreshMask()));
connect(UBApplication::mainWindow->actionVirtualKeyboard, SIGNAL(triggered(bool)), this, SLOT(refreshMask()));
connect(mDesktopPalette,SIGNAL(refreshMask()), this, SLOT(refreshMask()));
#endif
}

connect(mDesktopPalette, SIGNAL(uniboardClick()), this, SLOT(goToUniboard()));
Expand Down Expand Up @@ -167,11 +161,6 @@ UBDesktopAnnotationController::UBDesktopAnnotationController(QObject *parent, UB
connect(&mHoldTimerMarker, SIGNAL(timeout()), this, SLOT(markerActionReleased()));
connect(&mHoldTimerEraser, SIGNAL(timeout()), this, SLOT(eraserActionReleased()));

#ifdef UB_REQUIRES_MASK_UPDATE
connect(mDesktopPalette, SIGNAL(moving()), this, SLOT(refreshMask()));
connect(UBApplication::boardController->paletteManager()->rightPalette(), SIGNAL(resized()), this, SLOT(refreshMask()));
connect(UBApplication::boardController->paletteManager()->addItemPalette(), SIGNAL(closed()), this, SLOT(refreshMask()));
#endif
onDesktopPaletteMaximized();

// FIX #633: Ensure that these palettes stay on top of the other elements
Expand Down Expand Up @@ -346,9 +335,6 @@ void UBDesktopAnnotationController::showWindow()

mDesktopPalette->appear();

#ifdef UB_REQUIRES_MASK_UPDATE
updateMask(true);
#endif // UB_REQUIRES_MASK_UPDATE
}


Expand Down Expand Up @@ -392,9 +378,6 @@ void UBDesktopAnnotationController::updateBackground()
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Selector)
{
newBrush = QBrush(Qt::transparent);
#ifdef UB_REQUIRES_MASK_UPDATE
updateMask(true);
#endif //UB_REQUIRES_MASK_UPDATE
}
else
{
Expand All @@ -403,9 +386,6 @@ void UBDesktopAnnotationController::updateBackground()
#else
newBrush = QBrush(QColor(127, 127, 127, 1));
#endif
#ifdef UB_REQUIRES_MASK_UPDATE
updateMask(false);
#endif //UB_REQUIRES_MASK_UPDATE
}

if (mTransparentDrawingScene && mTransparentDrawingScene->backgroundBrush() != newBrush)
Expand Down Expand Up @@ -554,7 +534,6 @@ void UBDesktopAnnotationController::penActionReleased()
mPendingPenButtonPressed = false;
}
UBApplication::mainWindow->actionPen->setChecked(true);

switchCursor(UBStylusTool::Pen);
}

Expand Down Expand Up @@ -608,7 +587,6 @@ void UBDesktopAnnotationController::eraserActionReleased()
mPendingEraserButtonPressed = false;
}
UBApplication::mainWindow->actionEraser->setChecked(true);

switchCursor(UBStylusTool::Eraser);
}

Expand Down Expand Up @@ -664,7 +642,6 @@ void UBDesktopAnnotationController::markerActionReleased()
mPendingMarkerButtonPressed = false;
}
UBApplication::mainWindow->actionMarker->setChecked(true);

switchCursor(UBStylusTool::Marker);
}

Expand All @@ -675,10 +652,28 @@ void UBDesktopAnnotationController::selectorActionPressed()

void UBDesktopAnnotationController::selectorActionReleased()
{
UBApplication::mainWindow->actionSelector->setChecked(true);
mDesktopPalette->minimizeMe(eMinimizedLocation_None);
switchCursor(UBStylusTool::Selector);

mTransparentDrawingView->setWindowFlag(Qt::WindowTransparentForInput);
mTransparentDrawingView->setWindowFlag(Qt::WindowDoesNotAcceptFocus);
mDesktopPalette->setAttribute(Qt::WA_TranslucentBackground);
mDesktopPalette->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
mDesktopPalette->show();
mTransparentDrawingView->show();
UBApplication::mainWindow->actionSelector->setChecked(true);

}
void UBDesktopAnnotationController::selectorModeLeaved()
{

mTransparentDrawingView->setWindowFlag(Qt::WindowTransparentForInput, false);
mTransparentDrawingView->setWindowFlag(Qt::WindowDoesNotAcceptFocus, false);
mTransparentDrawingView->show();
mDesktopPalette->setWindowFlags(Qt::Widget);
mDesktopPalette->show();

}

void UBDesktopAnnotationController::pointerActionPressed()
{
Expand Down Expand Up @@ -719,6 +714,7 @@ void UBDesktopAnnotationController::togglePropertyPalette(UBActionPalette *palet

void UBDesktopAnnotationController::switchCursor(const int tool)
{
selectorModeLeaved();
mTransparentDrawingScene->setToolCursor(tool);
mTransparentDrawingView->setToolCursor(tool);
}
Expand Down Expand Up @@ -822,136 +818,6 @@ void UBDesktopAnnotationController::onTransparentWidgetResized()
UBApplication::boardController->paletteManager()->leftPalette()->resize(lW, rH);
}

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());
mMask.fill(Qt::transparent);

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);
}

//Rquiered only for compiz wm
//TODO. Window manager detection screen

if (UBApplication::boardController->paletteManager()->addItemPalette()->isVisible()) {
p.drawRect(UBApplication::boardController->paletteManager()->addItemPalette()->geometry());
}


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() && pCrntItem->type() == UBGraphicsPolygonItem::Type)
{
QPainterPath crntPath = pCrntItem->shape();
QRectF rect = crntPath.boundingRect();

annotationPainter.drawRect(rect);
}
}

annotationPainter.end();

mTransparentDrawingView->setMask(mMask.mask());
}
else
{
mMask = QPixmap(mTransparentDrawingView->width(), mTransparentDrawingView->height());
mMask.fill(Qt::transparent);

QPainter p;

p.begin(&mMask);

p.setPen(Qt::red);
p.setBrush(QBrush(Qt::red));

p.drawRect(0, 0, mTransparentDrawingView->width(), mTransparentDrawingView->height());
p.end();

mTransparentDrawingView->setMask(mMask.mask());
}
}

void UBDesktopAnnotationController::refreshMask()
{
if (mTransparentDrawingScene && mTransparentDrawingView->isVisible()) {
if(mIsFullyTransparent
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Selector
//Needed to work correctly when another actions on stylus are checked
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Eraser
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Pointer
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Pen
|| UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Marker)
{
updateMask(true);
}
}
}

void UBDesktopAnnotationController::onToolClicked()
{
mDesktopEraserPalette->hide();
Expand Down
5 changes: 1 addition & 4 deletions src/desktop/UBDesktopAnnotationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,19 @@ class UBDesktopAnnotationController : public QObject
void eraserActionReleased();
void selectorActionPressed();
void selectorActionReleased();
void selectorModeLeaved();
void pointerActionPressed();
void pointerActionReleased();

void switchCursor(int tool);
void onDesktopPaletteMaximized();
void onDesktopPaletteMinimize();
void onTransparentWidgetResized();
void refreshMask();
void onToolClicked();

private:
void setAssociatedPalettePosition(UBActionPalette* palette, const QString& actionName);
void togglePropertyPalette(UBActionPalette* palette);
void updateMask(bool bTransparent);

UBDesktopPalette *mDesktopPalette;
//UBKeyboardPalette *mKeyboardPalette;
Expand Down Expand Up @@ -159,8 +158,6 @@ class UBDesktopAnnotationController : public QObject
int mBoardStylusTool;
int mDesktopStylusTool;

QPixmap mMask;

};

#endif /* UBUNINOTESWINDOWCONTROLLER_H_ */
11 changes: 0 additions & 11 deletions src/desktop/UBDesktopPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@

#include "frameworks/UBPlatformUtils.h"

#include "core/UBSettings.h"
#include "core/UBSetting.h"
#include "core/UBApplication.h"
#include "core/UBApplicationController.h"

#include "board/UBDrawingController.h"

#include "gui/UBMainWindow.h"

#include "core/memcheck.h"
Expand Down Expand Up @@ -172,10 +168,6 @@ void UBDesktopPalette::minimizeMe(eMinimizedLocation location)
setActions(actions);

adjustSizeAndPosition();

#ifdef UB_REQUIRES_MASK_UPDATE
emit refreshMask();
#endif
}

// Called when the user wants to maximize the palette
Expand Down Expand Up @@ -203,9 +195,6 @@ void UBDesktopPalette::maximizeMe()

// Notify that the maximization has been done
emit maximized();
#ifdef UB_REQUIRES_MASK_UPDATE
emit refreshMask();
#endif
}

void UBDesktopPalette::showEvent(QShowEvent *event)
Expand Down