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

#include <kis_single_action_shortcut.h>

+ Inheritance diagram for KisSingleActionShortcut:

Public Types

enum  WheelAction {
  WheelUp , WheelDown , WheelLeft , WheelRight ,
  WheelTrackpad
}
 

Public Member Functions

bool conflictsWith (const QKeySequence &seq)
 
 KisSingleActionShortcut (KisAbstractInputAction *action, int index)
 
bool match (const QSet< Qt::Key > &modifiers, Qt::Key key)
 
bool match (const QSet< Qt::Key > &modifiers, WheelAction wheelAction)
 
int priority () const override
 
void setKey (const QSet< Qt::Key > &modifiers, Qt::Key key)
 
void setWheel (const QSet< Qt::Key > &modifiers, WheelAction wheelAction)
 
 ~KisSingleActionShortcut () 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

Qt::Key key
 
QSet< Qt::Key > modifiers
 
bool useWheel
 
WheelAction wheelAction
 
- 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 executes a simple atomic action. It can be initiated either by a keyboard hotkey or by a mouse wheel rotation.

Definition at line 13 of file kis_single_action_shortcut.cpp.

Member Enumeration Documentation

◆ WheelAction

Enumerator
WheelUp 

Mouse wheel moves up.

WheelDown 

Mouse wheel moves down.

WheelLeft 

Mouse wheel moves left.

WheelRight 

Mouse wheel moves right.

WheelTrackpad 

A pan movement on a trackpad.

Definition at line 21 of file kis_single_action_shortcut.h.

21 {
22 WheelUp,
23 WheelDown,
24 WheelLeft,
27 };
@ WheelDown
Mouse wheel moves down.
@ WheelTrackpad
A pan movement on a trackpad.
@ WheelRight
Mouse wheel moves right.
@ WheelLeft
Mouse wheel moves left.

Constructor & Destructor Documentation

◆ KisSingleActionShortcut()

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

Definition at line 23 of file kis_single_action_shortcut.cpp.

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

◆ ~KisSingleActionShortcut()

KisSingleActionShortcut::~KisSingleActionShortcut ( )
override

Definition at line 29 of file kis_single_action_shortcut.cpp.

30{
31 delete m_d;
32}

References m_d.

Member Function Documentation

◆ conflictsWith()

bool KisSingleActionShortcut::conflictsWith ( const QKeySequence & seq)

Check is the shortcut or the key sequence is a prefix of one another

Definition at line 65 of file kis_single_action_shortcut.cpp.

66{
67 if (seq.isEmpty()) return false;
68
69 int seqMainKey = seq[0];
70 QVector<int> sequenceKeys;
71
72 if (seqMainKey & Qt::MetaModifier) {
73 sequenceKeys.append(Qt::Key_Meta);
74 seqMainKey &= ~Qt::MetaModifier;
75 } else if (seqMainKey & Qt::ControlModifier) {
76 sequenceKeys.append(Qt::Key_Control);
77 seqMainKey &= ~Qt::ControlModifier;
78 } else if (seqMainKey & Qt::ShiftModifier) {
79 sequenceKeys.append(Qt::Key_Shift);
80 seqMainKey &= ~Qt::ShiftModifier;
81 } else if (seqMainKey & Qt::AltModifier) {
82 sequenceKeys.append(Qt::Key_Alt);
83 seqMainKey &= ~Qt::AltModifier;
84 }
85
86 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(seqMainKey != 0, false);
87 sequenceKeys.append(seqMainKey);
88 std::sort(sequenceKeys.begin(), sequenceKeys.end());
89
90 QVector<int> shortcutKeys;
91 std::copy(m_d->modifiers.begin(), m_d->modifiers.end(), std::back_inserter(shortcutKeys));
92 shortcutKeys.append(m_d->key);
93 std::sort(shortcutKeys.begin(), shortcutKeys.end());
94
95 return
96 std::includes(sequenceKeys.begin(), sequenceKeys.end(),
97 shortcutKeys.begin(), shortcutKeys.end()) ||
98 std::includes(shortcutKeys.begin(), shortcutKeys.end(),
99 sequenceKeys.begin(), sequenceKeys.end());
100}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, and m_d.

◆ match() [1/2]

bool KisSingleActionShortcut::match ( const QSet< Qt::Key > & modifiers,
Qt::Key key )

Definition at line 53 of file kis_single_action_shortcut.cpp.

54{
55 return !m_d->useWheel && key == m_d->key &&
56 compareKeys(modifiers, m_d->modifiers);
57}
bool compareKeys(const QSet< Qt::Key > &keys1, const QSet< Qt::Key > &keys2)

References KisAbstractShortcut::compareKeys(), key, m_d, and modifiers.

◆ match() [2/2]

bool KisSingleActionShortcut::match ( const QSet< Qt::Key > & modifiers,
WheelAction wheelAction )

Definition at line 59 of file kis_single_action_shortcut.cpp.

60{
61 return m_d->useWheel && wheelAction == m_d->wheelAction &&
62 compareKeys(modifiers, m_d->modifiers);
63}

References KisAbstractShortcut::compareKeys(), m_d, modifiers, and wheelAction.

◆ priority()

int KisSingleActionShortcut::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_single_action_shortcut.cpp.

35{
36 return m_d->modifiers.size() * 2 + 1 + action()->priority();
37}

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

◆ setKey()

void KisSingleActionShortcut::setKey ( const QSet< Qt::Key > & modifiers,
Qt::Key key )

Definition at line 39 of file kis_single_action_shortcut.cpp.

40{
41 m_d->modifiers = modifiers;
42 m_d->key = key;
43 m_d->useWheel = false;
44}

References key, m_d, and modifiers.

◆ setWheel()

void KisSingleActionShortcut::setWheel ( const QSet< Qt::Key > & modifiers,
WheelAction wheelAction )

Definition at line 46 of file kis_single_action_shortcut.cpp.

47{
48 m_d->modifiers = modifiers;
49 m_d->wheelAction = wheelAction;
50 m_d->useWheel = true;
51}

References m_d, modifiers, and wheelAction.

Member Data Documentation

◆ key

Qt::Key KisSingleActionShortcut::key

Definition at line 17 of file kis_single_action_shortcut.cpp.

◆ m_d

Private* const KisSingleActionShortcut::m_d
private

Definition at line 47 of file kis_single_action_shortcut.h.

◆ modifiers

QSet<Qt::Key> KisSingleActionShortcut::modifiers

Definition at line 16 of file kis_single_action_shortcut.cpp.

◆ useWheel

bool KisSingleActionShortcut::useWheel

Definition at line 18 of file kis_single_action_shortcut.cpp.

◆ wheelAction

WheelAction KisSingleActionShortcut::wheelAction

Definition at line 19 of file kis_single_action_shortcut.cpp.


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