refs #892, key sequences / actions for settings

This commit is contained in:
Klaus Basan
2017-02-27 20:04:28 +01:00
committed by Mathew Sutcliffe
parent d504bfbee0
commit 72200d4bba
2 changed files with 74 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
#include <QTabBar>
#include <QToolButton>
#include <QtGlobal>
#include <QKeySequence>
using namespace BlackMisc;
using namespace BlackMisc::Network;
@@ -60,11 +61,65 @@ namespace BlackGui
connect(ui->pb_SimulatorBasics, &QPushButton::released, this, &CSettingsComponent::ps_overviewButtonClicked);
connect(ui->pb_DataLoadAndCaches, &QPushButton::released, this, &CSettingsComponent::ps_overviewButtonClicked);
connect(ui->pb_SimulatorMessages, &QPushButton::released, this, &CSettingsComponent::ps_overviewButtonClicked);
this->initActions();
}
CSettingsComponent::~CSettingsComponent()
{ }
void CSettingsComponent::initActions()
{
QAction *a = nullptr;
a = new QAction(this);
a->setObjectName("overview");
a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_O));
connect(a, &QAction::triggered, this, &CSettingsComponent::ps_actionTriggered);
this->addAction(a);
a = new QAction(this);
a->setObjectName("audio");
a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_A));
ui->pb_Audio->setToolTip(a->shortcut().toString());
connect(a, &QAction::triggered, this, &CSettingsComponent::ps_actionTriggered);
this->addAction(a);
a = new QAction(this);
a->setObjectName("data");
a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_D));
ui->pb_DataLoadAndCaches->setToolTip(a->shortcut().toString());
connect(a, &QAction::triggered, this, &CSettingsComponent::ps_actionTriggered);
this->addAction(a);
a = new QAction(this);
a->setObjectName("gui");
a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_G));
ui->pb_Gui->setToolTip(a->shortcut().toString());
connect(a, &QAction::triggered, this, &CSettingsComponent::ps_actionTriggered);
this->addAction(a);
a = new QAction(this);
a->setObjectName("hotkeys");
a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_H));
ui->pb_Hotkeys->setToolTip(a->shortcut().toString());
connect(a, &QAction::triggered, this, &CSettingsComponent::ps_actionTriggered);
this->addAction(a);
a = new QAction(this);
a->setObjectName("network");
a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_N));
ui->pb_Network->setToolTip(a->shortcut().toString());
connect(a, &QAction::triggered, this, &CSettingsComponent::ps_actionTriggered);
this->addAction(a);
a = new QAction(this);
a->setObjectName("simulator");
a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_S));
ui->pb_Simulator->setToolTip(a->shortcut().toString());
connect(a, &QAction::triggered, this, &CSettingsComponent::ps_actionTriggered);
this->addAction(a);
}
bool CSettingsComponent::playNotificationSounds() const
{
return ui->comp_AudioSetup->playNotificationSounds();
@@ -95,5 +150,18 @@ namespace BlackGui
if (sender == ui->pb_SimulatorMessages) { this->setCurrentIndex(SettingTabSimulatorMessages); return; }
this->setCurrentIndex(SettingTabOverview);
}
void CSettingsComponent::ps_actionTriggered()
{
const QString a = QObject::sender()->objectName().toLower().trimmed();
if (a.isEmpty()) { return; }
if (a.contains("audio")) { this->setCurrentIndex(SettingTabAudio); return; }
if (a.contains("data")) { this->setCurrentIndex(SettingTabDataAndCaches); return; }
if (a.contains("gui")) { this->setCurrentIndex(SettingTabGui); return; }
if (a.contains("hot")) { this->setCurrentIndex(SettingTabHotkeys); return; }
if (a.contains("network")) { this->setCurrentIndex(SettingTabNetwork); return; }
if (a.contains("overview")) { this->setCurrentIndex(SettingTabOverview); return; }
if (a.contains("simulator")) { this->setCurrentIndex(SettingTabSimulator); return; }
}
}
} // namespace

View File

@@ -31,7 +31,6 @@ namespace BlackGui
Q_OBJECT
public:
//! Tabs
//! \remark needs to be in sync with tab order
enum SettingTab
@@ -82,7 +81,13 @@ namespace BlackGui
//! An overview button was clicked
void ps_overviewButtonClicked();
//! Action triggered
void ps_actionTriggered();
private:
//! Init actions
void initActions();
QScopedPointer<Ui::CSettingsComponent> ui;
};
}