| 1077 | } |
| 1078 | |
| 1079 | QRect PageViewAnnotator::performRouteMouseOrTabletEvent(const AnnotatorEngine::EventType eventType, const AnnotatorEngine::Button button, const AnnotatorEngine::Modifiers modifiers, const QPointF pos, PageViewItem *item) |
| 1080 | { |
| 1081 | // creationCompleted is intended to be set by event(), handled subsequently by end(), and cleared within end(). |
| 1082 | // If it's set here, we recursed for some reason (e.g., stacked event loop). |
| 1083 | // Just bail out, all we want to do is already on stack. |
| 1084 | if (m_engine && m_engine->creationCompleted()) { |
| 1085 | return QRect(); |
| 1086 | } |
| 1087 | |
| 1088 | // if the right mouse button was pressed, we simply do nothing. In this way, we are still editing the annotation |
| 1089 | // and so this function will receive and process the right mouse button release event too. If we detach now the annotation tool, |
| 1090 | // the release event will be processed by the PageView class which would create the annotation property widget, and we do not want this. |
| 1091 | if (button == AnnotatorEngine::Right && eventType == AnnotatorEngine::Press) { |
| 1092 | return QRect(); |
| 1093 | } else if (button == AnnotatorEngine::Right && eventType == AnnotatorEngine::Release) { |
| 1094 | detachAnnotation(); |
| 1095 | return QRect(); |
| 1096 | } |
| 1097 | |
| 1098 | // 1. lock engine to current item |
| 1099 | if (!m_lockedItem && eventType == AnnotatorEngine::Press) { |
| 1100 | m_lockedItem = item; |
| 1101 | m_engine->setItem(m_lockedItem); |
| 1102 | } |
| 1103 | if (!m_lockedItem) { |
| 1104 | return QRect(); |
| 1105 | } |
| 1106 | |
| 1107 | // find out normalized mouse coords inside current item |
| 1108 | const QRect &itemRect = m_lockedItem->uncroppedGeometry(); |
| 1109 | const QPointF eventPos = m_pageView->contentAreaPoint(pos); |
| 1110 | const double nX = qBound(0.0, m_lockedItem->absToPageX(eventPos.x()), 1.0); |
| 1111 | const double nY = qBound(0.0, m_lockedItem->absToPageY(eventPos.y()), 1.0); |
| 1112 | |
| 1113 | QRect modifiedRect; |
| 1114 | |
| 1115 | // 2. use engine to perform operations |
| 1116 | const QRect paintRect = m_engine->event(eventType, button, modifiers, nX, nY, itemRect.width(), itemRect.height(), m_lockedItem->page()); |
| 1117 | |
| 1118 | // 3. update absolute extents rect and send paint event(s) |
| 1119 | if (paintRect.isValid()) { |
| 1120 | // 3.1. unite old and new painting regions |
| 1121 | QRegion compoundRegion(m_lastDrawnRect); |
| 1122 | m_lastDrawnRect = paintRect; |
| 1123 | m_lastDrawnRect.translate(itemRect.left(), itemRect.top()); |
| 1124 | // 3.2. decompose paint region in rects and send paint events |
| 1125 | const QRegion rgn = compoundRegion.united(m_lastDrawnRect); |
| 1126 | const QPoint areaPos = m_pageView->contentAreaPosition(); |
| 1127 | for (const QRect &r : rgn) { |
| 1128 | m_pageView->viewport()->update(r.translated(-areaPos)); |
| 1129 | } |
| 1130 | modifiedRect = compoundRegion.boundingRect() | m_lastDrawnRect; |
| 1131 | } |
| 1132 | |
| 1133 | // 4. if engine has finished, apply Annotation to the page |
| 1134 | if (m_engine->creationCompleted()) { |
| 1135 | // apply engine data to the Annotation's and reset engine |
| 1136 | const QList<Okular::Annotation *> annotations = m_engine->end(); |
nothing calls this directly
no test coverage detected