detect and handle change of stylusTool while device pressed

- Basically simulate a device release with the previous tool and a
device press with the new tool to correctly terminate the previous
action.
- Hide the eraser when switching to another tool.
preferencesAboutTextFull
letsfindaway 4 years ago
parent 36a9cdaccd
commit f2fce3cc0f
  1. 3
      src/board/UBDrawingController.cpp
  2. 2
      src/board/UBDrawingController.h
  3. 32
      src/domain/UBGraphicsScene.cpp
  4. 4
      src/domain/UBGraphicsScene.h

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

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

@ -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

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

Loading…
Cancel
Save