From c4ac3d195c19491b44ecf4bd55a0e121e59e66d6 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 9 Sep 2025 20:22:37 +1000 Subject: [PATCH] Qt: Improve padding in hotkey rows And fix incorrect parent widgets. --- src/duckstation-qt/graphicssettingswidget.cpp | 5 +- src/duckstation-qt/hotkeysettingswidget.cpp | 73 ++++++++++--------- src/duckstation-qt/hotkeysettingswidget.h | 4 +- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/duckstation-qt/graphicssettingswidget.cpp b/src/duckstation-qt/graphicssettingswidget.cpp index e78cd26b7..f9d6a6f9d 100644 --- a/src/duckstation-qt/graphicssettingswidget.cpp +++ b/src/duckstation-qt/graphicssettingswidget.cpp @@ -212,9 +212,10 @@ GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* dialog, QWidget* m_dialog->hasGameTrait(GameDatabase::Trait::ForcePGXPVertexCache)); SettingWidgetBinder::SetForceEnabled(m_ui.pgxpDisableOn2DPolygons, m_dialog->hasGameTrait(GameDatabase::Trait::DisablePGXPOn2DPolygons)); - if (auto dbentry = m_dialog->getDatabaseEntry(); dbentry && dbentry->gpu_pgxp_preserve_proj_fp.has_value()) + if (const GameDatabase::Entry* dbentry = m_dialog->getDatabaseEntry(); + dbentry && dbentry->gpu_pgxp_preserve_proj_fp.has_value()) { - if (*dbentry->gpu_pgxp_preserve_proj_fp) + if (dbentry->gpu_pgxp_preserve_proj_fp.value()) SettingWidgetBinder::SetForceEnabled(m_ui.pgxpPreserveProjPrecision, true); else SettingWidgetBinder::SetAvailability(m_ui.pgxpPreserveProjPrecision, false); diff --git a/src/duckstation-qt/hotkeysettingswidget.cpp b/src/duckstation-qt/hotkeysettingswidget.cpp index ef42f59f1..526e3bc2a 100644 --- a/src/duckstation-qt/hotkeysettingswidget.cpp +++ b/src/duckstation-qt/hotkeysettingswidget.cpp @@ -59,6 +59,8 @@ void HotkeySettingsWidget::createUi() m_scroll_area = new QScrollArea(this); m_container = new Container(m_scroll_area); m_layout = new QVBoxLayout(m_container); + m_layout->setContentsMargins(0, 0, 0, 0); + m_layout->setSpacing(0); m_scroll_area->setWidget(m_container); m_scroll_area->setWidgetResizable(true); m_scroll_area->setBackgroundRole(QPalette::Base); @@ -76,58 +78,63 @@ void HotkeySettingsWidget::createUi() void HotkeySettingsWidget::createButtons() { + static constexpr int LR_MARGIN = 8; + static constexpr int TB_MARGIN = 4; + const std::vector hotkeys(InputManager::GetHotkeyList()); for (const HotkeyInfo* hotkey : hotkeys) { const QString category(qApp->translate("Hotkeys", hotkey->category)); auto iter = m_categories.find(category); - int target_row = 0; if (iter == m_categories.end()) { CategoryWidgets cw; - cw.label = new QLabel(category, m_container); + cw.heading = new QWidget(m_container); + QVBoxLayout* row_layout = new QVBoxLayout(cw.heading); + row_layout->setContentsMargins(LR_MARGIN, TB_MARGIN + 4, LR_MARGIN, TB_MARGIN); + m_layout->addWidget(cw.heading); + + cw.label = new QLabel(category, cw.heading); QFont label_font(cw.label->font()); label_font.setPixelSize(19); label_font.setBold(true); cw.label->setFont(label_font); - m_layout->addWidget(cw.label); - - cw.line = new QLabel(m_container); + QPalette label_palette = cw.label->palette(); + const QColor label_default_color = label_palette.color(QPalette::Text); + const QColor label_color = + QtHost::IsDarkApplicationTheme() ? label_default_color.darker(120) : label_default_color.lighter(); + label_palette.setColor(QPalette::Text, label_color); + cw.label->setPalette(label_palette); + row_layout->addWidget(cw.label); + + cw.line = new QLabel(cw.heading); cw.line->setFrameShape(QFrame::HLine); cw.line->setFixedHeight(4); - m_layout->addWidget(cw.line); + cw.line->setPalette(label_palette); + row_layout->addWidget(cw.line); - cw.layout = new QGridLayout(); + cw.layout = new QVBoxLayout(); cw.layout->setContentsMargins(0, 0, 0, 0); + cw.layout->setSpacing(0); m_layout->addLayout(cw.layout); iter = m_categories.insert(category, cw); - - // row count starts at 1 for some reason - target_row = 0; - } - else - { - target_row = iter->layout->rowCount(); } - QGridLayout* layout = iter->layout; + QWidget* const row = new QWidget(m_container); + row->setAutoFillBackground(true); + row->setBackgroundRole((((iter->layout->count()) % 2) == 0) ? QPalette::Base : QPalette::AlternateBase); + iter->layout->addWidget(row); - QLabel* label = new QLabel(qApp->translate("Hotkeys", hotkey->display_name), m_container); + QHBoxLayout* row_layout = new QHBoxLayout(row); + row_layout->setContentsMargins(LR_MARGIN, TB_MARGIN, LR_MARGIN, TB_MARGIN); - InputBindingWidget* bind = new InputBindingWidget(m_container, m_dialog->getEditingSettingsInterface(), - InputBindingInfo::Type::Button, "Hotkeys", hotkey->name); - bind->setMinimumWidth(300); + row_layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey->display_name), row)); - QWidget* row = new QWidget(m_container); - row->setAutoFillBackground(true); - row->setBackgroundRole(target_row % 2 == 0 ? QPalette::Base : QPalette::AlternateBase); - - QHBoxLayout* h_box = new QHBoxLayout(row); - h_box->setContentsMargins(0, 0, 0, 0); - h_box->addWidget(label); - h_box->addWidget(bind); - layout->addWidget(row, target_row, 0, 1, 2); + InputBindingWidget* const bind = new InputBindingWidget(row, m_dialog->getEditingSettingsInterface(), + InputBindingInfo::Type::Button, "Hotkeys", hotkey->name); + bind->setMinimumWidth(300); + row_layout->addWidget(bind); } } @@ -135,11 +142,11 @@ void HotkeySettingsWidget::setFilter(const QString& filter) { for (const CategoryWidgets& cw : m_categories) { - const int row_count = cw.layout->rowCount(); + const int count = cw.layout->count(); int visible_row_count = 0; - for (int i = 0; i < row_count; i++) + for (int i = 0; i < count; i++) { - QWidget* row = qobject_cast(cw.layout->itemAtPosition(i, 0)->widget()); + QWidget* row = qobject_cast(cw.layout->itemAt(i)->widget()); if (!row) continue; @@ -153,8 +160,6 @@ void HotkeySettingsWidget::setFilter(const QString& filter) row->setBackgroundRole((visible_row_count - 1) % 2 == 0 ? QPalette::Base : QPalette::AlternateBase); } - const bool heading_visible = (visible_row_count > 0); - cw.label->setVisible(heading_visible); - cw.line->setVisible(heading_visible); + cw.heading->setVisible(visible_row_count > 0); } } diff --git a/src/duckstation-qt/hotkeysettingswidget.h b/src/duckstation-qt/hotkeysettingswidget.h index 09b78af9d..2aa874de6 100644 --- a/src/duckstation-qt/hotkeysettingswidget.h +++ b/src/duckstation-qt/hotkeysettingswidget.h @@ -12,7 +12,6 @@ class QLabel; class QLineEdit; class QScrollArea; -class QGridLayout; class QVBoxLayout; class ControllerSettingsWindow; @@ -28,9 +27,10 @@ public: private: struct CategoryWidgets { + QWidget* heading; QLabel* label; QLabel* line; - QGridLayout* layout; + QVBoxLayout* layout; }; class Container final : public QWidget