File indexing completed on 2025-01-26 05:09:32
0001 /* 0002 * This file is part of the KDE wacomtablet project. For copyright 0003 * information and license terms see the AUTHORS and COPYING files 0004 * in the top-level directory of this distribution. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef TABLETPAGEWIDGET_H 0021 #define TABLETPAGEWIDGET_H 0022 0023 #include "screenmap.h" 0024 #include "screenrotation.h" 0025 #include "screenspace.h" 0026 0027 #include <QString> 0028 #include <QWidget> 0029 0030 namespace Ui 0031 { 0032 class TabletPageWidget; 0033 } 0034 0035 namespace Wacom 0036 { 0037 0038 class ProfileManagementInterface; 0039 0040 /** 0041 * The "Tablet" tab of the main KCM widget. 0042 */ 0043 class TabletPageWidget : public QWidget 0044 { 0045 Q_OBJECT 0046 0047 public: 0048 explicit TabletPageWidget(QWidget *parent = nullptr); 0049 0050 ~TabletPageWidget() override; 0051 0052 void setTabletId(const QString &tabletId); 0053 0054 /** 0055 * Loads settings from the current profile and updates the widget accordingly. 0056 */ 0057 void loadFromProfile(ProfileManagementInterface &profileManagement); 0058 0059 /** 0060 * Reinitializes the widget when a new tablet gets connected. 0061 */ 0062 void reloadWidget(); 0063 0064 /** 0065 * Saves the current settings to the current profile. 0066 */ 0067 void saveToProfile(ProfileManagementInterface &profileManagement); 0068 0069 public slots: 0070 0071 /** 0072 * Called when the user enables/disables the auto-rotation checkbox. 0073 */ 0074 void onAutoRotateChanged(int state); 0075 0076 /** 0077 * Called when any profile property value changes. 0078 */ 0079 void onProfileChanged(); 0080 0081 /** 0082 * Called when the user changes the rotation settings. 0083 */ 0084 void onRotationChanged(); 0085 0086 /** 0087 * Called when the user presses the pad tablet mapping button. 0088 */ 0089 void onTabletMappingClicked(); 0090 0091 /** 0092 * Called when the state of the absolute tracking mode changes. 0093 */ 0094 void onTrackingModeAbsolute(bool activated); 0095 0096 /** 0097 * Called when the state of the relative tracking mode changes. 0098 */ 0099 void onTrackingModeRelative(bool activated); 0100 0101 signals: 0102 0103 /** 0104 * Emitted when the user changes configuration settings. 0105 */ 0106 void changed(); 0107 0108 /** 0109 * Emitted when the rotation changes to inform our other widgets about it. 0110 */ 0111 void rotationChanged(const ScreenRotation &rotation); 0112 0113 protected: 0114 /** 0115 * Gets the current rotation in profile format. 0116 * These are the values returned by ScreenRotation.key(). 0117 * 0118 * @return The current rotation in profile format. 0119 */ 0120 const QString getRotation() const; 0121 0122 /** 0123 * @return The current tablet to screen mapping. 0124 */ 0125 const ScreenMap &getScreenMap() const; 0126 0127 /** 0128 * Gets the current tablet area mapping in profile format as 0129 * returned by ScreenMap::toString(). 0130 * 0131 * @return The current tablet mapping in profile format. 0132 */ 0133 const QString getScreenMapAsString() const; 0134 0135 /** 0136 * @return The current screen space selection. 0137 */ 0138 const ScreenSpace &getScreenSpace() const; 0139 0140 /** 0141 * Gets the current screen area mapping in profile format. 0142 * 0143 * @return A screen mapping as returned by ScreenSpace::toString(). 0144 */ 0145 const QString getScreenSpaceAsString() const; 0146 0147 /** 0148 * Gets the current tracking mode selection. 0149 * 0150 * @return Either "absolute" or "relative". 0151 */ 0152 const QString getTrackingMode() const; 0153 0154 /** 0155 * Checks if auto-rotation or inverted auto-rotation is enabled. 0156 * 0157 * @return True if auto-rotation is enabled, else false. 0158 */ 0159 bool isAutoRotationEnabled() const; 0160 0161 /** 0162 * Check if inverted auto-rotation is enabled. 0163 * 0164 * @return True if inverted auto-rotation is active, else false. 0165 */ 0166 bool isAutoRotateInversionEnabled() const; 0167 0168 /** 0169 * Changes the auto-rotation configuration and updates the widgets. 0170 * 0171 * @param value True to enable auto-rotation, false to disable it. 0172 */ 0173 void setAutoRotationEnabled(bool value); 0174 0175 /** 0176 * Changes the inverted-auto rotation configuration. This will not 0177 * update the auto-rotation flag. 0178 * 0179 * @param value True to enable inverted auto-rotation, false to disable it. 0180 */ 0181 void setAutoRotateInversionEnabled(bool value); 0182 0183 /** 0184 * Sets the auto-rotation settings based on a string in profile format 0185 * and updates all widgets accordingly. Valid values for the parameter 0186 * are all values returned by ScreenRotation::key(). 0187 * 0188 * @param value The new rotation in profile format. 0189 */ 0190 void setRotation(const QString &value); 0191 0192 /** 0193 * Sets a new tablet area mapping and updates all widgets accordingly. 0194 * 0195 * @param screenMap The new tablet to screen mapping. 0196 */ 0197 void setScreenMap(const ScreenMap &screenMap); 0198 0199 /** 0200 * Sets a new tablet area mapping and updates all widgets accordingly. 0201 * The given value has to be in profile format as returned by ScreenMap::toString(). 0202 * 0203 * @param value The new tablet area mapping in profile format. 0204 */ 0205 void setScreenMap(const QString &value); 0206 0207 /** 0208 * Sets a new screen area mapping and updates all widgets accordingly. 0209 * 0210 * @param screenSpace The new screen space mapping selection. 0211 */ 0212 void setScreenSpace(const ScreenSpace &screenSpace); 0213 0214 /** 0215 * Sets a new screen area mapping and updates all widgets accordingly. 0216 * The given value has to be in profile format as returned by ScreenSpace::toString() 0217 * 0218 * @param value The new screen area mapping selection. 0219 */ 0220 void setScreenSpace(const QString &value); 0221 0222 /** 0223 * Sets the tracking mode and updates all widgets accordingly. 0224 * 0225 * @param value Either "absolute" or "relative" 0226 */ 0227 void setTrackingMode(const QString &value); 0228 0229 private: 0230 /** 0231 * Checks if the current tablet mapping is available for the currently selected 0232 * tracking mode. If it is not available, a warning is displayed to the user. 0233 */ 0234 void assertValidTabletMapping(); 0235 0236 /** 0237 * Initializes this widget. Must only be called once by the constructor. 0238 */ 0239 void setupUi(); 0240 0241 private: 0242 Ui::TabletPageWidget *ui; 0243 QString _tabletId; 0244 TabletArea _tabletGeometry; // The full tablet area as rectangle. 0245 ScreenMap _screenMap; // The current tablet to screen mapping of the pad. 0246 ScreenSpace _screenSpace; // The current screen mapping of the pad. 0247 0248 QString _deviceNameStylus; // The Xinput name of the stylus device of the current tablet. 0249 QString _deviceNameTouch; // The Xinput name of the touch device of the current tablet. 0250 0251 }; // CLASS 0252 } // NAMESPACE 0253 #endif // HEADER PROTECTION