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