From f76e0bc957b6ec2e07119a1f996d1d43f288ea16 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 19 Aug 2014 14:38:24 +0200 Subject: [PATCH] refs #313 Change GUI classes to use new hotkey settings wrapper classes --- src/blackcore/context_settings.h | 4 +- src/blackcore/context_settings_impl.cpp | 4 +- src/blackcore/context_settings_impl.h | 4 +- src/blackcore/context_settings_proxy.cpp | 4 +- src/blackcore/context_settings_proxy.h | 2 +- src/blackgui/components/settingscomponent.cpp | 8 +-- src/blackgui/models/keyboardkeylistmodel.cpp | 49 ++++++++++--------- src/blackgui/models/keyboardkeylistmodel.h | 11 +++-- src/blackgui/models/listmodelbase.cpp | 4 +- src/blackgui/views/keyboardkeyview.cpp | 2 +- src/swiftgui_standard/mainwindow.cpp | 6 +-- 11 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index bac99abc9..d73905494 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -11,7 +11,7 @@ #include "blackcore/context.h" #include "blackcore/dbus_server.h" #include "blackinput/keyboard.h" -#include "blackmisc/hwkeyboardkeylist.h" +#include "blackmisc/setkeyboardhotkeylist.h" #include "blackmisc/statusmessagelist.h" #include "blackmisc/dbus.h" #include "blackmisc/variant.h" @@ -143,7 +143,7 @@ namespace BlackCore virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const = 0; //! Hotkeys - virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const = 0; + virtual BlackMisc::Settings::CSettingKeyboardHotkeyList getHotkeys() const = 0; //! Save settings virtual BlackMisc::CStatusMessage write() const = 0; diff --git a/src/blackcore/context_settings_impl.cpp b/src/blackcore/context_settings_impl.cpp index af9fe9f54..8b49c8db8 100644 --- a/src/blackcore/context_settings_impl.cpp +++ b/src/blackcore/context_settings_impl.cpp @@ -186,7 +186,7 @@ namespace BlackCore /* * Hotkeys */ - CKeyboardKeyList CContextSettings::getHotkeys() const + CSettingKeyboardHotkeyList CContextSettings::getHotkeys() const { return this->m_hotkeys; } @@ -230,7 +230,7 @@ namespace BlackCore { if (command == CSettingUtilities::CmdUpdate()) { - BlackMisc::Hardware::CKeyboardKeyList hotkeys = value.value(); + BlackMisc::Settings::CSettingKeyboardHotkeyList hotkeys = value.value(); this->m_hotkeys = hotkeys; msgs.push_back(this->write()); // write settings emit this->changedSettings(static_cast(SettingsHotKeys)); diff --git a/src/blackcore/context_settings_impl.h b/src/blackcore/context_settings_impl.h index 406a1b7d5..98c6447d1 100644 --- a/src/blackcore/context_settings_impl.h +++ b/src/blackcore/context_settings_impl.h @@ -60,7 +60,7 @@ namespace BlackCore virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override; //! \copydoc IContextSettings::getHotkeys() - virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; + virtual BlackMisc::Settings::CSettingKeyboardHotkeyList getHotkeys() const override; //! read settings virtual BlackMisc::CStatusMessage read() override; @@ -81,7 +81,7 @@ namespace BlackCore BlackMisc::Settings::CSettingsNetwork m_settingsNetwork; BlackMisc::Settings::CSettingsAudio m_settingsAudio; BlackSim::Settings::CSettingsSimulator m_settingsSimulator; - BlackMisc::Hardware::CKeyboardKeyList m_hotkeys; + BlackMisc::Settings::CSettingKeyboardHotkeyList m_hotkeys; QJsonDocument toJsonDocument() const; void emitCompletelyChanged(); }; diff --git a/src/blackcore/context_settings_proxy.cpp b/src/blackcore/context_settings_proxy.cpp index 04f357ad1..f255ed15f 100644 --- a/src/blackcore/context_settings_proxy.cpp +++ b/src/blackcore/context_settings_proxy.cpp @@ -69,9 +69,9 @@ namespace BlackCore /* * Relay to DBus */ - CKeyboardKeyList CContextSettingsProxy::getHotkeys() const + CSettingKeyboardHotkeyList CContextSettingsProxy::getHotkeys() const { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getHotkeys")); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getHotkeys")); } /* diff --git a/src/blackcore/context_settings_proxy.h b/src/blackcore/context_settings_proxy.h index 8c83e31c2..2f778e349 100644 --- a/src/blackcore/context_settings_proxy.h +++ b/src/blackcore/context_settings_proxy.h @@ -55,7 +55,7 @@ namespace BlackCore virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override; //! \copydoc IContextSettings::getHotkeys() - virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; + virtual Settings::CSettingKeyboardHotkeyList getHotkeys() const override; //! \copydoc IContextSettings::value virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value) override; diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index 6a0a3b76b..b3af79efa 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -323,10 +323,10 @@ namespace BlackGui { QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex(); if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return; - BlackMisc::Hardware::CKeyboardKey key = this->ui->tvp_SettingsMiscHotkeys->at(i); - BlackMisc::Hardware::CKeyboardKey defaultKey; - defaultKey.setFunction(key.getFunction()); - this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultKey); + CSettingKeyboardHotkey hotkey = this->ui->tvp_SettingsMiscHotkeys->at(i); + CSettingKeyboardHotkey defaultHotkey; + defaultHotkey.setFunction(hotkey.getFunction()); + this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultHotkey); } /* diff --git a/src/blackgui/models/keyboardkeylistmodel.cpp b/src/blackgui/models/keyboardkeylistmodel.cpp index 537d6ff5e..31feec745 100644 --- a/src/blackgui/models/keyboardkeylistmodel.cpp +++ b/src/blackgui/models/keyboardkeylistmodel.cpp @@ -15,7 +15,7 @@ #include #include - +using namespace BlackMisc::Settings; using namespace BlackMisc::Hardware; namespace BlackGui @@ -26,14 +26,14 @@ namespace BlackGui * Constructor */ CKeyboardKeyListModel::CKeyboardKeyListModel(QObject *parent) : - CListModelBase("ViewKeyboardKeyList", parent) + CListModelBase("ViewKeyboardKeyList", parent) { - this->m_columns.addColumn(CColumn("key", CKeyboardKey::IndexKeyAsStringRepresentation, true)); - this->m_columns.addColumn(CColumn("modifier 1", CKeyboardKey::IndexModifier1AsString, true)); - this->m_columns.addColumn(CColumn("modifier 2", CKeyboardKey::IndexModifier2AsString, true)); - this->m_columns.addColumn(CColumn("function", CKeyboardKey::IndexFunctionAsString)); + this->m_columns.addColumn(CColumn("key", CSettingKeyboardHotkey::IndexKeyAsStringRepresentation, true)); + this->m_columns.addColumn(CColumn("modifier 1", CSettingKeyboardHotkey::IndexModifier1AsString, true)); + this->m_columns.addColumn(CColumn("modifier 2", CSettingKeyboardHotkey::IndexModifier2AsString, true)); + this->m_columns.addColumn(CColumn("function", CSettingKeyboardHotkey::IndexFunctionAsString)); - this->setSortColumnByPropertyIndex(CKeyboardKey::IndexFunctionAsString); + this->setSortColumnByPropertyIndex(CSettingKeyboardHotkey::IndexFunctionAsString); this->m_sortOrder = Qt::AscendingOrder; // force strings for translation in resource files @@ -57,21 +57,21 @@ namespace BlackGui if (role == Qt::EditRole) { int pi = this->indexToPropertyIndex(index); - if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString) + if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString) { if (index.row() >= this->m_container.size()) return true; - CKeyboardKey key = this->m_container[index.row()]; + CSettingKeyboardHotkey key = this->m_container[index.row()]; key.setPropertyByIndex(value, pi); key.cleanup(); this->m_container[index.row()] = key; return true; } - else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation) + else if (pi == CSettingKeyboardHotkey::IndexKey || pi == CSettingKeyboardHotkey::IndexKeyAsString || pi == CSettingKeyboardHotkey::IndexKeyAsStringRepresentation) { - Q_ASSERT(value.canConvert()); + Q_ASSERT(value.canConvert()); if (index.row() >= this->m_container.size()) return true; - CKeyboardKey key = this->m_container[index.row()]; - key.setPropertyByIndex(value, CKeyboardKey::IndexKeyObject); + CSettingKeyboardHotkey key = this->m_container[index.row()]; + key.setPropertyByIndex(value, CSettingKeyboardHotkey::IndexObject); key.cleanup(); this->m_container[index.row()] = key; return true; @@ -88,20 +88,20 @@ namespace BlackGui if (index.row() < model->rowCount()) { int pi = model->indexToPropertyIndex(index); - if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString) + if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString) { - CKeyboardKey key = model->at(index); - QString v = (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier1AsString) ? key.getModifier1AsString() : key.getModifier2AsString(); + CSettingKeyboardHotkey key = model->at(index); + QString v = (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier1AsString) ? key.getModifier1AsString() : key.getModifier2AsString(); QComboBox *edit = new QComboBox(parent); - edit->addItems(CKeyboardKey::modifiers()); + edit->addItems(CSettingKeyboardHotkey::modifiers()); edit->setCurrentText(v); return edit; } - else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation) + else if (pi == CSettingKeyboardHotkey::IndexKey || pi == CSettingKeyboardHotkey::IndexKeyAsString || pi == CSettingKeyboardHotkey::IndexKeyAsStringRepresentation) { - CKeyboardKey key = model->at(index); - CKeyboardLineEdit *edit = new CKeyboardLineEdit(key, parent); - edit->setText(key.getKeyAsString()); + CSettingKeyboardHotkey hotkey = model->at(index); + CKeyboardLineEdit *edit = new CKeyboardLineEdit(hotkey, parent); + edit->setText(hotkey.getKey().getKeyAsString()); return edit; } } @@ -146,9 +146,10 @@ namespace BlackGui { const Qt::Key k = static_cast(event->key()); if (k == Qt::Key_Shift || k == Qt::Key_Control || k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_CapsLock || k == Qt::Key_NumLock || k == Qt::Key_ScrollLock) return; - this->m_key.setKey(k); - this->m_key.setNativeVirtualKey(event->nativeVirtualKey()); - this->setText(CKeyboardKey::toStringRepresentation(event->key())); + BlackMisc::Hardware::CKeyboardKey key; + key.setKey(k); + this->m_hotkey.setKey(key); + this->setText(CSettingKeyboardHotkey::toStringRepresentation(event->key())); } } diff --git a/src/blackgui/models/keyboardkeylistmodel.h b/src/blackgui/models/keyboardkeylistmodel.h index 8c7ac73d3..c79c09ca9 100644 --- a/src/blackgui/models/keyboardkeylistmodel.h +++ b/src/blackgui/models/keyboardkeylistmodel.h @@ -11,6 +11,7 @@ #define BLACKGUI_KEYBOARDKEYLISTMODEL_H #include "blackmisc/hwkeyboardkeylist.h" +#include "blackmisc/setkeyboardhotkeylist.h" #include "blackgui/models/listmodelbase.h" #include #include @@ -24,7 +25,7 @@ namespace BlackGui /*! * Keyboard key list model */ - class CKeyboardKeyListModel : public CListModelBase + class CKeyboardKeyListModel : public CListModelBase { public: @@ -82,18 +83,18 @@ namespace BlackGui public: //! Constructor - CKeyboardLineEdit(BlackMisc::Hardware::CKeyboardKey &key, QWidget *parent = nullptr) : - QLineEdit(parent), m_key(key) { } + CKeyboardLineEdit(const BlackMisc::Settings::CSettingKeyboardHotkey &hotkey, QWidget *parent = nullptr) : + QLineEdit(parent), m_hotkey(hotkey) { } //! get key - BlackMisc::Hardware::CKeyboardKey getKey() const { return this->m_key; } + const BlackMisc::Settings::CSettingKeyboardHotkey &getKey() const { return this->m_hotkey; } protected: //! Overriding and handling key press virtual void keyPressEvent(QKeyEvent *event) override; private: - BlackMisc::Hardware::CKeyboardKey m_key; + BlackMisc::Settings::CSettingKeyboardHotkey m_hotkey; }; } } diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index 002166e69..5f5a826e3 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -16,7 +16,7 @@ #include "blackmisc/nwserverlist.h" #include "blackmisc/nwuserlist.h" #include "blackmisc/nwclientlist.h" -#include "blackmisc/hwkeyboardkeylist.h" +#include "blackmisc/setkeyboardhotkeylist.h" #include "blackmisc/blackmiscfreefunctions.h" namespace BlackGui @@ -239,6 +239,6 @@ namespace BlackGui template class CListModelBase; template class CListModelBase; template class CListModelBase; - template class CListModelBase; + template class CListModelBase; } } // namespace diff --git a/src/blackgui/views/keyboardkeyview.cpp b/src/blackgui/views/keyboardkeyview.cpp index e88c38b63..b64cf3fef 100644 --- a/src/blackgui/views/keyboardkeyview.cpp +++ b/src/blackgui/views/keyboardkeyview.cpp @@ -21,7 +21,7 @@ namespace BlackGui { this->m_model = new CKeyboardKeyListModel(this); this->setModel(this->m_model); // via QTableView - this->m_model->setSortColumnByPropertyIndex(BlackMisc::Hardware::CKeyboardKey::IndexFunctionAsString); + this->m_model->setSortColumnByPropertyIndex(BlackMisc::Settings::CSettingKeyboardHotkey::IndexFunctionAsString); if (this->m_model->hasValidSortColumn()) this->horizontalHeader()->setSortIndicator( this->m_model->getSortColumn(), diff --git a/src/swiftgui_standard/mainwindow.cpp b/src/swiftgui_standard/mainwindow.cpp index 7436659aa..2f385e29c 100644 --- a/src/swiftgui_standard/mainwindow.cpp +++ b/src/swiftgui_standard/mainwindow.cpp @@ -527,17 +527,17 @@ void MainWindow::ps_registerHotkeyFunctions() m_inputManager->registerHotkeyFunc(CHotkeyFunction::Opacity50(), this, [ this ](bool isPressed) { - if (isPressed) this->changeWindowOpacity(50); + if (isPressed) this->ps_changeWindowOpacity(50); }); m_inputManager->registerHotkeyFunc(CHotkeyFunction::Opacity100(), this, [ this ](bool isPressed) { - if (isPressed) this->changeWindowOpacity(100); + if (isPressed) this->ps_changeWindowOpacity(100); }); m_inputManager->registerHotkeyFunc(CHotkeyFunction::ToogleWindowsStayOnTop(), this, [ this ](bool isPressed) { - if (isPressed) this->toogleWindowStayOnTop(); + if (isPressed) this->ps_toogleWindowStayOnTop(); }); }