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

A widget to input a QKeySequence. More...

#include <kkeysequencewidget.h>

+ Inheritance diagram for KisKKeySequenceWidget:

Public Types

enum  Validation { Validate = 0 , NoValidate = 1 }
 

Public Member Functions

 KisKKeySequenceWidget (QWidget *parent=0)
 
 ~KisKKeySequenceWidget () override
 

Properties

ShortcutTypes checkForConflictsAgainst
 
bool modifierlessAllowed
 
bool multiKeyShortcutsAllowed
 

Configuration

Configuration options for the widget.

enum  ShortcutType { None = 0x00 , LocalShortcuts = 0x01 , StandardShortcuts = 0x02 , GlobalShortcuts = 0x04 }
 
class KisKKeySequenceWidgetPrivate
 
KisKKeySequenceWidgetPrivate *const d
 
void setCheckForConflictsAgainst (ShortcutTypes types)
 
ShortcutTypes checkForConflictsAgainst () const
 
void setMultiKeyShortcutsAllowed (bool)
 
bool multiKeyShortcutsAllowed () const
 
void setModifierlessAllowed (bool allow)
 
bool isModifierlessAllowed ()
 
void setClearButtonShown (bool show)
 
bool isKeySequenceAvailable (const QKeySequence &seq) const
 
QKeySequence keySequence () const
 
void setCheckActionCollections (const QList< KisKActionCollection * > &actionCollections)
 
void setComponentName (const QString &componentName)
 
void keySequenceChanged (const QKeySequence &seq)
 
void stealShortcut (const QKeySequence &seq, QAction *action)
 
void captureKeySequence ()
 
void setKeySequence (const QKeySequence &seq, Validation val=NoValidate)
 
void clearKeySequence ()
 
void applyStealShortcut ()
 

Detailed Description

A widget to input a QKeySequence.

This widget lets the user choose a QKeySequence, which is usually used as a shortcut key. The recording is initiated by calling captureKeySequence() or the user clicking into the widget.

The widgets provides support for conflict handling. See setCheckForConflictsAgainst() for more information.

KDE Key Sequence Widget
Author
Mark Donohoe donoh.nosp@m.oe@k.nosp@m.de.or.nosp@m.g

Definition at line 36 of file kkeysequencewidget.h.

Member Enumeration Documentation

◆ ShortcutType

Enumerator
None 

No checking for conflicts.

LocalShortcuts 

Check with local shortcuts.

See also
setCheckActionCollections()
StandardShortcuts 

Check against standard shortcuts.

See also
KStandardShortcut
GlobalShortcuts 

Check against global shortcuts.

See also
KGlobalAccel

Definition at line 84 of file kkeysequencewidget.h.

84 {
85 None = 0x00,
86 LocalShortcuts = 0x01,
87 StandardShortcuts = 0x02,
88 GlobalShortcuts = 0x04
89 };
@ GlobalShortcuts
Check against global shortcuts.
@ StandardShortcuts
Check against standard shortcuts.
@ None
No checking for conflicts.
@ LocalShortcuts
Check with local shortcuts.

◆ Validation

An enum about validation when setting a key sequence.

See also
setKeySequence()
Enumerator
Validate 

Validate key sequence.

NoValidate 

Use key sequence without validation.

Definition at line 60 of file kkeysequencewidget.h.

60 {
62 Validate = 0,
64 NoValidate = 1
65 };
@ Validate
Validate key sequence.
@ NoValidate
Use key sequence without validation.

Constructor & Destructor Documentation

◆ KisKKeySequenceWidget()

KisKKeySequenceWidget::KisKKeySequenceWidget ( QWidget * parent = 0)
explicit

Constructor.

Definition at line 203 of file kkeysequencewidget.cpp.

204 : QWidget(parent),
206{
207 d->init();
208 setFocusProxy(d->keyButton);
209 connect(d->keyButton, SIGNAL(clicked()), this, SLOT(captureKeySequence()));
210 connect(d->clearButton, SIGNAL(clicked()), this, SLOT(clearKeySequence()));
211 connect(&d->modifierlessTimeout, SIGNAL(timeout()), this, SLOT(doneRecording()));
212 //TODO: how to adopt style changes at runtime?
213 /*QFont modFont = d->clearButton->font();
214 modFont.setStyleHint(QFont::TypeWriter);
215 d->clearButton->setFont(modFont);*/
217}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
friend class KisKKeySequenceWidgetPrivate
KisKKeySequenceWidgetPrivate *const d

References captureKeySequence(), KisKKeySequenceWidgetPrivate::clearButton, clearKeySequence(), connect(), d, KisKKeySequenceWidgetPrivate::init(), KisKKeySequenceWidgetPrivate::keyButton, KisKKeySequenceWidgetPrivate::modifierlessTimeout, and KisKKeySequenceWidgetPrivate::updateShortcutDisplay().

◆ ~KisKKeySequenceWidget()

KisKKeySequenceWidget::~KisKKeySequenceWidget ( )
override

Destructs the widget.

Definition at line 240 of file kkeysequencewidget.cpp.

241{
242 delete d;
243}

References d.

Member Function Documentation

◆ applyStealShortcut

void KisKKeySequenceWidget::applyStealShortcut ( )
slot

Actually remove the shortcut that the user wanted to steal, from the action that was using it. This only applies to actions provided to us by setCheckActionCollections() and setCheckActionList().

Global and Standard Shortcuts have to be stolen immediately when the user gives his consent (technical reasons). That means those changes will be active even if you never call applyStealShortcut().

To be called before you apply your changes. No local shortcuts are stolen until this function is called.

Definition at line 345 of file kkeysequencewidget.cpp.

346{
347 QSet<KisKActionCollection *> changedCollections;
348
349 Q_FOREACH (QAction *stealAction, d->stealActions) {
350
351 // Stealing a shortcut means setting it to an empty one.
352 stealAction->setShortcuts(QList<QKeySequence>());
353
354 // The following code will find the action we are about to
355 // steal from and save its action collection.
356 KisKActionCollection *parentCollection = 0;
357 foreach (KisKActionCollection *collection, d->checkActionCollections) {
358 if (collection->actions().contains(stealAction)) {
359 parentCollection = collection;
360 break;
361 }
362 }
363
364 // Remember the changed collection
365 if (parentCollection) {
366 changedCollections.insert(parentCollection);
367 }
368 }
369
370 Q_FOREACH (KisKActionCollection *col, changedCollections) {
371 col->writeSettings();
372 }
373
374 d->stealActions.clear();
375}
A container for a set of QAction objects.
void writeSettings(KConfigGroup *config=0, bool writeScheme=false, QAction *oneAction=0) const
QList< QAction * > actions() const
QList< KisKActionCollection * > checkActionCollections

References KisKActionCollection::actions(), KisKKeySequenceWidgetPrivate::checkActionCollections, d, KisKKeySequenceWidgetPrivate::stealActions, and KisKActionCollection::writeSettings().

◆ captureKeySequence

void KisKKeySequenceWidget::captureKeySequence ( )
slot

Capture a shortcut from the keyboard. This call will only return once a key sequence has been captured or input was aborted. If a key sequence was input, keySequenceChanged() will be emitted.

See also
setModifierlessAllowed()

Definition at line 313 of file kkeysequencewidget.cpp.

References d, and KisKKeySequenceWidgetPrivate::startRecording().

◆ checkForConflictsAgainst()

KisKKeySequenceWidget::ShortcutTypes KisKKeySequenceWidget::checkForConflictsAgainst ( ) const

The shortcut types we check for conflicts.

See also
setCheckForConflictsAgainst()
Since
4.2

Definition at line 245 of file kkeysequencewidget.cpp.

246{
248}
KisKKeySequenceWidget::ShortcutTypes checkAgainstShortcutTypes
Check the key sequence against KStandardShortcut::find()

References KisKKeySequenceWidgetPrivate::checkAgainstShortcutTypes, and d.

◆ clearKeySequence

void KisKKeySequenceWidget::clearKeySequence ( )
slot

Clear the key sequence.

Definition at line 339 of file kkeysequencewidget.cpp.

340{
341 setKeySequence(QKeySequence());
342}
void setKeySequence(const QKeySequence &seq, Validation val=NoValidate)

References setKeySequence().

◆ isKeySequenceAvailable()

bool KisKKeySequenceWidget::isKeySequenceAvailable ( const QKeySequence & seq) const

Checks whether the key sequence seq is available to grab.

The sequence is checked under the same rules as if it has been typed by the user. This method is useful if you get key sequences from another input source and want to check if it is save to set them.

Since
4.2

Definition at line 275 of file kkeysequencewidget.cpp.

276{
277 if (keySequence.isEmpty()) {
278 // qDebug() << "Key sequence" << keySequence.toString() << "is empty and available.";
279 return true;
280 }
281
282 bool hasConflict = (d->conflictWithLocalShortcuts(keySequence)
285
286 if (hasConflict) {
287 /* qInfo() << "Key sequence" << keySequence.toString() << "has an unresolvable conflict." <<
288 QString("Local conflict: %1. Windows conflict: %2. Standard Shortcut conflict: %3") \
289 .arg(d->conflictWithLocalShortcuts(keySequence)) \
290 .arg(d->conflictWithGlobalShortcuts(keySequence)) \
291 .arg(d->conflictWithStandardShortcuts(keySequence)); */
292 }
293 return !(hasConflict);
294
295}
bool conflictWithStandardShortcuts(const QKeySequence &seq)
bool conflictWithGlobalShortcuts(const QKeySequence &seq)
bool conflictWithLocalShortcuts(const QKeySequence &seq)
QKeySequence keySequence() const

References KisKKeySequenceWidgetPrivate::conflictWithGlobalShortcuts(), KisKKeySequenceWidgetPrivate::conflictWithLocalShortcuts(), KisKKeySequenceWidgetPrivate::conflictWithStandardShortcuts(), d, and keySequence().

◆ isModifierlessAllowed()

bool KisKKeySequenceWidget::isModifierlessAllowed ( )

◆ keySequence()

QKeySequence KisKKeySequenceWidget::keySequence ( ) const

Return the currently selected key sequence.

Definition at line 318 of file kkeysequencewidget.cpp.

319{
320 return d->keySequence;
321}

References d, and KisKKeySequenceWidgetPrivate::keySequence.

◆ keySequenceChanged

void KisKKeySequenceWidget::keySequenceChanged ( const QKeySequence & seq)
signal

This signal is emitted when the current key sequence has changed, be it by user input or programmatically.

◆ multiKeyShortcutsAllowed()

bool KisKKeySequenceWidget::multiKeyShortcutsAllowed ( ) const

◆ setCheckActionCollections()

void KisKKeySequenceWidget::setCheckActionCollections ( const QList< KisKActionCollection * > & actionCollections)

Set a list of action collections to check against for conflicting shortcut.

See also
setCheckForConflictsAgainst()

If a KAction with a conflicting shortcut is found inside this list and its shortcut can be configured (KAction::isShortcutConfigurable() returns true) the user will be prompted whether to steal the shortcut from this action.

Since
4.1

Definition at line 307 of file kkeysequencewidget.cpp.

308{
309 d->checkActionCollections = actionCollections;
310}

References KisKKeySequenceWidgetPrivate::checkActionCollections, and d.

◆ setCheckForConflictsAgainst()

void KisKKeySequenceWidget::setCheckForConflictsAgainst ( ShortcutTypes types)

Configure if the widget should check for conflicts with existing shortcuts.

When capturing a key sequence for local shortcuts you should check against GlobalShortcuts and your other local shortcuts. This is the default.

You have to provide the local actions to check against with setCheckActionCollections().

When capturing a key sequence for a global shortcut you should check against StandardShortcuts, GlobalShortcuts and your local shortcuts.

There are two ways to react to a user agreeing to steal a shortcut:

  1. Listen to the stealShortcut() signal and steal the shortcuts manually. It's your responsibility to save that change later when you think it is appropriate.
  2. Call applyStealShortcut and KisKKeySequenceWidget will steal the shortcut. This will save the actionCollections the shortcut is part of so make sure it doesn't inadvertently save some unwanted changes too. Read its documentation for some limitation when handling global shortcuts.

If you want to do the conflict checking yourself here are some code snippets for global ...

QStringList conflicting = KGlobalAccel::findActionNameSystemwide(keySequence);
if (!conflicting.isEmpty()) {
// Inform and ask the user about the conflict and reassigning
// the keys sequence
if (!KGlobalAccel::promptStealShortcutSystemwide(q, conflicting, keySequence)) {
return true;
}
KGlobalAccel::stealShortcutSystemwide(keySequence);
}

... and standard shortcuts

KStandardShortcut::StandardShortcut ssc = KStandardShortcut::find(keySequence);
if (ssc != KStandardShortcut::AccelNone) {
// We have a conflict
}
Since
4.2

Definition at line 265 of file kkeysequencewidget.cpp.

266{
268}

References KisKKeySequenceWidgetPrivate::checkAgainstShortcutTypes, and d.

◆ setClearButtonShown()

void KisKKeySequenceWidget::setClearButtonShown ( bool show)

Set whether a small button to set an empty key sequence should be displayed next to the main input widget. The default is to show the clear button.

Definition at line 302 of file kkeysequencewidget.cpp.

303{
304 d->clearButton->setVisible(show);
305}

References KisKKeySequenceWidgetPrivate::clearButton, and d.

◆ setComponentName()

void KisKKeySequenceWidget::setComponentName ( const QString & componentName)

If the component using this widget supports shortcuts contexts, it has to set its component name so we can check conflicts correctly.

Definition at line 250 of file kkeysequencewidget.cpp.

251{
252 d->componentName = componentName;
253}

References KisKKeySequenceWidgetPrivate::componentName, and d.

◆ setKeySequence

void KisKKeySequenceWidget::setKeySequence ( const QKeySequence & seq,
Validation val = NoValidate )
slot

Set the key sequence.

If val == Validate, and the call is actually changing the key sequence, conflicting shortcut will be checked.

Definition at line 324 of file kkeysequencewidget.cpp.

325{
326 // oldKeySequence holds the key sequence before recording started, if setKeySequence()
327 // is called while not recording then set oldKeySequence to the existing sequence so
328 // that the keySequenceChanged() signal is emitted if the new and previous key
329 // sequences are different
330 if (!d->isRecording) {
332 }
333
334 d->keySequence = seq;
335 d->doneRecording(validate == Validate);
336}
void doneRecording(bool validate=true)

References d, KisKKeySequenceWidgetPrivate::doneRecording(), KisKKeySequenceWidgetPrivate::isRecording, KisKKeySequenceWidgetPrivate::keySequence, KisKKeySequenceWidgetPrivate::oldKeySequence, and Validate.

◆ setModifierlessAllowed()

void KisKKeySequenceWidget::setModifierlessAllowed ( bool allow)

This only applies to user input, not to setShortcut(). Set whether to accept "plain" keys without modifiers (like Ctrl, Alt, Meta). Plain keys by our definition include letter and symbol keys and text editing keys (Return, Space, Tab, Backspace, Delete). "Special" keys like F1, Cursor keys, Insert, PageDown will always work.

Definition at line 270 of file kkeysequencewidget.cpp.

271{
272 d->allowModifierless = allow;
273}

References KisKKeySequenceWidgetPrivate::allowModifierless, and d.

◆ setMultiKeyShortcutsAllowed()

void KisKKeySequenceWidget::setMultiKeyShortcutsAllowed ( bool allowed)

Allow multikey shortcuts?

Definition at line 260 of file kkeysequencewidget.cpp.

261{
262 d->multiKeyShortcutsAllowed = allowed;
263}

References d, and KisKKeySequenceWidgetPrivate::multiKeyShortcutsAllowed.

◆ stealShortcut

void KisKKeySequenceWidget::stealShortcut ( const QKeySequence & seq,
QAction * action )
signal

This signal is emitted after the user agreed to steal a shortcut from an action. This is only done for local shortcuts. So you can be sure action is one of the actions you provided with setCheckActionList() or setCheckActionCollections().

If you listen to that signal and don't call applyStealShortcut() you are supposed to steal the shortcut and save this change.

Friends And Related Symbol Documentation

◆ KisKKeySequenceWidgetPrivate

friend class KisKKeySequenceWidgetPrivate
friend

Definition at line 281 of file kkeysequencewidget.h.

Member Data Documentation

◆ d

KisKKeySequenceWidgetPrivate* const KisKKeySequenceWidget::d
private

Definition at line 282 of file kkeysequencewidget.h.

Property Documentation

◆ checkForConflictsAgainst

ShortcutTypes KisKKeySequenceWidget::checkForConflictsAgainst
readwrite

Definition at line 47 of file kkeysequencewidget.h.

◆ modifierlessAllowed

bool KisKKeySequenceWidget::modifierlessAllowed
readwrite

Definition at line 52 of file kkeysequencewidget.h.

◆ multiKeyShortcutsAllowed

bool KisKKeySequenceWidget::multiKeyShortcutsAllowed
readwrite

Definition at line 42 of file kkeysequencewidget.h.


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