Skip to content
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

support multi-touch #963

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

ThomasLucky13
Copy link
Contributor

Add to OpenBoard multi touch drawing. It allows several people to draw at once on Board mode with tools Pen and Marker.

Add to OpenBoard multi touch drawing. It allows several people to draw at once with tool Pen and Marker.
@temaps
Copy link

temaps commented May 15, 2024

#860

@mikhailnov
Copy link

@ThomasLucky13 has been working very hard on this for quite a long time, and the resulting code looks tine and beautiful ;)

Copy link
Contributor

@Vekhir Vekhir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, I believe that multi-touch is a useful feature to have.
I'm not that familiar with Qt's multitouch support, so I have some general remarks which you might use as an opportunity to expand on your design choices.

Comment on lines 3158 to 3163
int distance = sqrt(pow((lastPoint_m.x() - endPoint_m.x()),2) + pow((lastPoint_m.y() - endPoint_m.y()),2)) + 1;
distance = sqrt(distance);
if (distance > 6)
distance = 6;
else if(distance < 4)
distance = 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is distance used for? It's defined here but never used.

Comment on lines +3155 to +3156
lastPoint_m = point.lastPos();
endPoint_m = point.pos();
Copy link
Contributor

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 not have lastPoint_m and endPoint_m as local variables if they are reassigned every time?

addPolygonItemToCurrentStroke(polygonItem);
}

lastPoint_m = endPoint_m;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have any effect? It's overwritten later, see above.

Comment on lines +3169 to +3171
if (!multiDrawLines.contains(line)) // to eliminate duplicates
{
multiDrawLines.append(line);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of performance, QList::contains has linear runtime in the number of lines contained, especially if the line isn't in the list. Are duplicates a serious issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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 QSet instead of QList. QSet requires a bit more memory, but look-up is really fast.
Can you test it with QSet and report back whether it makes an appreciable difference in performance? Otherwise I'd just leave it as is.

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

if(multiDrawLines.isEmpty()) // is it not polygons drawing by multiDraw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braces and indentation to better indicate the scope.

@ThomasLucky13
Copy link
Contributor Author

Thanks for your contribution, I believe that multi-touch is a useful feature to have. I'm not that familiar with Qt's multitouch support, so I have some general remarks which you might use as an opportunity to expand on your design choices.

Thank you for code review. I was careless in some places and corrected them.

clear code after code review by Vekhir
src/board/UBBoardView.cpp Outdated Show resolved Hide resolved
@@ -2052,6 +2055,27 @@ bool UBGraphicsScene::isEmpty() const
return mItemCount == 0;
}

bool UBGraphicsScene::eventFilter(QObject *watched, QEvent *event)
Copy link
Collaborator

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 eventFilter in the scene instead of overriding event() 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.

src/domain/UBGraphicsScene.h Outdated Show resolved Hide resolved
{
QList <QTouchEvent::TouchPoint> touchPoints = event->touchPoints();
QPointF lastPoint_m, endPoint_m;
foreach (QTouchEvent::TouchPoint point, touchPoints)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qt6 recommends to prefer the C++ range based for over the foreach keyword. See https://doc.qt.io/qt-6/foreach-keyword.html. It is also recommended to use a const reference in a case like this to avoid copying the point.

1. Remove 'if' construct from releaseAllInputDevices() in UBBoardView;
2. Rename MultiTouchDrawing to multiTouchDrawing and MultiTouchEndDrawing to multiTouchEndDrawing;
3. Make point const in multiTouchDrawing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants