add a small widget for showing an animation from the "animations" category of the...
[kdegraphics.git] / okular / ui / pageviewutils.h
blobd252562c4f9a18be4f6186253e98027a4d51f2b1
1 /***************************************************************************
2 * Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #ifndef _PAGEVIEW_UTILS_H_
11 #define _PAGEVIEW_UTILS_H_
13 #include <qwidget.h>
14 #include <qpixmap.h>
15 #include <qrect.h>
16 #include <qhash.h>
17 #include <qtoolbutton.h>
19 #include <KIcon>
21 #include "core/area.h"
23 class QAction;
24 class QLabel;
25 class QTimer;
26 class FormWidgetIface;
27 class VideoWidget;
29 namespace Okular {
30 class Movie;
31 class Page;
34 /**
35 * @short PageViewItem represents graphically a page into the PageView.
37 * It has methods for settings Item's geometry and other visual properties such
38 * as the individual zoom factor.
40 class PageViewItem
42 public:
43 PageViewItem( const Okular::Page * page );
44 ~PageViewItem();
46 const Okular::Page * page() const;
47 int pageNumber() const;
48 double zoomFactor() const;
49 bool isVisible() const;
50 QHash<int, FormWidgetIface*>& formWidgets();
51 QHash< Okular::Movie *, VideoWidget * >& videoWidgets();
53 /* The page is cropped as follows: */
54 const Okular::NormalizedRect & crop() const;
56 /* Real geometry into which the cropped page is rendered: */
57 const QRect& croppedGeometry() const;
58 int croppedWidth() const;
59 int croppedHeight() const;
61 /* "Uncropped" geometry:
62 * If the whole page was rendered into the uncropped geometry then the
63 * cropped page would be rendered into the real geometry.
64 * (Hence, uncropped always contains cropped, and they are equal only if
65 * the page is uncropped.) This is just for convenience in calculations.
67 const QRect& uncroppedGeometry() const;
68 int uncroppedWidth() const;
69 int uncroppedHeight() const;
71 /* Convert absolute geometry coordinates to normalized [0,1] page coordinates: */
72 double absToPageX(double absX) const;
73 double absToPageY(double absY) const;
75 void setWHZC( int w, int h, double zoom, const Okular::NormalizedRect & c );
76 void moveTo( int x, int y );
77 void setVisible( bool visible );
78 void invalidate();
79 bool setFormWidgetsVisible( bool visible );
81 private:
82 const Okular::Page * m_page;
83 double m_zoomFactor;
84 bool m_visible;
85 bool m_formsVisible;
86 QRect m_croppedGeometry;
87 QRect m_uncroppedGeometry;
88 Okular::NormalizedRect m_crop;
89 QHash<int, FormWidgetIface*> m_formWidgets;
90 QHash< Okular::Movie *, VideoWidget * > m_videoWidgets;
94 /**
95 * @short A widget that displays messages in the top-left corner.
97 * This is a widget with thin border and rounded corners that displays a given
98 * text along as an icon. It's meant to be used for displaying messages to the
99 * user by placing this above other widgets.
101 class PageViewMessage : public QWidget
103 public:
104 PageViewMessage( QWidget * parent );
106 enum Icon { None, Info, Warning, Error, Find, Annotation };
107 void display( const QString & message, Icon icon = Info, int durationMs = 4000 );
109 protected:
110 void paintEvent( QPaintEvent * e );
111 void mousePressEvent( QMouseEvent * e );
113 private:
114 QString m_message;
115 QPixmap m_symbol;
116 QTimer * m_timer;
121 * @short A widget that displays messages in the top part of the page view.
123 * ...
125 class PageViewTopMessage : public QWidget
127 Q_OBJECT
128 public:
129 PageViewTopMessage( QWidget * parent );
131 void setup( const QString & message, const KIcon& icon = KIcon() );
132 void setIconSize( int size );
133 void setActionButton( QAction * action );
135 signals:
136 void action();
138 private:
139 QLabel * m_label;
140 QLabel * m_icon;
141 QToolButton * m_button;
145 struct AnnotationToolItem
147 AnnotationToolItem()
148 : id( -1 ), isText( false )
152 int id;
153 QString text;
154 QString pixmap;
155 QString shortcut;
156 bool isText;
159 class ToolBarButton : public QToolButton
161 Q_OBJECT
162 public:
163 static const int iconSize = 32;
164 static const int buttonSize = 40;
166 ToolBarButton( QWidget * parent, const AnnotationToolItem &item );
167 int buttonID() const { return m_id; }
168 bool isText() const { return m_isText; }
170 private:
171 int m_id;
172 bool m_isText;
176 * @short A widget containing exclusive buttons, that slides in from a side.
178 * This is a shaped widget that slides in from a side of the 'anchor widget'
179 * it's attached to. It can be dragged and docked on {left,top,right,bottom}
180 * sides and contains toggable exclusive buttons.
181 * When a 'tool' of this 'toolBar' is selected, a signal is emitted.
183 class PageViewToolBar : public QWidget
185 Q_OBJECT
186 public:
187 PageViewToolBar( QWidget * parent, QWidget * anchorWidget );
188 ~PageViewToolBar();
190 // animated widget controls
191 enum Side { Left = 0, Top = 1, Right = 2, Bottom = 3 };
193 void setItems( const QLinkedList<AnnotationToolItem> &items );
194 void setSide( Side side );
196 void showAndAnimate();
197 void hideAndDestroy();
199 void selectButton( int id );
201 void setToolsEnabled( bool on );
202 void setTextToolsEnabled( bool on );
204 // query properties
206 signals:
207 // the tool 'toolID' has been selected
208 void toolSelected( int toolID );
209 // orientation has been changed
210 void orientationChanged( int side );
212 protected:
213 // handle widget events { anchor_resize, paint, animation, drag }
214 bool eventFilter( QObject * o, QEvent * e );
215 void paintEvent( QPaintEvent * );
216 void mousePressEvent( QMouseEvent * e );
217 void mouseMoveEvent( QMouseEvent * e );
218 void mouseReleaseEvent( QMouseEvent * e );
220 private:
221 // private variables
222 friend class ToolBarPrivate;
223 class ToolBarPrivate * d;
225 private slots:
226 void slotAnimate();
227 void slotButtonClicked();
230 #endif