okular/part/pageview.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

307 lines
11 KiB
C
Raw Normal View History

2021-05-24 07:25:56 +00:00
/*
SPDX-FileCopyrightText: 2004 Enrico Ros <eros.kde@email.it>
SPDX-FileCopyrightText: 2004 Albert Astals Cid <aacid@kde.org>
Work sponsored by the LiMux project of the city of Munich:
SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com>
2021-05-24 07:25:56 +00:00
With portions of code from kpdf/kpdf_pagewidget.h by:
SPDX-FileCopyrightText: 2002 Wilco Greven <greven@kde.org>
SPDX-FileCopyrightText: 2003 Christophe Devriese <Christophe.Devriese@student.kuleuven.ac.be>
2021-05-24 07:25:56 +00:00
SPDX-FileCopyrightText: 2003 Laurent Montel <montel@kde.org>
SPDX-FileCopyrightText: 2003 Kurt Pfeifle <kpfeifle@danka.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
// This file follows coding style described in kdebase/kicker/HACKING
#ifndef _OKULAR_PAGEVIEW_H_
#define _OKULAR_PAGEVIEW_H_
2023-05-12 13:45:24 +00:00
#include "config-okular.h"
#include "core/area.h"
#include "core/observer.h"
#include "core/view.h"
#include "pageviewutils.h"
2020-07-08 11:54:37 +00:00
#include <QAbstractScrollArea>
#include <QList>
#include <QVector>
Overhaul annotations UX Create a new new annotation toolbar to replace the current one as discussed in the task T8076. Fixes: BUG: 386578 BUG: 374728 BUG: 352310 BUG: 330518 BUG: 341914 BUG: 157289 BUG: 358057 BUG: 412767 BUG: 413595 BUG: 420462 FIXED-IN: 1.11.0 Test Plan Before testing this revision Delete or Temporary move aside the following files: ~/.config/okularpartrc ~/.config/okularrc ~/.local/share/kxmlgui5/okular/part.rc ~/.local/share/kxmlgui5/okular/shell.rc Nomenclature Actions in the main toolbar: Quick annotations Actions in the annotation toolbar: Annotation actions Highlighter, Underline, Squiggle, Strike out, Typewriter, Inline note, Popup note, Freehand line, Arrow, Straight line, Rectangle, Ellipse, Polygon, Stamp Annotation config actions Line width, Color, Inner color, Opacity, Font, Annotation settings Other actions Add to Quick Annotations, Pin Autotests First run: annotation toolbar is not visible Selecting Tools > Annotations shows the annotation toolbar (below the main toolbar by default) Select an annotation > toolbar is shown Select a quick annotation > toolbar is shown Hide action (red cross) on the toolbar hides the toolbar Keys 1-9,0 select the (builtin) Annotation actions (one case tested) Keys Alt+1-9,0 select the quick annotation actions (one case tested) No annotation action selected: Quick Annotations is enabled, Add to quick annotations is disabled, Annotation config actions are disabled, Pin is enabled The current document is an image: Highlighter, Underline, Squiggle, Strike out are disabled (also in Quick annotations) The current document is protected: All actions are disabled Select annotation: the Annotation config actions are enabled and their values set to the ones for the current annotation (taken from okularpartrc) Click an annotation action when none selected: browse mode is selected Click the currently selected annotation action: the action is unchecked and the tool disabled (back to browse mode) Click ESC: the currently selected annotation action is unchecked If Pin unchecked the selected annotation is unchecked after it has be used once and we are back to Browse mode The annotation systems works when multiple Okular tabs are open (the selected annotation is per-tab) Manual tests (TODO) Check that kconf_update updates the key AnnotationTools to QuickAnnotationTools in ~/.config/okularpartrc Color icon is a format-text-color (if inline note or typewriter) or format-stroke-color for all other annotations All actions have tooltips (some change based on the fact that the icon is enabled or not) If a custom Line Width or Opacity is set through the Annotation Settings dialog, its value appears as a new checked action in the Line width or Opacity menu If a custom stamp is selected through the Annotation Settings dialog, its name or filename (without path) appears as a new checked action in the Stamp menu In Configure Okular > Annotations it is only possible to configure the quick annotations. Modifying them here updates the Quick annotations list after clicking Apply The current document is an image: Highlighter, Underline, Squiggle, Strike out are disabled in Quick annotations The state of Pin action is remembered across Okular launches Selecting a quick action selects the corresponding action and loads its config values (color, line width, ...) Setting the color and fill color works for all annotations (to be tested carefully, can be problematic for typewriter and inline note given the different internal mechanism to store the color in the settings) Test stamp annotation (handled differently from the rest of the annotations) Merge Request: https://invent.kde.org/graphics/okular/-/merge_requests/105
2020-06-04 13:01:31 +00:00
class QMenu;
class QMimeData;
class KActionCollection;
namespace Okular
{
class Action;
class Document;
class DocumentViewport;
class FormFieldSignature;
class Annotation;
class MovieAction;
class RenditionAction;
}
class PageViewPrivate;
class QGestureEvent;
/**
* @short The main view. Handles zoom and continuous mode.. oh, and page
* @short display of course :-)
* ...
*/
class PageView : public QAbstractScrollArea, public Okular::DocumentObserver, public Okular::View
{
Q_OBJECT
public:
PageView(QWidget *parent, Okular::Document *document);
~PageView() override;
// Zoom mode ( last 4 are internally used only! )
enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitAuto = 3, ZoomIn, ZoomOut, ZoomRefreshCurrent, ZoomActual };
enum ClearMode { ClearAllSelection, ClearOnlyDividers };
// create actions that interact with this widget
void setupBaseActions(KActionCollection *ac);
void setupViewerActions(KActionCollection *ac);
void setupActions(KActionCollection *ac);
Overhaul annotations UX Create a new new annotation toolbar to replace the current one as discussed in the task T8076. Fixes: BUG: 386578 BUG: 374728 BUG: 352310 BUG: 330518 BUG: 341914 BUG: 157289 BUG: 358057 BUG: 412767 BUG: 413595 BUG: 420462 FIXED-IN: 1.11.0 Test Plan Before testing this revision Delete or Temporary move aside the following files: ~/.config/okularpartrc ~/.config/okularrc ~/.local/share/kxmlgui5/okular/part.rc ~/.local/share/kxmlgui5/okular/shell.rc Nomenclature Actions in the main toolbar: Quick annotations Actions in the annotation toolbar: Annotation actions Highlighter, Underline, Squiggle, Strike out, Typewriter, Inline note, Popup note, Freehand line, Arrow, Straight line, Rectangle, Ellipse, Polygon, Stamp Annotation config actions Line width, Color, Inner color, Opacity, Font, Annotation settings Other actions Add to Quick Annotations, Pin Autotests First run: annotation toolbar is not visible Selecting Tools > Annotations shows the annotation toolbar (below the main toolbar by default) Select an annotation > toolbar is shown Select a quick annotation > toolbar is shown Hide action (red cross) on the toolbar hides the toolbar Keys 1-9,0 select the (builtin) Annotation actions (one case tested) Keys Alt+1-9,0 select the quick annotation actions (one case tested) No annotation action selected: Quick Annotations is enabled, Add to quick annotations is disabled, Annotation config actions are disabled, Pin is enabled The current document is an image: Highlighter, Underline, Squiggle, Strike out are disabled (also in Quick annotations) The current document is protected: All actions are disabled Select annotation: the Annotation config actions are enabled and their values set to the ones for the current annotation (taken from okularpartrc) Click an annotation action when none selected: browse mode is selected Click the currently selected annotation action: the action is unchecked and the tool disabled (back to browse mode) Click ESC: the currently selected annotation action is unchecked If Pin unchecked the selected annotation is unchecked after it has be used once and we are back to Browse mode The annotation systems works when multiple Okular tabs are open (the selected annotation is per-tab) Manual tests (TODO) Check that kconf_update updates the key AnnotationTools to QuickAnnotationTools in ~/.config/okularpartrc Color icon is a format-text-color (if inline note or typewriter) or format-stroke-color for all other annotations All actions have tooltips (some change based on the fact that the icon is enabled or not) If a custom Line Width or Opacity is set through the Annotation Settings dialog, its value appears as a new checked action in the Line width or Opacity menu If a custom stamp is selected through the Annotation Settings dialog, its name or filename (without path) appears as a new checked action in the Stamp menu In Configure Okular > Annotations it is only possible to configure the quick annotations. Modifying them here updates the Quick annotations list after clicking Apply The current document is an image: Highlighter, Underline, Squiggle, Strike out are disabled in Quick annotations The state of Pin action is remembered across Okular launches Selecting a quick action selects the corresponding action and loads its config values (color, line width, ...) Setting the color and fill color works for all annotations (to be tested carefully, can be problematic for typewriter and inline note given the different internal mechanism to store the color in the settings) Test stamp annotation (handled differently from the rest of the annotations) Merge Request: https://invent.kde.org/graphics/okular/-/merge_requests/105
2020-06-04 13:01:31 +00:00
void setupActionsPostGUIActivated();
void updateActionState(bool docHasPages, bool docHasFormWidgets);
// misc methods (from RMB menu/children)
bool canFitPageWidth() const;
void fitPageWidth(int page);
- Page/Link: tooltips for links backported - Page: rotation does not switch height and width - Document/Part/Generator: 1. Add API for attaching stuff to the interface: ActionCollection and the Navigation Panel also add possibility to merge an XML .rc file with menu layout. Relevant functions are: QString Generator::getXMLFile(), returns a QString with your .rc file name. void Generator::setupGUI (KActionCollection* , QToolbox* ), add your components to the user interface 2. Supporting backend settings: If during startup, backends which provide a configuration ([X-KDE-oKularHasInternalSettings] set to true) are found, a menu item: configure backends is created, clicking on it results in loading all the generators that have settings, but not those that dont. the Generator::addPages(KConfigDialog *dlg) function should be overloaded by a generator and dlg->addPage should be used to add pages. If a user opens a file that needs an already loaded generator, the already loaded one is used instead of loading another. 3. Error/Warning/Notice sending support, to send a notice/error/warning, add a relevant notice/error/warning(QString& txt ,int duration) to the generator class, and sending a message to the user is as simple as emitting a signal! 4. Intercepting of events generated by the PageView is done by Generator::handleEvent(QEvent*), subclass it, do a switch on QEvent::type(), handle your event and return true if pageview is to proceed with its handling or false if not. 5. Support configuring the KPrinter on the generator side, use Generator::canConfigurePrinter(), return true there, and you get a nonconfigured KPrinter in your Generator::print() 6. PixmapRequest handling update: a.) Generator::canGeneratePixmap is now Generator::canGeneratePixmap(bool async) b.) Document::sendGeneratorRequests is a slot now c.) Old way of sending pixmaps (Document::requestPixmaps(QValueList<PixmapRequest*> checking if we can generate pixmap if not, waiting for receiving) is replaced with: requestPixmaps only queues the pixmap all checking if w can generate is done in sendGeneratorReqest, the sendGeneratorRequest is run in three places: 1. in requestPixmaps when we receive a request 2. in requestDone if pixmapStack is not empty 3. sendGeneratorRequest, apart from removing invalid requests, takes the current request and if generator canGeratePixmap(request->async) it removes the pixmap from stack and sends to generator if not, QTimer::singleshots to itself after 20ms, it ends when stack has no valid pixmap request 7. Added a commented out zoom field to PixmapGenerator, mightcome in handy sometime - TextPage: add instructions that handle simplyfing the RegularAreaRect, no more double painted borders in selection rectangles, this rocks. svn path=/trunk/playground/graphics/oKular/kpdf/; revision=445196
2005-08-10 16:14:39 +00:00
// keep in sync with pageviewutils
void displayMessage(const QString &message, const QString &details = QString(), PageViewMessage::Icon icon = PageViewMessage::Info, int duration = -1);
// inherited from DocumentObserver
2017-03-02 19:39:24 +00:00
void notifySetup(const QVector<Okular::Page *> &pages, int setupFlags) override;
void notifyViewportChanged(bool smoothMove) override;
void notifyPageChanged(int pageNumber, int changedFlags) override;
void notifyContentsCleared(int changedFlags) override;
void notifyZoom(int factor) override;
bool canUnloadPixmap(int pageNum) const override;
void notifyCurrentPageChanged(int previous, int current) override;
// inherited from View
2017-03-02 19:39:24 +00:00
bool supportsCapability(ViewCapability capability) const override;
CapabilityFlags capabilityFlags(ViewCapability capability) const override;
QVariant capability(ViewCapability capability) const override;
void setCapability(ViewCapability capability, const QVariant &option) override;
2020-02-20 17:45:46 +00:00
QList<Okular::RegularAreaRect *> textSelections(const QPoint start, const QPoint end, int &firstpage);
Okular::RegularAreaRect *textSelectionForItem(const PageViewItem *item, const QPoint startPoint = QPoint(), const QPoint endPoint = QPoint());
void reparseConfig();
KActionCollection *actionCollection() const;
2014-08-13 10:45:40 +00:00
QAction *toggleFormsAction() const;
int contentAreaWidth() const;
int contentAreaHeight() const;
QPoint contentAreaPosition() const;
2020-02-20 17:45:46 +00:00
QPoint contentAreaPoint(const QPoint pos) const;
QPointF contentAreaPoint(const QPointF pos) const;
bool areSourceLocationsShownGraphically() const;
void setShowSourceLocationsGraphically(bool show);
void setLastSourceLocationViewport(const Okular::DocumentViewport &vp);
void clearLastSourceLocationViewport();
void updateCursor();
void highlightSignatureFormWidget(const Okular::FormFieldSignature *form);
void showNoSigningCertificatesDialog(bool nonDateValidCerts);
Okular::Document *document() const;
public Q_SLOTS:
void copyTextSelection() const;
void selectAll();
void openAnnotationWindow(Okular::Annotation *annotation, int pageNumber);
void reloadForms();
void slotSelectPage();
void slotAction(Okular::Action *action);
void slotFormChanged(int pageNumber);
2020-02-20 14:48:08 +00:00
void externalKeyPressEvent(QKeyEvent *e);
Q_SIGNALS:
2020-02-20 17:45:46 +00:00
void rightClick(const Okular::Page *, const QPoint);
void mouseBackButtonClick();
void mouseForwardButtonClick();
void escPressed();
2020-02-20 17:45:46 +00:00
void fitWindowToPage(const QSize pageViewPortSize, const QSize pageSize);
void triggerSearch(const QString &text);
void requestOpenFile(const QString &filePath, int pageNumber);
protected:
2017-03-02 19:39:24 +00:00
bool event(QEvent *event) override;
2017-03-02 19:39:24 +00:00
void resizeEvent(QResizeEvent *) override;
bool gestureEvent(QGestureEvent *e);
// mouse / keyboard events
2017-03-02 19:39:24 +00:00
void keyPressEvent(QKeyEvent *) override;
void keyReleaseEvent(QKeyEvent *) override;
void inputMethodEvent(QInputMethodEvent *) override;
void wheelEvent(QWheelEvent *) override;
2017-03-02 19:39:24 +00:00
void paintEvent(QPaintEvent *e) override;
void tabletEvent(QTabletEvent *e) override;
2023-02-05 19:46:57 +00:00
void continuousZoom(double delta);
void continuousZoomEnd();
2017-03-02 19:39:24 +00:00
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
2017-03-02 19:39:24 +00:00
bool viewportEvent(QEvent *e) override;
2017-03-02 19:39:24 +00:00
void scrollContentsBy(int dx, int dy) override;
private:
// draw background and items on the opened qpainter
2020-02-20 17:45:46 +00:00
void drawDocumentOnPainter(const QRect contentsRect, QPainter *p);
// update item width and height using current zoom parameters
void updateItemSize(PageViewItem *item, int colWidth, int rowHeight);
// return the widget placed on a certain point or 0 if clicking on empty space
PageViewItem *pickItemOnPoint(int x, int y);
// start / modify / clear selection rectangle
2020-02-20 17:45:46 +00:00
void selectionStart(const QPoint pos, const QColor &color, bool aboveAll = false);
void selectionClear(const ClearMode mode = ClearAllSelection);
QMimeData *getTableContents() const;
void drawTableDividers(QPainter *screenPainter);
void guessTableDividers();
// update either text or rectangle selection
2020-02-20 17:45:46 +00:00
void updateSelection(const QPoint pos);
// compute the zoom factor value for FitWidth and FitPage mode
double zoomFactorFitMode(ZoomMode mode);
// update internal zoom values and end in a slotRelayoutPages();
void updateZoom(ZoomMode newZoomMode);
// update the text on the label using global zoom value or current page's one
void updateZoomText();
// update the text enabled status of the zoom actions
void updateZoomActionsEnabledStatus();
// update view mode (single, facing...)
void updateViewMode(const int nr);
void textSelectionClear();
// updates cursor
2020-02-20 17:45:46 +00:00
void updateCursor(const QPoint p);
2020-02-20 17:45:46 +00:00
void moveMagnifier(const QPoint p);
void updateMagnifier(const QPoint p);
int viewColumns() const;
void center(int cx, int cy, bool smoothMove = false);
void scrollTo(int x, int y, bool smoothMove = false);
void toggleFormWidgets(bool on);
2020-02-20 17:45:46 +00:00
void resizeContentArea(const QSize newSize);
void updatePageStep();
void addSearchWithinDocumentAction(QMenu *menu, const QString &searchText);
2014-08-13 10:45:40 +00:00
void addWebShortcutsMenu(QMenu *menu, const QString &text);
2020-02-20 17:45:46 +00:00
QMenu *createProcessLinkMenu(PageViewItem *item, const QPoint eventPos);
// used when selecting stuff, makes the view scroll as necessary to keep the mouse inside the view
2020-02-20 17:45:46 +00:00
void scrollPosIntoView(const QPoint pos);
2018-11-22 17:50:14 +00:00
QPoint viewportToContentArea(const Okular::DocumentViewport &vp) const;
// called from slots to turn off trim modes mutually exclusive to id
void updateTrimMode(int except_id);
// handle link clicked
bool mouseReleaseOverLink(const Okular::ObjectRect *rect) const;
void createAnnotationsVideoWidgets(PageViewItem *item, const QList<Okular::Annotation *> &annotations);
// Update speed of animated smooth scroll transitions
void updateSmoothScrollAnimationSpeed();
/*
* returns the continuous mode value of the current document, by either:
* - if the continuous mode action is initialized, then we return its associated value
* - if not, then we will fallback to the default settings
*/
bool getContinuousMode() const;
// don't want to expose classes in here
class PageViewPrivate *d;
private Q_SLOTS:
// used to decouple the notifyViewportChanged calle
void slotRealNotifyViewportChanged(bool smoothMove);
// activated either directly or via queued connection on notifySetup
void slotRelayoutPages();
// activated by the resize event delay timer
void delayedResizeEvent();
// activated either directly or via the contentsMoving(int,int) signal
void slotRequestVisiblePixmaps(int newValue = -1);
// activated by the autoscroll timer (Shift+Up/Down keys)
void slotAutoScroll();
// activated by the dragScroll timer
void slotDragScroll();
// show the welcome message
void slotShowWelcome();
// activated by left click timer
void slotShowSizeAllCursor();
void slotHandleWebShortcutAction();
void slotConfigureWebShortcuts();
// connected to local actions (toolbar, menu, ..)
void slotZoom();
void slotZoomIn();
void slotZoomOut();
void slotZoomActual();
void slotFitToWidthToggled(bool);
void slotFitToPageToggled(bool);
void slotAutoFitToggled(bool);
void slotViewMode(QAction *action);
void slotContinuousToggled();
void slotReadingDirectionToggled(bool leftToRight);
void slotUpdateReadingDirectionAction();
void slotSetMouseNormal();
void slotSetMouseZoom();
2014-02-24 22:42:10 +00:00
void slotSetMouseMagnifier();
void slotSetMouseSelect();
void slotSetMouseTextSelect();
void slotSetMouseTableSelect();
void slotSignature();
void slotAutoScrollUp();
void slotAutoScrollDown();
void slotScrollUp(int nSteps = 0);
void slotScrollDown(int nSteps = 0);
void slotRotateClockwise();
void slotRotateCounterClockwise();
void slotRotateOriginal();
void slotTrimMarginsToggled(bool);
void slotTrimToSelectionToggled(bool);
void slotToggleForms();
void slotRefreshPage();
2023-05-12 13:45:24 +00:00
#if HAVE_SPEECH
void slotSpeakDocument();
void slotSpeakCurrentPage();
void slotStopSpeaks();
void slotPauseResumeSpeech();
#endif
void slotAnnotationWindowDestroyed(QObject *window);
void slotProcessMovieAction(const Okular::MovieAction *action);
void slotProcessRenditionAction(const Okular::RenditionAction *action);
void slotFitWindowToPage();
};
#endif
2012-10-15 18:21:43 +00:00
/* kate: replace-tabs on; indent-width 4; */