Qt: use button box for most buttons

This commit is contained in:
Megamouse 2020-07-04 13:05:53 +02:00
parent be8980fc23
commit ea4cc0b395
3 changed files with 57 additions and 64 deletions

View File

@ -170,11 +170,27 @@ pad_settings_dialog::pad_settings_dialog(QWidget *parent, const GameInfo *game)
}
});
// Cancel Button
connect(ui->b_cancel, &QAbstractButton::clicked, this, &pad_settings_dialog::CancelExit);
ui->buttonBox->button(QDialogButtonBox::Reset)->setText(tr("Filter Noise"));
// Save Button
connect(ui->b_ok, &QAbstractButton::clicked, this, &pad_settings_dialog::SaveExit);
connect(ui->buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton* button)
{
if (button == ui->buttonBox->button(QDialogButtonBox::Save))
{
SaveExit();
}
else if (button == ui->buttonBox->button(QDialogButtonBox::Cancel))
{
CancelExit();
}
else if (button == ui->buttonBox->button(QDialogButtonBox::Reset))
{
OnPadButtonClicked(button_ids::id_blacklist);
}
else if (button == ui->buttonBox->button(QDialogButtonBox::RestoreDefaults))
{
OnPadButtonClicked(button_ids::id_reset_parameters);
}
});
// Refresh Button
connect(ui->b_refresh, &QPushButton::clicked, this, &pad_settings_dialog::RefreshInputTypes);
@ -260,12 +276,8 @@ void pad_settings_dialog::InitButtons()
insertButton(button_ids::id_pad_rstick_right, ui->b_rstick_right);
insertButton(button_ids::id_pad_rstick_up, ui->b_rstick_up);
m_padButtons->addButton(ui->b_reset, button_ids::id_reset_parameters);
m_padButtons->addButton(ui->b_blacklist, button_ids::id_blacklist);
m_padButtons->addButton(ui->b_refresh, button_ids::id_refresh);
m_padButtons->addButton(ui->b_addProfile, button_ids::id_add_profile);
m_padButtons->addButton(ui->b_ok, button_ids::id_ok);
m_padButtons->addButton(ui->b_cancel, button_ids::id_cancel);
connect(m_padButtons, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &pad_settings_dialog::OnPadButtonClicked);
@ -560,6 +572,11 @@ void pad_settings_dialog::ReactivateButtons()
but->setFocusPolicy(Qt::StrongFocus);
}
for (auto but : ui->buttonBox->buttons())
{
but->setFocusPolicy(Qt::StrongFocus);
}
ui->tabWidget->setFocusPolicy(Qt::TabFocus);
ui->chooseProfile->setFocusPolicy(Qt::WheelFocus);
@ -894,7 +911,7 @@ void pad_settings_dialog::SwitchButtons(bool is_enabled)
ui->gb_mouse_accel->setEnabled(is_enabled && m_handler->m_type == pad_handler::keyboard);
ui->gb_mouse_dz->setEnabled(is_enabled && m_handler->m_type == pad_handler::keyboard);
ui->gb_stick_lerp->setEnabled(is_enabled && m_handler->m_type == pad_handler::keyboard);
ui->b_blacklist->setEnabled(is_enabled && m_handler->m_type != pad_handler::keyboard);
ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(is_enabled && m_handler->m_type != pad_handler::keyboard);
for (int i = button_ids::id_pad_begin + 1; i < button_ids::id_pad_end; i++)
{
@ -931,6 +948,11 @@ void pad_settings_dialog::OnPadButtonClicked(int id)
but->setFocusPolicy(Qt::ClickFocus);
}
for (auto but : ui->buttonBox->buttons())
{
but->setFocusPolicy(Qt::ClickFocus);
}
ui->tabWidget->setFocusPolicy(Qt::ClickFocus);
ui->chooseProfile->setFocusPolicy(Qt::ClickFocus);
@ -1184,7 +1206,7 @@ void pad_settings_dialog::ChangeInputType()
ui->b_addProfile->setEnabled(config_enabled);
ui->chooseProfile->setEnabled(config_enabled);
ui->b_reset->setEnabled(!is_ldd_pad);
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)->setEnabled(!is_ldd_pad);
ui->chooseHandler->setEnabled(!is_ldd_pad);
}
@ -1464,10 +1486,18 @@ bool pad_settings_dialog::GetIsLddPad(int index) const
void pad_settings_dialog::ResizeDialog()
{
// Widgets
const QSize buttons_size(0, ui->buttonBox->sizeHint().height());
const QSize tabwidget_size = ui->tabWidget->sizeHint();
// Spacing
const int nr_of_spacings = 1; // Number of widgets - 1
const QSize spacing_size(0, layout()->spacing() * nr_of_spacings);
// Margins
const auto margins = layout()->contentsMargins();
const QSize tab_size = ui->tabWidget->sizeHint();
const QSize margin_size(margins.left() + margins.right(), margins.top() + margins.bottom());
resize(tab_size + margin_size);
resize(tabwidget_size + buttons_size + margin_size + spacing_size);
setMaximumSize(size());
}

View File

@ -101,8 +101,6 @@ private Q_SLOTS:
void HandleDeviceClassChange(int index);
/** Save the Pad Configuration to the current Pad Handler Config File */
void SaveProfile();
void SaveExit();
void CancelExit();
private:
Ui::pad_settings_dialog *ui;
@ -151,6 +149,9 @@ private:
// Input timer. Its Callback handles the input
QTimer m_timer_input;
void SaveExit();
void CancelExit();
// Set vibrate data while keeping the current color
void SetPadData(u32 large_motor, u32 small_motor);

View File

@ -38,7 +38,7 @@
<x>0</x>
<y>0</y>
<width>848</width>
<height>697</height>
<height>668</height>
</rect>
</property>
<widget class="QWidget" name="tab">
@ -980,30 +980,6 @@
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="button_layout_left">
<item>
<widget class="QPushButton" name="b_ok">
<property name="text">
<string>Save</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="b_cancel">
<property name="text">
<string>Close</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
@ -2089,7 +2065,7 @@
<item>
<widget class="QStackedWidget" name="right_stack">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="stick_page">
<layout class="QVBoxLayout" name="stick_page_layout">
@ -2370,30 +2346,6 @@
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="button_layout_right" stretch="0,1">
<item>
<widget class="QPushButton" name="b_blacklist">
<property name="text">
<string>Filter Noise</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="b_reset">
<property name="text">
<string>Restore Defaults</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
@ -2403,6 +2355,16 @@
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Save</set>
</property>
<property name="centerButtons">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources>