diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 72d4e5998..8f8ae556e 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -1924,3 +1924,10 @@ bool UBBoardView::hasSelectedParents(QGraphicsItem * item) return false; return hasSelectedParents(item->parentItem()); } + +void UBBoardView::releaseAllInputDevices() +{ + mMouseButtonIsPressed = false; + mTabletStylusIsPressed = false; + mPendingStylusReleaseEvent = false; +} diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index 05438c6d7..996876635 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -64,6 +64,8 @@ class UBBoardView : public QGraphicsView void setMultiselection(bool enable); bool isMultipleSelectionEnabled() { return mMultipleSelectionIsEnabled; } + + void releaseAllInputDevices(); // work around for handling tablet events on MAC OS with Qt 4.8.0 and above #if defined(Q_OS_OSX) bool directTabletEvent(QEvent *event); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 42aab2268..b754b2200 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -366,6 +366,8 @@ UBGraphicsScene::UBGraphicsScene(std::shared_ptr document, bool // connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int))); connect(UBDrawingController::drawingController(), SIGNAL(stylusToolChanged(int,int)), this, SLOT(stylusToolChanged(int,int))); + + installEventFilter(this); } UBGraphicsScene::~UBGraphicsScene() @@ -715,8 +717,9 @@ bool UBGraphicsScene::inputDeviceRelease(int tool) } // replace the stroke by a simplified version of it - if ((currentTool == UBStylusTool::Pen && UBSettings::settings()->boardSimplifyPenStrokes->get().toBool()) - || (currentTool == UBStylusTool::Marker && UBSettings::settings()->boardSimplifyMarkerStrokes->get().toBool())) + if(multiDrawLines.isEmpty() && // is it not polygons drawing by multiDraw + ((currentTool == UBStylusTool::Pen && UBSettings::settings()->boardSimplifyPenStrokes->get().toBool()) + || (currentTool == UBStylusTool::Marker && UBSettings::settings()->boardSimplifyMarkerStrokes->get().toBool()))) { simplifyCurrentStroke(); } @@ -2052,6 +2055,28 @@ bool UBGraphicsScene::isEmpty() const return mItemCount == 0; } +bool UBGraphicsScene::eventFilter(QObject *watched, QEvent *event) +{ + if( UBApplication::applicationController != NULL ) // it needs to work only on Board mode + if( UBApplication::applicationController->displayMode() != UBApplicationController::Board || + UBApplication::applicationController->isShowingDesktop()) + return false; + if (watched == this) + { + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); + if ((event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) //for use multiDraw + && (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker)) // when Pen or Marker + { + + multiTouchDrawing(static_cast(event), currentTool); + if (event->type() == QEvent::TouchEnd) //end of multiDraw + multiTouchEndDrawing(); + return true; + } + } + return false; +} + QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation, bool pExpand) { if (mBackgroundObject) @@ -3122,3 +3147,42 @@ void UBGraphicsScene::initStroke() { mCurrentStroke = new UBGraphicsStroke(shared_from_this()); } + +void UBGraphicsScene::multiTouchDrawing(QTouchEvent* event, UBStylusTool::Enum currentTool) +{ + QList touchPoints = event->touchPoints(); + QPointF lastPoint_m, endPoint_m; + foreach (const QTouchEvent::TouchPoint point, touchPoints) + { + lastPoint_m = point.lastPos(); + endPoint_m = point.pos(); + + UBBoardView* boardView = controlView(); + QLineF line; + line.setP1(boardView->mapToScene(UBGeometryUtils::pointConstrainedInRect(lastPoint_m.toPoint(), boardView->rect()))); + line.setP2(boardView->mapToScene(UBGeometryUtils::pointConstrainedInRect(endPoint_m.toPoint(), boardView->rect()))); + if (!multiDrawLines.contains(line)) // to eliminate duplicates + { + multiDrawLines.append(line); + + qreal penWidth = 0; + if (currentTool == UBStylusTool::Pen) + penWidth = UBSettings::settings()->currentPenWidth(); + else if (currentTool == UBStylusTool::Marker) + penWidth = UBSettings::settings()->currentMarkerWidth(); + penWidth /= UBApplication::boardController->systemScaleFactor(); + penWidth /= UBApplication::boardController->currentZoom(); + + UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(line, penWidth, penWidth); + addPolygonItemToCurrentStroke(polygonItem); + } + + } +} + +void UBGraphicsScene::multiTouchEndDrawing() +{ + inputDeviceRelease(); + multiDrawLines.clear(); + controlView()->releaseAllInputDevices(); +} diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index b78cce987..b767b83a5 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -350,6 +350,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem, public std::en QRectF annotationsBoundingRect() const; + bool eventFilter(QObject *watched, QEvent *event) override; + public slots: void updateSelectionFrame(); void updateSelectionFrameWrapper(int); @@ -415,6 +417,8 @@ public slots: void hideMarkerCircle(); void hidePenCircle(); void DisposeMagnifierQWidgets(); + void multiTouchDrawing(QTouchEvent* event, UBStylusTool::Enum currentTool); + void multiTouchEndDrawing(); virtual void keyReleaseEvent(QKeyEvent * keyEvent); @@ -500,6 +504,8 @@ public slots: UBSelectionFrame *mSelectionFrame; UBGraphicsCache* mGraphicsCache; + + QList multiDrawLines; };