mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-11 08:54:33 +00:00
Qt: Improve padding in hotkey rows
And fix incorrect parent widgets.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<const HotkeyInfo*> 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);
|
||||
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(m_container);
|
||||
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;
|
||||
|
||||
QLabel* label = new QLabel(qApp->translate("Hotkeys", hotkey->display_name), m_container);
|
||||
|
||||
InputBindingWidget* bind = new InputBindingWidget(m_container, m_dialog->getEditingSettingsInterface(),
|
||||
InputBindingInfo::Type::Button, "Hotkeys", hotkey->name);
|
||||
bind->setMinimumWidth(300);
|
||||
|
||||
QWidget* row = new QWidget(m_container);
|
||||
QWidget* const row = new QWidget(m_container);
|
||||
row->setAutoFillBackground(true);
|
||||
row->setBackgroundRole(target_row % 2 == 0 ? QPalette::Base : QPalette::AlternateBase);
|
||||
row->setBackgroundRole((((iter->layout->count()) % 2) == 0) ? QPalette::Base : QPalette::AlternateBase);
|
||||
iter->layout->addWidget(row);
|
||||
|
||||
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);
|
||||
QHBoxLayout* row_layout = new QHBoxLayout(row);
|
||||
row_layout->setContentsMargins(LR_MARGIN, TB_MARGIN, LR_MARGIN, TB_MARGIN);
|
||||
|
||||
row_layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey->display_name), row));
|
||||
|
||||
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<QWidget*>(cw.layout->itemAtPosition(i, 0)->widget());
|
||||
QWidget* row = qobject_cast<QWidget*>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user