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

Widget for configuration of KAccel and KGlobalAccel. More...

#include <KisShortcutsEditor.h>

+ Inheritance diagram for KisShortcutsEditor:

Public Types

enum  ActionType {
  WidgetAction = Qt::WidgetShortcut , WindowAction = Qt::WindowShortcut , ApplicationAction = Qt::ApplicationShortcut , GlobalAction = 4 ,
  AllActions = 0xffffffff
}
 
enum  LetterShortcuts { LetterShortcutsDisallowed = 0 , LetterShortcutsAllowed }
 

Public Slots

void allDefault ()
 
void printShortcuts () const
 
void resizeColumns ()
 
void searchUpdated (QString s)
 
void slotScrollerStateChanged (QScroller::State state)
 

Signals

void keyChange ()
 

Public Member Functions

ActionTypes actionTypes () const
 
void addCollection (KisKActionCollection *, const QString &title=QString())
 
void clearCollections ()
 
void clearConfiguration ()
 
void clearSearch ()
 
void commit ()
 
void exportConfiguration (KConfigBase *config) const
 
void importConfiguration (KConfigBase *config, bool isScheme)
 
bool isModified () const
 
 KisShortcutsEditor (QWidget *parent, ActionTypes actionTypes=AllActions, LetterShortcuts allowLetterShortcuts=LetterShortcutsAllowed)
 
void save ()
 
void saveShortcuts (KConfigGroup *config=0) const
 
void setActionTypes (ActionTypes actionTypes)
 
void undo ()
 
 ~KisShortcutsEditor () override
 Destructor.
 

Properties

ActionTypes actionTypes
 

Private Attributes

KisShortcutsEditorPrivate *const d
 

Friends

class KisShortcutsDialog
 
class KisShortcutsEditorPrivate
 

Detailed Description

Widget for configuration of KAccel and KGlobalAccel.

WARNING: KisShortcutsEditor expects that the list of existing shortcuts is already free of conflicts. If it is not, nothing will crash, but your users won't like the resulting behavior.

TODO: Find the right place to check for conflicts.

Configure dictionaries of key/action associations for KActions, including global shortcuts.

The class takes care of all aspects of configuration, including handling key conflicts internally. Connect to the allDefault() slot if you want to set all configurable shortcuts to their default values.

See also
KShortcutsDialog
Author
Nicolas Hadacek hadac.nosp@m.ek@v.nosp@m.ia.ec.nosp@m.p.fr
Hamish Rodda rodda.nosp@m.@kde.nosp@m..org (KDE 4 porting)
Michael Jansen kde@m.nosp@m.icha.nosp@m.el-ja.nosp@m.nsen.nosp@m..biz

Definition at line 55 of file KisShortcutsEditor.h.

Member Enumeration Documentation

◆ ActionType

Enumerator
WidgetAction 

Actions which are triggered by any keypress in a widget which has the action added to it.

WindowAction 

Actions which are triggered by any keypress in a window which has the action added to it or its child widget(s)

ApplicationAction 

Actions which are triggered by any keypress in the application.

GlobalAction 

Actions which are triggered by any keypress in the windowing system.

AllActions 

All actions.

Definition at line 69 of file KisShortcutsEditor.h.

69 {
71 WidgetAction = Qt::WidgetShortcut /*0*/,
73 WindowAction = Qt::WindowShortcut /*1*/,
75 ApplicationAction = Qt::ApplicationShortcut /*2*/,
77 GlobalAction = 4,
79 AllActions = 0xffffffff
80 };
@ GlobalAction
Actions which are triggered by any keypress in the windowing system.
@ WidgetAction
Actions which are triggered by any keypress in a widget which has the action added to it.
@ ApplicationAction
Actions which are triggered by any keypress in the application.
@ WindowAction
Actions which are triggered by any keypress in a window which has the action added to it or its child...

◆ LetterShortcuts

Enumerator
LetterShortcutsDisallowed 

Shortcuts without a modifier are not allowed, so 'A' would not be valid, whereas 'Ctrl+A' would be. This only applies to printable characters, however. 'F1', 'Insert' etc. could still be used.

LetterShortcutsAllowed 

Letter shortcuts are allowed.

Definition at line 83 of file KisShortcutsEditor.h.

83 {
90 };
@ LetterShortcutsAllowed
Letter shortcuts are allowed.

Constructor & Destructor Documentation

◆ KisShortcutsEditor()

KisShortcutsEditor::KisShortcutsEditor ( QWidget * parent,
ActionTypes actionTypes = AllActions,
LetterShortcuts allowLetterShortcuts = LetterShortcutsAllowed )
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Creates a key chooser without a starting action collection.

Parameters
parentparent widget
actionTypestypes of actions to display in this widget.
allowLetterShortcutsset to LetterShortcutsDisallowed if unmodified alphanumeric keys ('A', '1', etc.) are not permissible shortcuts.

Definition at line 48 of file KisShortcutsEditor.cpp.

49 : QWidget(parent)
50 , d(new KisShortcutsEditorPrivate(this))
51{
52 d->initGUI(actionType, allowLetterShortcuts);
53}
void initGUI(KisShortcutsEditor::ActionTypes actionTypes, KisShortcutsEditor::LetterShortcuts allowLetterShortcuts)
friend class KisShortcutsEditorPrivate
KisShortcutsEditorPrivate *const d

◆ ~KisShortcutsEditor()

KisShortcutsEditor::~KisShortcutsEditor ( )
override

Destructor.

Definition at line 55 of file KisShortcutsEditor.cpp.

56{
57 delete d;
58}

References d.

Member Function Documentation

◆ actionTypes()

KisShortcutsEditor::ActionTypes KisShortcutsEditor::actionTypes ( ) const
Returns
The types of actions currently displayed in this widget.
Since
5.0

Definition at line 297 of file KisShortcutsEditor.cpp.

298{
299 return d->actionTypes;
300}
KisShortcutsEditor::ActionTypes actionTypes

References KisShortcutsEditorPrivate::actionTypes, and d.

◆ addCollection()

void KisShortcutsEditor::addCollection ( KisKActionCollection * collection,
const QString & title = QString() )

Note: the reason this is so damn complicated is because it's supposed to support having multiple applications running inside of each other through KisParts. That means we have to be able to separate sections within each configuration file.

Insert an action collection, i.e. add all its actions to the ones already associated with the KisShortcutsEditor object.

Parameters
collectionthe action collection.
titlesubtree title of this collection of shortcut.

Forward this action collection to the delegate which will do conflict checking. This replaces existing collections in the delegate.

Definition at line 88 of file KisShortcutsEditor.cpp.

89{
90 // KXmlGui add action collections unconditionally. If some plugin doesn't
91 // provide actions we don't want to create empty subgroups.
92 if (collection->isEmpty()) {
93 return;
94 }
95
96 // Pause updating.
97 setUpdatesEnabled(false);
98
99
104 d->actionCollections.append(collection);
106
107
108 // Determine how we should label this collection in the widget.
109 QString collectionTitle;
110 if (!title.isEmpty()) {
111 collectionTitle = title;
112 } else {
113 // Use the programName (Translated).
114 collectionTitle = collection->componentDisplayName();
115 }
116
117 // Create the collection root node.
118 QTreeWidgetItem *hierarchy[3];
119 hierarchy[KisShortcutsEditorPrivate::Root] = d->ui.list->invisibleRootItem();
121 d->findOrMakeItem(hierarchy[KisShortcutsEditorPrivate::Root], collectionTitle);
123
124 // Remember which actions we have seen. We will be adding categorized
125 // actions first, so this will help us keep track of which actions haven't
126 // been categorized yet, so we can add them as uncategorized at the end.
127 QSet<QAction *> actionsSeen;
128
129 // Add a subtree for each category? Perhaps easier to think that this
130 // doesn't exist. Basically you add KisKActionCategory as a QObject child of
131 // KisKActionCollection, and then tag objects as belonging to the category.
132 foreach (KisKActionCategory *category, collection->categories()) {
133
134 // Don't display empty categories.
135 if (category->actions().isEmpty()) {
136 continue;
137 }
138
141
142 // Add every item from the category.
143 foreach (QAction *action, category->actions()) {
144 actionsSeen.insert(action);
145 d->addAction(action, hierarchy, KisShortcutsEditorPrivate::Action);
146 }
147
148 // Fold in each KisKActionCategory by default.
149 hierarchy[KisShortcutsEditorPrivate::Action]->setExpanded(false);
150
151 }
152
153 // Finally, tack on any uncategorized actions.
154 foreach (QAction *action, collection->actions()) {
155 if (!actionsSeen.contains(action)) {
157 }
158 }
159
160 // sort the list
161 d->ui.list->sortItems(Name, Qt::AscendingOrder);
162
163 // Now turn on updating again.
164 setUpdatesEnabled(true);
165
166 QTimer::singleShot(0, this, SLOT(resizeColumns()));
167}
const QList< QAction * > actions() const
QList< KisKActionCategory * > categories() const
QString componentDisplayName() const
QList< QAction * > actions() const
void setCheckActionCollections(const QList< KisKActionCollection * > checkActionCollections)
QList< KisKActionCollection * > actionCollections
KisShortcutsEditorDelegate * delegate
Ui::KisShortcutsDialog ui
QTreeWidgetItem * findOrMakeItem(QTreeWidgetItem *parent, const QString &name)
bool addAction(QAction *action, QTreeWidgetItem *hier[], hierarchyLevel level)

References KisShortcutsEditorPrivate::Action, KisShortcutsEditorPrivate::actionCollections, KisKActionCategory::actions(), KisKActionCollection::actions(), KisShortcutsEditorPrivate::addAction(), KisKActionCollection::categories(), KisKActionCollection::componentDisplayName(), d, KisShortcutsEditorPrivate::delegate, KisShortcutsEditorPrivate::findOrMakeItem(), KisKActionCollection::isEmpty(), Name, KisShortcutsEditorPrivate::Program, resizeColumns(), KisShortcutsEditorPrivate::Root, KisShortcutsEditorDelegate::setCheckActionCollections(), KisKActionCategory::text, and KisShortcutsEditorPrivate::ui.

◆ allDefault

void KisShortcutsEditor::allDefault ( )
slot

Set all shortcuts to their default values (bindings).

Definition at line 276 of file KisShortcutsEditor.cpp.

References KisShortcutsEditorPrivate::allDefault(), and d.

◆ clearCollections()

void KisShortcutsEditor::clearCollections ( )

Removes all action collections from the editor

Definition at line 74 of file KisShortcutsEditor.cpp.

75{
76 d->delegate->contractAll();
77 d->ui.list->clear();
78 d->actionCollections.clear();
79 QTimer::singleShot(0, this, SLOT(resizeColumns()));
80}

References KisShortcutsEditorPrivate::actionCollections, d, KisShortcutsEditorPrivate::delegate, resizeColumns(), and KisShortcutsEditorPrivate::ui.

◆ clearConfiguration()

void KisShortcutsEditor::clearConfiguration ( )

Removes all configured shortcuts.

Definition at line 169 of file KisShortcutsEditor.cpp.

References KisShortcutsEditorPrivate::clearConfiguration(), and d.

◆ clearSearch()

void KisShortcutsEditor::clearSearch ( )

Clears search area

Definition at line 82 of file KisShortcutsEditor.cpp.

83{
84 d->ui.searchFilter->searchLine()->clear();
85}

References d, and KisShortcutsEditorPrivate::ui.

◆ commit()

void KisShortcutsEditor::commit ( )

Update the dialog entries without saving.

Since
4.2

Definition at line 251 of file KisShortcutsEditor.cpp.

252{
253 for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
254 if (KisShortcutsEditorItem *item = dynamic_cast<KisShortcutsEditorItem *>(*it)) {
255 item->commit();
256 }
257 }
258}

References d, and KisShortcutsEditorPrivate::ui.

◆ exportConfiguration()

void KisShortcutsEditor::exportConfiguration ( KConfigBase * config) const

Write the current shortcuts to a new scheme to configuration file

Parameters
configConfig object to save to.

Definition at line 204 of file KisShortcutsEditor.cpp.

205{
206 Q_ASSERT(config);
207 if (!config) {
208 return;
209 }
210
211 if (d->actionTypes) {
212 KConfigGroup group(config,QStringLiteral("Shortcuts"));
213 foreach (KisKActionCollection *collection, d->actionCollections) {
214 collection->writeSettings(&group, true);
215 }
216 }
217
219}
static KisActionRegistry * instance()
A container for a set of QAction objects.
void writeSettings(KConfigGroup *config=0, bool writeScheme=false, QAction *oneAction=0) const

References KisShortcutsEditorPrivate::actionCollections, KisShortcutsEditorPrivate::actionTypes, d, KisActionRegistry::instance(), KisActionRegistry::notifySettingsUpdated(), and KisKActionCollection::writeSettings().

◆ importConfiguration()

void KisShortcutsEditor::importConfiguration ( KConfigBase * config,
bool isScheme )

Import a shortcut configuration file.

Parameters
configConfig object to load from.
isSchemetrue for shortcut scheme, false for custom shortcuts

Definition at line 174 of file KisShortcutsEditor.cpp.

175{
176 Q_ASSERT(config);
177 if (!config) {
178 return;
179 }
180
181 // If this is a shortcut scheme, apply it
182 if (isScheme) {
184 }
185
186 // Update the dialog entry items
187 const KConfigGroup schemeShortcuts(config, QStringLiteral("Shortcuts"));
188 for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
189
190 if (!(*it)->parent()) {
191 continue;
192 }
193 KisShortcutsEditorItem *item = static_cast<KisShortcutsEditorItem *>(*it);
194 const QString actionId = item->data(Id).toString();
195 if (!schemeShortcuts.hasKey(actionId))
196 continue;
197
198 QList<QKeySequence> sc = QKeySequence::listFromString(schemeShortcuts.readEntry(actionId, QString()));
201 }
202}
QKeySequence alternateSequence(const QList< QKeySequence > &sequences)
QKeySequence primarySequence(const QList< QKeySequence > &sequences)
@ LocalAlternate
@ LocalPrimary
void applyShortcutScheme(const KConfigBase *config=0)
QVariant data(int column, int role=Qt::DisplayRole) const override
void changeKeyShortcut(KisShortcutsEditorItem *item, uint column, const QKeySequence &capture)

References alternateSequence(), KisActionRegistry::applyShortcutScheme(), KisShortcutsEditorPrivate::changeKeyShortcut(), d, KisShortcutsEditorItem::data(), Id, KisActionRegistry::instance(), LocalAlternate, LocalPrimary, primarySequence(), and KisShortcutsEditorPrivate::ui.

◆ isModified()

bool KisShortcutsEditor::isModified ( ) const
Returns
true if there are unsaved changes.

Definition at line 60 of file KisShortcutsEditor.cpp.

61{
62 // Iterate over all items
63 QTreeWidgetItemIterator it(d->ui.list, QTreeWidgetItemIterator::NoChildren);
64
65 for (; (*it); ++it) {
66 KisShortcutsEditorItem *item = dynamic_cast<KisShortcutsEditorItem *>(*it);
67 if (item && item->isModified()) {
68 return true;
69 }
70 }
71 return false;
72}
bool isModified(uint column) const

References d, KisShortcutsEditorItem::isModified(), and KisShortcutsEditorPrivate::ui.

◆ keyChange

void KisShortcutsEditor::keyChange ( )
signal

Emitted when an action's shortcut has been changed.

◆ printShortcuts

void KisShortcutsEditor::printShortcuts ( ) const
slot

Opens a printing dialog to print all the shortcuts

Definition at line 281 of file KisShortcutsEditor.cpp.

282{
283 d->printShortcuts();
284}

References d, and KisShortcutsEditorPrivate::printShortcuts().

◆ resizeColumns

void KisShortcutsEditor::resizeColumns ( )
slot

Resize columns to width required

Definition at line 241 of file KisShortcutsEditor.cpp.

242{
243 for (int i = 0; i < d->ui.list->columnCount(); i++) {
244 d->ui.list->resizeColumnToContents(i);
245 }
246}

References d, and KisShortcutsEditorPrivate::ui.

◆ save()

void KisShortcutsEditor::save ( )

Save the changes.

Before saving the changes are committed. This saves the actions to disk. Any KisKActionCollection objects with the xmlFile() value set will be written to an XML file. All other will be written to the application's rc file.

Definition at line 260 of file KisShortcutsEditor.cpp.

261{
263 commit(); // Not doing this would be bad
264}
void saveShortcuts(KConfigGroup *config=0) const

References commit(), and saveShortcuts().

◆ saveShortcuts()

void KisShortcutsEditor::saveShortcuts ( KConfigGroup * config = 0) const

Write the current custom shortcut settings to the config object.

Parameters
configConfig object to save to. Default is kritashortcutsrc.

Definition at line 221 of file KisShortcutsEditor.cpp.

222{
223 // This is a horrible mess with pointers...
224 KConfigGroup cg;
225 if (config == 0) {
226 cg = KConfigGroup(KSharedConfig::openConfig("kritashortcutsrc"),
227 QStringLiteral("Shortcuts"));
228 config = &cg;
229 }
230
231 // Clear and reset temporary shortcuts
232 config->deleteGroup();
233 foreach (KisKActionCollection *collection, d->actionCollections) {
234 collection->writeSettings(config, false);
235 }
236
238}

References KisShortcutsEditorPrivate::actionCollections, d, KisActionRegistry::instance(), KisActionRegistry::notifySettingsUpdated(), and KisKActionCollection::writeSettings().

◆ searchUpdated

void KisShortcutsEditor::searchUpdated ( QString s)
slot

Expand or collapse the tree view when the search text changes

Definition at line 286 of file KisShortcutsEditor.cpp.

287{
288 if (s.isEmpty()) {
289 // Reset the tree area
290 d->ui.list->collapseAll();
291 d->ui.list->expandToDepth(0);
292 } else {
293 d->ui.list->expandAll();
294 }
295}

References d, and KisShortcutsEditorPrivate::ui.

◆ setActionTypes()

void KisShortcutsEditor::setActionTypes ( ActionTypes actionTypes)

Sets the types of actions to display in this widget.

Parameters
actionTypesNew types of actions
Since
5.0

Definition at line 302 of file KisShortcutsEditor.cpp.

303{
305}
void setActionTypes(KisShortcutsEditor::ActionTypes actionTypes)

References actionTypes, d, and KisShortcutsEditorPrivate::setActionTypes().

◆ slotScrollerStateChanged

void KisShortcutsEditor::slotScrollerStateChanged ( QScroller::State state)
inlineslot

Definition at line 230 of file KisShortcutsEditor.h.

KRITAWIDGETUTILS_EXPORT void updateCursor(QWidget *source, QScroller::State state)

References KisKineticScroller::updateCursor().

◆ undo()

void KisShortcutsEditor::undo ( )

Undo all change made since the last commit().

Definition at line 266 of file KisShortcutsEditor.cpp.

267{
268 // TODO: is this working?
269 for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
270 if (KisShortcutsEditorItem *item = dynamic_cast<KisShortcutsEditorItem *>(*it)) {
271 item->undo();
272 }
273 }
274}

References d, and KisShortcutsEditorPrivate::ui.

Friends And Related Symbol Documentation

◆ KisShortcutsDialog

friend class KisShortcutsDialog
friend

Definition at line 236 of file KisShortcutsEditor.h.

◆ KisShortcutsEditorPrivate

friend class KisShortcutsEditorPrivate
friend

Definition at line 237 of file KisShortcutsEditor.h.

Member Data Documentation

◆ d

KisShortcutsEditorPrivate* const KisShortcutsEditor::d
private

Definition at line 238 of file KisShortcutsEditor.h.

Property Documentation

◆ actionTypes

ActionTypes KisShortcutsEditor::actionTypes
readwrite

Definition at line 58 of file KisShortcutsEditor.h.


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