From 7b3d8c3dc3d9d284ecad54942880ef2f9f1df4a4 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Fri, 18 Oct 2024 18:14:46 -0400 Subject: [PATCH] refactor: actiondialog to not have ui as base of the class --- src/gui/src/ActionDialog.cpp | 72 ++++++++++--------- src/gui/src/ActionDialog.h | 18 ++--- .../{ActionDialogBase.ui => ActionDialog.ui} | 8 +-- 3 files changed, 53 insertions(+), 45 deletions(-) rename src/gui/src/{ActionDialogBase.ui => ActionDialog.ui} (98%) diff --git a/src/gui/src/ActionDialog.cpp b/src/gui/src/ActionDialog.cpp index cb0d70ab2..21b9847fa 100644 --- a/src/gui/src/ActionDialog.cpp +++ b/src/gui/src/ActionDialog.cpp @@ -17,6 +17,7 @@ */ #include "ActionDialog.h" +#include "ui_ActionDialog.h" #include "Action.h" #include "Hotkey.h" @@ -24,58 +25,56 @@ #include "ServerConfig.h" #include -#include -#include ActionDialog::ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), - Ui::ActionDialogBase(), + ui{std::make_unique()}, m_ServerConfig(config), m_Hotkey(hotkey), m_Action(action), m_pButtonGroupType(new QButtonGroup(this)) { - setupUi(this); + ui->setupUi(this); // work around Qt Designer's lack of a QButtonGroup; we need it to get // at the button id of the checked radio button QRadioButton *const typeButtons[] = { - m_pRadioPress, - m_pRadioRelease, - m_pRadioPressAndRelease, - m_pRadioSwitchToScreen, - m_pRadioSwitchInDirection, - m_pRadioLockCursorToScreen, - m_pRadioRestartAllConnections + ui->m_pRadioPress, + ui->m_pRadioRelease, + ui->m_pRadioPressAndRelease, + ui->m_pRadioSwitchToScreen, + ui->m_pRadioSwitchInDirection, + ui->m_pRadioLockCursorToScreen, + ui->m_pRadioRestartAllConnections }; for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++) m_pButtonGroupType->addButton(typeButtons[i], i); - m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString()); - m_pKeySequenceWidgetHotkey->setKeySequence(m_Action.keySequence()); + ui->m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString()); + ui->m_pKeySequenceWidgetHotkey->setKeySequence(m_Action.keySequence()); m_pButtonGroupType->button(m_Action.type())->setChecked(true); - m_pComboSwitchInDirection->setCurrentIndex(m_Action.switchDirection()); - m_pComboLockCursorToScreen->setCurrentIndex(m_Action.lockCursorMode()); + ui->m_pComboSwitchInDirection->setCurrentIndex(m_Action.switchDirection()); + ui->m_pComboLockCursorToScreen->setCurrentIndex(m_Action.lockCursorMode()); if (m_Action.activeOnRelease()) - m_pRadioHotkeyReleased->setChecked(true); + ui->m_pRadioHotkeyReleased->setChecked(true); else - m_pRadioHotkeyPressed->setChecked(true); + ui->m_pRadioHotkeyPressed->setChecked(true); - m_pGroupBoxScreens->setChecked(m_Action.haveScreens()); + ui->m_pGroupBoxScreens->setChecked(m_Action.haveScreens()); int idx = 0; foreach (const Screen &screen, serverConfig().screens()) if (!screen.isNull()) { QListWidgetItem *pListItem = new QListWidgetItem(screen.name()); - m_pListScreens->addItem(pListItem); + ui->m_pListScreens->addItem(pListItem); if (m_Action.typeScreenNames().indexOf(screen.name()) != -1) - m_pListScreens->setCurrentItem(pListItem); + ui->m_pListScreens->setCurrentItem(pListItem); - m_pComboSwitchToScreen->addItem(screen.name()); + ui->m_pComboSwitchToScreen->addItem(screen.name()); if (screen.name() == m_Action.switchScreenName()) - m_pComboSwitchToScreen->setCurrentIndex(idx); + ui->m_pComboSwitchToScreen->setCurrentIndex(idx); idx++; } @@ -88,17 +87,17 @@ void ActionDialog::accept() m_Action.setKeySequence(sequenceWidget()->keySequence()); m_Action.setType(m_pButtonGroupType->checkedId()); - m_Action.setHaveScreens(m_pGroupBoxScreens->isChecked()); + m_Action.setHaveScreens(ui->m_pGroupBoxScreens->isChecked()); m_Action.typeScreenNames().clear(); - foreach (const QListWidgetItem *pItem, m_pListScreens->selectedItems()) + foreach (const QListWidgetItem *pItem, ui->m_pListScreens->selectedItems()) m_Action.typeScreenNames().append(pItem->text()); - m_Action.setSwitchScreenName(m_pComboSwitchToScreen->currentText()); - m_Action.setSwitchDirection(m_pComboSwitchInDirection->currentIndex()); - m_Action.setLockCursorMode(m_pComboLockCursorToScreen->currentIndex()); - m_Action.setActiveOnRelease(m_pRadioHotkeyReleased->isChecked()); - m_Action.setRestartServer(m_pRadioRestartAllConnections->isChecked()); + m_Action.setSwitchScreenName(ui->m_pComboSwitchToScreen->currentText()); + m_Action.setSwitchDirection(ui->m_pComboSwitchInDirection->currentIndex()); + m_Action.setLockCursorMode(ui->m_pComboLockCursorToScreen->currentIndex()); + m_Action.setActiveOnRelease(ui->m_pRadioHotkeyReleased->isChecked()); + m_Action.setRestartServer(ui->m_pRadioRestartAllConnections->isChecked()); QDialog::accept(); } @@ -106,10 +105,17 @@ void ActionDialog::accept() void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged() { if (sequenceWidget()->keySequence().isMouseButton()) { - m_pGroupBoxScreens->setEnabled(false); - m_pListScreens->setEnabled(false); + ui->m_pGroupBoxScreens->setEnabled(false); + ui->m_pListScreens->setEnabled(false); } else { - m_pGroupBoxScreens->setEnabled(true); - m_pListScreens->setEnabled(true); + ui->m_pGroupBoxScreens->setEnabled(true); + ui->m_pListScreens->setEnabled(true); } } + +const KeySequenceWidget *ActionDialog::sequenceWidget() const +{ + return ui->m_pKeySequenceWidgetHotkey; +} + +ActionDialog::~ActionDialog() = default; diff --git a/src/gui/src/ActionDialog.h b/src/gui/src/ActionDialog.h index 62fcda6f4..3519d3c8b 100644 --- a/src/gui/src/ActionDialog.h +++ b/src/gui/src/ActionDialog.h @@ -20,36 +20,38 @@ #include -#include "ui_ActionDialogBase.h" - class Hotkey; class Action; class QRadioButton; class QButtonGroup; class ServerConfig; +class KeySequenceWidget; -class ActionDialog : public QDialog, public Ui::ActionDialogBase +namespace Ui { +class ActionDialog; +} + +class ActionDialog : public QDialog { Q_OBJECT public: ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action); + ~ActionDialog() override; protected slots: - void accept(); + void accept() override; void on_m_pKeySequenceWidgetHotkey_keySequenceChanged(); protected: - const KeySequenceWidget *sequenceWidget() const - { - return m_pKeySequenceWidgetHotkey; - } + const KeySequenceWidget *sequenceWidget() const; const ServerConfig &serverConfig() const { return m_ServerConfig; } private: + std::unique_ptr ui; const ServerConfig &m_ServerConfig; Hotkey &m_Hotkey; Action &m_Action; diff --git a/src/gui/src/ActionDialogBase.ui b/src/gui/src/ActionDialog.ui similarity index 98% rename from src/gui/src/ActionDialogBase.ui rename to src/gui/src/ActionDialog.ui index c111a03f2..40b8255a3 100644 --- a/src/gui/src/ActionDialogBase.ui +++ b/src/gui/src/ActionDialog.ui @@ -1,7 +1,7 @@ - ActionDialogBase - + ActionDialog + 0 @@ -313,7 +313,7 @@ buttonBox accepted() - ActionDialogBase + ActionDialog accept() @@ -329,7 +329,7 @@ buttonBox rejected() - ActionDialogBase + ActionDialog reject()