MCPcopy Create free account
hub / github.com/KDE/okular / routeMouseDrawingEvent

Method routeMouseDrawingEvent

part/presentationwidget.cpp:1337–1412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1335}
1336
1337QRect PresentationWidget::routeMouseDrawingEvent(QMouseEvent *e)
1338{
1339 if (m_frameIndex == -1) { // Can't draw on the summary page
1340 return QRect();
1341 }
1342
1343 const QRect &geom = m_frames[m_frameIndex]->geometry;
1344 const Okular::Page *page = m_frames[m_frameIndex]->page;
1345
1346 AnnotatorEngine::EventType eventType;
1347 AnnotatorEngine::Button button;
1348 AnnotatorEngine::Modifiers modifiers;
1349
1350 // figure out the event type and button
1351 AnnotatorEngine::decodeEvent(e, &eventType, &button);
1352
1353 static bool hasclicked = false;
1354 if (eventType == AnnotatorEngine::Press) {
1355 hasclicked = true;
1356 }
1357
1358 QPointF mousePos = e->position();
1359 double nX = (mousePos.x() - (double)geom.left()) / (double)geom.width();
1360 double nY = (mousePos.y() - (double)geom.top()) / (double)geom.height();
1361 QRect ret;
1362 bool isInside = nX >= 0 && nX < 1 && nY >= 0 && nY < 1;
1363
1364 if (hasclicked && !isInside) {
1365 // Fake a move to the last border pos
1366 nX = qBound(0., nX, 1.);
1367 nY = qBound(0., nY, 1.);
1368 m_drawingEngine->event(AnnotatorEngine::Move, button, modifiers, nX, nY, geom.width(), geom.height(), page);
1369
1370 // Fake a release in the following lines
1371 eventType = AnnotatorEngine::Release;
1372 isInside = true;
1373 } else if (!hasclicked && isInside) {
1374 // we're coming from the outside, pretend we started clicking at the closest border
1375 if (nX < (1 - nX) && nX < nY && nX < (1 - nY)) {
1376 nX = 0;
1377 } else if (nY < (1 - nY) && nY < nX && nY < (1 - nX)) {
1378 nY = 0;
1379 } else if ((1 - nX) < nX && (1 - nX) < nY && (1 - nX) < (1 - nY)) {
1380 nX = 1;
1381 } else {
1382 nY = 1;
1383 }
1384
1385 hasclicked = true;
1386 eventType = AnnotatorEngine::Press;
1387 }
1388
1389 if (hasclicked && isInside) {
1390 ret = m_drawingEngine->event(eventType, button, modifiers, nX, nY, geom.width(), geom.height(), page);
1391 }
1392
1393 if (eventType == AnnotatorEngine::Release) {
1394 hasclicked = false;

Callers

nothing calls this directly

Calls 6

creationCompletedMethod · 0.80
endSmoothPathMethod · 0.80
QRectClass · 0.50
widthMethod · 0.45
heightMethod · 0.45
eventMethod · 0.45

Tested by

no test coverage detected