refactor: ActionDialog, Aaccess the keySequenceWidget only thru the ui member

This commit is contained in:
sithlord48 2025-01-04 19:50:43 -05:00 committed by Nick Bolton
parent 0944d918b7
commit c36c0f2938
3 changed files with 18 additions and 24 deletions

View file

@ -35,6 +35,7 @@ ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey &
m_buttonGroupType(new QButtonGroup(this))
{
ui->setupUi(this);
connect(ui->keySequenceWidget, &KeySequenceWidget::keySequenceChanged, this, &ActionDialog::keySequenceChanged);
// work around Qt Designer's lack of a QButtonGroup; we need it to get
// at the button id of the checked radio button
@ -51,8 +52,8 @@ ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey &
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++)
m_buttonGroupType->addButton(typeButtons[i], i);
ui->m_pKeySequenceWidgetHotkey->setText(m_action.keySequence().toString());
ui->m_pKeySequenceWidgetHotkey->setKeySequence(m_action.keySequence());
ui->keySequenceWidget->setText(m_action.keySequence().toString());
ui->keySequenceWidget->setKeySequence(m_action.keySequence());
m_buttonGroupType->button(m_action.type())->setChecked(true);
ui->m_pComboSwitchInDirection->setCurrentIndex(m_action.switchDirection());
ui->m_pComboLockCursorToScreen->setCurrentIndex(m_action.lockCursorMode());
@ -80,10 +81,10 @@ ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey &
void ActionDialog::accept()
{
if (!sequenceWidget()->valid() && m_buttonGroupType->checkedId() >= 0 && m_buttonGroupType->checkedId() < 3)
if (!ui->keySequenceWidget->valid() && m_buttonGroupType->checkedId() >= 0 && m_buttonGroupType->checkedId() < 3)
return;
m_action.setKeySequence(sequenceWidget()->keySequence());
m_action.setKeySequence(ui->keySequenceWidget->keySequence());
m_action.setType(m_buttonGroupType->checkedId());
m_action.setHaveScreens(ui->m_pGroupBoxScreens->isChecked());
@ -102,9 +103,9 @@ void ActionDialog::accept()
QDialog::accept();
}
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged()
void ActionDialog::keySequenceChanged()
{
if (sequenceWidget()->keySequence().isMouseButton()) {
if (ui->keySequenceWidget->keySequence().isMouseButton()) {
ui->m_pGroupBoxScreens->setEnabled(false);
ui->m_pListScreens->setEnabled(false);
} else {
@ -113,9 +114,4 @@ void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged()
}
}
const KeySequenceWidget *ActionDialog::sequenceWidget() const
{
return ui->m_pKeySequenceWidgetHotkey;
}
ActionDialog::~ActionDialog() = default;

View file

@ -41,12 +41,10 @@ public:
protected slots:
void accept() override;
void on_m_pKeySequenceWidgetHotkey_keySequenceChanged();
protected:
const KeySequenceWidget *sequenceWidget() const;
private:
void keySequenceChanged();
std::unique_ptr<Ui::ActionDialog> ui;
Hotkey &m_hotkey;
Action &m_action;

View file

@ -50,7 +50,7 @@
</widget>
</item>
<item>
<widget class="KeySequenceWidget" name="m_pKeySequenceWidgetHotkey">
<widget class="KeySequenceWidget" name="keySequenceWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
@ -345,7 +345,7 @@
<connection>
<sender>m_pGroupType</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -361,7 +361,7 @@
<connection>
<sender>m_pRadioSwitchInDirection</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -377,7 +377,7 @@
<connection>
<sender>m_pRadioLockCursorToScreen</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -393,7 +393,7 @@
<connection>
<sender>m_pRadioRestartAllConnections</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -409,7 +409,7 @@
<connection>
<sender>m_pRadioPress</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -425,7 +425,7 @@
<connection>
<sender>m_pRadioRelease</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -441,7 +441,7 @@
<connection>
<sender>m_pRadioPressAndRelease</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -617,7 +617,7 @@
<connection>
<sender>m_pRadioSwitchToScreen</sender>
<signal>toggled(bool)</signal>
<receiver>m_pKeySequenceWidgetHotkey</receiver>
<receiver>keySequenceWidget</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">