mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 17:50:04 +00:00
Add unit settings to settings dialog
This commit is contained in:
parent
3bfcaede96
commit
a29256d77e
7 changed files with 224 additions and 5 deletions
160
scwx-qt/source/scwx/qt/ui/settings/unit_settings_widget.cpp
Normal file
160
scwx-qt/source/scwx/qt/ui/settings/unit_settings_widget.cpp
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
#include <scwx/qt/ui/settings/unit_settings_widget.hpp>
|
||||
#include <scwx/qt/settings/settings_interface.hpp>
|
||||
#include <scwx/qt/settings/unit_settings.hpp>
|
||||
#include <scwx/qt/types/unit_types.hpp>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/unordered/unordered_flat_map.hpp>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
#include <QScrollArea>
|
||||
#include <QToolButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#define SCWX_SETTINGS_COMBO_BOX(settingsInterface, comboBox, Iterator, ToName) \
|
||||
for (const auto& enumValue : Iterator) \
|
||||
{ \
|
||||
comboBox->addItem(QString::fromStdString(ToName(enumValue))); \
|
||||
} \
|
||||
\
|
||||
settingsInterface.SetMapFromValueFunction( \
|
||||
[](const std::string& text) -> std::string \
|
||||
{ \
|
||||
for (const auto& enumValue : Iterator) \
|
||||
{ \
|
||||
const std::string valueName = ToName(enumValue); \
|
||||
\
|
||||
if (boost::iequals(text, valueName)) \
|
||||
{ \
|
||||
return valueName; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return "?"; \
|
||||
}); \
|
||||
settingsInterface.SetMapToValueFunction( \
|
||||
[](std::string text) -> std::string \
|
||||
{ \
|
||||
boost::to_lower(text); \
|
||||
return text; \
|
||||
}); \
|
||||
\
|
||||
settingsInterface.SetEditWidget(comboBox);
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ =
|
||||
"scwx::qt::ui::settings::unit_settings_widget";
|
||||
|
||||
class UnitSettingsWidget::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl(UnitSettingsWidget* self)
|
||||
{
|
||||
auto& unitSettings = settings::UnitSettings::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;
|
||||
|
||||
auto AddRow =
|
||||
[&row, &self, this](
|
||||
settings::SettingsInterface<std::string>& settingsInterface,
|
||||
const std::string& labelName,
|
||||
QComboBox* comboBox)
|
||||
{
|
||||
QLabel* label = new QLabel(QObject::tr(labelName.c_str()), self);
|
||||
QToolButton* resetButton = new QToolButton(self);
|
||||
|
||||
resetButton->setIcon(
|
||||
QIcon {":/res/icons/font-awesome-6/rotate-left-solid.svg"});
|
||||
resetButton->setVisible(false);
|
||||
|
||||
settingsInterface.SetResetButton(resetButton);
|
||||
|
||||
gridLayout_->addWidget(label, row, 0);
|
||||
gridLayout_->addWidget(comboBox, row, 1);
|
||||
gridLayout_->addWidget(resetButton, row, 2);
|
||||
|
||||
// Add to settings list
|
||||
self->AddSettingsInterface(&settingsInterface);
|
||||
|
||||
++row;
|
||||
};
|
||||
|
||||
QComboBox* accumulationComboBox = new QComboBox(self);
|
||||
accumulationComboBox->setSizePolicy(QSizePolicy::Expanding,
|
||||
QSizePolicy::Preferred);
|
||||
accumulationUnits_.SetSettingsVariable(unitSettings.accumulation_units());
|
||||
SCWX_SETTINGS_COMBO_BOX(accumulationUnits_,
|
||||
accumulationComboBox,
|
||||
types::AccumulationUnitsIterator(),
|
||||
types::GetAccumulationUnitsName);
|
||||
AddRow(accumulationUnits_, "Accumulation", accumulationComboBox);
|
||||
|
||||
QComboBox* echoTopsComboBox = new QComboBox(self);
|
||||
echoTopsComboBox->setSizePolicy(QSizePolicy::Expanding,
|
||||
QSizePolicy::Preferred);
|
||||
echoTopsUnits_.SetSettingsVariable(unitSettings.echo_tops_units());
|
||||
SCWX_SETTINGS_COMBO_BOX(echoTopsUnits_,
|
||||
echoTopsComboBox,
|
||||
types::EchoTopsUnitsIterator(),
|
||||
types::GetEchoTopsUnitsName);
|
||||
AddRow(echoTopsUnits_, "Echo Tops", echoTopsComboBox);
|
||||
|
||||
QComboBox* speedComboBox = new QComboBox(self);
|
||||
speedComboBox->setSizePolicy(QSizePolicy::Expanding,
|
||||
QSizePolicy::Preferred);
|
||||
speedUnits_.SetSettingsVariable(unitSettings.speed_units());
|
||||
SCWX_SETTINGS_COMBO_BOX(speedUnits_,
|
||||
speedComboBox,
|
||||
types::SpeedUnitsIterator(),
|
||||
types::GetSpeedUnitsName);
|
||||
AddRow(speedUnits_, "Speed", speedComboBox);
|
||||
|
||||
QSpacerItem* spacer =
|
||||
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
gridLayout_->addItem(spacer, row, 0);
|
||||
}
|
||||
~Impl() = default;
|
||||
|
||||
QWidget* contents_;
|
||||
QLayout* layout_;
|
||||
QScrollArea* scrollArea_ {};
|
||||
QGridLayout* gridLayout_ {};
|
||||
|
||||
settings::SettingsInterface<std::string> accumulationUnits_ {};
|
||||
settings::SettingsInterface<std::string> echoTopsUnits_ {};
|
||||
settings::SettingsInterface<std::string> speedUnits_ {};
|
||||
};
|
||||
|
||||
UnitSettingsWidget::UnitSettingsWidget(QWidget* parent) :
|
||||
SettingsPageWidget(parent), p {std::make_shared<Impl>(this)}
|
||||
{
|
||||
}
|
||||
|
||||
UnitSettingsWidget::~UnitSettingsWidget() = default;
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
29
scwx-qt/source/scwx/qt/ui/settings/unit_settings_widget.hpp
Normal file
29
scwx-qt/source/scwx/qt/ui/settings/unit_settings_widget.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/ui/settings/settings_page_widget.hpp>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
class UnitSettingsWidget : public SettingsPageWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UnitSettingsWidget(QWidget* parent = nullptr);
|
||||
~UnitSettingsWidget();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::shared_ptr<Impl> p;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
#include <scwx/qt/ui/county_dialog.hpp>
|
||||
#include <scwx/qt/ui/radar_site_dialog.hpp>
|
||||
#include <scwx/qt/ui/settings/hotkey_settings_widget.hpp>
|
||||
#include <scwx/qt/ui/settings/unit_settings_widget.hpp>
|
||||
#include <scwx/qt/util/color.hpp>
|
||||
#include <scwx/qt/util/file.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
|
@ -178,6 +179,7 @@ public:
|
|||
void SetupGeneralTab();
|
||||
void SetupPalettesColorTablesTab();
|
||||
void SetupPalettesAlertsTab();
|
||||
void SetupUnitsTab();
|
||||
void SetupAudioTab();
|
||||
void SetupTextTab();
|
||||
void SetupHotkeysTab();
|
||||
|
|
@ -222,6 +224,7 @@ public:
|
|||
|
||||
std::vector<SettingsPageWidget*> settingsPages_ {};
|
||||
HotkeySettingsWidget* hotkeySettingsWidget_ {};
|
||||
UnitSettingsWidget* unitSettingsWidget_ {};
|
||||
|
||||
settings::SettingsInterface<std::string> defaultRadarSite_ {};
|
||||
settings::SettingsInterface<std::int64_t> gridWidth_ {};
|
||||
|
|
@ -292,6 +295,9 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
|
|||
// Palettes > Alerts
|
||||
p->SetupPalettesAlertsTab();
|
||||
|
||||
// Units
|
||||
p->SetupUnitsTab();
|
||||
|
||||
// Audio
|
||||
p->SetupAudioTab();
|
||||
|
||||
|
|
@ -897,6 +903,16 @@ void SettingsDialogImpl::SetupPalettesAlertsTab()
|
|||
}
|
||||
}
|
||||
|
||||
void SettingsDialogImpl::SetupUnitsTab()
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(self_->ui->units);
|
||||
|
||||
unitSettingsWidget_ = new UnitSettingsWidget(self_->ui->units);
|
||||
layout->addWidget(unitSettingsWidget_);
|
||||
|
||||
settingsPages_.push_back(unitSettingsWidget_);
|
||||
}
|
||||
|
||||
void SettingsDialogImpl::SetupAudioTab()
|
||||
{
|
||||
QObject::connect(
|
||||
|
|
|
|||
|
|
@ -77,6 +77,15 @@
|
|||
<normaloff>:/res/icons/font-awesome-6/palette-solid.svg</normaloff>:/res/icons/font-awesome-6/palette-solid.svg</iconset>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Units</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../scwx-qt.qrc">
|
||||
<normaloff>:/res/icons/font-awesome-6/ruler-combined-solid.svg</normaloff>:/res/icons/font-awesome-6/ruler-combined-solid.svg</iconset>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Audio</string>
|
||||
|
|
@ -482,8 +491,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>63</width>
|
||||
<height>18</height>
|
||||
<width>506</width>
|
||||
<height>383</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
|
|
@ -554,7 +563,8 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page">
|
||||
<widget class="QWidget" name="units"/>
|
||||
<widget class="QWidget" name="audio">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="alertAudioGroupBox">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue