Skip to content

Commit 5ad0a9c

Browse files
committed
multi-touch
Add to OpenBoard multi touch drawing. It allows several people to draw at once with tool Pen and Marker.
1 parent 09c2e25 commit 5ad0a9c

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

src/board/UBBoardView.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,3 +1924,13 @@ bool UBBoardView::hasSelectedParents(QGraphicsItem * item)
19241924
return false;
19251925
return hasSelectedParents(item->parentItem());
19261926
}
1927+
1928+
void UBBoardView::releaseAllInputDevices()
1929+
{
1930+
if (mMouseButtonIsPressed || mTabletStylusIsPressed || mPendingStylusReleaseEvent)
1931+
{
1932+
mMouseButtonIsPressed = false;
1933+
mTabletStylusIsPressed = false;
1934+
mPendingStylusReleaseEvent = false;
1935+
}
1936+
}

src/board/UBBoardView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class UBBoardView : public QGraphicsView
6464

6565
void setMultiselection(bool enable);
6666
bool isMultipleSelectionEnabled() { return mMultipleSelectionIsEnabled; }
67+
68+
void releaseAllInputDevices();
6769
// work around for handling tablet events on MAC OS with Qt 4.8.0 and above
6870
#if defined(Q_OS_OSX)
6971
bool directTabletEvent(QEvent *event);

src/domain/UBGraphicsScene.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ UBGraphicsScene::UBGraphicsScene(std::shared_ptr<UBDocumentProxy> document, bool
366366
// connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
367367
connect(UBApplication::undoStack.data(), SIGNAL(indexChanged(int)), this, SLOT(updateSelectionFrameWrapper(int)));
368368
connect(UBDrawingController::drawingController(), SIGNAL(stylusToolChanged(int,int)), this, SLOT(stylusToolChanged(int,int)));
369+
370+
installEventFilter(this);
369371
}
370372

371373
UBGraphicsScene::~UBGraphicsScene()
@@ -714,6 +716,7 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
714716
addPolygonItemToCurrentStroke(poly);
715717
}
716718

719+
if(multiDrawLines.isEmpty()) // is it not polygons drawing by multiDraw
717720
// replace the stroke by a simplified version of it
718721
if ((currentTool == UBStylusTool::Pen && UBSettings::settings()->boardSimplifyPenStrokes->get().toBool())
719722
|| (currentTool == UBStylusTool::Marker && UBSettings::settings()->boardSimplifyMarkerStrokes->get().toBool()))
@@ -2052,6 +2055,27 @@ bool UBGraphicsScene::isEmpty() const
20522055
return mItemCount == 0;
20532056
}
20542057

2058+
bool UBGraphicsScene::eventFilter(QObject *watched, QEvent *event)
2059+
{
2060+
if( UBApplication::applicationController != NULL ) // it needs to work only on Board mode
2061+
if( UBApplication::applicationController->displayMode() != UBApplicationController::Board ||
2062+
UBApplication::applicationController->isShowingDesktop())
2063+
return false;
2064+
if (watched == this)
2065+
{
2066+
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
2067+
if ((event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) //for use multiDraw
2068+
&& (currentTool == UBStylusTool::Pen || currentTool == UBStylusTool::Marker)) // when Pen or Marker
2069+
{
2070+
MultiTouchDrawing(static_cast<QTouchEvent*>(event), currentTool);
2071+
if (event->type() == QEvent::TouchEnd) //end of multiDraw
2072+
MultiTouchEndDrawing();
2073+
return true;
2074+
}
2075+
}
2076+
return false;
2077+
}
2078+
20552079
QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation, bool pExpand)
20562080
{
20572081
if (mBackgroundObject)
@@ -3122,3 +3146,49 @@ void UBGraphicsScene::initStroke()
31223146
{
31233147
mCurrentStroke = new UBGraphicsStroke(shared_from_this());
31243148
}
3149+
3150+
void UBGraphicsScene::MultiTouchDrawing(QTouchEvent* event, UBStylusTool::Enum currentTool)
3151+
{
3152+
QList <QTouchEvent::TouchPoint> touchPoints = event->touchPoints();
3153+
foreach (QTouchEvent::TouchPoint point, touchPoints)
3154+
{
3155+
lastPoint_m = point.lastPos();
3156+
endPoint_m = point.pos();
3157+
3158+
int distance = sqrt(pow((lastPoint_m.x() - endPoint_m.x()),2) + pow((lastPoint_m.y() - endPoint_m.y()),2)) + 1;
3159+
distance = sqrt(distance);
3160+
if (distance > 6)
3161+
distance = 6;
3162+
else if(distance < 4)
3163+
distance = 4;
3164+
3165+
UBBoardView* boardView = controlView();
3166+
QLineF line;
3167+
line.setP1(boardView->mapToScene(UBGeometryUtils::pointConstrainedInRect(lastPoint_m.toPoint(), boardView->rect())));
3168+
line.setP2(boardView->mapToScene(UBGeometryUtils::pointConstrainedInRect(endPoint_m.toPoint(), boardView->rect())));
3169+
if (!multiDrawLines.contains(line)) // to eliminate duplicates
3170+
{
3171+
multiDrawLines.append(line);
3172+
3173+
qreal penWidth = 0;
3174+
if (currentTool == UBStylusTool::Pen)
3175+
penWidth = UBSettings::settings()->currentPenWidth();
3176+
else if (currentTool == UBStylusTool::Marker)
3177+
penWidth = UBSettings::settings()->currentMarkerWidth();
3178+
penWidth /= UBApplication::boardController->systemScaleFactor();
3179+
penWidth /= UBApplication::boardController->currentZoom();
3180+
3181+
UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(line, penWidth, penWidth);
3182+
addPolygonItemToCurrentStroke(polygonItem);
3183+
}
3184+
3185+
lastPoint_m = endPoint_m;
3186+
}
3187+
}
3188+
3189+
void UBGraphicsScene::MultiTouchEndDrawing()
3190+
{
3191+
inputDeviceRelease();
3192+
multiDrawLines.clear();
3193+
controlView()->releaseAllInputDevices();
3194+
}

src/domain/UBGraphicsScene.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem, public std::en
350350

351351
QRectF annotationsBoundingRect() const;
352352

353+
bool eventFilter(QObject *watched, QEvent *event) override;
354+
353355
public slots:
354356
void updateSelectionFrame();
355357
void updateSelectionFrameWrapper(int);
@@ -415,6 +417,8 @@ public slots:
415417
void hideMarkerCircle();
416418
void hidePenCircle();
417419
void DisposeMagnifierQWidgets();
420+
void MultiTouchDrawing(QTouchEvent* event, UBStylusTool::Enum currentTool);
421+
void MultiTouchEndDrawing();
418422

419423

420424
virtual void keyReleaseEvent(QKeyEvent * keyEvent);
@@ -500,6 +504,9 @@ public slots:
500504
UBSelectionFrame *mSelectionFrame;
501505

502506
UBGraphicsCache* mGraphicsCache;
507+
508+
QPointF lastPoint_m, endPoint_m;
509+
QList<QLineF> multiDrawLines;
503510
};
504511

505512

0 commit comments

Comments
 (0)