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

#include <src/ckb/settingswidget.h>

+ Inheritance diagram for SettingsWidget:
+ Collaboration diagram for SettingsWidget:

Public Member Functions

 SettingsWidget (QWidget *parent=0)
 
 ~SettingsWidget ()
 
void setVersion (const QString &version)
 
void setStatus (const QString &text)
 
void pollUpdates ()
 

Private Slots

void on_pushButton_clicked ()
 
void on_capsBox_activated (int index)
 
void on_shiftBox_activated (int index)
 
void on_ctrlBox_activated (int index)
 
void on_altBox_activated (int index)
 
void on_winBox_activated (int index)
 
void on_autoFWBox_clicked (bool checked)
 
void on_loginItemBox_clicked (bool checked)
 
void on_layoutBox_activated (int index)
 
void showLayoutDialog ()
 
void on_extraButton_clicked ()
 

Private Member Functions

void updateModifiers ()
 

Private Attributes

Ui::SettingsWidgetui
 
ExtraSettingsWidgetextra
 

Friends

class MainWindow
 

Detailed Description

Definition at line 11 of file settingswidget.h.

Constructor & Destructor Documentation

SettingsWidget::SettingsWidget ( QWidget parent = 0)
explicit

Definition at line 15 of file settingswidget.cpp.

References Ui_SettingsWidget::altBox, Ui_SettingsWidget::autoFWBox, AutoRun::available(), Ui_SettingsWidget::capsBox, Ui_SettingsWidget::ctrlBox, AutoRun::enable(), extra, KeyMap::getLayout(), KbBind::globalRemap(), AutoRun::isEnabled(), Kb::layout(), Ui_SettingsWidget::layoutBox, KeyMap::layoutNames(), KbBind::loadGlobalRemap(), KeyMap::locale(), Ui_SettingsWidget::loginItemBox, modKeys, modNames, KeyMap::NO_LAYOUT, AutoRun::once(), CkbSettings::remove(), Ui_SettingsWidget::setupUi(), CkbSettings::setValue(), Ui_SettingsWidget::shiftBox, showLayoutDialog(), ui, updateModifiers(), CkbSettings::value(), and Ui_SettingsWidget::winBox.

15  :
16  QWidget(parent),
18 {
19  ui->setupUi(this);
20  CkbSettings settings("Program");
21 
22  // Read keyboard layout
23  ui->layoutBox->addItems(KeyMap::layoutNames());
24  KeyMap::Layout layout = KeyMap::getLayout(settings.value("KbdLayout").toString());
25  if(layout == KeyMap::NO_LAYOUT){
26  // If the layout hasn't been set yet, show a dialog to let the user choose it
27  layout = KeyMap::locale();
28  QTimer::singleShot(1000, this, SLOT(showLayoutDialog())); // Run the function after a delay as the dialog may not appear correctly otherwise
29  settings.setValue("KbdLayout", KeyMap::getLayout(layout));
30  }
31  Kb::layout(layout);
32  ui->layoutBox->setCurrentIndex((int)layout);
33 
34  // Load modifier remap
36  if(modKeys.isEmpty()){
37  modKeys << "caps" << "lshift" << "lctrl" << "lalt" << "lwin";
38 #ifdef Q_OS_MACX
39  modNames << "Caps Lock" << "Shift" << "Control (⌃)" << "Option (⌥)" << "Command (⌘)";
40 #else
41  modNames << "Caps Lock" << "Shift" << "Control" << "Alt" << "Super";
42 #endif
43  }
44  foreach(const QString& name, modNames){
45  ui->capsBox->addItem(name);
46  ui->shiftBox->addItem(name);
47  ui->ctrlBox->addItem(name);
48  ui->altBox->addItem(name);
49  ui->winBox->addItem(name);
50  }
51 
52  int idx = modKeys.indexOf(KbBind::globalRemap("caps"));
53  if(idx >= 0)
54  ui->capsBox->setCurrentIndex(idx);
55  idx = modKeys.indexOf(KbBind::globalRemap("lshift"));
56  if(idx >= 0)
57  ui->shiftBox->setCurrentIndex(idx);
58  idx = modKeys.indexOf(KbBind::globalRemap("lctrl"));
59  if(idx >= 0)
60  ui->ctrlBox->setCurrentIndex(idx);
61  idx = modKeys.indexOf(KbBind::globalRemap("lwin"));
62  if(idx >= 0)
63  ui->winBox->setCurrentIndex(idx);
64  idx = modKeys.indexOf(KbBind::globalRemap("lalt"));
65  if(idx >= 0)
66  ui->altBox->setCurrentIndex(idx);
67 #ifdef Q_OS_MACX
68  if(settings.value("osxCmdSwap").toBool()){
69  // ckb <0.0.41
70  settings.remove("osxCmdSwap");
71  ui->ctrlBox->setCurrentIndex(modKeys.indexOf("lwin"));
72  ui->winBox->setCurrentIndex(modKeys.indexOf("lctrl"));
74  }
75 #endif
76 
77  // Read auto update settings
78  ui->autoFWBox->setChecked(!settings.value("DisableAutoFWCheck").toBool());
79 
80  // Read auto run settings
81  if(!AutoRun::available())
82  ui->loginItemBox->hide();
83  else {
84  if(!AutoRun::once())
85  // If this is the first time running the app, enable auto run by default
87  ui->loginItemBox->setChecked(AutoRun::isEnabled());
88  }
89 
90  // Prepare extra settings
91  extra = new ExtraSettingsWidget(this);
92 }
Layout
Definition: keymap.h:70
static KeyMap::Layout layout()
Definition: kb.h:30
static bool available()
Definition: autorun.cpp:20
ExtraSettingsWidget * extra
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
static QStringList layoutNames()
Definition: keymap.cpp:757
Ui::SettingsWidget * ui
static Layout getLayout(const QString &name)
Definition: keymap.cpp:677
void setupUi(QWidget *SettingsWidget)
static QStringList modNames
QCheckBox * loginItemBox
static bool isEnabled()
Definition: autorun.cpp:33
static void enable()
Definition: autorun.cpp:42
static Layout locale()
Definition: keymap.cpp:641
static bool once()
Definition: autorun.cpp:29
static void loadGlobalRemap()
Definition: kbbind.cpp:116
static QStringList modKeys

+ Here is the call graph for this function:

SettingsWidget::~SettingsWidget ( )

Definition at line 94 of file settingswidget.cpp.

References ui.

94  {
95  delete ui;
96 }
Ui::SettingsWidget * ui

Member Function Documentation

void SettingsWidget::on_altBox_activated ( int  index)
privateslot

Definition at line 155 of file settingswidget.cpp.

References updateModifiers().

155  {
156  updateModifiers();
157 }

+ Here is the call graph for this function:

void SettingsWidget::on_autoFWBox_clicked ( bool  checked)
privateslot

Definition at line 163 of file settingswidget.cpp.

References CkbSettings::set().

163  {
164  CkbSettings::set("Program/DisableAutoFWCheck", !checked);
165 }
static void set(const QString &key, const QVariant &value)

+ Here is the call graph for this function:

void SettingsWidget::on_capsBox_activated ( int  index)
privateslot

Definition at line 143 of file settingswidget.cpp.

References updateModifiers().

143  {
144  updateModifiers();
145 }

+ Here is the call graph for this function:

void SettingsWidget::on_ctrlBox_activated ( int  index)
privateslot

Definition at line 151 of file settingswidget.cpp.

References updateModifiers().

151  {
152  updateModifiers();
153 }

+ Here is the call graph for this function:

void SettingsWidget::on_extraButton_clicked ( )
privateslot

Definition at line 180 of file settingswidget.cpp.

References extra.

180  {
181  extra->exec();
182 }
ExtraSettingsWidget * extra
void SettingsWidget::on_layoutBox_activated ( int  index)
privateslot

Definition at line 174 of file settingswidget.cpp.

References KeyMap::getLayout(), Kb::layout(), and CkbSettings::set().

Referenced by showLayoutDialog().

174  {
175  KeyMap::Layout layout = (KeyMap::Layout)index;
176  CkbSettings::set("Program/KbdLayout", KeyMap::getLayout(layout));
177  Kb::layout(layout);
178 }
Layout
Definition: keymap.h:70
static KeyMap::Layout layout()
Definition: kb.h:30
static void set(const QString &key, const QVariant &value)
static Layout getLayout(const QString &name)
Definition: keymap.cpp:677

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SettingsWidget::on_loginItemBox_clicked ( bool  checked)
privateslot

Definition at line 167 of file settingswidget.cpp.

References AutoRun::disable(), and AutoRun::enable().

167  {
168  if(checked)
169  AutoRun::enable();
170  else
172 }
static void disable()
Definition: autorun.cpp:53
static void enable()
Definition: autorun.cpp:42

+ Here is the call graph for this function:

void SettingsWidget::on_pushButton_clicked ( )
privateslot

Definition at line 139 of file settingswidget.cpp.

139  {
140  qApp->quit();
141 }
void SettingsWidget::on_shiftBox_activated ( int  index)
privateslot

Definition at line 147 of file settingswidget.cpp.

References updateModifiers().

147  {
148  updateModifiers();
149 }

+ Here is the call graph for this function:

void SettingsWidget::on_winBox_activated ( int  index)
privateslot

Definition at line 159 of file settingswidget.cpp.

References updateModifiers().

159  {
160  updateModifiers();
161 }

+ Here is the call graph for this function:

void SettingsWidget::pollUpdates ( )

Definition at line 106 of file settingswidget.cpp.

References extra, and ExtraSettingsWidget::pollUpdates().

Referenced by MainWindow::timerTick().

106  {
107  extra->pollUpdates();
108 }
ExtraSettingsWidget * extra

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SettingsWidget::setStatus ( const QString &  text)

Definition at line 110 of file settingswidget.cpp.

References Ui_SettingsWidget::devicesLabel, and ui.

Referenced by MainWindow::MainWindow(), and MainWindow::updateVersion().

110  {
111  ui->devicesLabel->setText(text);
112 }
Ui::SettingsWidget * ui

+ Here is the caller graph for this function:

void SettingsWidget::setVersion ( const QString &  version)

Definition at line 114 of file settingswidget.cpp.

References ui, and Ui_SettingsWidget::versionLabel.

Referenced by MainWindow::MainWindow().

114  {
115  ui->versionLabel->setText(version);
116 }
Ui::SettingsWidget * ui

+ Here is the caller graph for this function:

void SettingsWidget::showLayoutDialog ( )
privateslot

Definition at line 98 of file settingswidget.cpp.

References Ui_SettingsWidget::layoutBox, on_layoutBox_activated(), LayoutDialog::selected(), and ui.

Referenced by SettingsWidget().

98  {
99  LayoutDialog dialog(this);
100  dialog.exec();
101  // Set selected layout
102  ui->layoutBox->setCurrentIndex((int)dialog.selected());
103  on_layoutBox_activated((int)dialog.selected()); // Call activated() signal manually to trigger save
104 }
Ui::SettingsWidget * ui
void on_layoutBox_activated(int index)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SettingsWidget::updateModifiers ( )
private

Definition at line 124 of file settingswidget.cpp.

References Ui_SettingsWidget::altBox, Ui_SettingsWidget::capsBox, Ui_SettingsWidget::ctrlBox, modKeys, right(), KbBind::saveGlobalRemap(), KbBind::setGlobalRemap(), Ui_SettingsWidget::shiftBox, ui, and Ui_SettingsWidget::winBox.

Referenced by on_altBox_activated(), on_capsBox_activated(), on_ctrlBox_activated(), on_shiftBox_activated(), on_winBox_activated(), and SettingsWidget().

124  {
125  QHash<QString, QString> newMods;
126  newMods["caps"] = modKeys[ui->capsBox->currentIndex()];
127  newMods["lshift"] = modKeys[ui->shiftBox->currentIndex()];
128  newMods["rshift"] = right(modKeys[ui->shiftBox->currentIndex()]);
129  newMods["lctrl"] = modKeys[ui->ctrlBox->currentIndex()];
130  newMods["rctrl"] = right(modKeys[ui->ctrlBox->currentIndex()]);
131  newMods["lalt"] = modKeys[ui->altBox->currentIndex()];
132  newMods["ralt"] = right(modKeys[ui->altBox->currentIndex()]);
133  newMods["lwin"] = modKeys[ui->winBox->currentIndex()];
134  newMods["rwin"] = right(modKeys[ui->winBox->currentIndex()]);
135  KbBind::setGlobalRemap(newMods);
137 }
static void setGlobalRemap(const QHash< QString, QString > keyToActual)
Definition: kbbind.cpp:104
Ui::SettingsWidget * ui
static QString right(const QString &left)
static void saveGlobalRemap()
Definition: kbbind.cpp:124
static QStringList modKeys

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class MainWindow
friend

Definition at line 44 of file settingswidget.h.

Field Documentation

ExtraSettingsWidget* SettingsWidget::extra
private

Definition at line 46 of file settingswidget.h.

Referenced by on_extraButton_clicked(), pollUpdates(), and SettingsWidget().

Ui::SettingsWidget* SettingsWidget::ui
private

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