Merge pull request #452 from letsfindaway/changing-tools

Detect and handle change of stylusTool while device pressed
preferencesAboutTextFull
kaamui 4 years ago committed by GitHub
commit 298af6158d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/board/UBDrawingController.cpp
  2. 2
      src/board/UBDrawingController.h
  3. 26
      src/domain/UBGraphicsScene.cpp
  4. 4
      src/domain/UBGraphicsScene.h

@ -120,6 +120,7 @@ void UBDrawingController::setStylusTool(int tool)
emit colorIndexChanged(UBSettings::settings()->markerColorIndex()); emit colorIndexChanged(UBSettings::settings()->markerColorIndex());
} }
UBStylusTool::Enum previousTool = mStylusTool;
mStylusTool = (UBStylusTool::Enum)tool; mStylusTool = (UBStylusTool::Enum)tool;
@ -148,7 +149,7 @@ void UBDrawingController::setStylusTool(int tool)
else if (mStylusTool == UBStylusTool::Capture) else if (mStylusTool == UBStylusTool::Capture)
UBApplication::mainWindow->actionCapture->setChecked(true); UBApplication::mainWindow->actionCapture->setChecked(true);
emit stylusToolChanged(tool); emit stylusToolChanged(tool, previousTool);
if (mStylusTool != UBStylusTool::Selector) if (mStylusTool != UBStylusTool::Selector)
emit colorPaletteChanged(); emit colorPaletteChanged();
} }

@ -82,7 +82,7 @@ class UBDrawingController : public QObject
void setEraserWidthIndex(int index); void setEraserWidthIndex(int index);
signals: signals:
void stylusToolChanged(int tool); void stylusToolChanged(int tool, int previousTool = -1);
void colorPaletteChanged(); void colorPaletteChanged();
void lineWidthIndexChanged(int index); void lineWidthIndexChanged(int index);

@ -362,6 +362,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
// Just for debug. Do not delete please // Just for debug. Do not delete please
// connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); // connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int))); 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() UBGraphicsScene::~UBGraphicsScene()
@ -615,6 +616,8 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
mTempPolygon = NULL; mTempPolygon = NULL;
} }
if (!mCurrentStroke->points().empty())
{
QPointF lastDrawnPoint = mCurrentStroke->points().last().first; QPointF lastDrawnPoint = mCurrentStroke->points().last().first;
mTempPolygon = lineToPolygonItem(QLineF(lastDrawnPoint, scenePos), mPreviousWidth, width); mTempPolygon = lineToPolygonItem(QLineF(lastDrawnPoint, scenePos), mPreviousWidth, width);
@ -622,6 +625,7 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
} }
} }
} }
}
else if (currentTool == UBStylusTool::Eraser) else if (currentTool == UBStylusTool::Eraser)
{ {
qreal eraserWidth = UBSettings::settings()->currentEraserWidth(); qreal eraserWidth = UBSettings::settings()->currentEraserWidth();
@ -641,7 +645,7 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
return accepted; return accepted;
} }
bool UBGraphicsScene::inputDeviceRelease() bool UBGraphicsScene::inputDeviceRelease(int tool)
{ {
bool accepted = false; bool accepted = false;
@ -651,10 +655,15 @@ bool UBGraphicsScene::inputDeviceRelease()
accepted = true; 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) if (currentTool == UBStylusTool::Eraser)
redrawEraser(false); hideEraser();
UBDrawingController *dc = UBDrawingController::drawingController(); 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) void UBGraphicsScene::addCompass(QPointF center)
{ {
UBGraphicsCompass* compass = new UBGraphicsCompass(); // mem : owned and destroyed by the scene UBGraphicsCompass* compass = new UBGraphicsCompass(); // mem : owned and destroyed by the scene

@ -141,7 +141,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0);
bool inputDeviceMove(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); void leaveEvent (QEvent* event);
@ -381,6 +381,8 @@ public slots:
void changeMagnifierMode(int mode); void changeMagnifierMode(int mode);
void resizedMagnifier(qreal newPercent); void resizedMagnifier(qreal newPercent);
void stylusToolChanged(int tool, int previousTool);
protected: protected:
UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth); UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth);

Loading…
Cancel
Save