Qt: Replace hotkey tabs with a scrollable view

This commit is contained in:
Connor McLaughlin 2022-07-09 20:17:36 +10:00 committed by refractionpcsx2
parent 9269792a8c
commit a77f78f08f
2 changed files with 38 additions and 27 deletions

View File

@ -25,7 +25,7 @@
#include <QtWidgets/QLabel> #include <QtWidgets/QLabel>
#include <QtWidgets/QMessageBox> #include <QtWidgets/QMessageBox>
#include <QtWidgets/QScrollArea> #include <QtWidgets/QScrollArea>
#include <QtWidgets/QTabWidget> #include <QtWidgets/QVBoxLayout>
HotkeySettingsWidget::HotkeySettingsWidget(QWidget* parent, ControllerSettingsDialog* dialog) HotkeySettingsWidget::HotkeySettingsWidget(QWidget* parent, ControllerSettingsDialog* dialog)
: QWidget(parent) : QWidget(parent)
@ -41,11 +41,16 @@ void HotkeySettingsWidget::createUi()
QGridLayout* layout = new QGridLayout(this); QGridLayout* layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0); 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(); createButtons();
layout->addWidget(m_tab_widget, 0, 0, 1, 1); layout->addWidget(m_scroll_area, 0, 0, 1, 1);
setLayout(layout); setLayout(layout);
} }
@ -55,31 +60,39 @@ void HotkeySettingsWidget::createButtons()
const std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList()); const std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList());
for (const HotkeyInfo* hotkey : hotkeys) 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); auto iter = m_categories.find(category);
if (iter == m_categories.end()) if (iter == m_categories.end())
{ {
QScrollArea* scroll = new QScrollArea(m_tab_widget); QLabel* label = new QLabel(category, m_container);
QWidget* container = new QWidget(scroll); QFont label_font(label->font());
QVBoxLayout* vlayout = new QVBoxLayout(container); 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(); QGridLayout* layout = new QGridLayout();
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
vlayout->addLayout(layout); m_layout->addLayout(layout);
vlayout->addStretch(1); iter = m_categories.insert(category, layout);
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);
} }
QWidget* container = iter->container; QGridLayout* layout = *iter;
QGridLayout* layout = iter->layout;
const int target_row = layout->count() / 2; const int target_row = layout->count() / 2;
layout->addWidget(new QLabel(qApp->translate("Hotkeys", hotkey->display_name), container), target_row, 0); QLabel* label = new QLabel(qApp->translate("Hotkeys", hotkey->display_name), m_container);
layout->addWidget(new InputBindingWidget(container, m_dialog->getProfileSettingsInterface(), "Hotkeys", hotkey->name), target_row, 1); 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);
} }

View File

@ -20,8 +20,9 @@
#include <array> #include <array>
#include <vector> #include <vector>
class QTabWidget; class QScrollArea;
class QGridLayout; class QGridLayout;
class QVBoxLayout;
class ControllerSettingsDialog; class ControllerSettingsDialog;
@ -38,12 +39,9 @@ private:
void createButtons(); void createButtons();
ControllerSettingsDialog* m_dialog; ControllerSettingsDialog* m_dialog;
QTabWidget* m_tab_widget; QScrollArea* m_scroll_area = nullptr;
QWidget* m_container = nullptr;
QVBoxLayout* m_layout = nullptr;
struct Category QMap<QString, QGridLayout*> m_categories;
{
QWidget* container;
QGridLayout* layout;
};
QMap<QString, Category> m_categories;
}; };