This class descends from `QGraphicsView` and is responsible for controlling and displaying the contents of a `Document` using a `QGraphicsScene`.
| 56 | // This class descends from `QGraphicsView` and is responsible for controlling |
| 57 | // and displaying the contents of a `Document` using a `QGraphicsScene`. |
| 58 | PDFDocumentView::PDFDocumentView(QWidget *parent /* = nullptr */): |
| 59 | Super(parent) |
| 60 | { |
| 61 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 62 | qRegisterMetaType<QtPDF::PDFSearcher::size_type>("QtPDF::PDFSearcher::size_type"); |
| 63 | #endif |
| 64 | initResources(); |
| 65 | setBackgroundRole(QPalette::Dark); |
| 66 | setAlignment(Qt::AlignCenter); |
| 67 | setFocusPolicy(Qt::StrongFocus); |
| 68 | |
| 69 | QColor fillColor(Qt::darkYellow); |
| 70 | fillColor.setAlphaF(0.3f); |
| 71 | _searchResultHighlightBrush = QBrush(fillColor); |
| 72 | |
| 73 | fillColor = QColor(Qt::yellow); |
| 74 | fillColor.setAlphaF(0.6f); |
| 75 | _currentSearchResultHighlightBrush = QBrush(fillColor); |
| 76 | |
| 77 | // If _currentPage is not set to -1, the compiler may default to 0. In that |
| 78 | // case, `goFirst()` or `goToPage(0)` will fail because the view will think |
| 79 | // it is already looking at page 0. |
| 80 | _currentPage = -1; |
| 81 | |
| 82 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::ZoomIn(this))); |
| 83 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::ZoomOut(this))); |
| 84 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::MagnifyingGlass(this))); |
| 85 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::MarqueeZoom(this))); |
| 86 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::Move(this))); |
| 87 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::ContextClick(this))); |
| 88 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::Measure(this))); |
| 89 | registerTool(std::unique_ptr<DocumentTool::AbstractTool>(new DocumentTool::Select(this))); |
| 90 | |
| 91 | // Some tools (e.g., the Select tool) may need to be informed of mouse events |
| 92 | // (e.g., mouseMoveEvent) when armed, even before a mouse button is pressed |
| 93 | viewport()->setMouseTracking(true); |
| 94 | |
| 95 | // We deliberately set the mouse mode to a different value above so we can |
| 96 | // call setMouseMode (which bails out if the mouse mode is not changed), which |
| 97 | // in turn sets up other variables such as _toolAccessors |
| 98 | setMouseMode(MouseMode_MagnifyingGlass); |
| 99 | |
| 100 | connect(&_searcher, &PDFSearcher::resultReady, this, &PDFDocumentView::searchResultReady); |
| 101 | connect(&_searcher, &PDFSearcher::progressValueChanged, this, &PDFDocumentView::searchProgressValueChanged); |
| 102 | |
| 103 | showRuler(false); |
| 104 | connect(&_ruler, &PDFRuler::dragStart, this, [this](QPoint pos, Qt::Edge origin) { |
| 105 | const Qt::Orientation orientation = [](Qt::Edge origin) { |
| 106 | switch (origin) { |
| 107 | case Qt::TopEdge: |
| 108 | case Qt::BottomEdge: |
| 109 | return Qt::Horizontal; |
| 110 | case Qt::LeftEdge: |
| 111 | case Qt::RightEdge: |
| 112 | return Qt::Vertical; |
| 113 | } |
| 114 | return Qt::Horizontal; |
| 115 | }(origin); |
nothing calls this directly
no test coverage detected