From c51a8159e29c5242abd837a1676ea565448ff5ec Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 18 Mar 2013 10:28:53 +0300 Subject: [PATCH] first cherry-pick for mac os table pressure fix --- src/board/UBBoardView.cpp | 67 ++++++++++++++++++++++++++++- src/board/UBBoardView.h | 9 ++-- src/gui/UBCachePropertiesWidget.cpp | 1 - src/gui/UBMainWindow.cpp | 32 ++++++++++++++ src/gui/UBMainWindow.h | 4 ++ 5 files changed, 108 insertions(+), 5 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 0fef3ac5..9273c0b2 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -864,12 +864,77 @@ void UBBoardView::setMultiselection(bool enable) mMultipleSelectionIsEnabled = enable; } +// work around for handling tablet events on MAC OS with Qt 4.8.0 and above +#if defined(Q_WS_MACX) +bool UBBoardView::directTabletEvent(QEvent *event) +{ + QTabletEvent *tEvent = static_cast(event); + tEvent = new QTabletEvent(tEvent->type() + , mapFromGlobal(tEvent->pos()) + , tEvent->globalPos() + , tEvent->hiResGlobalPos() + , tEvent->device() + , tEvent->pointerType() + , tEvent->pressure() + , tEvent->xTilt() + , tEvent->yTilt() + , tEvent->tangentialPressure() + , tEvent->rotation() + , tEvent->z() + , tEvent->modifiers() + , tEvent->uniqueId()); + + if (geometry().contains(tEvent->pos())) + { + if (NULL == widgetForTabletEvent(this->parentWidget(), tEvent->pos())) + { + tabletEvent(tEvent); + return true; + } + } + return false; +} + +QWidget *UBBoardView::widgetForTabletEvent(QWidget *w, const QPoint &pos) +{ + Q_ASSERT(w); + + UBBoardView *board = qobject_cast(w); + + QWidget *childAtPos = NULL; + + QList childs = w->children(); + foreach(QObject *child, childs) + { + QWidget *childWidget = qobject_cast(child); + if (childWidget) + { + if (childWidget->isVisible() && childWidget->geometry().contains(pos)) + { + QWidget *lastChild = widgetForTabletEvent(childWidget, pos); + + if (board && board->viewport() == lastChild) + continue; + + if (NULL != lastChild) + childAtPos = lastChild; + else + childAtPos = childWidget; + + break; + } + else + childAtPos = NULL; + } + } + return childAtPos; +} +#endif void UBBoardView::longPressEvent() { UBDrawingController *drawingController = UBDrawingController::drawingController(); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - disconnect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent())); if (UBStylusTool::Selector == currentTool) diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index fe709991..52883447 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -20,7 +20,6 @@ */ - #ifndef UBBOARDVIEW_H_ #define UBBOARDVIEW_H_ @@ -54,7 +53,11 @@ class UBBoardView : public QGraphicsView void setMultiselection(bool enable); bool isMultipleSelectionEnabled() { return mMultipleSelectionIsEnabled; } - +// work around for handling tablet events on MAC OS with Qt 4.8.0 and above +#if defined(Q_WS_MACX) + bool directTabletEvent(QEvent *event); + QWidget *widgetForTabletEvent(QWidget *w, const QPoint &pos); +#endif signals: void resized(QResizeEvent* event); @@ -153,7 +156,7 @@ class UBBoardView : public QGraphicsView bool moveRubberBand; UBRubberBand *mUBRubberBand; - + QList mRubberedItems; QSet mJustSelectedItems; diff --git a/src/gui/UBCachePropertiesWidget.cpp b/src/gui/UBCachePropertiesWidget.cpp index 8c87effe..e989d5fd 100644 --- a/src/gui/UBCachePropertiesWidget.cpp +++ b/src/gui/UBCachePropertiesWidget.cpp @@ -372,4 +372,3 @@ void UBCachePropertiesWidget::onCacheEnabled() { emit showTab(this); } - diff --git a/src/gui/UBMainWindow.cpp b/src/gui/UBMainWindow.cpp index d707a345..dc0497bf 100644 --- a/src/gui/UBMainWindow.cpp +++ b/src/gui/UBMainWindow.cpp @@ -27,6 +27,10 @@ #include "core/UBApplication.h" #include "core/UBApplicationController.h" #include "board/UBBoardController.h" +// work around for handling tablet events on MAC OS with Qt 4.8.0 and above +#if defined(Q_WS_MACX) +#include "board/UBBoardView.h" +#endif #include "core/memcheck.h" @@ -145,6 +149,34 @@ void UBMainWindow::closeEvent(QCloseEvent *event) emit closeEvent_Signal(event); } +// work around for handling tablet events on MAC OS with Qt 4.8.0 and above +#if defined(Q_WS_MACX) +bool UBMainWindow::event(QEvent *event) +{ + bool bRes = QMainWindow::event(event); + + if (NULL != UBApplication::boardController) + { + UBBoardView *controlV = UBApplication::boardController->controlView(); + if (controlV && controlV->isVisible()) + { + switch (event->type()) + { + case QEvent::TabletEnterProximity: + case QEvent::TabletLeaveProximity: + case QEvent::TabletMove: + case QEvent::TabletPress: + case QEvent::TabletRelease: + { + return controlV->directTabletEvent(event); + } + } + } + } + return bRes; +} +#endif + void UBMainWindow::onExportDone() { // HACK : When opening the file save dialog during the document exportation, diff --git a/src/gui/UBMainWindow.h b/src/gui/UBMainWindow.h index 2c3e75f6..f4d11ba3 100644 --- a/src/gui/UBMainWindow.h +++ b/src/gui/UBMainWindow.h @@ -83,6 +83,10 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow QWidget *mDocumentsWidget; private: +// work around for handling tablet events on MAC OS with Qt 4.8.0 and above +#if defined(Q_WS_MACX) + bool event(QEvent *event); +#endif UBDownloadWidget* mpDownloadWidget; };