1 /***************************************************************************
2 kmagview.h - description
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 /***************************************************************************
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 *
17 ***************************************************************************/
20 #ifndef KMagZoomView_h_
21 #define KMagZoomView_h_
23 // include files for Qt
28 #include <q3scrollview.h>
29 #include <QStringList>
33 #include <QFocusEvent>
37 #include <QResizeEvent>
38 #include <QMouseEvent>
41 #include "kmagselrect.h"
44 * The KMagZoomView class provides the view widget for the KmagApp instance.
46 * @author Sarang Lakare <sarang#users.sourceforge.net>
48 class KMagZoomView
: public Q3ScrollView
52 /// Constructor for the main view
53 KMagZoomView(QWidget
*parent
= 0, const char *name
=0);
55 /// Destructor for the main view
58 /// Toggles the refreshing of the window
61 /// Returns the currently displayed zoomed view
64 /// Returns the state of the refresh switch
65 bool getRefreshStatus() const { return m_refreshSwitch
; };
67 /// Returns teh status of followMouse
68 bool getFollowMouse() const { return m_followMouse
; };
70 /// Get the status of "show rect. always"
71 bool getShowSelRect() const { return (m_selRect
.getAlwaysVisible()); };
73 /// Get the coordinates of the selection rectangle
74 QRect
getSelRectPos() const { return static_cast<QRect
>(m_selRect
); };
76 /// Returns the current state of show mouse
77 unsigned int getShowMouseType() const;
79 /// Returns the different ways of showing mouse cursor
80 QStringList
getShowMouseStringList() const;
82 /// Returns the status of "fit to window" option
83 bool getFitToWindow() const { return (m_fitToWindow
); };
87 /// Sets zoom to the given value
88 void setZoom(float zoom
= 0.0);
90 /// Sets the rotation to the given value
91 void setRotation(int rotation
= 0);
93 /// Grabs a frame from the given portion of the display
96 /// Update the mouse cursor in the zoom view
97 void updateMouseView();
99 /// Set grab-window-follows-mouse mode
100 void followMouse(bool follow
= true);
102 /// Shows/Hides the selection marker
103 void showSelRect(bool show
=true);
105 /// Set the position of the selection region to the given pos
106 void setSelRectPos(const QRect
& rect
);
108 /// Set the refresh rate in fps (frames per second)
109 void setRefreshRate(float fps
);
111 /// Shows/Hides mouse cursor in the zoomed view
112 bool showMouse(unsigned int type
);
114 /// Set the status of "fit to window" option
115 void setFitToWindow (bool fit
=true);
117 /// Fits the zoom view to the zoom view window
121 /// Called when the widget is hidden
122 void hideEvent( QHideEvent
* e
);
124 /// Called when the widget is shown
125 void showEvent( QShowEvent
* e
);
127 /// Called when the widget has been resized
128 void resizeEvent(QResizeEvent
*e
);
130 /// Called when the widget is to be repainted
131 void drawContents ( QPainter
* p
, int clipx
, int clipy
, int clipw
, int cliph
);
133 /// This function calculates the mouse position relative to the image
134 QPoint
calcMousePos(bool updateMousePos
=true);
136 /// This function draws the mouse cursor
137 void paintMouseCursor(QPaintDevice
*dev
, QPoint mousePos
);
139 /// Called when mouse click is detected
140 void mousePressEvent (QMouseEvent
*e
);
142 /// Called when mouse is moved
143 void mouseMoveEvent(QMouseEvent
*e
);
145 /// Mouse button release event handler
146 void mouseReleaseEvent(QMouseEvent
*e
);
148 /// Mouse button release event handler
149 void keyPressEvent(QKeyEvent
*e
);
151 /// Mouse button release event handler
152 void keyReleaseEvent(QKeyEvent
*e
);
154 /// Mouse button release event handler
155 void focusOutEvent(QFocusEvent
*e
);
157 /// Returns the rectangle where the pixmap will be drawn
161 /// Stores the pixmap grabbed from the screen - to be zoomed
162 QPixmap m_grabbedPixmap
;
164 /// Stores the pixmap which is zoomed from the grabbed one - this will be actaully drawn
165 QPixmap m_grabbedZoomedPixmap
;
167 /// The selected rectangle which is to be grabbed
168 KMagSelRect m_selRect
;
170 /// Grabs a window when the timer goes off
173 /// Updates the mouse view
174 QTimer m_mouseViewTimer
;
177 QMatrix m_zoomMatrix
;
179 /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position
180 QPoint m_oldMousePos
;
182 /// Saves the center of the grab window
185 /// Possible modes for the mouse to be in
194 /// The current mode which the mouse is
195 KMagMouseMode m_mouseMode
;
197 /// stores the state of the Ctrl key
198 bool m_ctrlKeyPressed
;
200 /// stores the state of the Shift key
201 bool m_shiftKeyPressed
;
203 /// Store the more recent updated cursor position
204 QPoint m_latestCursorPos
;
206 /// Various ways of showing mouse cursor
207 QStringList m_showMouseTypes
;
209 // configuration options:
211 /// To follow mouse motion or not when no key is pressed
214 /// State of refreshing - on or off
215 bool m_refreshSwitch
;
217 /// Stores the state of the refresh switch on hide event
218 bool m_refreshSwitchStateOnHide
;
220 /// Show mouse cursor type - 0 : do not show, non zero: show
221 unsigned int m_showMouse
;
223 /// Frames per second for refresh
226 /// Stores the amount to zoom the pixmap
229 /// Stores the degrees to rotate the pixmap
232 /// Fit the zoom view to the zoom window
236 #endif // KMagZoomView_h_