Remove this line
[kdeaccessibility.git] / kmag / kmagzoomview.h
blob31223696c04a3efec49b4e2f9dbd85c5f44cd26c
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 ***************************************************************************/
13 /***************************************************************************
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; version 2 of the License *
18 * *
19 ***************************************************************************/
21 #ifndef KMagZoomView_h
22 #define KMagZoomView_h
24 // include files for Qt
25 #include <QtGui/QWidget>
26 #include <QtGui/QPainter>
27 #include <QtGui/QPixmap>
28 #include <QtCore/QTimer>
29 #include <Qt3Support/Q3ScrollView>
30 #include <QtCore/QRect>
31 #include <QtGui/QCursor>
32 #include <QtGui/QFocusEvent>
33 #include <QtGui/QHideEvent>
34 #include <QtGui/QKeyEvent>
35 #include <QtGui/QShowEvent>
36 #include <QtGui/QResizeEvent>
37 #include <QtGui/QMouseEvent>
39 //class KMagSelRect;
40 #include "kmagselrect.h"
42 /**
43 * The KMagZoomView class provides the view widget for the KmagApp instance.
45 * @author Sarang Lakare <sarang#users.sourceforge.net>
47 class KMagZoomView : public Q3ScrollView
49 Q_OBJECT
50 public:
51 /// Constructor for the main view
52 explicit KMagZoomView(QWidget *parent = 0, const char *name=0);
54 /// Destructor for the main view
55 ~KMagZoomView();
57 /// Toggles the refreshing of the window
58 void toggleRefresh();
60 /// Returns the currently displayed zoomed view
61 QPixmap getPixmap();
63 /// Returns the state of the refresh switch
64 bool getRefreshStatus() const { return m_refreshSwitch; }
66 /// Returns the status of followMouse
67 bool getFollowMouse() const { return m_followMouse; }
69 /// Get the status of "show rect. always"
70 bool getShowSelRect() const { return (m_selRect.getAlwaysVisible()); }
72 /// Get the coordinates of the selection rectangle
73 QRect getSelRectPos() const { return static_cast<QRect>(m_selRect); }
75 /// Returns the current state of show mouse
76 unsigned int getShowMouseType() const;
78 /// Returns the different ways of showing mouse cursor
79 QStringList getShowMouseStringList() const;
81 /// Returns the status of "fit to window" option
82 bool getFitToWindow() const { return (m_fitToWindow); }
84 public slots:
86 /// Sets zoom to the given value
87 void setZoom(float zoom = 0.0);
89 /// Sets the rotation to the given value
90 void setRotation(int rotation = 0);
92 /// Sets the color mode to the given value
93 void setColorMode(int mode = 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, const 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 recolored from the grabbed one
167 QPixmap m_coloredPixmap;
169 /// Stores the pixmap which is zoomed from the colored one - this will be actaully drawn
170 QPixmap m_zoomedPixmap;
172 /// The selected rectangle which is to be grabbed
173 KMagSelRect m_selRect;
175 /// Grabs a window when the timer goes off
176 QTimer m_grabTimer;
178 /// Updates the mouse view
179 QTimer m_mouseViewTimer;
181 /// Zoom matrix
182 QMatrix m_zoomMatrix;
184 /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position
185 QPoint m_oldMousePos;
187 /// Saves the center of the grab window
188 QPoint m_oldCenter;
190 /// Possible modes for the mouse to be in
191 enum KMagMouseMode {
192 Normal,
193 StartSelect,
194 ResizeSelection,
195 MoveSelection,
196 GrabSelection
199 /// The current mode which the mouse is
200 KMagMouseMode m_mouseMode;
202 /// stores the state of the Ctrl key
203 bool m_ctrlKeyPressed;
205 /// stores the state of the Shift key
206 bool m_shiftKeyPressed;
208 /// Store the more recent updated cursor position
209 QPoint m_latestCursorPos;
211 /// Various ways of showing mouse cursor
212 QStringList m_showMouseTypes;
214 // configuration options:
216 /// To follow mouse motion or not when no key is pressed
217 bool m_followMouse;
219 /// State of refreshing - on or off
220 bool m_refreshSwitch;
222 /// Stores the state of the refresh switch on hide event
223 bool m_refreshSwitchStateOnHide;
225 /// Show mouse cursor type - 0 : do not show, non zero: show
226 unsigned int m_showMouse;
228 /// Frames per second for refresh
229 unsigned int m_fps;
231 /// Stores the amount to zoom the pixmap
232 float m_zoom;
234 /// Stores the degrees to rotate the pixmap
235 int m_rotation;
237 /// Stores color simulation mode to apply
238 int m_colormode;
240 /// Fit the zoom view to the zoom window
241 bool m_fitToWindow;
244 #endif // KMagZoomView_h