From aaf4c35f80a155b6d63440efb5168f5ba4ec1b67 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 19 Dec 2017 06:26:24 +0100 Subject: [PATCH] Ref T211, formatting --- src/blackgui/components/hotkeydialog.cpp | 52 +++++++++---------- src/blackgui/components/hotkeydialog.h | 27 +++++----- .../components/settingshotkeycomponent.cpp | 29 +++++++---- .../components/settingshotkeycomponent.h | 16 +++--- src/blackmisc/identifier.h | 2 +- 5 files changed, 69 insertions(+), 57 deletions(-) diff --git a/src/blackgui/components/hotkeydialog.cpp b/src/blackgui/components/hotkeydialog.cpp index 80dbab6db..84ff7a4bd 100644 --- a/src/blackgui/components/hotkeydialog.cpp +++ b/src/blackgui/components/hotkeydialog.cpp @@ -39,6 +39,7 @@ using namespace BlackMisc; using namespace BlackMisc::Input; +using namespace BlackCore; namespace BlackGui { @@ -47,7 +48,7 @@ namespace BlackGui CKeySelectionBox::CKeySelectionBox(QWidget *parent) : QComboBox(parent) { - connect(this, static_cast(&CKeySelectionBox::currentIndexChanged), this, &CKeySelectionBox::ps_updateSelectedIndex); + connect(this, static_cast(&CKeySelectionBox::currentIndexChanged), this, &CKeySelectionBox::updateSelectedIndex); } void CKeySelectionBox::setSelectedIndex(int index) @@ -56,13 +57,13 @@ namespace BlackGui setCurrentIndex(m_oldIndex); } - void CKeySelectionBox::ps_updateSelectedIndex(int index) + void CKeySelectionBox::updateSelectedIndex(int index) { emit keySelectionChanged(m_oldIndex, index); m_oldIndex = index; } - CHotkeyDialog::CHotkeyDialog(const CActionHotkey &actionHotkey, const BlackMisc::CIdentifierList &applications, QWidget *parent) : + CHotkeyDialog::CHotkeyDialog(const CActionHotkey &actionHotkey, const CIdentifierList &identifiers, QWidget *parent) : QDialog(parent), ui(new Ui::CHotkeyDialog), m_actionHotkey(actionHotkey), @@ -74,7 +75,7 @@ namespace BlackGui ui->qf_Advanced->hide(); ui->tv_Actions->setModel(&m_actionModel); - ui->pb_AdvancedMode->setIcon(BlackMisc::CIcons::arrowMediumSouth16()); + ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumSouth16()); selectAction(); if (!actionHotkey.getCombination().isEmpty()) { ui->pb_SelectedHotkey->setText(actionHotkey.getCombination().toQString()); } @@ -92,13 +93,13 @@ namespace BlackGui ui->cb_Identifier->setCurrentIndex(index); } - connect(ui->pb_AdvancedMode, &QPushButton::clicked, this, &CHotkeyDialog::ps_advancedModeChanged); - connect(ui->pb_SelectedHotkey, &QPushButton::clicked, this, &CHotkeyDialog::ps_selectHotkey); - connect(ui->pb_Accept, &QPushButton::clicked, this, &CHotkeyDialog::ps_accept); + connect(ui->pb_AdvancedMode, &QPushButton::clicked, this, &CHotkeyDialog::advancedModeChanged); + connect(ui->pb_SelectedHotkey, &QPushButton::clicked, this, &CHotkeyDialog::selectHotkey); + connect(ui->pb_Accept, &QPushButton::clicked, this, &CHotkeyDialog::accept); connect(ui->pb_Cancel, &QPushButton::clicked, this, &CHotkeyDialog::reject); - connect(m_inputManager, &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::ps_combinationSelectionChanged); - connect(m_inputManager, &BlackCore::CInputManager::combinationSelectionFinished, this, &CHotkeyDialog::ps_combinationSelectionFinished); - connect(ui->tv_Actions->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CHotkeyDialog::ps_changeSelectedAction); + connect(m_inputManager, &BlackCore::CInputManager::combinationSelectionChanged, this, &CHotkeyDialog::combinationSelectionChanged); + connect(m_inputManager, &BlackCore::CInputManager::combinationSelectionFinished, this, &CHotkeyDialog::combinationSelectionFinished); + connect(ui->tv_Actions->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CHotkeyDialog::changeSelectedAction); connect(ui->cb_Identifier, static_cast(&QComboBox::currentIndexChanged), this, &CHotkeyDialog::changeApplicableMachine); initStyleSheet(); @@ -118,50 +119,49 @@ namespace BlackGui setStyleSheet(s); } - CActionHotkey CHotkeyDialog::getActionHotkey(const CActionHotkey &initial, const CIdentifierList &applications, QWidget *parent) + CActionHotkey CHotkeyDialog::getActionHotkey(const CActionHotkey &initial, const CIdentifierList &identifiers, QWidget *parent) { - CHotkeyDialog editDialog(initial, applications, parent); + CHotkeyDialog editDialog(initial, identifiers, parent); editDialog.setWindowModality(Qt::WindowModal); if (editDialog.exec()) { return editDialog.getSelectedActionHotkey(); } return {}; } - void CHotkeyDialog::ps_advancedModeChanged() + void CHotkeyDialog::advancedModeChanged() { if (m_actionHotkey.getCombination().isEmpty()) return; - if (!ui->qf_Advanced->isVisible()) { setupAdvancedFrame(); ui->qf_Advanced->show(); - ui->pb_AdvancedMode->setIcon(BlackMisc::CIcons::arrowMediumNorth16()); + ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumNorth16()); } else { - ui->pb_AdvancedMode->setIcon(BlackMisc::CIcons::arrowMediumSouth16()); + ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumSouth16()); ui->qf_Advanced->hide(); ui->gb_Hotkey->resize(0, 0); } } - void CHotkeyDialog::ps_selectHotkey() + void CHotkeyDialog::selectHotkey() { ui->pb_SelectedHotkey->setText("Press any key/button..."); m_inputManager->startCapture(); } - void CHotkeyDialog::ps_combinationSelectionChanged(const BlackMisc::Input::CHotkeyCombination &combination) + void CHotkeyDialog::combinationSelectionChanged(const CHotkeyCombination &combination) { ui->pb_SelectedHotkey->setText(combination.toFormattedQString()); } - void CHotkeyDialog::ps_combinationSelectionFinished(const BlackMisc::Input::CHotkeyCombination &combination) + void CHotkeyDialog::combinationSelectionFinished(const CHotkeyCombination &combination) { m_actionHotkey.setCombination(combination); synchronize(); } - void CHotkeyDialog::ps_changeSelectedAction(const QItemSelection &selected, const QItemSelection &deselected) + void CHotkeyDialog::changeSelectedAction(const QItemSelection &selected, const QItemSelection &deselected) { Q_UNUSED(deselected); if (selected.indexes().isEmpty()) { return; } @@ -172,28 +172,28 @@ namespace BlackGui void CHotkeyDialog::changeApplicableMachine(int index) { Q_UNUSED(index); - QVariant userData = ui->cb_Identifier->currentData(Qt::UserRole); + QVariant userData = ui->cb_Identifier->currentData(); Q_ASSERT(userData.canConvert()); m_actionHotkey.setApplicableMachine(userData.value()); } - void CHotkeyDialog::ps_accept() + void CHotkeyDialog::accept() { if (m_actionHotkey.getApplicableMachine().getMachineName().isEmpty()) { - CLogMessage().validationWarning("Missing %1") << ui->gb_Machine->title(); + CLogMessage().validationWarning("Missing '%1'") << ui->gb_Machine->title(); return; } if (m_actionHotkey.getCombination().isEmpty()) { - CLogMessage().validationWarning("Missing %1") << ui->gb_Hotkey->title(); + CLogMessage().validationWarning("Missing '%1'") << ui->gb_Hotkey->title(); return; } if (m_actionHotkey.getAction().isEmpty()) { - CLogMessage().validationWarning("Missing %1") << ui->gb_Action->title(); + CLogMessage().validationWarning("Missing '%1'") << ui->gb_Action->title(); return; } @@ -279,7 +279,7 @@ namespace BlackGui for (const auto &token : tokens) { - QModelIndex startIndex = m_actionModel.index(0, 0, parentIndex); + const QModelIndex startIndex = m_actionModel.index(0, 0, parentIndex); const auto indexList = m_actionModel.match(startIndex, Qt::DisplayRole, QVariant::fromValue(token)); if (indexList.isEmpty()) return; parentIndex = indexList.first(); diff --git a/src/blackgui/components/hotkeydialog.h b/src/blackgui/components/hotkeydialog.h index 117fd544d..626ee9e9a 100644 --- a/src/blackgui/components/hotkeydialog.h +++ b/src/blackgui/components/hotkeydialog.h @@ -28,7 +28,6 @@ class QWidget; namespace BlackCore { class CInputManager; } namespace BlackMisc { namespace Input { class CHotkeyCombination; } } namespace Ui { class CHotkeyDialog; } - namespace BlackGui { namespace Components @@ -51,10 +50,9 @@ namespace BlackGui //! User has changed the selection void keySelectionChanged(int oldIndex, int newIndex); - private slots: - void ps_updateSelectedIndex(int index); - private: + void updateSelectedIndex(int index); + int m_oldIndex; }; @@ -67,7 +65,10 @@ namespace BlackGui public: //! Constructor - CHotkeyDialog(const BlackMisc::Input::CActionHotkey &actionHotkey, const BlackMisc::CIdentifierList &applications, QWidget *parent = nullptr); + CHotkeyDialog( + const BlackMisc::Input::CActionHotkey &actionHotkey, + const BlackMisc::CIdentifierList &identifiers, + QWidget *parent = nullptr); //! Destructor virtual ~CHotkeyDialog(); @@ -78,19 +79,21 @@ namespace BlackGui //! Init style sheet void initStyleSheet(); + //! \copydoc QDialog::accept + virtual void accept() override; + //! Runs the hotkey dialog and returns the result static BlackMisc::Input::CActionHotkey getActionHotkey( const BlackMisc::Input::CActionHotkey &initial, - const BlackMisc::CIdentifierList &applications, + const BlackMisc::CIdentifierList &identifiers, QWidget *parent = nullptr); private: - void ps_advancedModeChanged(); - void ps_selectHotkey(); - void ps_combinationSelectionChanged(const BlackMisc::Input::CHotkeyCombination &combination); - void ps_combinationSelectionFinished(const BlackMisc::Input::CHotkeyCombination &combination); - void ps_changeSelectedAction(const QItemSelection &selected, const QItemSelection &deselected); - void ps_accept(); + void advancedModeChanged(); + void selectHotkey(); + void combinationSelectionChanged(const BlackMisc::Input::CHotkeyCombination &combination); + void combinationSelectionFinished(const BlackMisc::Input::CHotkeyCombination &combination); + void changeSelectedAction(const QItemSelection &selected, const QItemSelection &deselected); void changeApplicableMachine(int index); void synchronize(); diff --git a/src/blackgui/components/settingshotkeycomponent.cpp b/src/blackgui/components/settingshotkeycomponent.cpp index 896468820..f5a815e92 100644 --- a/src/blackgui/components/settingshotkeycomponent.cpp +++ b/src/blackgui/components/settingshotkeycomponent.cpp @@ -43,12 +43,13 @@ namespace BlackGui QFrame(parent), ui(new Ui::CSettingsHotkeyComponent) { + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); ui->setupUi(this); ui->tv_Hotkeys->setModel(&m_model); - connect(ui->pb_AddHotkey, &QPushButton::clicked, this, &CSettingsHotkeyComponent::ps_addEntry); - connect(ui->pb_EditHotkey, &QPushButton::clicked, this, &CSettingsHotkeyComponent::ps_editEntry); - connect(ui->pb_RemoveHotkey, &QPushButton::clicked, this, &CSettingsHotkeyComponent::ps_removeEntry); + connect(ui->pb_AddHotkey, &QPushButton::clicked, this, &CSettingsHotkeyComponent::addEntry); + connect(ui->pb_EditHotkey, &QPushButton::clicked, this, &CSettingsHotkeyComponent::editEntry); + connect(ui->pb_RemoveHotkey, &QPushButton::clicked, this, &CSettingsHotkeyComponent::removeEntry); reloadHotkeysFromSettings(); ui->tv_Hotkeys->selectRow(0); @@ -68,7 +69,7 @@ namespace BlackGui CInputManager::instance()->registerAction(IContextAudio::pttHotkeyAction(), IContextAudio::pttHotkeyIcon()); } - void CSettingsHotkeyComponent::ps_addEntry() + void CSettingsHotkeyComponent::addEntry() { BlackMisc::CIdentifierList registeredApps; if (sGui->getIContextApplication()) registeredApps = sGui->getIContextApplication()->getRegisteredApplications(); @@ -79,14 +80,14 @@ namespace BlackGui if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey)) { addHotkeytoSettings(selectedActionHotkey); - int position = m_model.rowCount(); + 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(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole); } } - void CSettingsHotkeyComponent::ps_editEntry() + void CSettingsHotkeyComponent::editEntry() { const auto index = ui->tv_Hotkeys->selectionModel()->currentIndex(); if (!index.isValid()) return; @@ -109,7 +110,7 @@ namespace BlackGui } } - void CSettingsHotkeyComponent::ps_removeEntry() + void CSettingsHotkeyComponent::removeEntry() { const QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows(); for (const auto &index : indexes) @@ -178,7 +179,17 @@ namespace BlackGui } } - void CSettingsHotkeyComponent::ps_hotkeySlot(bool keyDown) + CIdentifierList CSettingsHotkeyComponent::getAllIdentifiers() const + { + CIdentifierList identifiers; + if (sGui->getIContextApplication()) { identifiers = sGui->getIContextApplication()->getRegisteredApplications(); } + + // add local application + identifiers.push_back(CIdentifier("local identifer for hotkeys")); + return identifiers; + } + + void CSettingsHotkeyComponent::hotkeySlot(bool keyDown) { if (keyDown) { QMessageBox::information(this, "Test", "Hotkey test"); } } diff --git a/src/blackgui/components/settingshotkeycomponent.h b/src/blackgui/components/settingshotkeycomponent.h index 3ca2f913f..b00e28ecf 100644 --- a/src/blackgui/components/settingshotkeycomponent.h +++ b/src/blackgui/components/settingshotkeycomponent.h @@ -12,10 +12,10 @@ #ifndef BLACKGUI_COMPONENTS_SETTINGSHOTKEYCOMPONENT_H #define BLACKGUI_COMPONENTS_SETTINGSHOTKEYCOMPONENT_H -#include "blackcore/actionbind.h" -#include "blackcore/application/applicationsettings.h" #include "blackgui/blackguiexport.h" #include "blackgui/models/actionhotkeylistmodel.h" +#include "blackcore/actionbind.h" +#include "blackcore/application/applicationsettings.h" #include "blackmisc/settingscache.h" #include "blackmisc/icons.h" @@ -50,13 +50,11 @@ namespace BlackGui //! Create dummy/emtpy Ptt entry for wizard void registerDummyPttEntry(); - private slots: - void ps_addEntry(); - void ps_editEntry(); - void ps_removeEntry(); - void ps_hotkeySlot(bool keyDown); - private: + void addEntry(); + void editEntry(); + void removeEntry(); + void hotkeySlot(bool keyDown); void addHotkeytoSettings(const BlackMisc::Input::CActionHotkey &actionHotkey); void updateHotkeyInSettings(const BlackMisc::Input::CActionHotkey &oldValue, const BlackMisc::Input::CActionHotkey &newValue); void removeHotkeyFromSettings(const BlackMisc::Input::CActionHotkey &actionHotkey); @@ -66,7 +64,7 @@ namespace BlackGui QScopedPointer ui; BlackGui::Models::CActionHotkeyListModel m_model; BlackMisc::CSetting m_actionHotkeys { this }; - BlackCore::CActionBind m_action { "/Test/Message", BlackMisc::CIcons::wrench16(), this, &CSettingsHotkeyComponent::ps_hotkeySlot }; + BlackCore::CActionBind m_action { "/Test/Message", BlackMisc::CIcons::wrench16(), this, &CSettingsHotkeyComponent::hotkeySlot }; }; /** diff --git a/src/blackmisc/identifier.h b/src/blackmisc/identifier.h index 88f741536..e75ab7080 100644 --- a/src/blackmisc/identifier.h +++ b/src/blackmisc/identifier.h @@ -38,7 +38,7 @@ namespace BlackMisc //! Properties by index enum ColumnIndex { - IndexName = BlackMisc::CPropertyIndex::GlobalIndexCIdentifier, + IndexName = CPropertyIndex::GlobalIndexCIdentifier, IndexMachineId, IndexMachineIdBase64, IndexMachineName,