SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kmag / kmagzoomview.h
blob88d06535600be62924109075d33c14a772b04453
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 files for Qt
24 #include <qwidget.h>
25 #include <QPainter>
26 #include <QPixmap>
27 #include <QTimer>
28 #include <q3scrollview.h>
29 #include <QRect>
30 #include <QCursor>
31 //Added by qt3to4:
32 #include <QFocusEvent>
33 #include <QHideEvent>
34 #include <QKeyEvent>
35 #include <QShowEvent>
36 #include <QResizeEvent>
37 #include <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 teh 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 /// Grabs a frame from the given portion of the display
93 void grabFrame();
95 /// Update the mouse cursor in the zoom view
96 void updateMouseView();
98 /// Set grab-window-follows-mouse mode
99 void followMouse(bool follow = true);
101 /// Shows/Hides the selection marker
102 void showSelRect(bool show=true);
104 /// Set the position of the selection region to the given pos
105 void setSelRectPos(const QRect & rect);
107 /// Set the refresh rate in fps (frames per second)
108 void setRefreshRate(float fps);
110 /// Shows/Hides mouse cursor in the zoomed view
111 bool showMouse(unsigned int type);
113 /// Set the status of "fit to window" option
114 void setFitToWindow (bool fit=true);
116 /// Fits the zoom view to the zoom view window
117 void fitToWindow();
119 protected:
120 /// Called when the widget is hidden
121 void hideEvent( QHideEvent * e);
123 /// Called when the widget is shown
124 void showEvent( QShowEvent * e);
126 /// Called when the widget has been resized
127 void resizeEvent(QResizeEvent *e);
129 /// Called when the widget is to be repainted
130 void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
132 /// This function calculates the mouse position relative to the image
133 QPoint calcMousePos(bool updateMousePos=true);
135 /// This function draws the mouse cursor
136 void paintMouseCursor(QPaintDevice *dev, const QPoint & mousePos);
138 /// Called when mouse click is detected
139 void mousePressEvent (QMouseEvent *e);
141 /// Called when mouse is moved
142 void mouseMoveEvent(QMouseEvent *e);
144 /// Mouse button release event handler
145 void mouseReleaseEvent(QMouseEvent *e);
147 /// Mouse button release event handler
148 void keyPressEvent(QKeyEvent *e);
150 /// Mouse button release event handler
151 void keyReleaseEvent(QKeyEvent *e);
153 /// Mouse button release event handler
154 void focusOutEvent(QFocusEvent *e);
156 /// Returns the rectangle where the pixmap will be drawn
157 QRect pixmapRect();
159 private:
160 /// Stores the pixmap grabbed from the screen - to be zoomed
161 QPixmap m_grabbedPixmap;
163 /// Stores the pixmap which is zoomed from the grabbed one - this will be actaully drawn
164 QPixmap m_grabbedZoomedPixmap;
166 /// The selected rectangle which is to be grabbed
167 KMagSelRect m_selRect;
169 /// Grabs a window when the timer goes off
170 QTimer m_grabTimer;
172 /// Updates the mouse view
173 QTimer m_mouseViewTimer;
175 /// Zoom matrix
176 QMatrix m_zoomMatrix;
178 /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position
179 QPoint m_oldMousePos;
181 /// Saves the center of the grab window
182 QPoint m_oldCenter;
184 /// Possible modes for the mouse to be in
185 enum KMagMouseMode {
186 Normal,
187 StartSelect,
188 ResizeSelection,
189 MoveSelection,
190 GrabSelection
193 /// The current mode which the mouse is
194 KMagMouseMode m_mouseMode;
196 /// stores the state of the Ctrl key
197 bool m_ctrlKeyPressed;
199 /// stores the state of the Shift key
200 bool m_shiftKeyPressed;
202 /// Store the more recent updated cursor position
203 QPoint m_latestCursorPos;
205 /// Various ways of showing mouse cursor
206 QStringList m_showMouseTypes;
208 // configuration options:
210 /// To follow mouse motion or not when no key is pressed
211 bool m_followMouse;
213 /// State of refreshing - on or off
214 bool m_refreshSwitch;
216 /// Stores the state of the refresh switch on hide event
217 bool m_refreshSwitchStateOnHide;
219 /// Show mouse cursor type - 0 : do not show, non zero: show
220 unsigned int m_showMouse;
222 /// Frames per second for refresh
223 unsigned int m_fps;
225 /// Stores the amount to zoom the pixmap
226 float m_zoom;
228 /// Stores the degrees to rotate the pixmap
229 int m_rotation;
231 /// Fit the zoom view to the zoom window
232 bool m_fitToWindow;
235 #endif // KMagZoomView_h_