diff --git a/src/board/UBDrawingController.cpp b/src/board/UBDrawingController.cpp index 0af87fbd..279e2ca4 100644 --- a/src/board/UBDrawingController.cpp +++ b/src/board/UBDrawingController.cpp @@ -120,6 +120,7 @@ void UBDrawingController::setStylusTool(int tool) emit colorIndexChanged(UBSettings::settings()->markerColorIndex()); } + UBStylusTool::Enum previousTool = mStylusTool; mStylusTool = (UBStylusTool::Enum)tool; @@ -148,7 +149,7 @@ void UBDrawingController::setStylusTool(int tool) else if (mStylusTool == UBStylusTool::Capture) UBApplication::mainWindow->actionCapture->setChecked(true); - emit stylusToolChanged(tool); + emit stylusToolChanged(tool, previousTool); if (mStylusTool != UBStylusTool::Selector) emit colorPaletteChanged(); } diff --git a/src/board/UBDrawingController.h b/src/board/UBDrawingController.h index e40c156f..6b163117 100644 --- a/src/board/UBDrawingController.h +++ b/src/board/UBDrawingController.h @@ -82,7 +82,7 @@ class UBDrawingController : public QObject void setEraserWidthIndex(int index); signals: - void stylusToolChanged(int tool); + void stylusToolChanged(int tool, int previousTool = -1); void colorPaletteChanged(); void lineWidthIndexChanged(int index); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 44b14418..b264c1cb 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -362,6 +362,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta // Just for debug. Do not delete please // 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))); } UBGraphicsScene::~UBGraphicsScene() @@ -615,10 +616,13 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres mTempPolygon = NULL; } - QPointF lastDrawnPoint = mCurrentStroke->points().last().first; + if (!mCurrentStroke->points().empty()) + { + QPointF lastDrawnPoint = mCurrentStroke->points().last().first; - mTempPolygon = lineToPolygonItem(QLineF(lastDrawnPoint, scenePos), mPreviousWidth, width); - addItem(mTempPolygon); + mTempPolygon = lineToPolygonItem(QLineF(lastDrawnPoint, scenePos), mPreviousWidth, width); + addItem(mTempPolygon); + } } } } @@ -641,7 +645,7 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres return accepted; } -bool UBGraphicsScene::inputDeviceRelease() +bool UBGraphicsScene::inputDeviceRelease(int tool) { bool accepted = false; @@ -651,10 +655,15 @@ bool UBGraphicsScene::inputDeviceRelease() accepted = true; } - UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); + if (tool < 0) + { + tool = UBDrawingController::drawingController()->stylusTool(); + } + + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)tool; if (currentTool == UBStylusTool::Eraser) - redrawEraser(false); + hideEraser(); UBDrawingController *dc = UBDrawingController::drawingController(); @@ -2355,6 +2364,17 @@ void UBGraphicsScene::resizedMagnifier(qreal newPercent) } } +void UBGraphicsScene::stylusToolChanged(int tool, int previousTool) +{ + if (mInputDeviceIsPressed && tool != previousTool) + { + // tool was changed while input device is pressed + // simulate release and press to terminate pervious strokes + inputDeviceRelease(previousTool); + inputDevicePress(mPreviousPoint); + } +} + void UBGraphicsScene::addCompass(QPointF center) { UBGraphicsCompass* compass = new UBGraphicsCompass(); // mem : owned and destroyed by the scene diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 4040af7e..ab637756 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -141,7 +141,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0); - bool inputDeviceRelease(); + bool inputDeviceRelease(int tool = -1); void leaveEvent (QEvent* event); @@ -381,6 +381,8 @@ public slots: void changeMagnifierMode(int mode); void resizedMagnifier(qreal newPercent); + void stylusToolChanged(int tool, int previousTool); + protected: UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth);