Fix header
[kdeaccessibility.git] / kmag / kmagzoomview.h
blobe617dece8bd5d304d1e9df41c7ab2e731b45d541
1 /***************************************************************************
2 kmagview.h - description
3 -------------------
4 begin : Mon Feb 12 23:45:41 EST 2001
5 copyright : (C) 2001-2003 by Sarang Lakare
6 email : sarang#users.sf.net
7 copyright : (C) 2003-2004 by Olaf Schmidt
8 email : ojschmidt@kde.org
9 ***************************************************************************/
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; version 2 of the License *
16 * *
17 ***************************************************************************/
20 #ifndef KMagZoomView_h_
21 #define KMagZoomView_h_
23 #include <config.h>
25 // include files for Qt
26 #include <qwidget.h>
27 #include <QPainter>
28 #include <QPixmap>
29 #include <QTimer>
30 #include <q3scrollview.h>
31 #include <QStringList>
32 #include <QRect>
33 #include <QCursor>
34 //Added by qt3to4:
35 #include <QFocusEvent>
36 #include <QHideEvent>
37 #include <QKeyEvent>
38 #include <QShowEvent>
39 #include <QResizeEvent>
40 #include <QMouseEvent>
42 //class KMagSelRect;
43 #include "kmagselrect.h"
45 /**
46 * The KMagZoomView class provides the view widget for the KmagApp instance.
48 * @author Sarang Lakare <sarang#users.sourceforge.net>
50 class KMagZoomView : public Q3ScrollView
52 Q_OBJECT
53 public:
54 /// Constructor for the main view
55 KMagZoomView(QWidget *parent = 0, const char *name=0);
57 /// Destructor for the main view
58 ~KMagZoomView();
60 /// Toggles the refreshing of the window
61 void toggleRefresh();
63 /// Returns the currently displayed zoomed view
64 QPixmap getPixmap();
66 /// Returns the state of the refresh switch
67 bool getRefreshStatus() const { return m_refreshSwitch; };
69 /// Returns teh status of followMouse
70 bool getFollowMouse() const { return m_followMouse; };
72 /// Get the status of "show rect. always"
73 bool getShowSelRect() const { return (m_selRect.getAlwaysVisible()); };
75 /// Get the coordinates of the selection rectangle
76 QRect getSelRectPos() const { return static_cast<QRect>(m_selRect); };
78 /// Returns the current state of show mouse
79 unsigned int getShowMouseType() const;
81 /// Returns the different ways of showing mouse cursor
82 QStringList getShowMouseStringList() const;
84 /// Returns the status of "fit to window" option
85 bool getFitToWindow() const { return (m_fitToWindow); };
87 public slots:
89 /// Sets zoom to the given value
90 void setZoom(float zoom = 0.0);
92 /// Sets the rotation to the given value
93 void setRotation(int rotation = 0);
95 /// Grabs a frame from the given portion of the display
96 void grabFrame();
98 /// Update the mouse cursor in the zoom view
99 void updateMouseView();
101 /// Set grab-window-follows-mouse mode
102 void followMouse(bool follow = true);
104 /// Shows/Hides the selection marker
105 void showSelRect(bool show=true);
107 /// Set the position of the selection region to the given pos
108 void setSelRectPos(const QRect & rect);
110 /// Set the refresh rate in fps (frames per second)
111 void setRefreshRate(float fps);
113 /// Shows/Hides mouse cursor in the zoomed view
114 bool showMouse(unsigned int type);
116 /// Set the status of "fit to window" option
117 void setFitToWindow (bool fit=true);
119 /// Fits the zoom view to the zoom view window
120 void fitToWindow();
122 protected:
123 /// Called when the widget is hidden
124 void hideEvent( QHideEvent * e);
126 /// Called when the widget is shown
127 void showEvent( QShowEvent * e);
129 /// Called when the widget has been resized
130 void resizeEvent(QResizeEvent *e);
132 /// Called when the widget is to be repainted
133 void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
135 /// This function calculates the mouse position relative to the image
136 QPoint calcMousePos(bool updateMousePos=true);
138 /// This function draws the mouse cursor
139 void paintMouseCursor(QPaintDevice *dev, QPoint mousePos);
141 /// Called when mouse click is detected
142 void mousePressEvent (QMouseEvent *e);
144 /// Called when mouse is moved
145 void mouseMoveEvent(QMouseEvent *e);
147 /// Mouse button release event handler
148 void mouseReleaseEvent(QMouseEvent *e);
150 /// Mouse button release event handler
151 void keyPressEvent(QKeyEvent *e);
153 /// Mouse button release event handler
154 void keyReleaseEvent(QKeyEvent *e);
156 /// Mouse button release event handler
157 void focusOutEvent(QFocusEvent *e);
159 /// Returns the rectangle where the pixmap will be drawn
160 QRect pixmapRect();
162 private:
163 /// Stores the pixmap grabbed from the screen - to be zoomed
164 QPixmap m_grabbedPixmap;
166 /// Stores the pixmap which is zoomed from the grabbed one - this will be actaully drawn
167 QPixmap m_grabbedZoomedPixmap;
169 /// The selected rectangle which is to be grabbed
170 KMagSelRect m_selRect;
172 /// Grabs a window when the timer goes off
173 QTimer m_grabTimer;
175 /// Updates the mouse view
176 QTimer m_mouseViewTimer;
178 /// Zoom matrix
179 QMatrix m_zoomMatrix;
181 /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position
182 QPoint m_oldMousePos;
184 /// Saves the center of the grab window
185 QPoint m_oldCenter;
187 /// Possible modes for the mouse to be in
188 enum KMagMouseMode {
189 Normal,
190 StartSelect,
191 ResizeSelection,
192 MoveSelection,
193 GrabSelection
196 /// The current mode which the mouse is
197 KMagMouseMode m_mouseMode;
199 /// stores the state of the Ctrl key
200 bool m_ctrlKeyPressed;
202 /// stores the state of the Shift key
203 bool m_shiftKeyPressed;
205 /// Store the more recent updated cursor position
206 QPoint m_latestCursorPos;
208 /// Various ways of showing mouse cursor
209 QStringList m_showMouseTypes;
211 // configuration options:
213 /// To follow mouse motion or not when no key is pressed
214 bool m_followMouse;
216 /// State of refreshing - on or off
217 bool m_refreshSwitch;
219 /// Stores the state of the refresh switch on hide event
220 bool m_refreshSwitchStateOnHide;
222 /// Show mouse cursor type - 0 : do not show, non zero: show
223 unsigned int m_showMouse;
225 /// Frames per second for refresh
226 unsigned int m_fps;
228 /// Stores the amount to zoom the pixmap
229 float m_zoom;
231 /// Stores the degrees to rotate the pixmap
232 int m_rotation;
234 /// Fit the zoom view to the zoom window
235 bool m_fitToWindow;
238 #endif // KMagZoomView_h_