KGlobalAccel

globalshortcutcontext.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Michael Jansen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "globalshortcutcontext.h"
8 
9 #include "globalshortcut.h"
10 
12 
13  : _uniqueName(uniqueName)
14  , _friendlyName(friendlyName)
15  , _component(component)
16  , _actions()
17 {
18 }
19 
21 {
22  qDeleteAll(_actions);
23  _actions.clear();
24 }
25 
27 {
28  _actions.insert(shortcut->uniqueName(), shortcut);
29 }
30 
32 {
34  for (GlobalShortcut *shortcut : qAsConst(_actions)) {
35  rc.append(static_cast<KGlobalShortcutInfo>(*shortcut));
36  }
37  return rc;
38 }
39 
40 KdeDGlobalAccel::Component const *GlobalShortcutContext::component() const
41 {
42  return _component;
43 }
44 
45 KdeDGlobalAccel::Component *GlobalShortcutContext::component()
46 {
47  return _component;
48 }
49 
50 QString GlobalShortcutContext::friendlyName() const
51 {
52  return _friendlyName;
53 }
54 
56 {
57  // Qt triggers both shortcuts that include Shift+Backtab and Shift+Tab
58  // when user presses Shift+Tab. Do the same here.
59  int keySym = key & ~Qt::KeyboardModifierMask;
60  int keyMod = key & Qt::KeyboardModifierMask;
61  if ((keyMod & Qt::SHIFT) && (keySym == Qt::Key_Backtab || keySym == Qt::Key_Tab)) {
62  for (GlobalShortcut *sc : qAsConst(_actions)) {
63  if (sc->keys().contains(keyMod | Qt::Key_Tab) || sc->keys().contains(keyMod | Qt::Key_Backtab))
64  return sc;
65  }
66  } else {
67  for (GlobalShortcut *sc : qAsConst(_actions)) {
68  if (sc->keys().contains(key))
69  return sc;
70  }
71  }
72  return nullptr;
73 }
74 
76 {
77  // Try to take the shortcut. Result could be nullptr if the shortcut doesn't
78  // belong to this component.
79  return _actions.take(shortcut->uniqueName());
80 }
81 
83 {
84  return _uniqueName;
85 }
KeyboardModifierMask
QHash::iterator insert(const Key &key, const T &value)
QList< KGlobalShortcutInfo > allShortcutInfos() const
Return KGlobalShortcutInfos for all shortcuts.
GlobalShortcut * getShortcutByKey(int key) const
Get shortcut for key or nullptr.
QString uniqueName() const
Returns the unique name aka id for the shortcuts.
void addShortcut(GlobalShortcut *shortcut)
Adds shortcut to the context.
void append(const T &value)
Represents a global shortcut.
void clear()
GlobalShortcutContext(const QString &uniqueName, const QString &friendlyName, KdeDGlobalAccel::Component *component)
Default constructor.
T take(const Key &key)
GlobalShortcut * takeShortcut(GlobalShortcut *shortcut)
Remove shortcut from the context. The shortcut is not deleted.
virtual ~GlobalShortcutContext()
Destructor.
QString uniqueName() const
Get the name for the context.
Key_Backtab
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun May 16 2021 22:53:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.