pageview.h 9.1 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>                  *
3
4
 *   Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es>            *
 *                                                                         *
5
 *   With portions of code from kpdf/kpdf_pagewidget.h by:                 *
6
7
8
9
10
11
 *     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>              *
 *                                                                         *
12
13
14
15
16
 *   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.                                   *
 ***************************************************************************/
17
// This file follows coding style described in kdebase/kicker/HACKING
18

19
20
#ifndef _OKULAR_PAGEVIEW_H_
#define _OKULAR_PAGEVIEW_H_
21

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

30
class KAction;
31
class KActionCollection;
32
class KMenu;
33
class KUrl;
34

35
namespace Okular {
36
class Action;
37
class Document;
Christian Ehrlicher's avatar
Christian Ehrlicher committed
38
class Annotation;
39
class FormField;
40
41
}

42
class FormWidgetIface;
43
class PageViewPrivate;
Laurent Montel's avatar
Laurent Montel committed
44

45
/**
46
 * @short The main view. Handles zoom and continuous mode.. oh, and page
47
 * @short display of course :-)
48
 * ...
49
 */
50
class PageView : public QAbstractScrollArea, public Okular::DocumentObserver, public Okular::View
51
{
52
53
Q_OBJECT

54
    public:
55
        PageView( QWidget *parent, Okular::Document *document );
56
57
58
        ~PageView();

        // Zoom mode ( last 4 are internally used only! )
59
        enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitText,
60
                        ZoomIn, ZoomOut, ZoomRefreshCurrent };
61
        enum MouseMode { MouseNormal, MouseZoom, MouseSelect, MouseImageSelect, MouseTextSelect };
62
63

        // create actions that interact with this widget
64
        void setupBaseActions( KActionCollection * collection );
65
66
        void setupActions( KActionCollection * collection );

67
        // misc methods (from RMB menu/children)
Pino Toscano's avatar
Pino Toscano committed
68
        bool canFitPageWidth() const;
69
        void fitPageWidth( int page );
70
        // keep in sync with pageviewutils
71
        void displayMessage( const QString & message, const QString & details = QString(), PageViewMessage::Icon icon=PageViewMessage::Info, int duration=-1 );
72

73
        // inherited from DocumentObserver
74
        uint observerId() const { return PAGEVIEW_ID; }
75
        void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
Enrico Ros's avatar
Enrico Ros committed
76
        void notifyViewportChanged( bool smoothMove );
77
78
        void notifyPageChanged( int pageNumber, int changedFlags );
        void notifyContentsCleared( int changedFlags );
79
        void notifyZoom(int factor);
80
        bool canUnloadPixmap( int pageNum ) const;
81

82
        // inherited from View
Pino Toscano's avatar
Pino Toscano committed
83
        uint viewId() const { return observerId(); }
84
85
86
87
88
        bool supportsCapability( ViewCapability capability ) const;
        CapabilityFlags capabilityFlags( ViewCapability capability ) const;
        QVariant capability( ViewCapability capability ) const;
        void setCapability( ViewCapability capability, const QVariant &option );

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

92
93
        void reparseConfig();

94
95
        KAction *toggleFormsAction() const;

96
97
98
99
100
        int contentAreaWidth() const;
        int contentAreaHeight() const;
        QPoint contentAreaPosition() const;
        QPoint contentAreaPoint( const QPoint & pos ) const;

101
    public slots:
102
        void errorMessage( const QString & message, int duration = -1 )
103
        {
104
            displayMessage( message, QString(), PageViewMessage::Error, duration );
105
106
        }

107
        void noticeMessage( const QString & message, int duration = -1 )
108
        {
109
            displayMessage( message, QString(), PageViewMessage::Info, duration );
110
111
        }

112
        void warningMessage( const QString & message, int duration = -1 )
113
        {
114
            displayMessage( message, QString(), PageViewMessage::Warning, duration );
115
116
        }

117
        void copyTextSelection() const;
118
        void selectAll();
119

120
121
122
123
        void setAnnotationWindow( Okular::Annotation *annotation );

        void removeAnnotationWindow( Okular::Annotation *annotation );

124
    signals:
125
        void urlDropped( const KUrl& );
126
        void rightClick( const Okular::Page *, const QPoint & );
127
128

    protected:
129
        void resizeEvent( QResizeEvent* );
130
131
132

        // mouse / keyboard events
        void keyPressEvent( QKeyEvent* );
133
        void keyReleaseEvent( QKeyEvent* );
Albert Astals Cid's avatar
Albert Astals Cid committed
134
        void inputMethodEvent( QInputMethodEvent * );
135
136
137
138
        void wheelEvent( QWheelEvent* );

        // drag and drop related events
        void dragEnterEvent( QDragEnterEvent* );
139
        void dragMoveEvent( QDragMoveEvent* );
140
141
        void dropEvent( QDropEvent* );

142
143
144
145
        void paintEvent( QPaintEvent *e );
        void mouseMoveEvent( QMouseEvent *e );
        void mousePressEvent( QMouseEvent *e );
        void mouseReleaseEvent( QMouseEvent *e );
146
        void mouseDoubleClickEvent( QMouseEvent *e );
147

148
149
        bool viewportEvent( QEvent *e );

150
151
        void scrollContentsBy( int dx, int dy );

152
    private:
Enrico Ros's avatar
Enrico Ros committed
153
154
        // draw background and items on the opened qpainter
        void drawDocumentOnPainter( const QRect & pageViewRect, QPainter * p );
155
156
157
158
        // update item width and height using current zoom parameters
        void updateItemSize( PageViewItem * item, int columnWidth, int rowHeight );
        // return the widget placed on a certain point or 0 if clicking on empty space
        PageViewItem * pickItemOnPoint( int x, int y );
159
        // start / modify / clear selection rectangle
160
161
        void selectionStart( const QPoint & pos, const QColor & color, bool aboveAll = false );
        void selectionEndPoint( const QPoint & pos );
162
        void selectionClear();
163
164
165
166
        // update internal zoom values and end in a slotRelayoutPages();
        void updateZoom( ZoomMode newZm );
        // update the text on the label using global zoom value or current page's one
        void updateZoomText();
167
        void textSelectionClear();
168
169
        // updates cursor
        void updateCursor( const QPoint &p );
Albert Astals Cid's avatar
Albert Astals Cid committed
170

Pino Toscano's avatar
const    
Pino Toscano committed
171
        int viewColumns() const;
172
173

        void center(int cx, int cy);
174

175
176
        void toggleFormWidgets( bool on );

177
178
        void resizeContentArea( const QSize & newSize );

179
180
        void addWebShortcutsMenu( KMenu * menu, const QString & text );

181
182
183
184
        // don't want to expose classes in here
        class PageViewPrivate * d;

    private slots:
185
        // activated either directly or via queued connection on notifySetup
186
        void slotRelayoutPages();
187
188
        // activated by the resize event delay timer
        void delayedResizeEvent();
189
        // activated either directly or via the contentsMoving(int,int) signal
190
        void slotRequestVisiblePixmaps( int newValue = -1 );
Enrico Ros's avatar
Enrico Ros committed
191
192
        // activated by the viewport move timer
        void slotMoveViewport();
193
194
        // activated by the autoscroll timer (Shift+Up/Down keys)
        void slotAutoScoll();
195
196
197
        // activated by the dragScroll timer
        void slotDragScroll();
        // show the welcome message
198
        void slotShowWelcome();
199
200
        // activated by left click timer
        void slotShowSizeAllCursor();
201

202
203
204
        void slotHandleWebShortcutAction();
        void slotConfigureWebShortcuts();

Enrico Ros's avatar
Enrico Ros committed
205
        // connected to local actions (toolbar, menu, ..)
206
207
208
209
210
211
        void slotZoom();
        void slotZoomIn();
        void slotZoomOut();
        void slotFitToWidthToggled( bool );
        void slotFitToPageToggled( bool );
        void slotFitToTextToggled( bool );
212
        void slotViewMode( QAction *action );
213
        void slotContinuousToggled( bool );
214
        void slotSetMouseNormal();
215
        void slotSetMouseZoom();
216
        void slotSetMouseSelect();
217
        void slotSetMouseTextSelect();
218
        void slotToggleAnnotator( bool );
219
220
        void slotScrollUp();
        void slotScrollDown();
221
222
223
        void slotRotateClockwise();
        void slotRotateCounterClockwise();
        void slotRotateOriginal();
224
        void slotPageSizes( int );
225
        void slotTrimMarginsToggled( bool );
226
        void slotToggleForms();
227
        void slotFormWidgetChanged( FormWidgetIface *w );
228
        void slotRefreshPage();
229
230
        void slotSpeakDocument();
        void slotSpeakCurrentPage();
231
        void slotStopSpeaks();
232
        void slotAction( Okular::Action *action );
233
        void slotFormFieldChanged( Okular::FormField *formField );
234
        void externalKeyPressEvent( QKeyEvent *e );
235
};
236

237
#endif