File indexing completed on 2024-04-28 03:40:29
0001 // SPDX-FileCopyrightText: 2001-2003 Sarang Lakare <sarang@users.sourceforge.net> 0002 // SPDX-FileCopyrightText: 2003-2004 Olaf Schmidt <ojschmidt@kde.org> 0003 // SPDX-FileCopyrightText: 2008 Matthew Woehlke <mw_triad@users.sourceforge.net> 0004 // SPDX-FileCopyrightText: 2010 Sebastian Sauer <sebsauer@kdab.com> 0005 // SPDX-License-Identifier: GPL-2.0-or-later 0006 0007 #ifndef KMagZoomView_h 0008 #define KMagZoomView_h 0009 0010 // include files for Qt 0011 #include <QWidget> 0012 #include <QPixmap> 0013 #include <QTimer> 0014 #include <QAbstractScrollArea> 0015 #include <QRect> 0016 #include <QFocusEvent> 0017 #include <QHideEvent> 0018 #include <QKeyEvent> 0019 #include <QShowEvent> 0020 #include <QResizeEvent> 0021 #include <QMouseEvent> 0022 0023 //class KMagSelRect; 0024 #include "kmagselrect.h" 0025 0026 #include "focustrackconfig.h" 0027 #if HAVE_QACCESSIBILITYCLIENT 0028 #include <qaccessibilityclient/registry.h> 0029 #endif 0030 0031 /** 0032 * The KMagZoomView class provides the view widget for the KmagApp instance. 0033 * 0034 * @author Sarang Lakare <sarang#users.sourceforge.net> 0035 */ 0036 class KMagZoomView : public QAbstractScrollArea 0037 { 0038 Q_OBJECT 0039 public: 0040 /// Constructor for the main view 0041 explicit KMagZoomView(QWidget *parent = nullptr, const char *name=nullptr); 0042 0043 /// Destructor for the main view 0044 ~KMagZoomView() override; 0045 0046 /// Toggles the refreshing of the window 0047 void toggleRefresh(); 0048 0049 /// Returns the currently displayed zoomed view 0050 QImage getImage(); 0051 0052 /// Returns the state of the refresh switch 0053 bool getRefreshStatus() const { return m_refreshSwitch; } 0054 0055 /// Returns the status of followMouse 0056 bool getFollowMouse() const { return m_followMouse; } 0057 0058 #if HAVE_QACCESSIBILITYCLIENT 0059 /// Returns the status of followFocus 0060 bool getFollowFocus() const { return m_followFocus; } 0061 #endif 0062 0063 /// Get the status of "show rect. always" 0064 bool getShowSelRect() const { return (m_selRect.getAlwaysVisible()); } 0065 0066 /// Get the coordinates of the selection rectangle 0067 QRect getSelRectPos() const { return static_cast<QRect>(m_selRect); } 0068 0069 /// Returns the current state of show mouse 0070 unsigned int getShowMouseType() const; 0071 0072 /// Returns the different ways of showing mouse cursor 0073 QStringList getShowMouseStringList() const; 0074 0075 /// Returns the status of "fit to window" option 0076 bool getFitToWindow() const { return (m_fitToWindow); } 0077 0078 public Q_SLOTS: 0079 0080 /// Sets zoom to the given value 0081 void setZoom(float zoom = 0.0); 0082 0083 /// Sets the rotation to the given value 0084 void setRotation(int rotation = 0); 0085 0086 /// Sets the color mode to the given value 0087 void setColorMode(int mode = 0); 0088 0089 /// Grabs a frame from the given portion of the display 0090 void grabFrame(); 0091 0092 /// Update the mouse cursor in the zoom view 0093 void updateMouseView(); 0094 0095 /// Set grab-window-follows-mouse mode 0096 void followMouse(bool follow = true); 0097 0098 #if HAVE_QACCESSIBILITYCLIENT 0099 /// Set grab-window-follows-mouse-and-keyboard-focus mode 0100 void followBoth(bool follow = true); 0101 0102 /// Set grab-window-follows-keyboard-focus mode 0103 void followFocus(bool follow = true); 0104 #endif 0105 0106 /// Shows/Hides the selection marker 0107 void showSelRect(bool show=true); 0108 0109 /// Set the position of the selection region to the given pos 0110 void setSelRectPos(const QRect & rect); 0111 0112 /// Set the refresh rate in fps (frames per second) 0113 void setRefreshRate(float fps); 0114 0115 /// Shows/Hides mouse cursor in the zoomed view 0116 bool showMouse(unsigned int type); 0117 0118 /// Set the status of "fit to window" option 0119 void setFitToWindow (bool fit=true); 0120 0121 /// Fits the zoom view to the zoom view window 0122 void fitToWindow(); 0123 0124 #if HAVE_QACCESSIBILITYCLIENT 0125 private Q_SLOTS: 0126 /// Called from a dbus service when followFocus is true 0127 void focusChanged(const QAccessibleClient::AccessibleObject &object); 0128 #endif 0129 protected: 0130 /// Called when the widget is hidden 0131 void hideEvent( QHideEvent * e) override; 0132 0133 /// Called when the widget is shown 0134 void showEvent( QShowEvent * e) override; 0135 0136 /// Called when the widget has been resized 0137 void resizeEvent(QResizeEvent *e) override; 0138 0139 /// Called when the widget is to be repainted 0140 void paintEvent(QPaintEvent *e) override; 0141 0142 /// This function calculates the mouse position relative to the image 0143 QPoint calcMousePos(bool updateMousePos=true); 0144 0145 /// This function draws the mouse cursor 0146 void paintMouseCursor(QPaintDevice *dev, const QPoint & mousePos); 0147 0148 /// Called when mouse click is detected 0149 void mousePressEvent (QMouseEvent *e) override; 0150 0151 /// Called when mouse is moved 0152 void mouseMoveEvent(QMouseEvent *e) override; 0153 0154 /// Mouse button release event handler 0155 void mouseReleaseEvent(QMouseEvent *e) override; 0156 0157 /// Mouse button release event handler 0158 void keyPressEvent(QKeyEvent *e) override; 0159 0160 /// Mouse button release event handler 0161 void keyReleaseEvent(QKeyEvent *e) override; 0162 0163 /// Mouse button release event handler 0164 void focusOutEvent(QFocusEvent *e) override; 0165 0166 /// Returns the rectangle where the pixmap will be drawn 0167 QRect pixmapRect(); 0168 0169 /// Q3ScrollView porting helpers, maybe inline them 0170 int contentsX() const; 0171 int contentsY() const; 0172 int contentsWidth() const; 0173 int contentsHeight() const; 0174 int visibleWidth() const; 0175 int visibleHeight() const; 0176 void setContentsPos(int x, int y); 0177 0178 /// Setup transformation matrix for zooming, rotating, and mirroring 0179 void setupMatrix(); 0180 0181 private: 0182 0183 #if HAVE_QACCESSIBILITYCLIENT 0184 /// Global Accessibility Registry 0185 QAccessibleClient::Registry m_registry; 0186 #endif 0187 0188 /// Stores the pixmap which is recolored from the grabbed one 0189 QPixmap m_coloredPixmap; 0190 0191 /// The selected rectangle which is to be grabbed 0192 KMagSelRect m_selRect; 0193 0194 /// Grabs a window when the timer goes off 0195 QTimer m_grabTimer; 0196 0197 /// Updates the mouse view 0198 QTimer m_mouseViewTimer; 0199 0200 /// Zoom matrix 0201 QTransform m_zoomMatrix; 0202 0203 /// Saves the mouse position when a button is clicked and b4 the cursor is moved to new position 0204 QPoint m_oldMousePos; 0205 0206 /// Saves the center of the grab window 0207 QPoint m_oldCenter; 0208 0209 #if HAVE_QACCESSIBILITYCLIENT 0210 /// Saves the keyboard focus position 0211 QPoint m_oldFocus; 0212 #endif 0213 0214 /// Possible modes for the mouse to be in 0215 enum KMagMouseMode { 0216 Normal, 0217 StartSelect, 0218 ResizeSelection, 0219 MoveSelection, 0220 GrabSelection 0221 }; 0222 0223 /// The current mode which the mouse is 0224 KMagMouseMode m_mouseMode; 0225 0226 /// stores the state of the Ctrl key 0227 bool m_ctrlKeyPressed; 0228 0229 /// stores the state of the Shift key 0230 bool m_shiftKeyPressed; 0231 0232 /// Store the more recent updated cursor position 0233 QPoint m_latestCursorPos; 0234 0235 /// Various ways of showing mouse cursor 0236 QStringList m_showMouseTypes; 0237 0238 // configuration options: 0239 0240 /// To follow mouse motion or not when no key is pressed 0241 bool m_followMouse; 0242 0243 /// To follow keyboard focus or not 0244 bool m_followFocus; 0245 bool m_followBoth; 0246 0247 /// State of refreshing - on or off 0248 bool m_refreshSwitch; 0249 0250 /// Stores the state of the refresh switch on hide event 0251 bool m_refreshSwitchStateOnHide; 0252 0253 /// Show mouse cursor type - 0 : do not show, non zero: show 0254 unsigned int m_showMouse; 0255 0256 /// Frames per second for refresh 0257 unsigned int m_fps; 0258 0259 /// Stores the amount to zoom the pixmap 0260 float m_zoom; 0261 0262 /// Stores the degrees to rotate the pixmap 0263 int m_rotation; 0264 0265 /// Stores color simulation mode to apply 0266 int m_colormode; 0267 0268 /// Fit the zoom view to the zoom window 0269 bool m_fitToWindow; 0270 }; 0271 0272 #endif // KMagZoomView_h