File indexing completed on 2025-01-26 05:09:30

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 BUTTONACTIONSELECTIONWIDGET_H
0021 #define BUTTONACTIONSELECTIONWIDGET_H
0022 
0023 #include <QWidget>
0024 
0025 class QCheckBox;
0026 class QKeySequence;
0027 
0028 namespace Ui
0029 {
0030 class ButtonActionSelectionWidget;
0031 }
0032 
0033 namespace Wacom
0034 {
0035 
0036 class ButtonShortcut;
0037 class ButtonActionSelectionWidgetPrivate;
0038 
0039 class ButtonActionSelectionWidget : public QWidget
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044     explicit ButtonActionSelectionWidget(QWidget *parent = nullptr);
0045 
0046     ~ButtonActionSelectionWidget() override;
0047 
0048     /**
0049      * @return The currently selected shortcut.
0050      */
0051     const ButtonShortcut &getShortcut() const;
0052 
0053     /**
0054      * Sets a shortcut.
0055      *
0056      * @param shortcut The shortcut to set.
0057      */
0058     void setShortcut(const ButtonShortcut &shortcut);
0059 
0060 private slots:
0061 
0062     /**
0063      * Called when one of the clear buttons is clicked.
0064      */
0065     void onClearButtonClicked(bool checked);
0066 
0067     /**
0068      * Called when the keyboard shortcut sequence is modified.
0069      */
0070     void onShortcutChanged(QKeySequence sequence);
0071 
0072     /**
0073      * Called when the user tries to select the action text.
0074      */
0075     void onActionLineEditSelectionChanged();
0076 
0077     /**
0078      * Called when the state of a modifier checkbox changes.
0079      */
0080     void onModifierChanged(int state);
0081 
0082     /**
0083      * Called when the mouse button selection was changed.
0084      */
0085     void onMouseSelectionChanged(int index);
0086 
0087 private:
0088     /**
0089      * Sets up the user interface. This should only be called once by the constructor.
0090      */
0091     void setupUi();
0092 
0093     /**
0094      * Determines a name for the current shortcut and updates the
0095      * name widget. This will also take into account global shortcuts.
0096      *
0097      * @param shortcut The current shortcut.
0098      */
0099     void updateCurrentActionName(const ButtonShortcut &shortcut);
0100 
0101     /**
0102      * Updates the modifier selection widgets for the current shortcut.
0103      * While the update is in progress all signals will be blocked.
0104      *
0105      * @param shortcut The current shortcut.
0106      */
0107     void updateModifierWidgets(const ButtonShortcut &shortcut);
0108 
0109     /**
0110      * Updates the mouse button selection for the current shortcut.
0111      * While the update is in progress all signals will be blocked.
0112      *
0113      * @param shortcut The current shortcut.
0114      */
0115     void updateMouseButtonSeletion(const ButtonShortcut &shortcut);
0116 
0117     /**
0118      * Updates the checked state of a  QCheckBox. While the
0119      * update is in progress all signals will be blocked.
0120      *
0121      * @param checkbox The checkbox to update.
0122      * @param isChecked A flag to signal if the checkbox is checked.
0123      */
0124     void updateQCheckBox(QCheckBox &checkbox, bool isChecked) const;
0125 
0126     /**
0127      * Updates the keyboard shortcut widget according to the current shortcut.
0128      * While the update is in progress all shortcut widgets will be blocked.
0129      *
0130      * @param shortcut The current shortcut.
0131      */
0132     void updateShortcutWidgets(const ButtonShortcut &shortcut);
0133 
0134     Q_DECLARE_PRIVATE(ButtonActionSelectionWidget)
0135     ButtonActionSelectionWidgetPrivate *const d_ptr; //!< D-Pointer for this class.
0136 
0137 }; // CLASS
0138 } // NAMESPACE
0139 #endif // HEADER PROTECTION