File indexing completed on 2024-05-19 12:17:56
0001 /* 0002 SPDX-FileCopyrightText: 2004 Enrico Ros <eros.kde@email.it> 0003 SPDX-FileCopyrightText: 2004 Albert Astals Cid <aacid@kde.org> 0004 0005 Work sponsored by the LiMux project of the city of Munich: 0006 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com> 0007 0008 With portions of code from kpdf/kpdf_pagewidget.h by: 0009 SPDX-FileCopyrightText: 2002 Wilco Greven <greven@kde.org> 0010 SPDX-FileCopyrightText: 2003 Christophe Devriese <Christophe.Devriese@student.kuleuven.ac.be> 0011 SPDX-FileCopyrightText: 2003 Laurent Montel <montel@kde.org> 0012 SPDX-FileCopyrightText: 2003 Kurt Pfeifle <kpfeifle@danka.de> 0013 0014 SPDX-License-Identifier: GPL-2.0-or-later 0015 */ 0016 // This file follows coding style described in kdebase/kicker/HACKING 0017 0018 #ifndef _OKULAR_PAGEVIEW_H_ 0019 #define _OKULAR_PAGEVIEW_H_ 0020 0021 #include "config-okular.h" 0022 #include "core/area.h" 0023 #include "core/observer.h" 0024 #include "core/view.h" 0025 #include "pageviewutils.h" 0026 #include <QAbstractScrollArea> 0027 #include <QList> 0028 #include <QVector> 0029 0030 class QMenu; 0031 class QMimeData; 0032 class KActionCollection; 0033 0034 namespace Okular 0035 { 0036 class Action; 0037 class Document; 0038 class DocumentViewport; 0039 class FormField; 0040 class FormFieldSignature; 0041 class Annotation; 0042 class MovieAction; 0043 class RenditionAction; 0044 } 0045 0046 class PageViewPrivate; 0047 0048 class QGestureEvent; 0049 0050 /** 0051 * @short The main view. Handles zoom and continuous mode.. oh, and page 0052 * @short display of course :-) 0053 * ... 0054 */ 0055 class PageView : public QAbstractScrollArea, public Okular::DocumentObserver, public Okular::View 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 PageView(QWidget *parent, Okular::Document *document); 0061 ~PageView() override; 0062 0063 // Zoom mode ( last 4 are internally used only! ) 0064 enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitAuto = 3, ZoomIn, ZoomOut, ZoomRefreshCurrent, ZoomActual }; 0065 0066 enum ClearMode { ClearAllSelection, ClearOnlyDividers }; 0067 0068 // create actions that interact with this widget 0069 void setupBaseActions(KActionCollection *ac); 0070 void setupViewerActions(KActionCollection *ac); 0071 void setupActions(KActionCollection *ac); 0072 void setupActionsPostGUIActivated(); 0073 void updateActionState(bool docHasPages, bool docHasFormWidgets); 0074 0075 // misc methods (from RMB menu/children) 0076 bool canFitPageWidth() const; 0077 void fitPageWidth(int page); 0078 // keep in sync with pageviewutils 0079 void displayMessage(const QString &message, const QString &details = QString(), PageViewMessage::Icon icon = PageViewMessage::Info, int duration = -1); 0080 0081 // inherited from DocumentObserver 0082 void notifySetup(const QVector<Okular::Page *> &pages, int setupFlags) override; 0083 void notifyViewportChanged(bool smoothMove) override; 0084 void notifyPageChanged(int pageNumber, int changedFlags) override; 0085 void notifyContentsCleared(int changedFlags) override; 0086 void notifyZoom(int factor) override; 0087 bool canUnloadPixmap(int pageNum) const override; 0088 void notifyCurrentPageChanged(int previous, int current) override; 0089 0090 // inherited from View 0091 bool supportsCapability(ViewCapability capability) const override; 0092 CapabilityFlags capabilityFlags(ViewCapability capability) const override; 0093 QVariant capability(ViewCapability capability) const override; 0094 void setCapability(ViewCapability capability, const QVariant &option) override; 0095 0096 QList<Okular::RegularAreaRect *> textSelections(const QPoint start, const QPoint end, int &firstpage); 0097 Okular::RegularAreaRect *textSelectionForItem(const PageViewItem *item, const QPoint startPoint = QPoint(), const QPoint endPoint = QPoint()); 0098 0099 void reparseConfig(); 0100 0101 KActionCollection *actionCollection() const; 0102 QAction *toggleFormsAction() const; 0103 0104 int contentAreaWidth() const; 0105 int contentAreaHeight() const; 0106 QPoint contentAreaPosition() const; 0107 QPoint contentAreaPoint(const QPoint pos) const; 0108 QPointF contentAreaPoint(const QPointF pos) const; 0109 0110 bool areSourceLocationsShownGraphically() const; 0111 void setShowSourceLocationsGraphically(bool show); 0112 0113 void setLastSourceLocationViewport(const Okular::DocumentViewport &vp); 0114 void clearLastSourceLocationViewport(); 0115 0116 void updateCursor(); 0117 0118 void highlightSignatureFormWidget(const Okular::FormFieldSignature *form); 0119 0120 void showNoSigningCertificatesDialog(bool nonDateValidCerts); 0121 0122 Okular::Document *document() const; 0123 0124 public Q_SLOTS: 0125 void copyTextSelection() const; 0126 void selectAll(); 0127 0128 void openAnnotationWindow(Okular::Annotation *annotation, int pageNumber); 0129 void reloadForms(); 0130 0131 void slotSelectPage(); 0132 0133 void slotAction(Okular::Action *action); 0134 void slotMouseUpAction(Okular::Action *action, Okular::FormField *form); 0135 void slotFormChanged(int pageNumber); 0136 0137 void externalKeyPressEvent(QKeyEvent *e); 0138 0139 Q_SIGNALS: 0140 void rightClick(const Okular::Page *, const QPoint); 0141 void mouseBackButtonClick(); 0142 void mouseForwardButtonClick(); 0143 void escPressed(); 0144 void fitWindowToPage(const QSize pageViewPortSize, const QSize pageSize); 0145 void triggerSearch(const QString &text); 0146 void requestOpenFile(const QString &filePath, int pageNumber); 0147 0148 protected: 0149 bool event(QEvent *event) override; 0150 0151 void resizeEvent(QResizeEvent *) override; 0152 bool gestureEvent(QGestureEvent *e); 0153 0154 // mouse / keyboard events 0155 void keyPressEvent(QKeyEvent *) override; 0156 void keyReleaseEvent(QKeyEvent *) override; 0157 void inputMethodEvent(QInputMethodEvent *) override; 0158 void wheelEvent(QWheelEvent *) override; 0159 0160 void paintEvent(QPaintEvent *e) override; 0161 void tabletEvent(QTabletEvent *e) override; 0162 void continuousZoom(double delta); 0163 void continuousZoomEnd(); 0164 void mouseMoveEvent(QMouseEvent *e) override; 0165 void mousePressEvent(QMouseEvent *e) override; 0166 void mouseReleaseEvent(QMouseEvent *e) override; 0167 void mouseDoubleClickEvent(QMouseEvent *e) override; 0168 0169 bool viewportEvent(QEvent *e) override; 0170 0171 void scrollContentsBy(int dx, int dy) override; 0172 0173 private: 0174 // draw background and items on the opened qpainter 0175 void drawDocumentOnPainter(const QRect contentsRect, QPainter *p); 0176 // update item width and height using current zoom parameters 0177 void updateItemSize(PageViewItem *item, int colWidth, int rowHeight); 0178 // return the widget placed on a certain point or 0 if clicking on empty space 0179 PageViewItem *pickItemOnPoint(int x, int y); 0180 // start / modify / clear selection rectangle 0181 void selectionStart(const QPoint pos, const QColor &color, bool aboveAll = false); 0182 void selectionClear(const ClearMode mode = ClearAllSelection); 0183 QMimeData *getTableContents() const; 0184 void drawTableDividers(QPainter *screenPainter); 0185 void guessTableDividers(); 0186 // update either text or rectangle selection 0187 void updateSelection(const QPoint pos); 0188 // compute the zoom factor value for FitWidth and FitPage mode 0189 double zoomFactorFitMode(ZoomMode mode); 0190 // update internal zoom values and end in a slotRelayoutPages(); 0191 void updateZoom(ZoomMode newZoomMode); 0192 // update the text on the label using global zoom value or current page's one 0193 void updateZoomText(); 0194 // update the text enabled status of the zoom actions 0195 void updateZoomActionsEnabledStatus(); 0196 // update view mode (single, facing...) 0197 void updateViewMode(const int nr); 0198 void textSelectionClear(); 0199 // updates cursor 0200 void updateCursor(const QPoint p); 0201 0202 void moveMagnifier(const QPoint p); 0203 void updateMagnifier(const QPoint p); 0204 0205 int viewColumns() const; 0206 0207 void center(int cx, int cy, bool smoothMove = false); 0208 void scrollTo(int x, int y, bool smoothMove = false); 0209 0210 void toggleFormWidgets(bool on); 0211 0212 void resizeContentArea(const QSize newSize); 0213 void updatePageStep(); 0214 0215 void addSearchWithinDocumentAction(QMenu *menu, const QString &searchText); 0216 void addWebShortcutsMenu(QMenu *menu, const QString &text); 0217 QMenu *createProcessLinkMenu(PageViewItem *item, const QPoint eventPos); 0218 // used when selecting stuff, makes the view scroll as necessary to keep the mouse inside the view 0219 void scrollPosIntoView(const QPoint pos); 0220 QPoint viewportToContentArea(const Okular::DocumentViewport &vp) const; 0221 0222 // called from slots to turn off trim modes mutually exclusive to id 0223 void updateTrimMode(int except_id); 0224 0225 // handle link clicked 0226 bool mouseReleaseOverLink(const Okular::ObjectRect *rect) const; 0227 0228 void createAnnotationsVideoWidgets(PageViewItem *item, const QList<Okular::Annotation *> &annotations); 0229 0230 // Update speed of animated smooth scroll transitions 0231 void updateSmoothScrollAnimationSpeed(); 0232 0233 /* 0234 * returns the continuous mode value of the current document, by either: 0235 * - if the continuous mode action is initialized, then we return its associated value 0236 * - if not, then we will fallback to the default settings 0237 */ 0238 bool getContinuousMode() const; 0239 0240 // Zoom around the point given as zoomCenter 0241 // zoomCenter is given in viewport coordinates 0242 // newZoom is the intended new zoom level. A value of 0.0 means: Don't change the current zoom level. 0243 // The zoomMode is set to newZoomMode. 0244 void zoomWithFixedCenter(ZoomMode newZoomMode, QPointF zoomCenter, float newZoom = 0.0); 0245 0246 // don't want to expose classes in here 0247 class PageViewPrivate *d; 0248 0249 private Q_SLOTS: 0250 // used to decouple the notifyViewportChanged calle 0251 void slotRealNotifyViewportChanged(bool smoothMove); 0252 // activated either directly or via queued connection on notifySetup 0253 void slotRelayoutPages(); 0254 // activated by the resize event delay timer 0255 void delayedResizeEvent(); 0256 // activated either directly or via the contentsMoving(int,int) signal 0257 void slotRequestVisiblePixmaps(int newValue = -1); 0258 // activated by the autoscroll timer (Shift+Up/Down keys) 0259 void slotAutoScroll(); 0260 // activated by the dragScroll timer 0261 void slotDragScroll(); 0262 // show the welcome message 0263 void slotShowWelcome(); 0264 // activated by left click timer 0265 void slotShowSizeAllCursor(); 0266 0267 void slotHandleWebShortcutAction(); 0268 void slotConfigureWebShortcuts(); 0269 0270 // connected to local actions (toolbar, menu, ..) 0271 void slotZoom(); 0272 void slotZoomIn(); 0273 void slotZoomOut(); 0274 void slotZoomActual(); 0275 void slotFitToWidthToggled(bool); 0276 void slotFitToPageToggled(bool); 0277 void slotAutoFitToggled(bool); 0278 void slotViewMode(QAction *action); 0279 void slotContinuousToggled(); 0280 void slotReadingDirectionToggled(bool leftToRight); 0281 void slotUpdateReadingDirectionAction(); 0282 void slotSetMouseNormal(); 0283 void slotSetMouseZoom(); 0284 void slotSetMouseMagnifier(); 0285 void slotSetMouseSelect(); 0286 void slotSetMouseTextSelect(); 0287 void slotSetMouseTableSelect(); 0288 void slotSignature(); 0289 void slotAutoScrollUp(); 0290 void slotAutoScrollDown(); 0291 void slotScrollUp(int nSteps = 0); 0292 void slotScrollDown(int nSteps = 0); 0293 void slotRotateClockwise(); 0294 void slotRotateCounterClockwise(); 0295 void slotRotateOriginal(); 0296 void slotTrimMarginsToggled(bool); 0297 void slotTrimToSelectionToggled(bool); 0298 void slotToggleForms(); 0299 void slotRefreshPage(); 0300 #if HAVE_SPEECH 0301 void slotSpeakDocument(); 0302 void slotSpeakCurrentPage(); 0303 void slotStopSpeaks(); 0304 void slotPauseResumeSpeech(); 0305 #endif 0306 void slotAnnotationWindowDestroyed(QObject *window); 0307 void slotProcessMovieAction(const Okular::MovieAction *action); 0308 void slotProcessRenditionAction(const Okular::RenditionAction *action); 0309 void slotFitWindowToPage(); 0310 }; 0311 0312 #endif 0313 0314 /* kate: replace-tabs on; indent-width 4; */