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 TABLETAREASELECTIONVIEW_H
0021 #define TABLETAREASELECTIONVIEW_H
0022 
0023 #include "tabletarea.h"
0024 
0025 #include <QObject>
0026 #include <QRect>
0027 #include <QString>
0028 #include <QWidget>
0029 
0030 namespace Wacom
0031 {
0032 
0033 class TabletAreaSelectionViewPrivate;
0034 
0035 /**
0036  * A widget which displays the current screen area selection and lets
0037  * the user map this selection to a tablet area.
0038  */
0039 class TabletAreaSelectionView : public QWidget
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044     explicit TabletAreaSelectionView(QWidget *parent = nullptr);
0045 
0046     ~TabletAreaSelectionView() override;
0047 
0048     /**
0049      * @return The current selection as rectangle.
0050      */
0051     const TabletArea getSelection() const;
0052 
0053     /**
0054      * Selects all of the tablet.
0055      */
0056     void selectFullTablet();
0057 
0058     /**
0059      * Selects part of the tablet.
0060      *
0061      * @param selection The part to select, may not be empty.
0062      */
0063     void selectPartOfTablet(const TabletArea &selection);
0064 
0065     /**
0066      * Switches to the given screen and selects the given tablet region.
0067      *
0068      * @param output The name of the screen to switch to.
0069      * @param isDesktop Whether the screen is a desktop screen.
0070      * @param tabletSelection The selection to set on the tablet.
0071      */
0072     void select(QString output, bool isDesktop, const TabletArea &tabletSelection);
0073 
0074     /**
0075      * Shows or hides a warning that the current selection is only
0076      * available in absolute tracking mode.
0077      *
0078      * @param doShow If true the warning is displayed, else it is hidden.
0079      */
0080     void setTrackingModeWarning(bool doShow);
0081 
0082     /**
0083      * Sets up the screen area widget.
0084      *
0085      * @param screenGeometries The X11 geometries of the connected screens.
0086      * @param widgetTargetSize The target size of the screen area widget.
0087      */
0088     void setupScreens(const QMap<QString, QRect> &screenGeometries, const QSize &widgetTargetSize);
0089 
0090     /**
0091      * Sets up the tablet area widget.
0092      *
0093      * @param geometry The geometry of the tablet.
0094      * @param widgetTargetSize The target size of the tablet area widget.
0095      */
0096     void setupTablet(const TabletArea &geometry, const QSize &widgetTargetSize);
0097 
0098 public slots:
0099 
0100     /**
0101      * Called by the UI when the user wants to calibrate the current device.
0102      */
0103     void onCalibrateClicked();
0104 
0105     /**
0106      * Called by the UI when the user wants to adjust the selection to the screen proportions.
0107      */
0108     void onForceProportionsClicked();
0109 
0110     /**
0111      * Called by the UI when the user wants to select the full tablet area.
0112      */
0113     void onFullTabletSelected(bool checked);
0114 
0115     /**
0116      * Called by the UI when the user wants to toggle the screen.
0117      */
0118     void onScreenToggle();
0119 
0120     /**
0121      * Called by the UI when the user wants to select an area of the tablet.
0122      */
0123     void onTabletAreaSelected(bool checked);
0124 
0125     /**
0126      * @brief onLockProportionsToggled
0127      * @param enabled
0128      */
0129     void onLockProportionsToggled(bool enabled);
0130 
0131     void onSelectionChanged();
0132 
0133     void onFineTuneValuesChanged(QString);
0134 
0135 signals:
0136 
0137     /**
0138      * Signals the controller that the user wants to calibrate the tablet.
0139      */
0140     void signalCalibrateClicked();
0141 
0142     /**
0143      * Signals the controller that the user selected the full tablet area.
0144      */
0145     void signalFullTabletSelection();
0146 
0147     /**
0148      * Signals the controller that the user wants to toggle the screen.
0149      */
0150     void signalScreenToggle();
0151 
0152     /**
0153      * Signals the controller that the user wants to set screen proportions.
0154      */
0155     void signalSetScreenProportions();
0156 
0157     /**
0158      * Signals the controller that the user selected a tablet area.
0159      */
0160     void signalTabletAreaSelection();
0161 
0162 protected:
0163     /**
0164      * The available mapping types for the tablet.
0165      */
0166     enum TabletAreaType {
0167         FullTabletArea, //!< Enables full desktop selection.
0168         PartialTabletArea //!< Enables area selection.
0169     };
0170 
0171     /**
0172      * Sets a selection on the tablet based on the given geometry.
0173      * This does not update any other widgets. It only tells the
0174      * area widget to select the specified area. However a check
0175      * is done if the selection is valid. If it is invalid, the full
0176      * area will be selected.
0177      *
0178      * @param selection The geometry of the new selection.
0179      */
0180     void setSelection(const TabletArea &selection);
0181 
0182     /**
0183      * Sets the given mapping type and updates the widgets
0184      * and the selection.
0185      *
0186      * @param type The new mapping type.
0187      */
0188     void setTabletAreaType(TabletAreaType type);
0189 
0190 private:
0191     /**
0192      * Checks if the given selection selects the full tablet area.
0193      *
0194      * @param selection The selection to check.
0195      *
0196      * @return True if the given selection selects the full tablet area, else false.
0197      */
0198     bool isFullAreaSelection(const TabletArea &selection) const;
0199 
0200     /**
0201      * Sets up this widget. Must only be called once by the constructor.
0202      */
0203     void setupUi();
0204 
0205     Q_DECLARE_PRIVATE(TabletAreaSelectionView)
0206     TabletAreaSelectionViewPrivate *const d_ptr; //!< D-Pointer for this class.
0207 
0208 }; // CLASS
0209 } // NAMESPACE
0210 #endif // HEADER PROTECTION