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>
32 #include <QFocusEvent>
36 #include <QResizeEvent>
37 #include <QMouseEvent>
40 #include "kmagselrect.h"
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
51 /// Constructor for the main view
52 explicit KMagZoomView(QWidget
*parent
= 0, const char *name
=0);
54 /// Destructor for the main view
57 /// Toggles the refreshing of the window
60 /// Returns the currently displayed zoomed view
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
); }
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
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
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
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
172 /// Updates the mouse view
173 QTimer m_mouseViewTimer
;
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
184 /// Possible modes for the mouse to be in
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
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
225 /// Stores the amount to zoom the pixmap
228 /// Stores the degrees to rotate the pixmap
231 /// Fit the zoom view to the zoom window
235 #endif // KMagZoomView_h_