-
Notifications
You must be signed in to change notification settings - Fork 502
support multi-touch #963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
support multi-touch #963
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -366,6 +366,8 @@ UBGraphicsScene::UBGraphicsScene(std::shared_ptr<UBDocumentProxy> 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<QTouchEvent*>(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 <QTouchEvent::TouchPoint> touchPoints = event->touchPoints(); | ||
| QPointF lastPoint_m, endPoint_m; | ||
| foreach (const QTouchEvent::TouchPoint point, touchPoints) | ||
| { | ||
| lastPoint_m = point.lastPos(); | ||
| endPoint_m = point.pos(); | ||
|
Comment on lines
+3157
to
+3158
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to not have |
||
|
|
||
| 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); | ||
|
Comment on lines
+3164
to
+3166
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In terms of performance,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is important because there are so many duplicates that the page can take a long time to load
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are spending so much time on searching rather than appending, it might be worth using |
||
|
|
||
| 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(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to use an
eventFilterin the scene instead of overridingevent()in the view? I would assume (but have not tested!) that the touch events arrive at the view and can be handled there. If this is the case, then I would also move the event handling to the view, while the multi-touch drawing code could be here in the scene.What you're touching with your finger is a screen with a widget, which is the view. You don't "touch" the scene. The scene just holds all the graphics items.