Port to qt4
[kdeaccessibility.git] / kmag / kmagzoomview.h
blob6756d988af7ad4e7b6aadbe2abfa7e93a42585c5
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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 // include files for Qt
28 #include <qwidget.h>
29 #include <qpainter.h>
30 #include <qpixmap.h>
31 #include <qtimer.h>
32 #include <q3scrollview.h>
33 #include <qstringlist.h>
34 #include <qrect.h>
35 #include <qcursor.h>
36 //Added by qt3to4:
37 #include <QFocusEvent>
38 #include <QHideEvent>
39 #include <QKeyEvent>
40 #include <QShowEvent>
41 #include <QResizeEvent>
42 #include <QMouseEvent>
44 //class KMagSelRect;
45 #include "kmagselrect.h"
47 /**
48 * The KMagZoomView class provides the view widget for the KmagApp instance.
50 * @author Sarang Lakare <sarang#users.sourceforge.net>
52 class KMagZoomView : public Q3ScrollView
54 Q_OBJECT
55 public:
56 /// Constructor for the main view
57 KMagZoomView(QWidget *parent = 0, const char *name=0);
59 /// Destructor for the main view
60 ~KMagZoomView();
62 /// Toggles the refreshing of the window
63 void toggleRefresh();
65 /// Returns the currently displayed zoomed view
66 QPixmap getPixmap();
68 /// Returns the state of the refresh switch
69 bool getRefreshStatus() const { return m_refreshSwitch; };
71 /// Returns teh status of followMouse
72 bool getFollowMouse() const { return m_followMouse; };
74 /// Get the status of "show rect. always"
75 bool getShowSelRect() const { return (m_selRect.getAlwaysVisible()); };
77 /// Get the coordinates of the selection rectangle
78 QRect getSelRectPos() const { return static_cast<QRect>(m_selRect); };
80 /// Returns the current state of show mouse
81 unsigned int getShowMouseType() const;
83 /// Returns the different ways of showing mouse cursor
84 QStringList getShowMouseStringList() const;
86 /// Returns the status of "fit to window" option
87 bool getFitToWindow() const { return (m_fitToWindow); };
89 public slots:
91 /// Sets zoom to the given value
92 void setZoom(float zoom = 0.0);
94 /// Sets the rotation to the given value
95 void setRotation(int rotation = 0);
97 /// Grabs a frame from the given portion of the display
98 void grabFrame();
100 /// Update the mouse cursor in the zoom view
101 void updateMouseView();
103 /// Set grab-window-follows-mouse mode
104 void followMouse(bool follow = true);
106 /// Shows/Hides the selection marker
107 void showSelRect(bool show=true);
109 /// Set the position of the selection region to the given pos
110 void setSelRectPos(const QRect & rect);
112 /// Set the refresh rate in fps (frames per second)
113 void setRefreshRate(float fps);
115 /// Shows/Hides mouse cursor in the zoomed view
116 bool showMouse(unsigned int type);
118 /// Set the status of "fit to window" option
119 void setFitToWindow (bool fit=true);
121 /// Fits the zoom view to the zoom view window
122 void fitToWindow();
124 protected:
125 /// Called when the widget is hidden
126 void hideEvent( QHideEvent * e);
128 /// Called when the widget is shown
129 void showEvent( QShowEvent * e);
131 /// Called when the widget has been resized
132 void resizeEvent(QResizeEvent *e);
134 /// Called when the widget is to be repainted
135 void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
137 /// This function calculates the mouse position relative to the image
138 QPoint calcMousePos(bool updateMousePos=true);
140 /// This function draws the mouse cursor
141 void paintMouseCursor(QPaintDevice *dev, QPoint mousePos);
143 /// Called when mouse click is detected
144 void mousePressEvent (QMouseEvent *e);
146 /// Called when mouse is moved
147 void mouseMoveEvent(QMouseEvent *e);
149 /// Mouse button release event handler
150 void mouseReleaseEvent(QMouseEvent *e);
152 /// Mouse button release event handler
153 void keyPressEvent(QKeyEvent *e);
155 /// Mouse button release event handler
156 void keyReleaseEvent(QKeyEvent *e);
158 /// Mouse button release event handler
159 void focusOutEvent(QFocusEvent *e);
161 /// Returns the rectangle where the pixmap will be drawn
162 QRect pixmapRect();
164 private:
165 /// Stores the pixmap grabbed from the screen - to be zoomed
166 QPixmap m_grabbedPixmap;
168 /// Stores the pixmap which is zoomed from the grabbed one - this will be actaully drawn
169 QPixmap m_grabbedZoomedPixmap;
171 /// The selected rectangle which is to be grabbed
172 KMagSelRect m_selRect;
174 /// Grabs a window when the timer goes off
175 QTimer m_grabTimer;
177 /// Updates the mouse view
178 QTimer m_mouseViewTimer;
180 /// Zoom matrix
181 QMatrix m_zoomMatrix;
183 /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position
184 QPoint m_oldMousePos;
186 /// Saves the center of the grab window
187 QPoint m_oldCenter;
189 /// Possible modes for the mouse to be in
190 enum KMagMouseMode {
191 Normal,
192 StartSelect,
193 ResizeSelection,
194 MoveSelection,
195 GrabSelection
198 /// The current mode which the mouse is
199 KMagMouseMode m_mouseMode;
201 /// stores the state of the Ctrl key
202 bool m_ctrlKeyPressed;
204 /// stores the state of the Shift key
205 bool m_shiftKeyPressed;
207 /// Store the more recent updated cursor position
208 QPoint m_latestCursorPos;
210 /// Various ways of showing mouse cursor
211 QStringList m_showMouseTypes;
213 // configuration options:
215 /// To follow mouse motion or not when no key is pressed
216 bool m_followMouse;
218 /// State of refreshing - on or off
219 bool m_refreshSwitch;
221 /// Stores the state of the refresh switch on hide event
222 bool m_refreshSwitchStateOnHide;
224 /// Show mouse cursor type - 0 : do not show, non zero: show
225 unsigned int m_showMouse;
227 /// Frames per second for refresh
228 unsigned int m_fps;
230 /// Stores the amount to zoom the pixmap
231 float m_zoom;
233 /// Stores the degrees to rotate the pixmap
234 int m_rotation;
236 /// Fit the zoom view to the zoom window
237 bool m_fitToWindow;
240 #endif // KMagZoomView_h_