This class descends from `QGraphicsRectItem` and serves the following functions: Provides easy access to the on-screen geometry of a markup annotation. Handles tasks such as cursor changes on mouse hover and link activation on mouse clicks. Displays note popups if necessary
| 2353 | // |
| 2354 | // * Displays note popups if necessary |
| 2355 | PDFMarkupAnnotationGraphicsItem::PDFMarkupAnnotationGraphicsItem(QSharedPointer<Annotation::Markup> annot, QGraphicsItem *parent /* = nullptr */): |
| 2356 | Super(parent), |
| 2357 | _annot(annot), |
| 2358 | _activated(false), |
| 2359 | _popup(nullptr) |
| 2360 | { |
| 2361 | // The area is expressed in "normalized page coordinates", i.e. values |
| 2362 | // in the range [0, 1]. The transformation matrix of this item will have to |
| 2363 | // be adjusted so that links will show up correctly in a graphics view. |
| 2364 | setRect(_annot->rect()); |
| 2365 | |
| 2366 | // Allows annotations to provide a context-specific cursor when the mouse is |
| 2367 | // hovering over them. |
| 2368 | // |
| 2369 | // **NOTE:** _Requires Qt 4.4 or newer._ |
| 2370 | setAcceptHoverEvents(true); |
| 2371 | |
| 2372 | // Only left-clicks will trigger the popup (if any). |
| 2373 | setAcceptedMouseButtons(annot->popup() ? Qt::LeftButton : Qt::NoButton); |
| 2374 | |
| 2375 | #ifdef DEBUG |
| 2376 | // **TODO:** |
| 2377 | // _Currently for debugging purposes only so that the annotation area can be |
| 2378 | // determined visually, but might make a nice option._ |
| 2379 | setPen(QPen(Qt::blue)); |
| 2380 | #else |
| 2381 | // Perhaps there is a way to not draw the outline at all? Might be more |
| 2382 | // efficient... |
| 2383 | setPen(QPen(Qt::transparent)); |
| 2384 | #endif |
| 2385 | |
| 2386 | QString tooltip(annot->richContents()); |
| 2387 | // If the text is not already split into paragraphs, we do that here to ensure |
| 2388 | // proper line folding in the tooltip and hence to avoid very wide tooltips. |
| 2389 | if (tooltip.indexOf(QString::fromLatin1("<p>")) < 0) |
| 2390 | tooltip = QString::fromLatin1("<p>%1</p>").arg(tooltip.replace(QChar::fromLatin1('\n'), QString::fromLatin1("</p>\n<p>"))); |
| 2391 | setToolTip(tooltip); |
| 2392 | } |
| 2393 | |
| 2394 | int PDFMarkupAnnotationGraphicsItem::type() const { return Type; } |
| 2395 |
nothing calls this directly
no test coverage detected