File indexing completed on 2024-05-26 04:30:18

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_STROKE_SHORTCUT_H
0008 #define __KIS_STROKE_SHORTCUT_H
0009 
0010 #include "kis_abstract_shortcut.h"
0011 
0012 class QMouseEvent;
0013 class QPointF;
0014 
0015 /**
0016  * This class represents a shortcut that starts an action that can
0017  * involve pressing the mouse button and, probably, moving the cursor.
0018  *
0019  * The stroke shortcut may be represented as a simple state machine:
0020  * It transits between 3 states:
0021  *
0022  * Idle <-> Ready <-> Running
0023  *
0024  * The possibility of transition between Idle <-> Ready is defined
0025  * with a matchReady() method. The transition Ready <-> Running is
0026  * defined by matchBegin(). The Ready state is used for showing the
0027  * user the cursor of the upcoming action and the Running state shows
0028  * that the action linked to the shortcut should be activated.
0029  */
0030 class KRITAUI_EXPORT KisStrokeShortcut : public KisAbstractShortcut
0031 {
0032 public:
0033     KisStrokeShortcut(KisAbstractInputAction *action, int index);
0034     ~KisStrokeShortcut() override;
0035 
0036     int priority() const override;
0037 
0038     /**
0039      * Sets the configuration for this shortcut
0040      *
0041      * \param modifiers keyboard keys that should be held
0042      *                  for the shortcut to trigger
0043      * \param buttons mouse buttons that should be pressed (simultaneously)
0044      *                for the shortcut to trigger
0045      */
0046     void setButtons(const QSet<Qt::Key> &modifiers,
0047                     const QSet<Qt::MouseButton> &buttons);
0048 
0049     /**
0050      * Reports whether all but one buttons and modifiers are pressed
0051      * for the shortcut. Such configuration means that the input manager
0052      * can show the user that pressing the mouse button will start some
0053      * action. This can be done with, e.g. changing the cursor.
0054      */
0055     bool matchReady(const QSet<Qt::Key> &modifiers,
0056                     const QSet<Qt::MouseButton> &buttons);
0057 
0058     /**
0059      * Reports whether the shortcut can transit form the "Ready"
0060      * to "Running" state. It means that the last button of the shortcut
0061      * is pressed.
0062      */
0063     bool matchBegin(Qt::MouseButton button);
0064 
0065     QMouseEvent fakeEndEvent(const QPointF &localPos) const;
0066 
0067 private:
0068     class Private;
0069     Private * const m_d;
0070 };
0071 
0072 #endif /* __KIS_STROKE_SHORTCUT_H */