hotkeysettingswidget.cpp (2578B)
1 // SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #include "hotkeysettingswidget.h" 5 #include "controllersettingswindow.h" 6 #include "util/input_manager.h" 7 #include "inputbindingwidgets.h" 8 #include "qtutils.h" 9 #include "settingwidgetbinder.h" 10 #include <QtWidgets/QGridLayout> 11 #include <QtWidgets/QLabel> 12 #include <QtWidgets/QMessageBox> 13 #include <QtWidgets/QScrollArea> 14 15 HotkeySettingsWidget::HotkeySettingsWidget(QWidget* parent, ControllerSettingsWindow* dialog) 16 : QWidget(parent), m_dialog(dialog) 17 { 18 createUi(); 19 } 20 21 HotkeySettingsWidget::~HotkeySettingsWidget() = default; 22 23 void HotkeySettingsWidget::createUi() 24 { 25 QGridLayout* layout = new QGridLayout(this); 26 layout->setContentsMargins(0, 0, 0, 0); 27 28 m_scroll_area = new QScrollArea(this); 29 m_container = new QWidget(m_scroll_area); 30 m_layout = new QVBoxLayout(m_container); 31 m_scroll_area->setWidget(m_container); 32 m_scroll_area->setWidgetResizable(true); 33 m_scroll_area->setBackgroundRole(QPalette::Base); 34 35 createButtons(); 36 37 m_layout->addStretch(1); 38 layout->addWidget(m_scroll_area, 0, 0, 1, 1); 39 40 setLayout(layout); 41 } 42 43 void HotkeySettingsWidget::createButtons() 44 { 45 const std::vector<const HotkeyInfo*> hotkeys(InputManager::GetHotkeyList()); 46 for (const HotkeyInfo* hotkey : hotkeys) 47 { 48 const QString category(qApp->translate("Hotkeys", hotkey->category)); 49 50 auto iter = m_categories.find(category); 51 if (iter == m_categories.end()) 52 { 53 QLabel* label = new QLabel(category, m_container); 54 QFont label_font(label->font()); 55 label_font.setPointSizeF(14.0f); 56 label->setFont(label_font); 57 m_layout->addWidget(label); 58 59 QLabel* line = new QLabel(m_container); 60 line->setFrameShape(QFrame::HLine); 61 line->setFixedHeight(4); 62 m_layout->addWidget(line); 63 64 QGridLayout* layout = new QGridLayout(); 65 layout->setContentsMargins(0, 0, 0, 0); 66 m_layout->addLayout(layout); 67 iter = m_categories.insert(category, layout); 68 } 69 70 QGridLayout* layout = *iter; 71 const int target_row = layout->count() / 2; 72 73 QLabel* label = new QLabel(qApp->translate("Hotkeys", hotkey->display_name), m_container); 74 layout->addWidget(label, target_row, 0); 75 76 InputBindingWidget* bind = new InputBindingWidget(m_container, m_dialog->getEditingSettingsInterface(), 77 InputBindingInfo::Type::Button, "Hotkeys", hotkey->name); 78 bind->setMinimumWidth(300); 79 layout->addWidget(bind, target_row, 1); 80 } 81 }