pageview.h 11.8 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>                  *
Albert Astals Cid's avatar
Albert Astals Cid committed
3
 *   Copyright (C) 2004 by Albert Astals Cid <aacid@kde.org>               *
4
5
6
 *   Copyright (C) 2017    Klarälvdalens Datakonsult AB, a KDAB Group      *
 *                         company, info@kdab.com. Work sponsored by the   *
 *                         LiMux project of the city of Munich             *
7
 *                                                                         *
8
 *   With portions of code from kpdf/kpdf_pagewidget.h by:                 *
9
10
11
12
13
14
 *     Copyright (C) 2002 by Wilco Greven <greven@kde.org>                 *
 *     Copyright (C) 2003 by Christophe Devriese                           *
 *                           <Christophe.Devriese@student.kuleuven.ac.be>  *
 *     Copyright (C) 2003 by Laurent Montel <montel@kde.org>               *
 *     Copyright (C) 2003 by Kurt Pfeifle <kpfeifle@danka.de>              *
 *                                                                         *
15
16
17
18
19
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
20
// This file follows coding style described in kdebase/kicker/HACKING
21

22
23
#ifndef _OKULAR_PAGEVIEW_H_
#define _OKULAR_PAGEVIEW_H_
24

25
#include <qabstractscrollarea.h>
26
#include <qlist.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
27
#include <qvector.h>
28
#include "ui/pageviewutils.h"
29
#include "core/area.h"
30
#include "core/observer.h"
31
#include "core/view.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
32

33
class KActionCollection;
34

35
namespace Okular {
36
class Action;
37
class Document;
38
class DocumentViewport;
39
class FormFieldSignature;
Christian Ehrlicher's avatar
Christian Ehrlicher committed
40
class Annotation;
41
class MovieAction;
42
class RenditionAction;
43
44
45
}

class PageViewPrivate;
Laurent Montel's avatar
Laurent Montel committed
46

Michal Humpula's avatar
Michal Humpula committed
47

48
49
class QGestureEvent;

50
/**
51
 * @short The main view. Handles zoom and continuous mode.. oh, and page
52
 * @short display of course :-)
53
 * ...
54
 */
55
class PageView : public QAbstractScrollArea, public Okular::DocumentObserver, public Okular::View
56
{
57
58
Q_OBJECT

59
    public:
60
        PageView( QWidget *parent, Okular::Document *document );
61
        ~PageView() override;
62

Nate Graham's avatar
Nate Graham committed
63
        // Zoom mode ( last 4 are internally used only! )
Thomas Fischer's avatar
Thomas Fischer committed
64
        enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitAuto = 3,
Nate Graham's avatar
Nate Graham committed
65
                        ZoomIn, ZoomOut, ZoomRefreshCurrent, ZoomActual };
66

67
68
        enum ClearMode { ClearAllSelection, ClearOnlyDividers };

69
        // create actions that interact with this widget
70
71
72
73
        void setupBaseActions( KActionCollection * ac );
        void setupViewerActions( KActionCollection * ac );
        void setupActions( KActionCollection * ac );
        void updateActionState( bool docHasPages, bool documentChanged, bool docHasFormWidgets );
74

75
        // misc methods (from RMB menu/children)
Pino Toscano's avatar
Pino Toscano committed
76
        bool canFitPageWidth() const;
77
        void fitPageWidth( int page );
78
        // keep in sync with pageviewutils
79
        void displayMessage( const QString & message, const QString & details = QString(), PageViewMessage::Icon icon=PageViewMessage::Info, int duration=-1 );
80

81
        // inherited from DocumentObserver
82
83
84
85
86
87
88
        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;
89

90
        // inherited from View
91
92
93
94
        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;
95

96
        QList< Okular::RegularAreaRect * > textSelections( const QPoint& start, const QPoint& end, int& firstpage );
97
        Okular::RegularAreaRect * textSelectionForItem( const PageViewItem * item, const QPoint & startPoint = QPoint(), const QPoint & endPoint = QPoint() );
98

99
100
        void reparseConfig();

101
        KActionCollection *actionCollection() const;
Vishesh Handa's avatar
Vishesh Handa committed
102
        QAction *toggleFormsAction() const;
103

104
105
106
107
        int contentAreaWidth() const;
        int contentAreaHeight() const;
        QPoint contentAreaPosition() const;
        QPoint contentAreaPoint( const QPoint & pos ) const;
Albert Astals Cid's avatar
Albert Astals Cid committed
108
        QPointF contentAreaPoint( const QPointF & pos ) const;
109

110
111
112
        bool areSourceLocationsShownGraphically() const;
        void setShowSourceLocationsGraphically(bool show);

113
        void setLastSourceLocationViewport( const Okular::DocumentViewport& vp );
114
        void clearLastSourceLocationViewport();
115
116
117

        void updateCursor();

118
119
        void highlightSignatureFormWidget( const Okular::FormFieldSignature *form );

120
    public Q_SLOTS:
121
        void copyTextSelection() const;
122
        void selectAll();
123

124
        void openAnnotationWindow( Okular::Annotation *annotation, int pageNumber );
125
        void reloadForms();
126

127
128
129
        void slotToggleChangeColors();
        void slotSetChangeColors(bool active);

130
131
        void slotSelectPage();

132
133
134
        void slotAction( Okular::Action *action );
        void slotFormChanged( int pageNumber );

135
    Q_SIGNALS:
136
        void rightClick( const Okular::Page *, const QPoint & );
137
138
        void mouseBackButtonClick();
        void mouseForwardButtonClick();
139
        void escPressed();
140
        void fitWindowToPage( const QSize& pageViewPortSize, const QSize& pageSize );
141
        void triggerSearch( const QString& text );
142
143

    protected:
144
        bool event( QEvent * event ) override;
145

146
        void resizeEvent( QResizeEvent* ) override;
147
        bool gestureEvent( QGestureEvent * e );
148
149

        // mouse / keyboard events
150
151
152
153
        void keyPressEvent( QKeyEvent* ) override;
        void keyReleaseEvent( QKeyEvent* ) override;
        void inputMethodEvent( QInputMethodEvent * ) override;
        void wheelEvent( QWheelEvent* ) override;
154

155
156
157
158
159
160
        void paintEvent( QPaintEvent *e ) override;
        void tabletEvent (QTabletEvent *e ) override;
        void mouseMoveEvent( QMouseEvent *e ) override;
        void mousePressEvent( QMouseEvent *e ) override;
        void mouseReleaseEvent( QMouseEvent *e ) override;
        void mouseDoubleClickEvent( QMouseEvent *e ) override;
161

162
        bool viewportEvent( QEvent *e ) override;
163

164
        void scrollContentsBy( int dx, int dy ) override;
165

166
    private:
Enrico Ros's avatar
Enrico Ros committed
167
        // draw background and items on the opened qpainter
168
        void drawDocumentOnPainter( const QRect & contentsRect, QPainter * p );
169
        // update item width and height using current zoom parameters
170
        void updateItemSize( PageViewItem * item, int colWidth, int rowHeight );
171
172
        // return the widget placed on a certain point or 0 if clicking on empty space
        PageViewItem * pickItemOnPoint( int x, int y );
173
        // start / modify / clear selection rectangle
174
        void selectionStart( const QPoint & pos, const QColor & color, bool aboveAll = false );
175
        void selectionClear( const ClearMode mode = ClearAllSelection );
Jiri Baum's avatar
Jiri Baum committed
176
        void drawTableDividers(QPainter * screenPainter);
177
        void guessTableDividers();
178
179
        // update either text or rectangle selection
        void updateSelection( const QPoint & pos );
Tingnan Zhang's avatar
Tingnan Zhang committed
180
181
        // compute the zoom factor value for FitWidth and FitPage mode
        double zoomFactorFitMode( ZoomMode mode );
182
        // update internal zoom values and end in a slotRelayoutPages();
183
        void updateZoom( ZoomMode newZoomMode );
184
185
        // update the text on the label using global zoom value or current page's one
        void updateZoomText();
Felix Mauch's avatar
Felix Mauch committed
186
187
        // update view mode (single, facing...)
        void updateViewMode ( const int nr );
188
        void textSelectionClear();
189
190
        // updates cursor
        void updateCursor( const QPoint &p );
Albert Astals Cid's avatar
Albert Astals Cid committed
191

Michal Humpula's avatar
Michal Humpula committed
192
193
194
        void moveMagnifier( const QPoint &p );
        void updateMagnifier( const QPoint &p );

Pino Toscano's avatar
const    
Pino Toscano committed
195
        int viewColumns() const;
196

197
198
        void center(int cx, int cy, bool smoothMove = false);
        void scrollTo( int x, int y, bool smoothMove = false);
199

200
201
        void toggleFormWidgets( bool on );

202
        void resizeContentArea( const QSize & newSize );
203
        void updatePageStep();
204

205
        void addSearchWithinDocumentAction(QMenu * menu, const QString & searchText );
Vishesh Handa's avatar
Vishesh Handa committed
206
        void addWebShortcutsMenu( QMenu * menu, const QString & text );
207
        QMenu* createProcessLinkMenu( PageViewItem *item, const QPoint & eventPos );
208
209
        // used when selecting stuff, makes the view scroll as necessary to keep the mouse inside the view
        void scrollPosIntoView( const QPoint & pos );
210
        QPoint viewportToContentArea( const Okular::DocumentViewport & vp ) const;
211

Jake Linder's avatar
Jake Linder committed
212
213
214
        // called from slots to turn off trim modes mutually exclusive to id
        void updateTrimMode( int except_id );

215
216
217
        // handle link clicked
        bool mouseReleaseOverLink( const Okular::ObjectRect * rect ) const;

218
219
        void createAnnotationsVideoWidgets(PageViewItem *item, const QLinkedList< Okular::Annotation * > &annotations);

220
221
222
        // don't want to expose classes in here
        class PageViewPrivate * d;

223
    private Q_SLOTS:
224
225
        // used to decouple the notifyViewportChanged calle
        void slotRealNotifyViewportChanged(bool smoothMove);
226
        // activated either directly or via queued connection on notifySetup
227
        void slotRelayoutPages();
228
229
        // activated by the resize event delay timer
        void delayedResizeEvent();
230
        // activated either directly or via the contentsMoving(int,int) signal
231
        void slotRequestVisiblePixmaps( int newValue = -1 );
232
        // activated by the autoscroll timer (Shift+Up/Down keys)
233
        void slotAutoScroll();
234
235
236
        // activated by the dragScroll timer
        void slotDragScroll();
        // show the welcome message
237
        void slotShowWelcome();
238
239
        // activated by left click timer
        void slotShowSizeAllCursor();
240

241
242
243
        void slotHandleWebShortcutAction();
        void slotConfigureWebShortcuts();

Enrico Ros's avatar
Enrico Ros committed
244
        // connected to local actions (toolbar, menu, ..)
245
246
247
        void slotZoom();
        void slotZoomIn();
        void slotZoomOut();
Nate Graham's avatar
Nate Graham committed
248
        void slotZoomActual();
249
250
        void slotFitToWidthToggled( bool );
        void slotFitToPageToggled( bool );
Thomas Fischer's avatar
Thomas Fischer committed
251
        void slotAutoFitToggled( bool );
252
        void slotViewMode( QAction *action );
253
        void slotContinuousToggled( bool );
254
        void slotSetMouseNormal();
255
        void slotSetMouseZoom();
Michal Humpula's avatar
Michal Humpula committed
256
        void slotSetMouseMagnifier();
257
        void slotSetMouseSelect();
258
        void slotSetMouseTextSelect();
Jiri Baum's avatar
Jiri Baum committed
259
        void slotSetMouseTableSelect();
260
        void slotToggleAnnotator( bool );
261
262
        void slotAutoScrollUp();
        void slotAutoScrollDown();
263
264
        void slotScrollUp( int nSteps = 0 );
        void slotScrollDown(int nSteps = 0 );
265
266
267
        void slotRotateClockwise();
        void slotRotateCounterClockwise();
        void slotRotateOriginal();
268
        void slotPageSizes( int );
269
        void slotTrimMarginsToggled( bool );
Jake Linder's avatar
Jake Linder committed
270
        void slotTrimToSelectionToggled( bool );
271
        void slotToggleForms();
272
        void slotRefreshPage();
273
#ifdef HAVE_SPEECH
274
275
        void slotSpeakDocument();
        void slotSpeakCurrentPage();
276
        void slotStopSpeaks();
277
        void slotPauseResumeSpeech();
278
#endif
279
        void externalKeyPressEvent( QKeyEvent *e );
280
        void slotAnnotationWindowDestroyed( QObject *window );
281
        void slotProcessMovieAction( const Okular::MovieAction *action );
282
        void slotProcessRenditionAction( const Okular::RenditionAction *action );
283
        void slotFitWindowToPage();
284
};
285

286
#endif
Albert Astals Cid's avatar
Albert Astals Cid committed
287
288

/* kate: replace-tabs on; indent-width 4; */