Duckstation/src/duckstation-qt/hotkeysettingswidget.cpp

73 lines
2.2 KiB
C++
Raw Normal View History

2020-01-05 02:46:03 +00:00
#include "hotkeysettingswidget.h"
#include "core/controller.h"
#include "core/settings.h"
#include "inputbindingwidgets.h"
#include "qthostinterface.h"
#include "qtutils.h"
#include <QtCore/QCoreApplication>
2020-01-05 02:46:03 +00:00
#include <QtCore/QTimer>
#include <QtGui/QKeyEvent>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QScrollArea>
2020-01-05 02:46:03 +00:00
HotkeySettingsWidget::HotkeySettingsWidget(QtHostInterface* host_interface, QWidget* parent /* = nullptr */)
: QWidget(parent), m_host_interface(host_interface)
{
createUi();
}
HotkeySettingsWidget::~HotkeySettingsWidget() = default;
void HotkeySettingsWidget::createUi()
{
QGridLayout* layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
2020-01-05 02:46:03 +00:00
m_tab_widget = new QTabWidget(this);
createButtons();
layout->addWidget(m_tab_widget, 0, 0, 1, 1);
setLayout(layout);
}
void HotkeySettingsWidget::createButtons()
{
const auto& hotkeys = m_host_interface->getHotkeyInfoList();
for (const auto& hi : hotkeys)
2020-01-05 02:46:03 +00:00
{
const auto category = qApp->translate("Hotkeys", hi.category);
auto iter = m_categories.find(category);
2020-01-05 02:46:03 +00:00
if (iter == m_categories.end())
{
QScrollArea* scroll = new QScrollArea(m_tab_widget);
QWidget* container = new QWidget(scroll);
2020-01-05 02:46:03 +00:00
QVBoxLayout* vlayout = new QVBoxLayout(container);
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);
2020-01-05 02:46:03 +00:00
}
QWidget* container = iter->container;
QGridLayout* layout = iter->layout;
const int target_row = layout->count() / 2;
2020-01-05 02:46:03 +00:00
std::string section_name("Hotkeys");
std::string key_name(hi.name.GetCharArray());
layout->addWidget(new QLabel(qApp->translate("Hotkeys", hi.display_name), container), target_row, 0);
layout->addWidget(
new InputButtonBindingWidget(m_host_interface, std::move(section_name), std::move(key_name), container),
target_row, 1);
2020-01-05 02:46:03 +00:00
}
}