Skip to content

Commit

Permalink
Qt: Replace hotkey tabs with a scrollable view
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and refractionpcsx2 committed Jul 17, 2022
1 parent 9269792 commit a77f78f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
51 changes: 32 additions & 19 deletions pcsx2-qt/Settings/HotkeySettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QtWidgets/QLabel>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QScrollArea>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QVBoxLayout>

HotkeySettingsWidget::HotkeySettingsWidget(QWidget* parent, ControllerSettingsDialog* dialog)
: QWidget(parent)
Expand All @@ -41,11 +41,16 @@ void HotkeySettingsWidget::createUi()
QGridLayout* layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);

m_tab_widget = new QTabWidget(this);
m_scroll_area = new QScrollArea(this);
m_container = new QWidget(m_scroll_area);
m_layout = new QVBoxLayout(m_container);
m_scroll_area->setWidget(m_container);
m_scroll_area->setWidgetResizable(true);
m_scroll_area->setBackgroundRole(QPalette::Base);

createButtons();

layout->addWidget(m_tab_widget, 0, 0, 1, 1);
layout->addWidget(m_scroll_area, 0, 0, 1, 1);

setLayout(layout);
}
Expand All @@ -55,31 +60,39 @@ void HotkeySettingsWidget::createButtons()
const std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList());
for (const HotkeyInfo* hotkey : hotkeys)
{
const auto category = qApp->translate("Hotkeys", hotkey->category);
const QString category(qApp->translate("Hotkeys", hotkey->category));

auto iter = m_categories.find(category);
if (iter == m_categories.end())
{
QScrollArea* scroll = new QScrollArea(m_tab_widget);
QWidget* container = new QWidget(scroll);
QVBoxLayout* vlayout = new QVBoxLayout(container);
QLabel* label = new QLabel(category, m_container);
QFont label_font(label->font());
label_font.setPointSizeF(14.0f);
label->setFont(label_font);
m_layout->addWidget(label);

QLabel* line = new QLabel(m_container);
line->setFrameShape(QFrame::HLine);
line->setFixedHeight(4);
m_layout->addWidget(line);

QGridLayout* layout = new QGridLayout();
layout->setContentsMargins(0, 0, 0, 0);
vlayout->addLayout(layout);
vlayout->addStretch(1);
iter = m_categories.insert(category, Category{container, layout});
scroll->setWidget(container);
scroll->setWidgetResizable(true);
scroll->setBackgroundRole(QPalette::Base);
scroll->setFrameShape(QFrame::NoFrame);
m_tab_widget->addTab(scroll, category);
m_layout->addLayout(layout);
iter = m_categories.insert(category, layout);
}

QWidget* container = iter->container;
QGridLayout* layout = iter->layout;
QGridLayout* layout = *iter;
const int target_row = layout->count() / 2;

layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey->display_name), container), target_row, 0);
layout->addWidget(new InputBindingWidget(container, m_dialog->getProfileSettingsInterface(), "Hotkeys", hotkey->name), target_row, 1);
QLabel* label = new QLabel(qApp->translate("Hotkeys", hotkey->display_name), m_container);
layout->addWidget(label, target_row, 0);

InputBindingWidget* bind = new InputBindingWidget(m_container, m_dialog->getProfileSettingsInterface(), "Hotkeys", hotkey->name);
bind->setMinimumWidth(300);
layout->addWidget(bind, target_row, 1);
}

// Fill remaining space.
m_layout->addStretch(1);
}
16 changes: 7 additions & 9 deletions pcsx2-qt/Settings/HotkeySettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#include <array>
#include <vector>

class QTabWidget;
class QScrollArea;
class QGridLayout;
class QVBoxLayout;

class ControllerSettingsDialog;

Expand All @@ -38,12 +39,9 @@ class HotkeySettingsWidget : public QWidget
void createButtons();

ControllerSettingsDialog* m_dialog;
QTabWidget* m_tab_widget;

struct Category
{
QWidget* container;
QGridLayout* layout;
};
QMap<QString, Category> m_categories;
QScrollArea* m_scroll_area = nullptr;
QWidget* m_container = nullptr;
QVBoxLayout* m_layout = nullptr;

QMap<QString, QGridLayout*> m_categories;
};

0 comments on commit a77f78f

Please sign in to comment.