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 copyright : (C) 2008 by Matthew Woehlke
10 email : mw_triad@users.sourceforge.net
11 copyright (C) 2010 Sebastian Sauer
12 email sebsauer@kdab.com
13 ***************************************************************************/
14
15/***************************************************************************
16 * *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
21 * *
22 ***************************************************************************/
23
24#ifndef KMagZoomView_h
25#define KMagZoomView_h
26
27// include files for Qt
28#include <QtGui/QWidget>
29#include <QtGui/QPainter>
30#include <QtGui/QPixmap>
31#include <QtCore/QTimer>
32#include <QtGui/QAbstractScrollArea>
33#include <QtCore/QRect>
34#include <QtGui/QCursor>
35#include <QtGui/QFocusEvent>
36#include <QtGui/QHideEvent>
37#include <QtGui/QKeyEvent>
38#include <QtGui/QShowEvent>
39#include <QtGui/QResizeEvent>
40#include <QtGui/QMouseEvent>
41
42//class KMagSelRect;
43#include "kmagselrect.h"
44
45#include "focustrackconfig.h"
46#ifdef QAccessibilityClient_FOUND
47#include <qaccessibilityclient/registry.h>
48#endif
49
50/**
51 * The KMagZoomView class provides the view widget for the KmagApp instance.
52 *
53 * @author Sarang Lakare <sarang#users.sourceforge.net>
54 */
55class KMagZoomView : public QAbstractScrollArea
56{
57 Q_OBJECT
58 public:
59 /// Constructor for the main view
60 explicit KMagZoomView(QWidget *parent = 0, const char *name=0);
61
62 /// Destructor for the main view
63 ~KMagZoomView();
64
65 /// Toggles the refreshing of the window
66 void toggleRefresh();
67
68 /// Returns the currently displayed zoomed view
69 QImage getImage();
70
71 /// Returns the state of the refresh switch
72 bool getRefreshStatus() const { return m_refreshSwitch; }
73
74 /// Returns the status of followMouse
75 bool getFollowMouse() const { return m_followMouse; }
76
77#ifdef QAccessibilityClient_FOUND
78 /// Returns the status of followFocus
79 bool getFollowFocus() const { return m_followFocus; }
80#endif
81
82 /// Get the status of "show rect. always"
83 bool getShowSelRect() const { return (m_selRect.getAlwaysVisible()); }
84
85 /// Get the coordinates of the selection rectangle
86 QRect getSelRectPos() const { return static_cast<QRect>(m_selRect); }
87
88 /// Returns the current state of show mouse
89 unsigned int getShowMouseType() const;
90
91 /// Returns the different ways of showing mouse cursor
92 QStringList getShowMouseStringList() const;
93
94 /// Returns the status of "fit to window" option
95 bool getFitToWindow() const { return (m_fitToWindow); }
96
97 public slots:
98
99 /// Sets zoom to the given value
100 void setZoom(float zoom = 0.0);
101
102 /// Sets the rotation to the given value
103 void setRotation(int rotation = 0);
104
105 /// Sets the color mode to the given value
106 void setColorMode(int mode = 0);
107
108 /// Grabs a frame from the given portion of the display
109 void grabFrame();
110
111 /// Update the mouse cursor in the zoom view
112 void updateMouseView();
113
114 /// Set grab-window-follows-mouse mode
115 void followMouse(bool follow = true);
116
117#ifdef QAccessibilityClient_FOUND
118 /// Set grab-window-follows-mouse-and-keyboard-focus mode
119 void followBoth(bool follow = true);
120
121 /// Set grab-window-follows-keyboard-focus mode
122 void followFocus(bool follow = true);
123#endif
124
125 /// Shows/Hides the selection marker
126 void showSelRect(bool show=true);
127
128 /// Set the position of the selection region to the given pos
129 void setSelRectPos(const QRect & rect);
130
131 /// Set the refresh rate in fps (frames per second)
132 void setRefreshRate(float fps);
133
134 /// Shows/Hides mouse cursor in the zoomed view
135 bool showMouse(unsigned int type);
136
137 /// Set the status of "fit to window" option
138 void setFitToWindow (bool fit=true);
139
140 /// Fits the zoom view to the zoom view window
141 void fitToWindow();
142
143#ifdef QAccessibilityClient_FOUND
144 private slots:
145 /// Called from a dbus service when followFocus is true
146 void focusChanged(const QAccessibleClient::AccessibleObject &object);
147#endif
148 protected:
149 /// Called when the widget is hidden
150 void hideEvent( QHideEvent * e);
151
152 /// Called when the widget is shown
153 void showEvent( QShowEvent * e);
154
155 /// Called when the widget has been resized
156 void resizeEvent(QResizeEvent *e);
157
158 /// Called when the widget is to be repainted
159 void paintEvent(QPaintEvent *e);
160
161 /// This function calculates the mouse position relative to the image
162 QPoint calcMousePos(bool updateMousePos=true);
163
164 /// This function draws the mouse cursor
165 void paintMouseCursor(QPaintDevice *dev, const QPoint & mousePos);
166
167 /// Called when mouse click is detected
168 void mousePressEvent (QMouseEvent *e);
169
170 /// Called when mouse is moved
171 void mouseMoveEvent(QMouseEvent *e);
172
173 /// Mouse button release event handler
174 void mouseReleaseEvent(QMouseEvent *e);
175
176 /// Mouse button release event handler
177 void keyPressEvent(QKeyEvent *e);
178
179 /// Mouse button release event handler
180 void keyReleaseEvent(QKeyEvent *e);
181
182 /// Mouse button release event handler
183 void focusOutEvent(QFocusEvent *e);
184
185 /// Returns the rectangle where the pixmap will be drawn
186 QRect pixmapRect();
187
188 /// Q3ScrollView porting helpers, maybe inline them
189 int contentsX() const;
190 int contentsY() const;
191 int contentsWidth() const;
192 int contentsHeight() const;
193 int visibleWidth() const;
194 int visibleHeight() const;
195 void setContentsPos(int x, int y);
196
197 /// Setup transformation matrix for zooming, rotating, and mirroring
198 void setupMatrix();
199
200 private:
201
202#ifdef QAccessibilityClient_FOUND
203 /// Global Accessibility Registry
204 QAccessibleClient::Registry m_registry;
205#endif
206
207 /// Stores the pixmap which is recolored from the grabbed one
208 QPixmap m_coloredPixmap;
209
210 /// The selected rectangle which is to be grabbed
211 KMagSelRect m_selRect;
212
213 /// Grabs a window when the timer goes off
214 QTimer m_grabTimer;
215
216 /// Updates the mouse view
217 QTimer m_mouseViewTimer;
218
219 /// Zoom matrix
220 QMatrix m_zoomMatrix;
221
222 /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position
223 QPoint m_oldMousePos;
224
225 /// Saves the center of the grab window
226 QPoint m_oldCenter;
227
228#ifdef QAccessibilityClient_FOUND
229 /// Saves the keyboard focus position
230 QPoint m_oldFocus;
231#endif
232
233 /// Possible modes for the mouse to be in
234 enum KMagMouseMode {
235 Normal,
236 StartSelect,
237 ResizeSelection,
238 MoveSelection,
239 GrabSelection
240 };
241
242 /// The current mode which the mouse is
243 KMagMouseMode m_mouseMode;
244
245 /// stores the state of the Ctrl key
246 bool m_ctrlKeyPressed;
247
248 /// stores the state of the Shift key
249 bool m_shiftKeyPressed;
250
251 /// Store the more recent updated cursor position
252 QPoint m_latestCursorPos;
253
254 /// Various ways of showing mouse cursor
255 QStringList m_showMouseTypes;
256
257 // configuration options:
258
259 /// To follow mouse motion or not when no key is pressed
260 bool m_followMouse;
261
262 /// To follow keyboard focus or not
263 bool m_followFocus;
264 bool m_followBoth;
265
266 /// State of refreshing - on or off
267 bool m_refreshSwitch;
268
269 /// Stores the state of the refresh switch on hide event
270 bool m_refreshSwitchStateOnHide;
271
272 /// Show mouse cursor type - 0 : do not show, non zero: show
273 unsigned int m_showMouse;
274
275 /// Frames per second for refresh
276 unsigned int m_fps;
277
278 /// Stores the amount to zoom the pixmap
279 float m_zoom;
280
281 /// Stores the degrees to rotate the pixmap
282 int m_rotation;
283
284 /// Stores color simulation mode to apply
285 int m_colormode;
286
287 /// Fit the zoom view to the zoom window
288 bool m_fitToWindow;
289};
290
291#endif // KMagZoomView_h
292