ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KbBind Class Reference

#include <src/ckb/kbbind.h>

+ Inheritance diagram for KbBind:
+ Collaboration diagram for KbBind:

Public Slots

void keyEvent (const QString &key, bool down)
 

Signals

void didLoad ()
 
void layoutChanged ()
 
void updated ()
 

Public Member Functions

 KbBind (KbMode *modeParent, Kb *devParent, const KeyMap &keyMap)
 
 KbBind (KbMode *modeParent, Kb *devParent, const KeyMap &keyMap, const KbBind &other)
 KbBind. More...
 
void load (CkbSettings &settings)
 
void save (CkbSettings &settings)
 
bool needsSave () const
 
const KeyMapmap ()
 
void map (const KeyMap &map)
 
bool isISO () const
 
bool isKeyboard () const
 
bool isMouse () const
 
KbPerfperf ()
 
KbLightlight ()
 
QString action (const QString &key)
 
QString defaultAction (const QString &key)
 
QString friendlyName (const QString &key)
 
QString friendlyActionName (const QString &key)
 
void setAction (const QString &key, const QString &action)
 
void setAction (const QStringList &keys, const QString &action)
 
void resetAction (const QString &key)
 
void resetAction (const QStringList &keys)
 
void noAction (const QString &key)
 
void noAction (const QStringList &keys)
 
bool winLock ()
 
void winLock (bool newWinLock)
 
void update (QFile &cmd, bool force=false)
 
void setNeedsUpdate ()
 
int getMacroNumber ()
 KbBind::getMacroNumber. More...
 
QString getMacroPath ()
 KbBind::getMacroPath. More...
 
void handleNotificationChannel (bool start)
 handleNotificationChannel sends commands to ckb-daemon for (de-) activating the notify channel. Send a notify cmd to the keyboard to set or clear notification for reading macro definition. The file handle for the cmd pipe is stored in lastCmd. More...
 

Static Public Member Functions

static QString globalRemap (const QString &key)
 
static void setGlobalRemap (const QHash< QString, QString > keyToActual)
 
static void loadGlobalRemap ()
 
static void saveGlobalRemap ()
 
static QString defaultAction (const QString &key, KeyMap::Model model)
 

Private Member Functions

KbdevParent () const
 
KbModemodeParent () const
 
KeyActionbindAction (const QString &key)
 

Private Attributes

Kb_devParent
 
quint64 lastGlobalRemapTime
 
QFile * lastCmd
 lastCmd is a cache-hack. Because the QFile ist opened in Kb, and we need it in the macro processing functions, we cache the value her in lastCmd. More...
 
KeyMap _map
 
QHash< QString, KeyAction * > _bind
 
bool _winLock
 
bool _needsUpdate
 
bool _needsSave
 

Static Private Attributes

static QHash< QString, QString > _globalRemap
 
static quint64 globalRemapTime = 0
 

Friends

class KeyAction
 

Detailed Description

Definition at line 20 of file kbbind.h.

Constructor & Destructor Documentation

KbBind::KbBind ( KbMode modeParent,
Kb devParent,
const KeyMap keyMap 
)
explicit

Definition at line 12 of file kbbind.cpp.

12  :
13  QObject(modeParent), _devParent(parentBoard), lastGlobalRemapTime(globalRemapTime), _map(keyMap),
14  _winLock(false), _needsUpdate(true), _needsSave(true) {
15 }
bool _winLock
Definition: kbbind.h:134
KeyMap _map
Definition: kbbind.h:130
bool _needsSave
Definition: kbbind.h:136
quint64 lastGlobalRemapTime
Definition: kbbind.h:122
static quint64 globalRemapTime
Definition: kbbind.h:121
Kb * _devParent
Definition: kbbind.h:114
bool _needsUpdate
Definition: kbbind.h:135
KbBind::KbBind ( KbMode modeParent,
Kb parentBoard,
const KeyMap keyMap,
const KbBind other 
)

KbBind::KbBind // copy all existing Key bindings.

Parameters
modeParent
devParent
keyMap
otherThis is the KbBind object to copy from Use this constructor to copy an existing Binding
modeParent
parentBoard
keyMap
other

Create a new Hash table and copy all entries

clear the destination list (there are the original KeyActions as references, so do not delete them)

and move the KeyActions we just created

Definition at line 24 of file kbbind.cpp.

References _bind, KeyAction, map(), and KeyAction::value().

24  :
25  QObject(modeParent), _devParent(parentBoard), lastGlobalRemapTime(globalRemapTime), _bind(other._bind),
26  _winLock(false), _needsUpdate(true), _needsSave(true) {
27  map(keyMap);
28 
30  QHash<QString, KeyAction*> newBind;
31  foreach(QString key, _bind.keys()) {
32  KeyAction* act = _bind.value(key);
33  if(act) {
34  newBind[key] = new KeyAction(act->value(), this);
35  }
36  }
37 
39  _bind.clear();
40  foreach(QString key, newBind.keys()) {
41  KeyAction* act = newBind.value(key);
42  if(act) {
44  _bind[key] = new KeyAction(act->value(), this);
45  }
46  }
47  newBind.clear(); // here we *must not* delete the KeyActions, because they are referenced by _bind now
48 }
bool _winLock
Definition: kbbind.h:134
QString value() const
Definition: keyaction.h:19
const KeyMap & map()
Definition: kbbind.h:41
bool _needsSave
Definition: kbbind.h:136
friend class KeyAction
Definition: kbbind.h:137
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132
quint64 lastGlobalRemapTime
Definition: kbbind.h:122
static quint64 globalRemapTime
Definition: kbbind.h:121
Kb * _devParent
Definition: kbbind.h:114
bool _needsUpdate
Definition: kbbind.h:135

+ Here is the call graph for this function:

Member Function Documentation

QString KbBind::action ( const QString &  key)

Definition at line 145 of file kbbind.cpp.

References bindAction(), globalRemap(), and KeyAction::value().

Referenced by friendlyActionName(), KbBindWidget::on_copyButton_clicked(), resetAction(), RebindWidget::setSelection(), and KbBindWidget::updateBind().

145  {
146  QString rKey = globalRemap(key);
147  return bindAction(rKey)->value();
148 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
QString value() const
Definition: keyaction.h:19
Definition: keymap.h:49
KeyAction * bindAction(const QString &key)
Definition: kbbind.cpp:140

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

KeyAction * KbBind::bindAction ( const QString &  key)
private

Definition at line 140 of file kbbind.cpp.

References _bind, KeyAction::defaultAction(), devParent(), and KeyAction.

Referenced by action(), keyEvent(), and update().

140  {
141  if(!_bind.contains(key)) return _bind[key] = new KeyAction(KeyAction::defaultAction(key, devParent()->model()), this);
142  return _bind[key];
143 }
Kb * devParent() const
Definition: kbbind.h:115
friend class KeyAction
Definition: kbbind.h:137
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132
static QString defaultAction(const QString &key, KeyMap::Model model)
Definition: keyaction.cpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::defaultAction ( const QString &  key)

Definition at line 155 of file kbbind.cpp.

References devParent().

Referenced by KeyWidget::paintEvent(), and RebindWidget::setBind().

155  {
156  return defaultAction(key, devParent()->model());
157 }
Kb * devParent() const
Definition: kbbind.h:115
Definition: keymap.h:49
QString defaultAction(const QString &key)
Definition: kbbind.cpp:155

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::defaultAction ( const QString &  key,
KeyMap::Model  model 
)
static

Definition at line 150 of file kbbind.cpp.

References KeyAction::defaultAction(), and globalRemap().

150  {
151  QString rKey = globalRemap(key);
152  return KeyAction::defaultAction(rKey, model);
153 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
Definition: keymap.h:49
static QString defaultAction(const QString &key, KeyMap::Model model)
Definition: keyaction.cpp:44

+ Here is the call graph for this function:

Kb* KbBind::devParent ( ) const
inlineprivate

Definition at line 115 of file kbbind.h.

References _devParent.

Referenced by bindAction(), defaultAction(), getMacroNumber(), getMacroPath(), KeyAction::keyEvent(), and save().

115 { return _devParent; }
Kb * _devParent
Definition: kbbind.h:114

+ Here is the caller graph for this function:

void KbBind::didLoad ( )
signal

Definition at line 155 of file moc_kbbind.cpp.

Referenced by load().

156 {
157  QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR);
158 }

+ Here is the caller graph for this function:

QString KbBind::friendlyActionName ( const QString &  key)

Definition at line 166 of file kbbind.cpp.

References _map, action(), and KeyAction.

Referenced by KbBindWidget::updateSelDisplay().

166  {
167  QString act = action(key);
168  return KeyAction(act).friendlyName(_map);
169 }
KeyMap _map
Definition: kbbind.h:130
friend class KeyAction
Definition: kbbind.h:137
Definition: keymap.h:49
QString action(const QString &key)
Definition: kbbind.cpp:145

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::friendlyName ( const QString &  key)

Definition at line 159 of file kbbind.cpp.

References _map, Key::friendlyName(), and globalRemap().

159  {
160  const Key& pos = _map[globalRemap(key)];
161  if(!pos)
162  return "(Unknown)";
163  return pos.friendlyName();
164 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
QString friendlyName(bool os=true) const
Definition: keymap.h:23
KeyMap _map
Definition: kbbind.h:130
Definition: keymap.h:49
Definition: keymap.h:8

+ Here is the call graph for this function:

int KbBind::getMacroNumber ( )
Returns
number of notification channel. Use it in combination with notifyon/off-Statement

Definition at line 266 of file kbbind.cpp.

References devParent(), and Kb::getMacroNumber().

Referenced by handleNotificationChannel(), and RebindWidget::on_btnStartMacro_clicked().

266  {
267  return devParent()->getMacroNumber();
268 }
Kb * devParent() const
Definition: kbbind.h:115
int getMacroNumber()
For usage with macro definions, these two params must only be readable. So there are no setters...
Definition: kb.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::getMacroPath ( )
Returns
Filepath of macro notification pipe. If not set, returns initial value ""

Definition at line 274 of file kbbind.cpp.

References devParent(), and Kb::getMacroPath().

Referenced by RebindWidget::on_btnStartMacro_clicked().

274  {
275  return devParent()->getMacroPath();
276 }
QString getMacroPath()
getMacroPath returns the macroPath (e.g. /dev/input/ckb1/notify), which we have saved in the construc...
Definition: kb.h:106
Kb * devParent() const
Definition: kbbind.h:115

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::globalRemap ( const QString &  key)
static

Definition at line 98 of file kbbind.cpp.

References _globalRemap.

Referenced by action(), defaultAction(), friendlyName(), keyEvent(), noAction(), KeyWidget::paintEvent(), resetAction(), setAction(), and SettingsWidget::SettingsWidget().

98  {
99  if(!_globalRemap.contains(key))
100  return key;
101  return _globalRemap.value(key);
102 }
Definition: keymap.h:49
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:120

+ Here is the caller graph for this function:

void KbBind::handleNotificationChannel ( bool  start)
Parameters
startis boolean. If true, notification channel is opened for all keys, otherwise channel ist closed.
startIf true, notification channel is opened for all keys, otherwise channel ist closed.

Definition at line 284 of file kbbind.cpp.

References getMacroNumber(), and lastCmd.

Referenced by RebindWidget::on_btnStartMacro_clicked(), and RebindWidget::on_btnStopMacro_clicked().

284  {
285  if (getMacroNumber() > 0 && lastCmd) {
286  if (start) {
287  lastCmd->write (QString("\nnotifyon %1\n@%1 notify all:on\n").arg(getMacroNumber()).toLatin1());
288  } else {
289  lastCmd->write (QString("\n@%1 notify all:off\nnotifyoff %1\n").arg(getMacroNumber()).toLatin1());
290  }
291  lastCmd->flush();
292  } else qDebug() << QString("No cmd or valid handle for notification found, macroNumber = %1, lastCmd = %2")
293  .arg(getMacroNumber()).arg(lastCmd? "set" : "unset");
294 }
QFile * lastCmd
lastCmd is a cache-hack. Because the QFile ist opened in Kb, and we need it in the macro processing f...
Definition: kbbind.h:128
int getMacroNumber()
KbBind::getMacroNumber.
Definition: kbbind.cpp:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool KbBind::isISO ( ) const
inline

Definition at line 43 of file kbbind.h.

References _map, and KeyMap::isISO().

43 { return _map.isISO(); }
KeyMap _map
Definition: kbbind.h:130
static bool isISO(Layout layout)
Definition: keymap.h:94

+ Here is the call graph for this function:

bool KbBind::isKeyboard ( ) const
inline

Definition at line 44 of file kbbind.h.

References _map, and KeyMap::isKeyboard().

44 { return _map.isKeyboard(); }
KeyMap _map
Definition: kbbind.h:130
static bool isKeyboard(Model model)
Definition: keymap.h:109

+ Here is the call graph for this function:

bool KbBind::isMouse ( ) const
inline

Definition at line 45 of file kbbind.h.

References _map, and KeyMap::isMouse().

Referenced by KbBindWidget::on_copyButton_clicked(), KbBindWidget::on_resetButton_clicked(), RebindWidget::setBind(), and KbBindWidget::updateSelDisplay().

45 { return _map.isMouse(); }
static bool isMouse(Model model)
Definition: keymap.h:111
KeyMap _map
Definition: kbbind.h:130

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::keyEvent ( const QString &  key,
bool  down 
)
slot

Definition at line 296 of file kbbind.cpp.

References bindAction(), globalRemap(), and KeyAction::keyEvent().

Referenced by Kb::readNotify().

296  {
297  QString rKey = globalRemap(key);
298  KeyAction* act = bindAction(rKey);
299  if(act)
300  act->keyEvent(this, down);
301 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
Definition: keymap.h:49
KeyAction * bindAction(const QString &key)
Definition: kbbind.cpp:140
void keyEvent(KbBind *bind, bool down)
Definition: keyaction.cpp:245

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::layoutChanged ( )
signal

Definition at line 161 of file moc_kbbind.cpp.

Referenced by map().

162 {
163  QMetaObject::activate(this, &staticMetaObject, 1, Q_NULLPTR);
164 }

+ Here is the caller graph for this function:

KbLight * KbBind::light ( )

Definition at line 54 of file kbbind.cpp.

References KbMode::light(), and modeParent().

Referenced by RebindWidget::applyChanges(), KeyAction::keyEvent(), and RebindWidget::setSelection().

54  {
55  return modeParent()->light();
56 }
KbLight * light()
Definition: kbmode.h:60
KbMode * modeParent() const
Definition: kbbind.h:116

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::load ( CkbSettings settings)

Definition at line 58 of file kbbind.cpp.

References _bind, _map, _needsSave, _winLock, CkbSettings::childKeys(), didLoad(), KeyMap::fromName(), KeyMap::fromStorage(), KeyAction, map(), and CkbSettings::value().

Referenced by KbMode::KbMode().

58  {
59  _needsSave = false;
60  SGroup group(settings, "Binding");
61  KeyMap currentMap = _map;
62  _map = KeyMap::fromName(settings.value("KeyMap").toString());
63  // Load key settings
64  bool useReal = settings.value("UseRealNames").toBool();
65  _bind.clear();
66  {
67  SGroup group(settings, "Keys");
68  foreach(QString key, settings.childKeys()){
69  QString name = key.toLower();
70  if(!useReal)
71  name = _map.fromStorage(name);
72  QString bind = settings.value(key).toString();
73  _bind[name] = new KeyAction(bind, this);
74  }
75  }
76  _winLock = settings.value("WinLock").toBool();
77  emit didLoad();
78  map(currentMap);
79 }
QStringList childKeys() const
bool _winLock
Definition: kbbind.h:134
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
const KeyMap & map()
Definition: kbbind.h:41
void didLoad()
Definition: moc_kbbind.cpp:155
KeyMap _map
Definition: kbbind.h:130
bool _needsSave
Definition: kbbind.h:136
friend class KeyAction
Definition: kbbind.h:137
QString fromStorage(const QString &storage)
Definition: keymap.h:151
Definition: keymap.h:49
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132
static KeyMap fromName(const QString &name)
Definition: keymap.cpp:835

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::loadGlobalRemap ( )
static

Definition at line 116 of file kbbind.cpp.

References _globalRemap, CkbSettings::childKeys(), globalRemapTime, and CkbSettings::value().

Referenced by SettingsWidget::SettingsWidget().

116  {
117  _globalRemap.clear();
118  CkbSettings settings("Program/GlobalRemap");
119  foreach(const QString& key, settings.childKeys())
120  _globalRemap[key] = settings.value(key).toString();
121  globalRemapTime = QDateTime::currentMSecsSinceEpoch();
122 }
Definition: keymap.h:49
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:120
static quint64 globalRemapTime
Definition: kbbind.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const KeyMap& KbBind::map ( )
inline
void KbBind::map ( const KeyMap map)

Definition at line 133 of file kbbind.cpp.

References _map, _needsSave, _needsUpdate, layoutChanged(), and map().

133  {
134  _map = map;
135  _needsUpdate = true;
136  _needsSave = true;
137  emit layoutChanged();
138 }
const KeyMap & map()
Definition: kbbind.h:41
KeyMap _map
Definition: kbbind.h:130
bool _needsSave
Definition: kbbind.h:136
bool _needsUpdate
Definition: kbbind.h:135
void layoutChanged()
Definition: moc_kbbind.cpp:161

+ Here is the call graph for this function:

KbMode* KbBind::modeParent ( ) const
inlineprivate

Definition at line 116 of file kbbind.h.

Referenced by light(), and perf().

116 { return (KbMode*)parent(); }
Definition: kbmode.h:36

+ Here is the caller graph for this function:

bool KbBind::needsSave ( ) const
inline

Definition at line 38 of file kbbind.h.

References _needsSave.

Referenced by KbMode::needsSave().

38 { return _needsSave; }
bool _needsSave
Definition: kbbind.h:136

+ Here is the caller graph for this function:

void KbBind::noAction ( const QString &  key)

Definition at line 181 of file kbbind.cpp.

References _bind, _map, globalRemap(), KeyMap::key(), KeyAction, and resetAction().

Referenced by RebindWidget::applyChanges(), and RebindWidget::on_unbindButton_clicked().

181  {
182  resetAction(key);
183  QString rKey = globalRemap(key);
184  if(!_map.key(rKey))
185  return;
186  _bind[rKey] = new KeyAction(this);
187 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
KeyMap _map
Definition: kbbind.h:130
Key key(const QString &name) const
Definition: keymap.h:141
friend class KeyAction
Definition: kbbind.h:137
Definition: keymap.h:49
void resetAction(const QString &key)
Definition: kbbind.cpp:171
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::noAction ( const QStringList &  keys)
inline

Definition at line 76 of file kbbind.h.

References noAction().

Referenced by noAction().

76 { foreach(const QString& key, keys) noAction(key); }
Definition: keymap.h:49
void noAction(const QString &key)
Definition: kbbind.cpp:181

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

KbPerf * KbBind::perf ( )

Definition at line 50 of file kbbind.cpp.

References modeParent(), and KbMode::perf().

Referenced by KeyAction::keyEvent(), and RebindWidget::setBind().

50  {
51  return modeParent()->perf();
52 }
KbMode * modeParent() const
Definition: kbbind.h:116
KbPerf * perf()
Definition: kbmode.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::resetAction ( const QString &  key)

Definition at line 171 of file kbbind.cpp.

References _bind, _needsSave, _needsUpdate, action(), and globalRemap().

Referenced by noAction(), KbBindWidget::on_resetButton_clicked(), RebindWidget::on_resetButton_clicked(), and setAction().

171  {
172  QString rKey = globalRemap(key);
173  // Clean up existing action (if any)
174  KeyAction* action = _bind.value(rKey);
175  delete action;
176  _bind.remove(rKey);
177  _needsUpdate = true;
178  _needsSave = true;
179 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
bool _needsSave
Definition: kbbind.h:136
Definition: keymap.h:49
QString action(const QString &key)
Definition: kbbind.cpp:145
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132
bool _needsUpdate
Definition: kbbind.h:135

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::resetAction ( const QStringList &  keys)
inline

Definition at line 73 of file kbbind.h.

References resetAction().

Referenced by resetAction().

73 { foreach(const QString& key, keys) resetAction(key); }
Definition: keymap.h:49
void resetAction(const QString &key)
Definition: kbbind.cpp:171

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::save ( CkbSettings settings)

Definition at line 81 of file kbbind.cpp.

References _bind, _map, _needsSave, _winLock, KeyAction::defaultAction(), devParent(), KeyMap::name(), CkbSettings::setValue(), and KeyAction::value().

Referenced by KbMode::save().

81  {
82  _needsSave = false;
83  SGroup group(settings, "Binding");
84  settings.setValue("KeyMap", _map.name());
85  // Save key settings
86  settings.setValue("UseRealNames", true);
87  {
88  SGroup group(settings, "Keys");
89  foreach(QString key, _bind.keys()){
90  KeyAction* act = _bind.value(key);
91  if(act && act->value() != KeyAction::defaultAction(key, devParent()->model()))
92  settings.setValue(key, act->value());
93  }
94  }
95  settings.setValue("WinLock", _winLock);
96 }
void setValue(const QString &key, const QVariant &value)
bool _winLock
Definition: kbbind.h:134
Kb * devParent() const
Definition: kbbind.h:115
QString value() const
Definition: keyaction.h:19
KeyMap _map
Definition: kbbind.h:130
bool _needsSave
Definition: kbbind.h:136
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132
QString name() const
Definition: keymap.h:131
static QString defaultAction(const QString &key, KeyMap::Model model)
Definition: keyaction.cpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::saveGlobalRemap ( )
static

Definition at line 124 of file kbbind.cpp.

References _globalRemap, and CkbSettings::setValue().

Referenced by SettingsWidget::updateModifiers().

124  {
125  CkbSettings settings("Program/GlobalRemap", true);
126  QHashIterator<QString, QString> i(_globalRemap);
127  while(i.hasNext()){
128  i.next();
129  settings.setValue(i.key(), i.value());
130  }
131 }
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::setAction ( const QString &  key,
const QString &  action 
)

Definition at line 189 of file kbbind.cpp.

References _bind, _map, globalRemap(), KeyMap::key(), KeyAction, and resetAction().

Referenced by RebindWidget::applyChanges(), and KbBindWidget::on_copyButton_clicked().

189  {
190  resetAction(key);
191  QString rKey = globalRemap(key);
192  if(!_map.key(rKey))
193  return;
194  _bind[rKey] = new KeyAction(action, this);
195 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
KeyMap _map
Definition: kbbind.h:130
Key key(const QString &name) const
Definition: keymap.h:141
friend class KeyAction
Definition: kbbind.h:137
Definition: keymap.h:49
void resetAction(const QString &key)
Definition: kbbind.cpp:171
QString action(const QString &key)
Definition: kbbind.cpp:145
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::setAction ( const QStringList &  keys,
const QString &  action 
)
inline

Definition at line 70 of file kbbind.h.

References setAction().

Referenced by setAction().

70 { foreach(const QString& key, keys) setAction(key, action); }
Definition: keymap.h:49
QString action(const QString &key)
Definition: kbbind.cpp:145
void setAction(const QString &key, const QString &action)
Definition: kbbind.cpp:189

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::setGlobalRemap ( const QHash< QString, QString >  keyToActual)
static

Definition at line 104 of file kbbind.cpp.

References _globalRemap, and globalRemapTime.

Referenced by SettingsWidget::updateModifiers().

104  {
105  _globalRemap.clear();
106  // Ignore any keys with the standard binding
107  QHashIterator<QString, QString> i(keyToActual);
108  while(i.hasNext()){
109  i.next();
110  if(i.key() != i.value())
111  _globalRemap[i.key()] = i.value();
112  }
113  globalRemapTime = QDateTime::currentMSecsSinceEpoch();
114 }
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:120
static quint64 globalRemapTime
Definition: kbbind.h:121

+ Here is the caller graph for this function:

void KbBind::setNeedsUpdate ( )
inline

Definition at line 85 of file kbbind.h.

References _needsUpdate.

Referenced by KbMode::setNeedsUpdate().

85 { _needsUpdate = true; }
bool _needsUpdate
Definition: kbbind.h:135

+ Here is the caller graph for this function:

void KbBind::update ( QFile &  cmd,
bool  force = false 
)

Definition at line 197 of file kbbind.cpp.

References _bind, _globalRemap, _needsUpdate, _winLock, bindAction(), KeyAction::driverName(), globalRemapTime, KeyAction::isValidMacro(), lastCmd, lastGlobalRemapTime, KeyAction::macroContent(), updated(), and KeyAction::value().

Referenced by Kb::frameUpdate().

197  {
199  return;
201  emit updated();
202  _needsUpdate = false;
203  // Reset all keys and enable notifications for all
204  cmd.write("rebind all notify all");
205  // Make sure modifier keys are included as they may be remapped globally
206  QHash<QString, KeyAction*> bind(_bind);
207  if(!_bind.contains("caps")) bind["caps"] = 0;
208  if(!_bind.contains("lshift")) bind["lshift"] = 0;
209  if(!_bind.contains("rshift")) bind["rshift"] = 0;
210  if(!_bind.contains("lctrl")) bind["lctrl"] = 0;
211  if(!_bind.contains("rctrl")) bind["rctrl"] = 0;
212  if(!_bind.contains("lwin")) bind["lwin"] = 0;
213  if(!_bind.contains("rwin")) bind["rwin"] = 0;
214  if(!_bind.contains("lalt")) bind["lalt"] = 0;
215  if(!_bind.contains("ralt")) bind["ralt"] = 0;
216  if(!_bind.contains("fn")) bind["fn"] = 0;
217  QHashIterator<QString, KeyAction*> i(bind);
218 
219  // Initialize String buffer for macro Key definitions (G-keys)
220  // "macro clear" is neccessary, if an older definition is unbound.
221  QString macros = "\nmacro clear\n";
222 
223  // Write out rebound keys and collect infos for macro definitions
224  while(i.hasNext()){
225  i.next();
226  QString key = i.key();
227  KeyAction* act = i.value();
228  if(_globalRemap.contains(key))
229  act = bindAction(_globalRemap.value(key));
230  if(!act)
231  continue;
232  QString value = act->driverName();
233  if(value.isEmpty()){
234  // If the key is unbound or is a special action, unbind it
235  cmd.write(" unbind ");
236  cmd.write(key.toLatin1());
237  // if a macro definiton for the key is given,
238  // add the converted string to key-buffer "macro"
239  if (act->isValidMacro()) {
240  if (act->macroContent().length() > 0) {
241  macros.append("macro " + key.toLatin1() + ":" + act->macroContent().toLatin1() + "\n");
242  }
243  }
244  } else {
245  // Otherwise, write the binding
246  cmd.write(" bind ");
247  cmd.write(key.toLatin1());
248  cmd.write(":");
249  cmd.write(value.toLatin1());
250  }
251  }
252  // If win lock is enabled, unbind windows keys
253  if(_winLock)
254  cmd.write(" unbind lwin rwin");
255 
256  // At last, send Macro definitions if available.
257  // If no definitions are made, clear macro will be sent only to reset all macros,
258  cmd.write(macros.toLatin1());
259  lastCmd = &cmd;
260 }
bool _winLock
Definition: kbbind.h:134
cmd
Definition: command.h:7
QString value() const
Definition: keyaction.h:19
bool isValidMacro() const
isValidMacro checks whether a keyAction contains a valid macro. This is done easily: If the macro act...
Definition: keyaction.h:55
Definition: keymap.h:49
QString driverName() const
Definition: keyaction.cpp:239
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:120
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132
quint64 lastGlobalRemapTime
Definition: kbbind.h:122
QFile * lastCmd
lastCmd is a cache-hack. Because the QFile ist opened in Kb, and we need it in the macro processing f...
Definition: kbbind.h:128
static quint64 globalRemapTime
Definition: kbbind.h:121
QString macroContent() const
macroContent returns the macro key definition only (the second part of the macro action).
Definition: keyaction.h:86
void updated()
Definition: moc_kbbind.cpp:167
bool _needsUpdate
Definition: kbbind.h:135
KeyAction * bindAction(const QString &key)
Definition: kbbind.cpp:140

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::updated ( )
signal

Definition at line 167 of file moc_kbbind.cpp.

Referenced by update().

168 {
169  QMetaObject::activate(this, &staticMetaObject, 2, Q_NULLPTR);
170 }

+ Here is the caller graph for this function:

bool KbBind::winLock ( )
inline

Definition at line 79 of file kbbind.h.

References _winLock.

Referenced by KeyAction::keyEvent().

79 { return _winLock; }
bool _winLock
Definition: kbbind.h:134

+ Here is the caller graph for this function:

void KbBind::winLock ( bool  newWinLock)
inline

Definition at line 80 of file kbbind.h.

References _needsUpdate, and _winLock.

80 { _winLock = newWinLock; _needsUpdate = true; }
bool _winLock
Definition: kbbind.h:134
bool _needsUpdate
Definition: kbbind.h:135

Friends And Related Function Documentation

friend class KeyAction
friend

Definition at line 137 of file kbbind.h.

Referenced by bindAction(), friendlyActionName(), KbBind(), load(), noAction(), and setAction().

Field Documentation

QHash<QString, KeyAction*> KbBind::_bind
private

Definition at line 132 of file kbbind.h.

Referenced by bindAction(), KbBind(), load(), noAction(), resetAction(), save(), setAction(), and update().

Kb* KbBind::_devParent
private

Definition at line 114 of file kbbind.h.

Referenced by devParent().

QHash< QString, QString > KbBind::_globalRemap
staticprivate

Definition at line 120 of file kbbind.h.

Referenced by globalRemap(), loadGlobalRemap(), saveGlobalRemap(), setGlobalRemap(), and update().

KeyMap KbBind::_map
private
bool KbBind::_needsSave
private

Definition at line 136 of file kbbind.h.

Referenced by load(), map(), needsSave(), resetAction(), and save().

bool KbBind::_needsUpdate
private

Definition at line 135 of file kbbind.h.

Referenced by map(), resetAction(), setNeedsUpdate(), update(), and winLock().

bool KbBind::_winLock
private

Definition at line 134 of file kbbind.h.

Referenced by load(), save(), update(), and winLock().

quint64 KbBind::globalRemapTime = 0
staticprivate

Definition at line 121 of file kbbind.h.

Referenced by loadGlobalRemap(), setGlobalRemap(), and update().

QFile* KbBind::lastCmd
private

Definition at line 128 of file kbbind.h.

Referenced by handleNotificationChannel(), and update().

quint64 KbBind::lastGlobalRemapTime
private

Definition at line 122 of file kbbind.h.

Referenced by update().


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