refactor: actiondialog to not have ui as base of the class
This commit is contained in:
@ -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 <QButtonGroup>
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
ActionDialog::ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||
Ui::ActionDialogBase(),
|
||||
ui{std::make_unique<Ui::ActionDialog>()},
|
||||
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;
|
||||
|
||||
@ -20,36 +20,38 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#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::ActionDialog> ui;
|
||||
const ServerConfig &m_ServerConfig;
|
||||
Hotkey &m_Hotkey;
|
||||
Action &m_Action;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ActionDialogBase</class>
|
||||
<widget class="QDialog" name="ActionDialogBase">
|
||||
<class>ActionDialog</class>
|
||||
<widget class="QDialog" name="ActionDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -313,7 +313,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ActionDialogBase</receiver>
|
||||
<receiver>ActionDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
@ -329,7 +329,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ActionDialogBase</receiver>
|
||||
<receiver>ActionDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
Reference in New Issue
Block a user