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

#include <KisShortcutsEditor_p.h>

+ Inheritance diagram for KisShortcutsEditorItem:

Public Member Functions

void commit ()
 Commit the changes.
 
QVariant data (int column, int role=Qt::DisplayRole) const override
 
bool isModified () const
 
bool isModified (uint column) const
 
QKeySequence keySequence (uint column) const
 
 KisShortcutsEditorItem (QTreeWidgetItem *parent, QAction *action)
 
bool operator< (const QTreeWidgetItem &other) const override
 
void setKeySequence (uint column, const QKeySequence &seq)
 
void setNameBold (bool flag)
 
void undo ()
 Undo the changes since the last commit.
 
 ~KisShortcutsEditorItem () override
 Destructor will erase unsaved changes.
 

Private Member Functions

void updateModified ()
 Recheck modified status - could have changed back to initial value.
 

Private Attributes

QAction * m_action
 The action this item is responsible for.
 
QString m_actionNameInTable
 The localized action name.
 
QCollator m_collator
 The collator, for sorting.
 
QString m_id
 The action id. Needed for exporting and importing.
 
bool m_isNameBold {false}
 Should the Name column be painted in bold?
 
QList< QKeySequence > * m_oldLocalShortcut {0}
 The original shortcuts before user changes. 0 means no change.
 

Friends

class KisShortcutsEditorPrivate
 

Detailed Description

A QTreeWidgetItem that can handle QActions. It also provides undo functionality.

Call commit() to save pending changes.

Definition at line 118 of file KisShortcutsEditor_p.h.

Constructor & Destructor Documentation

◆ KisShortcutsEditorItem()

KisShortcutsEditorItem::KisShortcutsEditorItem ( QTreeWidgetItem * parent,
QAction * action )

Definition at line 21 of file KisShortcutsEditorItem.cpp.

22 : QTreeWidgetItem(parent, ActionItem)
23 , m_action(action)
24{
25 // Filtering message requested by translators (scripting).
26 m_id = m_action->objectName();
27 m_actionNameInTable = i18nc("@item:intable Action name in shortcuts configuration",
28 "%1", KLocalizedString::removeAcceleratorMarker(m_action->text()));
29 if (m_actionNameInTable.isEmpty()) {
30 warnKrita << "Action without text!" << m_action->objectName();
32 }
33
34 m_collator.setNumericMode(true);
35 m_collator.setCaseSensitivity(Qt::CaseSensitive);
36
37 // qDebug() << "Adding new action" << m_id << "with shortcut" << keySequence(LocalPrimary).toString();
38}
QAction * m_action
The action this item is responsible for.
QString m_id
The action id. Needed for exporting and importing.
QCollator m_collator
The collator, for sorting.
QString m_actionNameInTable
The localized action name.
#define warnKrita
Definition kis_debug.h:87

References m_action, m_actionNameInTable, m_collator, m_id, and warnKrita.

◆ ~KisShortcutsEditorItem()

KisShortcutsEditorItem::~KisShortcutsEditorItem ( )
override

Destructor will erase unsaved changes.

Definition at line 40 of file KisShortcutsEditorItem.cpp.

41{
42 delete m_oldLocalShortcut;
43}
QList< QKeySequence > * m_oldLocalShortcut
The original shortcuts before user changes. 0 means no change.

References m_oldLocalShortcut.

Member Function Documentation

◆ commit()

void KisShortcutsEditorItem::commit ( )

Commit the changes.

Definition at line 226 of file KisShortcutsEditorItem.cpp.

227{
228 if (m_oldLocalShortcut) { // || m_oldShapeGesture || m_oldRockerGesture) {
229 dbgUI << "Committing changes for " << data(Name, Qt::DisplayRole).toString();
230 }
231
232 delete m_oldLocalShortcut;
234}
QVariant data(int column, int role=Qt::DisplayRole) const override
#define dbgUI
Definition kis_debug.h:52

References data(), dbgUI, m_oldLocalShortcut, and Name.

◆ data()

QVariant KisShortcutsEditorItem::data ( int column,
int role = Qt::DisplayRole ) const
override

Definition at line 50 of file KisShortcutsEditorItem.cpp.

51{
52 switch (role) {
53 case Qt::DisplayRole:
54 switch (column) {
55 case Name:
57 case Id:
58 return m_id;
59 case LocalPrimary:
60 case LocalAlternate:
61 return QVariant::fromValue(keySequence(column));
62 default:
63 break;
64 }
65 break;
66 case Qt::DecorationRole:
67 if (column == Name) {
68 return m_action->icon();
69 } else {
70 return QIcon();
71 }
72 break;
73 case Qt::WhatsThisRole:
74 return m_action->whatsThis();
75 case Qt::ToolTipRole:
76 // TODO: show command descriptions/tooltips in the shortcut editor
77 return QVariant();
78 case Qt::FontRole:
79 if (column == Name && m_isNameBold) {
80 QFont modifiedFont = treeWidget()->font();
81 modifiedFont.setBold(true);
82 return modifiedFont;
83 }
84 break;
85 case KExtendableItemDelegate::ShowExtensionIndicatorRole:
86 switch (column) {
87 case Name:
88 return false;
89 case LocalPrimary:
90 case LocalAlternate:
91 return !m_action->property("isShortcutConfigurable").isValid()
92 || m_action->property("isShortcutConfigurable").toBool();
93 default:
94 return false;
95 }
96 //the following are custom roles, defined in this source file only
97 case ShortcutRole:
98 switch (column) {
99 case LocalPrimary:
100 case LocalAlternate:
101 return QVariant::fromValue(keySequence(column));
102 default:
103 // Column not valid for this role
104 Q_ASSERT(false);
105 return QVariant();
106 }
107
108 case DefaultShortcutRole: {
109
110 // Note: we are using the QMetaObject system to store this property.
111 QList<QKeySequence> defaultShortcuts = m_action->property("defaultShortcuts").value<QList<QKeySequence> >();
112
113 switch (column) {
114 case LocalPrimary:
115 return QVariant::fromValue(primarySequence(defaultShortcuts));
116 case LocalAlternate:
117 return QVariant::fromValue(alternateSequence(defaultShortcuts));
118 default:
119 // Column not valid for this role
120 Q_ASSERT(false);
121 return QVariant();
122 }
123 }
124 case ObjectRole:
125 return QVariant::fromValue((QObject *)m_action);
126
127 default:
128 break;
129 }
130
131 return QVariant();
132}
QKeySequence alternateSequence(const QList< QKeySequence > &sequences)
QKeySequence primarySequence(const QList< QKeySequence > &sequences)
@ ShortcutRole
@ DefaultShortcutRole
@ LocalAlternate
@ LocalPrimary
bool m_isNameBold
Should the Name column be painted in bold?
QKeySequence keySequence(uint column) const

References alternateSequence(), DefaultShortcutRole, Id, keySequence(), LocalAlternate, LocalPrimary, m_action, m_actionNameInTable, m_id, m_isNameBold, Name, ObjectRole, primarySequence(), and ShortcutRole.

◆ isModified() [1/2]

bool KisShortcutsEditorItem::isModified ( ) const

Definition at line 45 of file KisShortcutsEditorItem.cpp.

46{
47 return m_oldLocalShortcut;
48}

References m_oldLocalShortcut.

◆ isModified() [2/2]

bool KisShortcutsEditorItem::isModified ( uint column) const

Definition at line 194 of file KisShortcutsEditorItem.cpp.

195{
196 switch (column) {
197 case Name:
198 return false;
199 case LocalPrimary:
200 case LocalAlternate:
201 if (!m_oldLocalShortcut) {
202 return false;
203 }
204 if (column == LocalPrimary) {
206 } else {
208 }
209 default:
210 return false;
211 }
212}

References alternateSequence(), LocalAlternate, LocalPrimary, m_action, m_oldLocalShortcut, Name, and primarySequence().

◆ keySequence()

QKeySequence KisShortcutsEditorItem::keySequence ( uint column) const

Definition at line 140 of file KisShortcutsEditorItem.cpp.

141{
142 QList<QKeySequence> shortcuts = m_action->shortcuts();
143
144 switch (column) {
145 case LocalPrimary:
146 return primarySequence(shortcuts);
147 case LocalAlternate:
148 return alternateSequence(shortcuts);
149 default:
150 return QKeySequence();
151 }
152}

References alternateSequence(), LocalAlternate, LocalPrimary, m_action, and primarySequence().

◆ operator<()

bool KisShortcutsEditorItem::operator< ( const QTreeWidgetItem & other) const
override

Definition at line 134 of file KisShortcutsEditorItem.cpp.

135{
136 const int column = treeWidget() ? treeWidget()->sortColumn() : 0;
137 return m_collator.compare(text(column), other.text(column)) < 0;
138}

References m_collator.

◆ setKeySequence()

void KisShortcutsEditorItem::setKeySequence ( uint column,
const QKeySequence & seq )

Definition at line 154 of file KisShortcutsEditorItem.cpp.

155{
157 ks = m_action->shortcuts();
158 if (!m_oldLocalShortcut) {
160 }
161
162 if (column == LocalAlternate) {
163 if (ks.isEmpty()) {
164 ks << QKeySequence();
165 }
166
167 if (ks.size() <= 1) {
168 ks << seq;
169 } else {
170 ks[1] = seq;
171 }
172 } else {
173 if (ks.isEmpty()) {
174 ks << seq;
175 } else {
176 ks[0] = seq;
177 }
178 }
179
180 m_action->setShortcuts(ks);
181
183}
void updateModified()
Recheck modified status - could have changed back to initial value.

References LocalAlternate, m_action, m_oldLocalShortcut, and updateModified().

◆ setNameBold()

void KisShortcutsEditorItem::setNameBold ( bool flag)
inline

Definition at line 142 of file KisShortcutsEditor_p.h.

143 {
144 m_isNameBold = flag;
145 }

References m_isNameBold.

◆ undo()

void KisShortcutsEditorItem::undo ( )

Undo the changes since the last commit.

Definition at line 214 of file KisShortcutsEditorItem.cpp.

215{
216 //dbgKrita << "Undoing changes for " << data(Name, Qt::DisplayRole).toString();
217
218 if (m_oldLocalShortcut) {
219 // We only ever reset the active Shortcut
220 m_action->setShortcuts(*m_oldLocalShortcut);
221 }
222
224}

References m_action, m_oldLocalShortcut, and updateModified().

◆ updateModified()

void KisShortcutsEditorItem::updateModified ( )
private

Recheck modified status - could have changed back to initial value.

Definition at line 186 of file KisShortcutsEditorItem.cpp.

187{
188 if (m_oldLocalShortcut && *m_oldLocalShortcut == m_action->shortcuts()) {
189 delete m_oldLocalShortcut;
191 }
192}

References m_action, and m_oldLocalShortcut.

Friends And Related Symbol Documentation

◆ KisShortcutsEditorPrivate

friend class KisShortcutsEditorPrivate
friend

Definition at line 148 of file KisShortcutsEditor_p.h.

Member Data Documentation

◆ m_action

QAction* KisShortcutsEditorItem::m_action
private

The action this item is responsible for.

Definition at line 154 of file KisShortcutsEditor_p.h.

◆ m_actionNameInTable

QString KisShortcutsEditorItem::m_actionNameInTable
private

The localized action name.

Definition at line 165 of file KisShortcutsEditor_p.h.

◆ m_collator

QCollator KisShortcutsEditorItem::m_collator
private

The collator, for sorting.

Definition at line 171 of file KisShortcutsEditor_p.h.

◆ m_id

QString KisShortcutsEditorItem::m_id
private

The action id. Needed for exporting and importing.

Definition at line 168 of file KisShortcutsEditor_p.h.

◆ m_isNameBold

bool KisShortcutsEditorItem::m_isNameBold {false}
private

Should the Name column be painted in bold?

Definition at line 157 of file KisShortcutsEditor_p.h.

157{false};

◆ m_oldLocalShortcut

QList<QKeySequence>* KisShortcutsEditorItem::m_oldLocalShortcut {0}
private

The original shortcuts before user changes. 0 means no change.

Definition at line 161 of file KisShortcutsEditor_p.h.

161{0};

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