mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:00:04 +00:00
Add hotkey settings page
This commit is contained in:
parent
589eff9882
commit
81f44add42
6 changed files with 299 additions and 35 deletions
|
|
@ -0,0 +1,90 @@
|
|||
#include <scwx/qt/ui/settings/hotkey_settings_widget.hpp>
|
||||
#include <scwx/qt/ui/hotkey_edit.hpp>
|
||||
#include <scwx/qt/settings/hotkey_settings.hpp>
|
||||
#include <scwx/qt/settings/settings_interface.hpp>
|
||||
#include <scwx/qt/types/hotkey_types.hpp>
|
||||
|
||||
#include <boost/unordered/unordered_flat_map.hpp>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ =
|
||||
"scwx::qt::ui::settings::hotkey_settings_widget";
|
||||
|
||||
class HotkeySettingsWidget::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl(HotkeySettingsWidget* self) :
|
||||
self_ {self}, layout_ {new QGridLayout(self)}
|
||||
{
|
||||
auto& hotkeySettings = settings::HotkeySettings::Instance();
|
||||
|
||||
layout_->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
int row = 0;
|
||||
|
||||
for (types::Hotkey hotkey : types::HotkeyIterator())
|
||||
{
|
||||
const std::string& labelText = types::GetHotkeyLongName(hotkey);
|
||||
|
||||
QLabel* label = new QLabel(QObject::tr(labelText.c_str()), self);
|
||||
HotkeyEdit* hotkeyEdit = new HotkeyEdit(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);
|
||||
|
||||
// Create settings interface
|
||||
auto result = hotkeys_.emplace(
|
||||
hotkey, settings::SettingsInterface<std::string> {});
|
||||
auto& pair = *result.first;
|
||||
auto& interface = pair.second;
|
||||
|
||||
// Add to settings list
|
||||
self_->AddSettingsInterface(&interface);
|
||||
|
||||
auto& hotkeyVariable = hotkeySettings.hotkey(hotkey);
|
||||
interface.SetSettingsVariable(hotkeyVariable);
|
||||
interface.SetEditWidget(hotkeyEdit);
|
||||
interface.SetResetButton(resetButton);
|
||||
|
||||
++row;
|
||||
}
|
||||
|
||||
QSpacerItem* spacer =
|
||||
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
layout_->addItem(spacer, row, 0);
|
||||
}
|
||||
~Impl() = default;
|
||||
|
||||
HotkeySettingsWidget* self_;
|
||||
QGridLayout* layout_;
|
||||
|
||||
boost::unordered_flat_map<types::Hotkey,
|
||||
settings::SettingsInterface<std::string>>
|
||||
hotkeys_ {};
|
||||
};
|
||||
|
||||
HotkeySettingsWidget::HotkeySettingsWidget(QWidget* parent) :
|
||||
SettingsPageWidget(parent), p {std::make_shared<Impl>(this)}
|
||||
{
|
||||
}
|
||||
|
||||
HotkeySettingsWidget::~HotkeySettingsWidget() = default;
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/ui/settings/settings_page_widget.hpp>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
class HotkeySettingsWidget : public SettingsPageWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HotkeySettingsWidget(QWidget* parent = nullptr);
|
||||
~HotkeySettingsWidget();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::shared_ptr<Impl> p;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
68
scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.cpp
Normal file
68
scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#include <scwx/qt/ui/settings/settings_page_widget.hpp>
|
||||
#include <scwx/qt/settings/settings_interface_base.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ =
|
||||
"scwx::qt::ui::settings::settings_page_widget";
|
||||
|
||||
class SettingsPageWidget::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl() {}
|
||||
~Impl() = default;
|
||||
|
||||
std::vector<settings::SettingsInterfaceBase*> settings_;
|
||||
};
|
||||
|
||||
SettingsPageWidget::SettingsPageWidget(QWidget* parent) :
|
||||
QWidget(parent), p {std::make_shared<Impl>()}
|
||||
{
|
||||
}
|
||||
|
||||
SettingsPageWidget::~SettingsPageWidget() = default;
|
||||
|
||||
void SettingsPageWidget::AddSettingsInterface(
|
||||
settings::SettingsInterfaceBase* setting)
|
||||
{
|
||||
p->settings_.push_back(setting);
|
||||
}
|
||||
|
||||
bool SettingsPageWidget::CommitChanges()
|
||||
{
|
||||
bool committed = false;
|
||||
|
||||
for (auto& setting : p->settings_)
|
||||
{
|
||||
committed |= setting->Commit();
|
||||
}
|
||||
|
||||
return committed;
|
||||
}
|
||||
|
||||
void SettingsPageWidget::DiscardChanges()
|
||||
{
|
||||
for (auto& setting : p->settings_)
|
||||
{
|
||||
setting->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsPageWidget::ResetToDefault()
|
||||
{
|
||||
for (auto& setting : p->settings_)
|
||||
{
|
||||
setting->StageDefault();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
36
scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.hpp
Normal file
36
scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.hpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/settings/settings_interface_base.hpp>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
class SettingsPageWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsPageWidget(QWidget* parent = nullptr);
|
||||
~SettingsPageWidget();
|
||||
|
||||
bool CommitChanges();
|
||||
void DiscardChanges();
|
||||
void ResetToDefault();
|
||||
|
||||
protected:
|
||||
void AddSettingsInterface(settings::SettingsInterfaceBase* setting);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::shared_ptr<Impl> p;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue