diff --git a/src/blackgui/components/settingshotkeycomponent.cpp b/src/blackgui/components/settingshotkeycomponent.cpp index 80c4f6674..896468820 100644 --- a/src/blackgui/components/settingshotkeycomponent.cpp +++ b/src/blackgui/components/settingshotkeycomponent.cpp @@ -32,6 +32,8 @@ using namespace BlackMisc; using namespace BlackMisc::Input; using namespace BlackGui::Models; +using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { @@ -55,13 +57,25 @@ namespace BlackGui CSettingsHotkeyComponent::~CSettingsHotkeyComponent() { } + void CSettingsHotkeyComponent::saveSettings() + { + const CStatusMessage msg = m_actionHotkeys.save(); + CLogMessage(this).preformatted(msg); + } + + void CSettingsHotkeyComponent::registerDummyPttEntry() + { + CInputManager::instance()->registerAction(IContextAudio::pttHotkeyAction(), IContextAudio::pttHotkeyIcon()); + } + void CSettingsHotkeyComponent::ps_addEntry() { BlackMisc::CIdentifierList registeredApps; if (sGui->getIContextApplication()) registeredApps = sGui->getIContextApplication()->getRegisteredApplications(); + // add local application registeredApps.push_back(CIdentifier()); - auto selectedActionHotkey = CHotkeyDialog::getActionHotkey(CActionHotkey(), registeredApps, this); + const auto selectedActionHotkey = CHotkeyDialog::getActionHotkey(CActionHotkey(), registeredApps, this); if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey)) { addHotkeytoSettings(selectedActionHotkey); @@ -74,7 +88,7 @@ namespace BlackGui void CSettingsHotkeyComponent::ps_editEntry() { - auto index = ui->tv_Hotkeys->selectionModel()->currentIndex(); + const auto index = ui->tv_Hotkeys->selectionModel()->currentIndex(); if (!index.isValid()) return; const auto model = ui->tv_Hotkeys->model(); @@ -97,7 +111,7 @@ namespace BlackGui void CSettingsHotkeyComponent::ps_removeEntry() { - QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows(); + const QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows(); for (const auto &index : indexes) { CActionHotkey actionHotkey = index.data(CActionHotkeyListModel::ActionHotkeyRole).value(); @@ -129,7 +143,7 @@ namespace BlackGui bool CSettingsHotkeyComponent::checkAndConfirmConflicts(const CActionHotkey &actionHotkey, const CActionHotkeyList &ignore) { - auto configuredHotkeys = m_actionHotkeys.getThreadLocal(); + const auto configuredHotkeys = m_actionHotkeys.getThreadLocal(); CActionHotkeyList conflicts = configuredHotkeys.findSupersetsOf(actionHotkey); conflicts.push_back(configuredHotkeys.findSubsetsOf(actionHotkey)); conflicts.removeIfIn(ignore); @@ -143,9 +157,7 @@ namespace BlackGui message += "\n"; } message += "\n Do you want to use it anway?"; - auto reply = QMessageBox::warning(this, "SettingsHotkeyComponent", - message, - QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + const auto reply = QMessageBox::warning(this, "SettingsHotkeyComponent", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (reply == QMessageBox::No) { return false; } } return true; @@ -155,11 +167,13 @@ namespace BlackGui { const CActionHotkeyList hotkeys = m_actionHotkeys.getThreadLocal(); m_model.clear(); - for (const auto &hotkey : hotkeys) + + // list of all defined hotkeys (not the dialog) + for (const CActionHotkey &hotkey : hotkeys) { const int position = m_model.rowCount(); m_model.insertRows(position, 1, QModelIndex()); - QModelIndex index = m_model.index(position, 0, QModelIndex()); + const QModelIndex index = m_model.index(position, 0, QModelIndex()); m_model.setData(index, QVariant::fromValue(hotkey), CActionHotkeyListModel::ActionHotkeyRole); } } @@ -168,5 +182,12 @@ namespace BlackGui { if (keyDown) { QMessageBox::information(this, "Test", "Hotkey test"); } } + + bool CConfigHotkeyWizardPage::validatePage() + { + if (CConfigurationWizard::lastWizardStepSkipped(this->wizard())) { return true; } + m_config->saveSettings(); + return true; + } } // ns } // ns diff --git a/src/blackgui/components/settingshotkeycomponent.h b/src/blackgui/components/settingshotkeycomponent.h index 90752d703..3ca2f913f 100644 --- a/src/blackgui/components/settingshotkeycomponent.h +++ b/src/blackgui/components/settingshotkeycomponent.h @@ -16,13 +16,12 @@ #include "blackcore/application/applicationsettings.h" #include "blackgui/blackguiexport.h" #include "blackgui/models/actionhotkeylistmodel.h" -#include "blackmisc/input/actionhotkey.h" -#include "blackmisc/input/actionhotkeylist.h" #include "blackmisc/settingscache.h" #include "blackmisc/icons.h" #include #include +#include #include class QWidget; @@ -45,6 +44,12 @@ namespace BlackGui //! Destructor virtual ~CSettingsHotkeyComponent(); + //! Save settings + void saveSettings(); + + //! Create dummy/emtpy Ptt entry for wizard + void registerDummyPttEntry(); + private slots: void ps_addEntry(); void ps_editEntry(); @@ -63,6 +68,25 @@ namespace BlackGui BlackMisc::CSetting m_actionHotkeys { this }; BlackCore::CActionBind m_action { "/Test/Message", BlackMisc::CIcons::wrench16(), this, &CSettingsHotkeyComponent::ps_hotkeySlot }; }; + + /** + * Wizard page for CConfigSimulatorComponent + */ + class CConfigHotkeyWizardPage : public QWizardPage + { + public: + //! Constructors + using QWizardPage::QWizardPage; + + //! Set config + void setConfigComponent(CSettingsHotkeyComponent *config) { m_config = config; } + + //! \copydoc QWizardPage::validatePage + virtual bool validatePage() override; + + private: + CSettingsHotkeyComponent *m_config = nullptr; + }; } // ns } // ns