File indexing completed on 2024-12-22 05:17:21

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 TABLETHANDLER_H
0021 #define TABLETHANDLER_H
0022 
0023 #include "property.h"
0024 #include "screenrotation.h"
0025 #include "tablethandlerinterface.h"
0026 #include "tabletinformation.h"
0027 
0028 #include <QObject>
0029 #include <QString>
0030 #include <QStringList>
0031 
0032 class QScreen;
0033 
0034 namespace Wacom
0035 {
0036 class ScreenSpace;
0037 class TabletProfile;
0038 class TabletHandlerPrivate;
0039 
0040 class TabletHandler : public TabletHandlerInterface
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     TabletHandler();
0046 
0047     /**
0048      * A constructor used for unit testing.
0049      *
0050      * @param profileFile The full path to the profiles configuration file.
0051      * @param configFile  The full path to the main configuration file.
0052      */
0053     TabletHandler(const QString &profileFile, const QString configFile);
0054 
0055     ~TabletHandler() override;
0056 
0057     /**
0058      * returns the current value for a specific tablet setting
0059      * This is forwarded to the right backend specified by m_curDevice
0060      *
0061      * @param tabletId The id of the tablet where the property should be fetched from
0062      * @param deviceType name of the tablet device we set. Internal name of the pad/stylus/eraser/cursor
0063      * @param property the property we are looking for
0064      *
0065      * @return the value as string
0066      */
0067     QString getProperty(const QString &tabletId, const DeviceType &deviceType, const Property &property) const override;
0068 
0069     /**
0070      * @brief Reads a list of all available profiles from the profile manager.
0071      *
0072      * @param tabletId The id of the tablet which shall be queried
0073      * @return the list of all available profiles
0074      */
0075     QStringList listProfiles(const QString &tabletId) override;
0076 
0077     /**
0078      * @brief Applies a profile to the tablet device
0079      *
0080      * The profile must be known to the profile manager, otherwise a
0081      * notification error is displayed.
0082      *
0083      * @param tabletId The id of the tablet for which the profile shall be set
0084      * @param profile The name of the profile to apply.
0085      */
0086     void setProfile(const QString &tabletId, const QString &profile) override;
0087 
0088     /**
0089      * Sets the configuration of @p param from @p device with @p value
0090      * This is forwarded to the right backend specified by m_curDevice
0091      *
0092      * @param tabletId The identifier of the device to set the property on.
0093      * @param deviceType The type of the device to set the property on.
0094      * @param property The property to set.
0095      * @param value    New value of the parameter
0096      */
0097     void setProperty(const QString &tabletId, const DeviceType &deviceType, const Property &property, const QString &value) override;
0098 
0099     QStringList getProfileRotationList(const QString &tabletId) override;
0100 
0101     void setProfileRotationList(const QString &tabletId, const QStringList &rotationList) override;
0102 
0103 public Q_SLOTS:
0104     /**
0105      * @brief Handles the connection of a new tablet device.
0106      *
0107      * This slot has to be connected to the X device event notifier and
0108      * executed when a new tablet device is plugged in.
0109      *
0110      * @param info The device info as reported by X11.
0111      */
0112     void onTabletAdded(const TabletInformation &info);
0113 
0114     /**
0115      * @brief Handles the removal of a tablet device.
0116      *
0117      * This slot has to be connected to the X device event notifier and
0118      * executed when a tablet is disconnected from the system.
0119      *
0120      * @param info The device info as reported by X11.
0121      */
0122     void onTabletRemoved(const TabletInformation &info);
0123 
0124     /**
0125      * @brief Handles rotating the tablet.
0126      *
0127      * This slot has to be connected to the X event notifier and executed
0128      * when the screen is rotated.
0129      *
0130      * @param output Name of the screen that has been rotated.
0131      * @param newScreenRotation The screen rotation.
0132      */
0133     void onScreenRotated(QString output, const Qt::ScreenOrientation &newScreenRotation);
0134 
0135     /**
0136      * @brief Handles screens being connected and disconnected
0137      * @param screen Screen being connected or disconnected
0138      */
0139     void onScreenAddedRemoved(QScreen *screen);
0140 
0141     /**
0142      * @brief Handles changes in existing screen's geometry
0143      */
0144     void onScreenGeometryChanged();
0145 
0146     /**
0147      * Toggles the stylus/eraser to absolute/relative mode
0148      */
0149     void onTogglePenMode();
0150 
0151     /**
0152      * Toggles the touch tool on/off
0153      */
0154     void onToggleTouch();
0155 
0156     /**
0157      * @brief Toggles to which screen the stylus/eraser/touch will be mapped
0158      *
0159      * the order is
0160      * @li full
0161      * @li screen1
0162      * @li screen2
0163      */
0164     void onToggleScreenMapping();
0165 
0166     /**
0167      * @brief Maps stylus/eraser/touch to the full available screen space
0168      *
0169      * in xsetwacom file
0170      *  @li copies AreaMapFull to Area
0171      *  @li sets ScreenSpace=full
0172      */
0173     void onMapToFullScreen();
0174 
0175     /**
0176      * @brief Maps stylus/eraser/touch to the second screen
0177      *
0178      * in xsetwacom file
0179      *  @li copies AreaMap0 to Area in
0180      *  @li sets MapToOutput=0
0181      *  @li sets ScreenSpace=map0
0182      */
0183     void onMapToScreen1();
0184 
0185     /**
0186      * @brief Maps stylus/eraser/touch to the second screen
0187      *
0188      * in xsetwacom file
0189      *  @li copies AreaMap1 to Area in
0190      *  @li sets MapToOutput=1
0191      *  @li sets ScreenSpace=map1
0192      */
0193     void onMapToScreen2();
0194 
0195     /**
0196      * @brief Switch to the next profile in the rotation list
0197      */
0198     void onNextProfile();
0199 
0200     /**
0201      * @brief Switch to the previous profile in the rotation list
0202      */
0203     void onPreviousProfile();
0204 
0205 Q_SIGNALS:
0206     /**
0207      * Emitted if the user should be notified.
0208      */
0209     void notify(const QString &eventId, const QString &title, const QString &message, bool suggestConfigure);
0210 
0211     /**
0212      * Emitted when the profile of the current tablet is changed.
0213      *
0214      * @param tabletId The identifier of the tablet.
0215      * @param profile The name of the new active profile.
0216      */
0217     void profileChanged(const QString &tabletId, const QString &profile);
0218 
0219     /**
0220      * Emitted when a new tablet is connected or if the currently active tablet changes.
0221      */
0222     void tabletAdded(const TabletInformation &info);
0223 
0224     /**
0225      * Emitted when the currently active tablet is removed.
0226      */
0227     void tabletRemoved(const QString &tabletId);
0228 
0229 private:
0230     /**
0231      * Auto rotates the tablet if auto-rotation is enabled. If auto-rotation
0232      * is disabled, the tablet's rotation settings will be left untouched.
0233      *
0234      * @param tabletId The id of the Tablet that will be used
0235      * @param tabletProfile  The tablet profile to read the rotation settings from.
0236      * @param output Name of the screen that has been rotated. Empty string means scan all devices.
0237      * @param screenRotation Rotation of the screen specified by screenIndex.
0238      */
0239     void autoRotateTablet(const QString &tabletId,
0240                           const TabletProfile &tabletProfile,
0241                           QString output = QString(),
0242                           ScreenRotation screenRotations = ScreenRotation::NONE);
0243 
0244     /**
0245      * Checks if the current tablet supports the given device type.
0246      *
0247      * @param tabletId The id of the Tablet that will be checked
0248      * @param type The device type to check for.
0249      *
0250      * @return True if the tablet supports the given device, else false.
0251      */
0252     bool hasDevice(const QString &tabletId, const DeviceType &type) const;
0253 
0254     /**
0255      * Checks if there currently is a tablet available.
0256      *
0257      * @param tabletId The id of the Tablet that will be checked
0258      * @return True if a tablet is available, else false.
0259      */
0260     bool hasTablet(const QString &tabletId) const;
0261 
0262     /**
0263      * Maps a tablet device to a screen and updated its profile.
0264      * However the profile will not be saved, only updated with
0265      * the new settings.
0266      *
0267      * @param tabletId The id of the Tablet that will be altered
0268      * @param device The device to map.
0269      * @param screepSpace The screen space to map the device to.
0270      * @param trackingMode The tracking mode to apply.
0271      * @param tabletProfile The profile to update.
0272      */
0273     void mapDeviceToOutput(const QString &tabletId,
0274                            const Wacom::DeviceType &device,
0275                            const ScreenSpace &screenSpace,
0276                            const QString &trackingMode,
0277                            TabletProfile &tabletProfile);
0278 
0279     /**
0280      * Maps the stylus, eraser and touch device to the given output and
0281      * updates the profiles accordingly. If no mapping is configured the
0282      * device is mapped to the full desktop.
0283      *
0284      * @param tabletId The id of the Tablet that will be altered
0285      * @param output A string returned by ScreenSpace::toString()
0286      */
0287     void mapPenToScreenSpace(const QString &tabletId, const ScreenSpace &screenSpace, const QString &trackingMode = QLatin1String("absolute"));
0288 
0289     /**
0290      * Maps stylus/eraser/touch to their current screen space.
0291      * The tablet profile will be saved after the operation is complete.
0292      *
0293      * @param tabletId The id of the Tablet that will be altered
0294      * @param tabletProfile The tablet profile to use.
0295      */
0296     void mapTabletToCurrentScreenSpace(const QString &tabletId, TabletProfile &tabletProfile);
0297 
0298     Q_DECLARE_PRIVATE(TabletHandler)
0299     TabletHandlerPrivate *const d_ptr; /**< d-pointer for this class */
0300 
0301 }; // CLASS
0302 } // NAMESPACE
0303 #endif // HEADER PROTECTION