Skip to content

Commit 9c1a65c

Browse files
committed
feat: seamless switching between tools
- switch between tools in board mode even if pen down - new tool starts at current position - fix conflict between panning and page change
1 parent 463030f commit 9c1a65c

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

src/board/UBDrawingController.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,16 @@ void UBDrawingController::setStylusTool(int tool)
156156
}
157157

158158

159-
bool UBDrawingController::isDrawingTool()
159+
bool UBDrawingController::isDrawingTool(int tool)
160160
{
161-
return (stylusTool() == UBStylusTool::Pen)
162-
|| (stylusTool() == UBStylusTool::Marker)
163-
|| (stylusTool() == UBStylusTool::Line);
161+
if (tool < 0)
162+
{
163+
tool = stylusTool();
164+
}
165+
166+
return (tool == UBStylusTool::Pen)
167+
|| (tool == UBStylusTool::Marker)
168+
|| (tool == UBStylusTool::Line);
164169
}
165170

166171

src/board/UBDrawingController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class UBDrawingController : public QObject
5252
int stylusTool();
5353
int latestDrawingTool();
5454

55-
bool isDrawingTool();
55+
bool isDrawingTool(int tool = -1);
5656

5757
int currentToolWidthIndex();
5858
qreal currentToolWidth();

src/domain/UBGraphicsScene.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
502502
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)dc->stylusTool();
503503

504504
QPointF position = QPointF(scenePos);
505+
mCurrentPoint = position;
505506

506507
if (currentTool == UBStylusTool::Eraser)
507508
{
@@ -669,14 +670,9 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
669670
}
670671

671672
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)tool;
672-
673-
if (currentTool == UBStylusTool::Eraser)
674-
hideEraser();
675-
676-
677673
UBDrawingController *dc = UBDrawingController::drawingController();
678674

679-
if (dc->isDrawingTool() || mDrawWithCompass)
675+
if (dc->isDrawingTool(tool) || mDrawWithCompass)
680676
{
681677
if(mArcPolygonItem){
682678

@@ -2394,12 +2390,21 @@ void UBGraphicsScene::resizedMagnifier(qreal newPercent)
23942390

23952391
void UBGraphicsScene::stylusToolChanged(int tool, int previousTool)
23962392
{
2397-
if (mInputDeviceIsPressed && tool != previousTool)
2393+
if (tool != previousTool)
23982394
{
2399-
// tool was changed while input device is pressed
2400-
// simulate release and press to terminate pervious strokes
2401-
inputDeviceRelease(previousTool);
2402-
inputDevicePress(mPreviousPoint);
2395+
hideTool();
2396+
2397+
if (mInputDeviceIsPressed)
2398+
{
2399+
// tool was changed while input device is pressed
2400+
// simulate release and press to terminate previous strokes
2401+
inputDeviceRelease(previousTool);
2402+
inputDevicePress(mCurrentPoint);
2403+
}
2404+
else if (previousTool >= 0)
2405+
{
2406+
inputDeviceMove(mCurrentPoint);
2407+
}
24032408
}
24042409
}
24052410

src/domain/UBGraphicsScene.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ public slots:
465465
QPointF mPreviousPoint;
466466
qreal mPreviousWidth;
467467
qreal mDistanceFromLastStrokePoint;
468+
QPointF mCurrentPoint;
468469

469470
QList<UBGraphicsPolygonItem*> mPreviousPolygonItems;
470471

0 commit comments

Comments
 (0)