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
KbBindWidget Class Reference

#include <src/ckb/kbbindwidget.h>

+ Inheritance diagram for KbBindWidget:
+ Collaboration diagram for KbBindWidget:

Public Member Functions

 KbBindWidget (QWidget *parent=0)
 
 ~KbBindWidget ()
 
void setBind (KbBind *newBind, KbProfile *newProfile)
 

Private Slots

void updateBind ()
 
void newLayout ()
 
void newSelection (QStringList selection)
 
void updateSelDisplay ()
 
void on_resetButton_clicked ()
 
void on_copyButton_clicked ()
 

Private Attributes

Ui::KbBindWidgetui
 
KbBindbind
 
KbProfileprofile
 
QStringList currentSelection
 

Detailed Description

Definition at line 12 of file kbbindwidget.h.

Constructor & Destructor Documentation

KbBindWidget::KbBindWidget ( QWidget parent = 0)
explicit

Definition at line 7 of file kbbindwidget.cpp.

References Ui_KbBindWidget::keyWidget, newSelection(), KeyWidget::rgbMode(), Ui_KbBindWidget::setupUi(), and ui.

7  :
8  QWidget(parent),
9  ui(new Ui::KbBindWidget), bind(0), profile(0)
10 {
11  ui->setupUi(this);
12  ui->keyWidget->rgbMode(false);
13  connect(ui->keyWidget, SIGNAL(selectionChanged(QStringList)), this, SLOT(newSelection(QStringList)));
14 }
KbProfile * profile
Definition: kbbindwidget.h:35
bool rgbMode()
Definition: keywidget.h:17
KbBind * bind
Definition: kbbindwidget.h:34
void setupUi(QWidget *KbBindWidget)
KeyWidget * keyWidget
Ui::KbBindWidget * ui
Definition: kbbindwidget.h:32
void newSelection(QStringList selection)

+ Here is the call graph for this function:

KbBindWidget::~KbBindWidget ( )

Definition at line 16 of file kbbindwidget.cpp.

References ui.

16  {
17  delete ui;
18 }
Ui::KbBindWidget * ui
Definition: kbbindwidget.h:32

Member Function Documentation

void KbBindWidget::newLayout ( )
privateslot

Definition at line 50 of file kbbindwidget.cpp.

References bind, Ui_KbBindWidget::keyWidget, KeyWidget::map(), KbBind::map(), profile, Ui_KbBindWidget::rbWidget, RebindWidget::setBind(), ui, and updateSelDisplay().

Referenced by setBind().

50  {
51  ui->keyWidget->map(bind->map());
54 }
KbProfile * profile
Definition: kbbindwidget.h:35
KbBind * bind
Definition: kbbindwidget.h:34
const KeyMap & map()
Definition: kbbind.h:41
const KeyMap & map() const
Definition: keywidget.h:24
RebindWidget * rbWidget
void updateSelDisplay()
KeyWidget * keyWidget
Ui::KbBindWidget * ui
Definition: kbbindwidget.h:32
void setBind(KbBind *newBind, KbProfile *newProfile)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBindWidget::newSelection ( QStringList  selection)
privateslot

Definition at line 56 of file kbbindwidget.cpp.

References currentSelection, Ui_KbBindWidget::rbWidget, RebindWidget::setSelection(), ui, and updateSelDisplay().

Referenced by KbBindWidget(), and setBind().

56  {
57  currentSelection = selection;
58  ui->rbWidget->setSelection(selection, true);
60 }
RebindWidget * rbWidget
void updateSelDisplay()
Ui::KbBindWidget * ui
Definition: kbbindwidget.h:32
void setSelection(const QStringList &newSelection, bool applyPrevious=false)
QStringList currentSelection
Definition: kbbindwidget.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBindWidget::on_copyButton_clicked ( )
privateslot

Definition at line 103 of file kbbindwidget.cpp.

References KbBind::action(), bind, KbMode::bind(), KeyMap::count(), KbProfile::currentMode(), currentSelection, KbBind::isMouse(), KeyMap::keys(), KbBind::map(), KbProfile::modes(), profile, ModeSelectDialog::selection(), KbBind::setAction(), and KeyAction::type().

103  {
104  QStringList selection = currentSelection;
105  const KeyMap& map = bind->map();
106  int count = selection.count();
107  QString type = bind->isMouse() ? "button" : "key";
108  QString text = tr("%1 %2").arg(count).arg(type) + (count == 1 ? "" : "s");
109  if(count == 0){
110  // Copy all keys if none selected
111  selection = map.keys();
112  text = tr("all %1s").arg(type);
113  }
114  text = "Copy binding for " + text + " to:";
115  // Display popup
116  ModeSelectDialog dialog(this, profile->currentMode(), profile->modes(), text);
117  if(dialog.exec() != QDialog::Accepted)
118  return;
119  // Copy selected keys to selected modes
120  QList<KbMode*> selectedModes = dialog.selection();
121  foreach(KbMode* mode, selectedModes){
122  KbBind* modeBind = mode->bind();
123  foreach(const QString& key, selection){
124  modeBind->setAction(key, bind->action(key));
125  }
126  }
127 }
KbMode * currentMode() const
Definition: kbprofile.h:54
const ModeList & modes() const
Definition: kbprofile.h:42
bool isMouse() const
Definition: kbbind.h:45
KbBind * bind()
Definition: kbmode.h:61
KbProfile * profile
Definition: kbbindwidget.h:35
KbBind * bind
Definition: kbbindwidget.h:34
const KeyMap & map()
Definition: kbbind.h:41
Definition: keymap.h:49
Definition: kbmode.h:36
QString action(const QString &key)
Definition: kbbind.cpp:145
Definition: kbbind.h:20
QStringList keys() const
Definition: keymap.h:147
Definition: keymap.h:49
void setAction(const QString &key, const QString &action)
Definition: kbbind.cpp:189
QList< KbMode * > selection()
QStringList currentSelection
Definition: kbbindwidget.h:36
uint count() const
Definition: keymap.h:134

+ Here is the call graph for this function:

void KbBindWidget::on_resetButton_clicked ( )
privateslot

Definition at line 82 of file kbbindwidget.cpp.

References bind, KeyMap::count(), currentSelection, KbBind::isMouse(), KeyMap::keys(), KbBind::map(), KbBind::resetAction(), KeyAction::type(), and updateBind().

82  {
83  QStringList selection = currentSelection;
84  const KeyMap& map = bind->map();
85  if(selection.isEmpty())
86  // Reset all keys if none selected
87  selection = map.keys();
88  uint count = selection.count();
89  QString type = bind->isMouse() ? "button" : "key";
90  QString text;
91  if(count == map.count())
92  text = "<center>Reset all %1s to default?</center>";
93  else if(count == 1)
94  text = "<center>Reset this %1 to default?</center>";
95  else
96  text = tr("<center>Reset %1 %2s to default?</center>").arg(count);
97  if(QMessageBox(QMessageBox::NoIcon, "Confirm action", text.arg(type), QMessageBox::Yes | QMessageBox::No, this).exec() != QMessageBox::Yes)
98  return;
99  bind->resetAction(selection);
100  updateBind();
101 }
bool isMouse() const
Definition: kbbind.h:45
KbBind * bind
Definition: kbbindwidget.h:34
const KeyMap & map()
Definition: kbbind.h:41
void resetAction(const QString &key)
Definition: kbbind.cpp:171
QStringList keys() const
Definition: keymap.h:147
Definition: keymap.h:49
QStringList currentSelection
Definition: kbbindwidget.h:36
void updateBind()
uint count() const
Definition: keymap.h:134

+ Here is the call graph for this function:

void KbBindWidget::setBind ( KbBind newBind,
KbProfile newProfile 
)

Definition at line 20 of file kbbindwidget.cpp.

References bind, KeyWidget::clearSelection(), Ui_KbBindWidget::keyWidget, newLayout(), newSelection(), profile, Ui_KbBindWidget::rbWidget, RebindWidget::setBind(), ui, and updateBind().

Referenced by KbWidget::modeChanged().

20  {
22  ui->rbWidget->setBind(newBind, newProfile);
23  newSelection(QStringList());
24  if(bind == newBind)
25  return;
26  if(bind){
27  disconnect(bind, SIGNAL(layoutChanged()), this, SLOT(newLayout()));
28  disconnect(bind, SIGNAL(updated()), this, SLOT(updateBind()));
29  }
30  connect(newBind, SIGNAL(layoutChanged()), this, SLOT(newLayout()));
31  connect(newBind, SIGNAL(updated()), this, SLOT(updateBind()));
32  bind = newBind;
33  profile = newProfile;
34  newLayout();
36  updateBind();
37 }
void clearSelection()
Definition: keywidget.cpp:617
KbProfile * profile
Definition: kbbindwidget.h:35
KbBind * bind
Definition: kbbindwidget.h:34
RebindWidget * rbWidget
KeyWidget * keyWidget
void newLayout()
Ui::KbBindWidget * ui
Definition: kbbindwidget.h:32
void newSelection(QStringList selection)
void setBind(KbBind *newBind, KbProfile *newProfile)
void updateBind()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBindWidget::updateBind ( )
privateslot

Definition at line 39 of file kbbindwidget.cpp.

References KbBind::action(), bind, KeyWidget::bindMap(), currentSelection, KeyMap::keys(), Ui_KbBindWidget::keyWidget, KbBind::map(), Ui_KbBindWidget::rbWidget, RebindWidget::setSelection(), ui, and updateSelDisplay().

Referenced by on_resetButton_clicked(), and setBind().

39  {
40  const KeyMap& map = bind->map();
41  // Build the action list based on the keymap
42  QHash<QString, QString> actions;
43  foreach(const QString& key, map.keys())
44  actions[key] = bind->action(key);
45  ui->keyWidget->bindMap(actions);
48 }
const BindMap & bindMap() const
Definition: keywidget.h:31
KbBind * bind
Definition: kbbindwidget.h:34
const KeyMap & map()
Definition: kbbind.h:41
Definition: keymap.h:49
RebindWidget * rbWidget
void updateSelDisplay()
QString action(const QString &key)
Definition: kbbind.cpp:145
KeyWidget * keyWidget
QStringList keys() const
Definition: keymap.h:147
Definition: keymap.h:49
Ui::KbBindWidget * ui
Definition: kbbindwidget.h:32
void setSelection(const QStringList &newSelection, bool applyPrevious=false)
QStringList currentSelection
Definition: kbbindwidget.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBindWidget::updateSelDisplay ( )
privateslot

Definition at line 62 of file kbbindwidget.cpp.

References bind, currentSelection, KbBind::friendlyActionName(), Key::friendlyName(), KbBind::isMouse(), KbBind::map(), Ui_KbBindWidget::selectLabel, and ui.

Referenced by newLayout(), newSelection(), and updateBind().

62  {
63  int count = currentSelection.count();
64  if(count == 0){
65  // No keys selected
66  ui->selectLabel->setText("Click to select");
67  return;
68  }
69  if(count == 1){
70  // Single key selected: show key name and binding
71  QString key = currentSelection[0];
72  const Key& pos = bind->map()[key];
73  if(!pos)
74  ui->selectLabel->setText("(Unknown)");
75  else
76  ui->selectLabel->setText(pos.friendlyName(false).split("\n")[0] + " → " + bind->friendlyActionName(key).split("\n")[0]);
77  return;
78  }
79  ui->selectLabel->setText(QString("%1 %2 selected").arg(count).arg(bind->isMouse() ? "buttons" : "keys"));
80 }
bool isMouse() const
Definition: kbbind.h:45
QLabel * selectLabel
QString friendlyName(bool os=true) const
Definition: keymap.h:23
KbBind * bind
Definition: kbbindwidget.h:34
const KeyMap & map()
Definition: kbbind.h:41
Definition: keymap.h:49
QString friendlyActionName(const QString &key)
Definition: kbbind.cpp:166
Definition: keymap.h:8
Ui::KbBindWidget * ui
Definition: kbbindwidget.h:32
QStringList currentSelection
Definition: kbbindwidget.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

KbBind* KbBindWidget::bind
private
QStringList KbBindWidget::currentSelection
private
KbProfile* KbBindWidget::profile
private

Definition at line 35 of file kbbindwidget.h.

Referenced by newLayout(), on_copyButton_clicked(), and setBind().

Ui::KbBindWidget* KbBindWidget::ui
private

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