Krita Source Code Documentation
Loading...
Searching...
No Matches
KisStrokeShortcut Class Reference

#include <kis_stroke_shortcut.h>

+ Inheritance diagram for KisStrokeShortcut:

Public Member Functions

QMouseEvent fakeEndEvent (const QPointF &localPos) const
 
 KisStrokeShortcut (KisAbstractInputAction *action, int index)
 
bool matchBegin (Qt::MouseButton button)
 
bool matchReady (const QSet< Qt::Key > &modifiers, const QSet< Qt::MouseButton > &buttons)
 
int priority () const override
 
void setButtons (const QSet< Qt::Key > &modifiers, const QSet< Qt::MouseButton > &buttons)
 
 ~KisStrokeShortcut () override
 
- Public Member Functions inherited from KisAbstractShortcut
KisAbstractInputActionaction () const
 
bool isAvailable (KisInputActionGroupsMask mask) const
 
 KisAbstractShortcut (KisAbstractInputAction *action, int index)
 
void setAction (KisAbstractInputAction *action)
 
int shortcutIndex () const
 
virtual ~KisAbstractShortcut ()
 

Public Attributes

QSet< Qt::MouseButton > buttons
 
QSet< Qt::Key > modifiers
 
- Public Attributes inherited from KisAbstractShortcut
KisAbstractInputActionaction
 
int shortcutIndex
 

Private Attributes

Private *const m_d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Protected Member Functions inherited from KisAbstractShortcut
bool compareKeys (const QSet< Qt::Key > &keys1, const QSet< Qt::Key > &keys2)
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

This class represents a shortcut that starts an action that can involve pressing the mouse button and, probably, moving the cursor.

The stroke shortcut may be represented as a simple state machine: It transits between 3 states:

Idle <-> Ready <-> Running

The possibility of transition between Idle <-> Ready is defined with a matchReady() method. The transition Ready <-> Running is defined by matchBegin(). The Ready state is used for showing the user the cursor of the upcoming action and the Running state shows that the action linked to the shortcut should be activated.

Definition at line 15 of file kis_stroke_shortcut.cpp.

Constructor & Destructor Documentation

◆ KisStrokeShortcut()

KisStrokeShortcut::KisStrokeShortcut ( KisAbstractInputAction * action,
int index )

Definition at line 23 of file kis_stroke_shortcut.cpp.

25 m_d(new Private)
26{
27}
KisAbstractInputAction * action
KisAbstractShortcut(KisAbstractInputAction *action, int index)

◆ ~KisStrokeShortcut()

KisStrokeShortcut::~KisStrokeShortcut ( )
override

Definition at line 29 of file kis_stroke_shortcut.cpp.

30{
31 delete m_d;
32}

References m_d.

Member Function Documentation

◆ fakeEndEvent()

QMouseEvent KisStrokeShortcut::fakeEndEvent ( const QPointF & localPos) const

Definition at line 76 of file kis_stroke_shortcut.cpp.

77{
78 Qt::MouseButton button = !m_d->buttons.isEmpty() ? *m_d->buttons.begin() : Qt::NoButton;
79 return QMouseEvent(QEvent::MouseButtonRelease, localPos, button, Qt::NoButton, Qt::NoModifier);
80}
QString button(const QWheelEvent &ev)

References button(), and m_d.

◆ matchBegin()

bool KisStrokeShortcut::matchBegin ( Qt::MouseButton button)

Reports whether the shortcut can transit form the "Ready" to "Running" state. It means that the last button of the shortcut is pressed.

Definition at line 71 of file kis_stroke_shortcut.cpp.

72{
73 return m_d->buttons.contains(button);
74}

References button(), and m_d.

◆ matchReady()

bool KisStrokeShortcut::matchReady ( const QSet< Qt::Key > & modifiers,
const QSet< Qt::MouseButton > & buttons )

Reports whether all but one buttons and modifiers are pressed for the shortcut. Such configuration means that the input manager can show the user that pressing the mouse button will start some action. This can be done with, e.g. changing the cursor.

Definition at line 54 of file kis_stroke_shortcut.cpp.

56{
57 bool modifiersOk =
58 (m_d->modifiers.isEmpty() && action()->canIgnoreModifiers()) ||
59 compareKeys(m_d->modifiers, modifiers);
60
61 if (!modifiersOk || buttons.size() < m_d->buttons.size() - 1) {
62 return false;
63 }
64
65 Q_FOREACH (Qt::MouseButton button, buttons) {
66 if (!m_d->buttons.contains(button)) return false;
67 }
68 return true;
69}
virtual bool canIgnoreModifiers() const
bool compareKeys(const QSet< Qt::Key > &keys1, const QSet< Qt::Key > &keys2)
QSet< Qt::MouseButton > buttons
QSet< Qt::Key > modifiers

References KisAbstractShortcut::action, button(), buttons, KisAbstractInputAction::canIgnoreModifiers(), KisAbstractShortcut::compareKeys(), m_d, and modifiers.

◆ priority()

int KisStrokeShortcut::priority ( ) const
overridevirtual

The priority of the shortcut. The shortcut with the greatest value will be chosen for execution

Implements KisAbstractShortcut.

Definition at line 34 of file kis_stroke_shortcut.cpp.

35{
36 const int maxScore = std::log2((int) Qt::MaxMouseButton);
37 int buttonScore = 0;
38 Q_FOREACH (Qt::MouseButton button, m_d->buttons) {
39 buttonScore += maxScore - std::log2((int) button);
40 }
41
42 return m_d->modifiers.size() * 0xFFFF + buttonScore * 0xFF + action()->priority();
43}

References KisAbstractShortcut::action, button(), m_d, and KisAbstractInputAction::priority().

◆ setButtons()

void KisStrokeShortcut::setButtons ( const QSet< Qt::Key > & modifiers,
const QSet< Qt::MouseButton > & buttons )

Sets the configuration for this shortcut

Parameters
modifierskeyboard keys that should be held for the shortcut to trigger
buttonsmouse buttons that should be pressed (simultaneously) for the shortcut to trigger

Definition at line 45 of file kis_stroke_shortcut.cpp.

47{
48 if (buttons.empty()) return;
49
50 m_d->modifiers = modifiers;
51 m_d->buttons = buttons;
52}

References buttons, m_d, and modifiers.

Member Data Documentation

◆ buttons

QSet<Qt::MouseButton> KisStrokeShortcut::buttons

Definition at line 19 of file kis_stroke_shortcut.cpp.

◆ m_d

Private* const KisStrokeShortcut::m_d
private

Definition at line 69 of file kis_stroke_shortcut.h.

◆ modifiers

QSet<Qt::Key> KisStrokeShortcut::modifiers

Definition at line 18 of file kis_stroke_shortcut.cpp.


The documentation for this class was generated from the following files: