1 /***************************************************************************
2 * Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
3 * Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
5 * With portions of code from kpdf/kpdf_pagewidget.h by: *
6 * Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
7 * Copyright (C) 2003 by Christophe Devriese *
8 * <Christophe.Devriese@student.kuleuven.ac.be> *
9 * Copyright (C) 2003 by Laurent Montel <montel@kde.org> *
10 * Copyright (C) 2003 by Kurt Pfeifle <kpfeifle@danka.de> *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 ***************************************************************************/
17 // This file follows coding style described in kdebase/kicker/HACKING
19 #ifndef _OKULAR_PAGEVIEW_H_
20 #define _OKULAR_PAGEVIEW_H_
22 #include <qscrollarea.h>
25 #include "ui/pageviewutils.h"
26 #include "core/area.h"
27 #include "core/observer.h"
28 #include "core/view.h"
31 class KActionCollection
;
40 class FormWidgetIface
;
41 class PageViewPrivate
;
45 * @short The main view. Handles zoom and continuous mode.. oh, and page
46 * @short display of course :-)
49 class PageView
: public QScrollArea
, public Okular::DocumentObserver
, public Okular::View
53 friend class PageViewWidget
;
56 PageView( QWidget
*parent
, Okular::Document
*document
);
59 // Zoom mode ( last 4 are internally used only! )
60 enum ZoomMode
{ ZoomFixed
= 0, ZoomFitWidth
= 1, ZoomFitPage
= 2, ZoomFitText
,
61 ZoomIn
, ZoomOut
, ZoomRefreshCurrent
};
62 enum MouseMode
{ MouseNormal
, MouseZoom
, MouseSelect
, MouseImageSelect
, MouseTextSelect
};
64 // create actions that interact with this widget
65 void setupBaseActions( KActionCollection
* collection
);
66 void setupActions( KActionCollection
* collection
);
68 // misc methods (from RMB menu/children)
69 bool canFitPageWidth() const;
70 void fitPageWidth( int page
);
71 // keep in sync with pageviewutils
72 void displayMessage( const QString
& message
, PageViewMessage::Icon icon
=PageViewMessage::Info
, int duration
=-1 );
74 // inherited from DocumentObserver
75 uint
observerId() const { return PAGEVIEW_ID
; }
76 void notifySetup( const QVector
< Okular::Page
* > & pages
, int setupFlags
);
77 void notifyViewportChanged( bool smoothMove
);
78 void notifyPageChanged( int pageNumber
, int changedFlags
);
79 void notifyContentsCleared( int changedFlags
);
80 void notifyZoom(int factor
);
81 bool canUnloadPixmap( int pageNum
) const;
83 // inherited from View
84 uint
viewId() const { return observerId(); }
85 bool supportsCapability( ViewCapability capability
) const;
86 CapabilityFlags
capabilityFlags( ViewCapability capability
) const;
87 QVariant
capability( ViewCapability capability
) const;
88 void setCapability( ViewCapability capability
, const QVariant
&option
);
90 QList
< Okular::RegularAreaRect
* > textSelections( const QPoint
& start
, const QPoint
& end
, int& firstpage
);
91 Okular::RegularAreaRect
* textSelectionForItem( PageViewItem
* item
, const QPoint
& startPoint
= QPoint(), const QPoint
& endPoint
= QPoint() );
95 KAction
*toggleFormsAction() const;
98 void errorMessage( const QString
& message
, int duration
= -1 )
100 displayMessage( message
, PageViewMessage::Error
, duration
);
103 void noticeMessage( const QString
& message
, int duration
= -1 )
105 displayMessage( message
, PageViewMessage::Info
, duration
);
108 void warningMessage( const QString
& message
, int duration
= -1 )
110 displayMessage( message
, PageViewMessage::Warning
, duration
);
113 void copyTextSelection() const;
116 void setAnnotationWindow( Okular::Annotation
*annotation
);
118 void removeAnnotationWindow( Okular::Annotation
*annotation
);
121 void urlDropped( const KUrl
& );
122 void rightClick( const Okular::Page
*, const QPoint
& );
125 void resizeEvent( QResizeEvent
* );
127 // mouse / keyboard events
128 void keyPressEvent( QKeyEvent
* );
129 void keyReleaseEvent( QKeyEvent
* );
130 void inputMethodEvent( QInputMethodEvent
* );
131 void wheelEvent( QWheelEvent
* );
133 // drag and drop related events
134 void dragEnterEvent( QDragEnterEvent
* );
135 void dragMoveEvent( QDragMoveEvent
* );
136 void dropEvent( QDropEvent
* );
139 void contentsPaintEvent( QPaintEvent
*e
);
140 void contentsMouseMoveEvent( QMouseEvent
*e
);
141 void contentsMousePressEvent( QMouseEvent
*e
);
142 void contentsMouseReleaseEvent( QMouseEvent
*e
);
144 // draw background and items on the opened qpainter
145 void drawDocumentOnPainter( const QRect
& pageViewRect
, QPainter
* p
);
146 // update item width and height using current zoom parameters
147 void updateItemSize( PageViewItem
* item
, int columnWidth
, int rowHeight
);
148 // return the widget placed on a certain point or 0 if clicking on empty space
149 PageViewItem
* pickItemOnPoint( int x
, int y
);
150 // start / modify / clear selection rectangle
151 void selectionStart( const QPoint
& pos
, const QColor
& color
, bool aboveAll
= false );
152 void selectionEndPoint( const QPoint
& pos
);
153 void selectionClear();
154 // update internal zoom values and end in a slotRelayoutPages();
155 void updateZoom( ZoomMode newZm
);
156 // update the text on the label using global zoom value or current page's one
157 void updateZoomText();
158 void textSelectionClear();
160 void updateCursor( const QPoint
&p
);
162 int viewColumns() const;
163 int viewRows() const;
165 void center(int cx
, int cy
);
167 void toggleFormWidgets( bool on
);
169 // don't want to expose classes in here
170 class PageViewPrivate
* d
;
173 // activated either directly or via QTimer on the viewportResizeEvent
174 void slotRelayoutPages();
175 // activated either directly or via the contentsMoving(int,int) signal
176 void slotRequestVisiblePixmaps( int newValue
= -1 );
177 // activated by the viewport move timer
178 void slotMoveViewport();
179 // activated by the autoscroll timer (Shift+Up/Down keys)
180 void slotAutoScoll();
181 // activated by the dragScroll timer
182 void slotDragScroll();
183 // show the welcome message
184 void slotShowWelcome();
186 // connected to local actions (toolbar, menu, ..)
190 void slotFitToWidthToggled( bool );
191 void slotFitToPageToggled( bool );
192 void slotFitToTextToggled( bool );
193 void slotViewMode( int );
194 void slotContinuousToggled( bool );
195 void slotSetMouseNormal();
196 void slotSetMouseZoom();
197 void slotSetMouseSelect();
198 void slotSetMouseTextSelect();
199 void slotToggleAnnotator( bool );
201 void slotScrollDown();
202 void slotRotateClockwise();
203 void slotRotateCounterClockwise();
204 void slotRotateOriginal();
205 void slotPageSizes( int );
206 void slotTrimMarginsToggled( bool );
207 void slotToggleForms();
208 void slotFormWidgetChanged( FormWidgetIface
*w
);
209 void slotRefreshPage();
210 void slotSpeakDocument();
211 void slotSpeakCurrentPage();
212 void slotStopSpeaks();
213 void slotAction( Okular::Action
*action
);