Warning, file /graphics/krita/libs/ui/input/config/kis_input_button.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * This file is part of the KDE project
0003  * SPDX-FileCopyrightText: 2013 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #ifndef KISINPUTBUTTON_H
0009 #define KISINPUTBUTTON_H
0010 
0011 #include <QPushButton>
0012 
0013 #include "input/kis_shortcut_configuration.h"
0014 
0015 /**
0016  * \brief A button that can detect input and will store its value.
0017  *
0018  * This button, when pressed, will detect input based on what type has been set.
0019  * It is mainly intended for shortcut configuration, that is, picking some input that is
0020  * later reused for shortcuts or similar.
0021  *
0022  */
0023 class KisInputButton : public QPushButton
0024 {
0025     Q_OBJECT
0026 public:
0027     /**
0028      * The type of button.
0029      */
0030     enum ButtonType {
0031         MouseType, ///< Detect and store any combination of pressed mouse buttons.
0032         KeyType, ///< Detect and store any combination of key presses.
0033         WheelType, ///< Detect and store mouse wheel movement.
0034     };
0035 
0036     /**
0037      * Constructor.
0038      */
0039     explicit KisInputButton(QWidget *parent = nullptr);
0040     /**
0041      * Destructor.
0042      */
0043     ~KisInputButton() override;
0044 
0045     /**
0046      * \return The type of input this button detects.
0047      */
0048     ButtonType type() const;
0049     /**
0050      * Set the type of input this button should detect.
0051      *
0052      * \param newType The type of input to detect.
0053      */
0054     void setType(ButtonType newType);
0055 
0056     /**
0057      * \return The list of keys that was detected. Only applicable when type is `KeyType`.
0058      */
0059     QList<Qt::Key> keys() const;
0060     /**
0061      * Set the list of keys to display.
0062      *
0063      * This is mostly intended to make sure the button displays the right keys when viewed
0064      * in a dialog or similar UI.
0065      *
0066      * Only applicable when type is `KeyType`.
0067      *
0068      * \param newKeys The list of keys to display.
0069      */
0070     void setKeys(const QList<Qt::Key> &newKeys);
0071 
0072     /**
0073      * \return The mouse buttons that were detected. Only applicable when type is `MouseType`.
0074      */
0075     Qt::MouseButtons buttons() const;
0076     /**
0077      * Set the mouse buttons to display.
0078      *
0079      * This is mostly intended to make sure the button displays the right buttons when viewed
0080      * in a dialog or similar UI.
0081      *
0082      * Only applicable when type is `MouseType`.
0083      *
0084      * \param newButtons The mouse buttons to display.
0085      */
0086     void setButtons(Qt::MouseButtons newButtons);
0087 
0088     /**
0089      * \return The mouse wheel movement that was detected. Only applicable when type is `WheelType`.
0090      */
0091     KisShortcutConfiguration::MouseWheelMovement wheel() const;
0092     /**
0093      * Set the mouse wheel movement to display.
0094      *
0095      * This is mostly intended to make sure the button displays the right wheel movement when
0096      * viewed in a dialog or similar UI.
0097      *
0098      * Only applicable when type is `WheelType`.
0099      *
0100      * \param wheel The wheel movement to display.
0101      */
0102     void setWheel(KisShortcutConfiguration::MouseWheelMovement wheel);
0103 
0104 public Q_SLOTS:
0105     /**
0106      * Clear all detected input and reset the button to an empty state.
0107      */
0108     void clear();
0109 
0110 Q_SIGNALS:
0111     /**
0112      * Emitted whenever one of the values (keys, buttons, wheel) changes.
0113      */
0114     void dataChanged();
0115 
0116 protected:
0117     void mousePressEvent(QMouseEvent *event) override;
0118     void mouseReleaseEvent(QMouseEvent *) override;
0119     void wheelEvent(QWheelEvent *event) override;
0120     void keyPressEvent(QKeyEvent *event) override;
0121     void keyReleaseEvent(QKeyEvent *event) override;
0122 
0123 private Q_SLOTS:
0124     void reset();
0125 
0126 private:
0127     class Private;
0128     Private *const d {nullptr};
0129 };
0130 
0131 #endif // KISINPUTBUTTON_H