Hotkey settings should be scrollable

This commit is contained in:
Dan Paulat 2024-04-13 21:44:24 -05:00
parent 7564a2af18
commit 21dc38bf82

View file

@ -7,7 +7,9 @@
#include <boost/unordered/unordered_flat_map.hpp> #include <boost/unordered/unordered_flat_map.hpp>
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QScrollArea>
#include <QToolButton> #include <QToolButton>
#include <QVBoxLayout>
namespace scwx namespace scwx
{ {
@ -22,12 +24,25 @@ static const std::string logPrefix_ =
class HotkeySettingsWidget::Impl class HotkeySettingsWidget::Impl
{ {
public: public:
explicit Impl(HotkeySettingsWidget* self) : explicit Impl(HotkeySettingsWidget* self)
self_ {self}, layout_ {new QGridLayout(self)}
{ {
auto& hotkeySettings = settings::HotkeySettings::Instance(); auto& hotkeySettings = settings::HotkeySettings::Instance();
gridLayout_ = new QGridLayout(self);
contents_ = new QWidget(self);
contents_->setLayout(gridLayout_);
scrollArea_ = new QScrollArea(self);
scrollArea_->setHorizontalScrollBarPolicy(
Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
scrollArea_->setWidgetResizable(true);
scrollArea_->setWidget(contents_);
layout_ = new QVBoxLayout(self);
layout_->setContentsMargins(0, 0, 0, 0); layout_->setContentsMargins(0, 0, 0, 0);
layout_->addWidget(scrollArea_);
self->setLayout(layout_);
int row = 0; int row = 0;
@ -37,15 +52,15 @@ public:
QLabel* label = new QLabel(QObject::tr(labelText.c_str()), self); QLabel* label = new QLabel(QObject::tr(labelText.c_str()), self);
HotkeyEdit* hotkeyEdit = new HotkeyEdit(self); HotkeyEdit* hotkeyEdit = new HotkeyEdit(self);
QToolButton* resetButton = new QToolButton(self_); QToolButton* resetButton = new QToolButton(self);
resetButton->setIcon( resetButton->setIcon(
QIcon {":/res/icons/font-awesome-6/rotate-left-solid.svg"}); QIcon {":/res/icons/font-awesome-6/rotate-left-solid.svg"});
resetButton->setVisible(false); resetButton->setVisible(false);
layout_->addWidget(label, row, 0); gridLayout_->addWidget(label, row, 0);
layout_->addWidget(hotkeyEdit, row, 1); gridLayout_->addWidget(hotkeyEdit, row, 1);
layout_->addWidget(resetButton, row, 2); gridLayout_->addWidget(resetButton, row, 2);
// Create settings interface // Create settings interface
auto result = hotkeys_.emplace( auto result = hotkeys_.emplace(
@ -54,7 +69,7 @@ public:
auto& interface = pair.second; auto& interface = pair.second;
// Add to settings list // Add to settings list
self_->AddSettingsInterface(&interface); self->AddSettingsInterface(&interface);
auto& hotkeyVariable = hotkeySettings.hotkey(hotkey); auto& hotkeyVariable = hotkeySettings.hotkey(hotkey);
interface.SetSettingsVariable(hotkeyVariable); interface.SetSettingsVariable(hotkeyVariable);
@ -66,12 +81,14 @@ public:
QSpacerItem* spacer = QSpacerItem* spacer =
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
layout_->addItem(spacer, row, 0); gridLayout_->addItem(spacer, row, 0);
} }
~Impl() = default; ~Impl() = default;
HotkeySettingsWidget* self_; QWidget* contents_;
QGridLayout* layout_; QLayout* layout_;
QScrollArea* scrollArea_ {};
QGridLayout* gridLayout_ {};
boost::unordered_flat_map<types::Hotkey, boost::unordered_flat_map<types::Hotkey,
settings::SettingsInterface<std::string>> settings::SettingsInterface<std::string>>