Add audio page to settings dialog

This commit is contained in:
Dan Paulat 2023-11-29 22:39:40 -06:00
parent ec97231bca
commit c03884c2c0
5 changed files with 317 additions and 2 deletions

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--! Font Awesome Pro 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M533.6 32.5C598.5 85.3 640 165.8 640 256s-41.5 170.8-106.4 223.5c-10.3 8.4-25.4 6.8-33.8-3.5s-6.8-25.4 3.5-33.8C557.5 398.2 592 331.2 592 256s-34.5-142.2-88.7-186.3c-10.3-8.4-11.8-23.5-3.5-33.8s23.5-11.8 33.8-3.5zM473.1 107c43.2 35.2 70.9 88.9 70.9 149s-27.7 113.8-70.9 149c-10.3 8.4-25.4 6.8-33.8-3.5s-6.8-25.4 3.5-33.8C475.3 341.3 496 301.1 496 256s-20.7-85.3-53.2-111.8c-10.3-8.4-11.8-23.5-3.5-33.8s23.5-11.8 33.8-3.5zm-60.5 74.5C434.1 199.1 448 225.9 448 256s-13.9 56.9-35.4 74.5c-10.3 8.4-25.4 6.8-33.8-3.5s-6.8-25.4 3.5-33.8C393.1 284.4 400 271 400 256s-6.9-28.4-17.7-37.3c-10.3-8.4-11.8-23.5-3.5-33.8s23.5-11.8 33.8-3.5zM301.1 34.8C312.6 40 320 51.4 320 64V448c0 12.6-7.4 24-18.9 29.2s-25 3.1-34.4-5.3L131.8 352H64c-35.3 0-64-28.7-64-64V224c0-35.3 28.7-64 64-64h67.8L266.7 40.1c9.4-8.4 22.9-10.4 34.4-5.3z"/></svg>

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -44,6 +44,7 @@
<file>res/icons/font-awesome-6/square-caret-right-regular.svg</file> <file>res/icons/font-awesome-6/square-caret-right-regular.svg</file>
<file>res/icons/font-awesome-6/square-minus-regular.svg</file> <file>res/icons/font-awesome-6/square-minus-regular.svg</file>
<file>res/icons/font-awesome-6/square-plus-regular.svg</file> <file>res/icons/font-awesome-6/square-plus-regular.svg</file>
<file>res/icons/font-awesome-6/volume-high-solid.svg</file>
<file>res/palettes/wct/CC.pal</file> <file>res/palettes/wct/CC.pal</file>
<file>res/palettes/wct/Default16.pal</file> <file>res/palettes/wct/Default16.pal</file>
<file>res/palettes/wct/DOD_DSD.pal</file> <file>res/palettes/wct/DOD_DSD.pal</file>

View file

@ -180,6 +180,32 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget)
// TODO: Display invalid status // TODO: Display invalid status
}); });
} }
else if constexpr (std::is_same_v<T, double>)
{
// If the line is edited (not programatically changed), stage the new
// value
QObject::connect(lineEdit,
&QLineEdit::textEdited,
p->context_.get(),
[this](const QString& text)
{
// Convert to a double
bool ok;
double value = text.toDouble(&ok);
if (ok)
{
// Attempt to stage the value
p->stagedValid_ =
p->variable_->StageValue(value);
p->UpdateResetButton();
}
else
{
p->stagedValid_ = false;
p->UpdateResetButton();
}
});
}
else if constexpr (std::is_same_v<T, std::vector<std::int64_t>>) else if constexpr (std::is_same_v<T, std::vector<std::int64_t>>)
{ {
// If the line is edited (not programatically changed), stage the new // If the line is edited (not programatically changed), stage the new
@ -310,6 +336,52 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget)
}); });
} }
} }
else if (QDoubleSpinBox* doubleSpinBox =
dynamic_cast<QDoubleSpinBox*>(widget))
{
if constexpr (std::is_floating_point_v<T>)
{
const std::optional<T> minimum = p->variable_->GetMinimum();
const std::optional<T> maximum = p->variable_->GetMaximum();
if (minimum.has_value())
{
doubleSpinBox->setMinimum(static_cast<double>(*minimum));
}
if (maximum.has_value())
{
doubleSpinBox->setMaximum(static_cast<double>(*maximum));
}
// If the spin box is edited, stage a changed value
QObject::connect(
doubleSpinBox,
&QDoubleSpinBox::valueChanged,
p->context_.get(),
[this](double d)
{
const T value = p->variable_->GetValue();
const std::optional<T> staged = p->variable_->GetStaged();
// If there is a value staged, and the new value is the same as
// the current value, reset the staged value
if (staged.has_value() && static_cast<T>(d) == value)
{
p->variable_->Reset();
p->stagedValid_ = true;
p->UpdateResetButton();
}
// If there is no staged value, or if the new value is different
// than what is staged, attempt to stage the value
else if (!staged.has_value() || static_cast<T>(d) != *staged)
{
p->stagedValid_ = p->variable_->StageValue(static_cast<T>(d));
p->UpdateResetButton();
}
// Otherwise, don't process an unchanged value
});
}
}
p->UpdateEditWidget(); p->UpdateEditWidget();
} }
@ -378,6 +450,10 @@ void SettingsInterface<T>::Impl::SetWidgetText(U* widget, const T& currentValue)
{ {
widget->setText(QString::number(currentValue)); widget->setText(QString::number(currentValue));
} }
else if constexpr (std::is_floating_point_v<T>)
{
widget->setText(QString::number(currentValue));
}
else if constexpr (std::is_same_v<T, std::string>) else if constexpr (std::is_same_v<T, std::string>)
{ {
if (mapFromValue_ != nullptr) if (mapFromValue_ != nullptr)
@ -448,6 +524,14 @@ void SettingsInterface<T>::Impl::UpdateEditWidget()
spinBox->setValue(static_cast<int>(currentValue)); spinBox->setValue(static_cast<int>(currentValue));
} }
} }
else if (QDoubleSpinBox* doubleSpinBox =
dynamic_cast<QDoubleSpinBox*>(editWidget_))
{
if constexpr (std::is_floating_point_v<T>)
{
doubleSpinBox->setValue(static_cast<double>(currentValue));
}
}
} }
template<class T> template<class T>

View file

@ -6,12 +6,14 @@
#include <scwx/qt/config/radar_site.hpp> #include <scwx/qt/config/radar_site.hpp>
#include <scwx/qt/manager/settings_manager.hpp> #include <scwx/qt/manager/settings_manager.hpp>
#include <scwx/qt/map/map_provider.hpp> #include <scwx/qt/map/map_provider.hpp>
#include <scwx/qt/settings/audio_settings.hpp>
#include <scwx/qt/settings/general_settings.hpp> #include <scwx/qt/settings/general_settings.hpp>
#include <scwx/qt/settings/palette_settings.hpp> #include <scwx/qt/settings/palette_settings.hpp>
#include <scwx/qt/settings/settings_interface.hpp> #include <scwx/qt/settings/settings_interface.hpp>
#include <scwx/qt/settings/text_settings.hpp> #include <scwx/qt/settings/text_settings.hpp>
#include <scwx/qt/types/alert_types.hpp> #include <scwx/qt/types/alert_types.hpp>
#include <scwx/qt/types/font_types.hpp> #include <scwx/qt/types/font_types.hpp>
#include <scwx/qt/types/location_types.hpp>
#include <scwx/qt/types/qt_types.hpp> #include <scwx/qt/types/qt_types.hpp>
#include <scwx/qt/types/text_types.hpp> #include <scwx/qt/types/text_types.hpp>
#include <scwx/qt/ui/radar_site_dialog.hpp> #include <scwx/qt/ui/radar_site_dialog.hpp>
@ -84,6 +86,24 @@ static const std::unordered_map<std::string, ColorTableConversions>
{"VIL", {0u, 255u, 1.0f, 2.5f}}, {"VIL", {0u, 255u, 1.0f, 2.5f}},
{"???", {0u, 15u, 0.0f, 1.0f}}}; {"???", {0u, 15u, 0.0f, 1.0f}}};
#define SCWX_ENUM_MAP_FROM_VALUE(Type, Iterator, ToName) \
[](const std::string& text) -> std::string \
{ \
for (Type enumValue : Iterator) \
{ \
const std::string enumName = ToName(enumValue); \
\
if (boost::iequals(text, enumName)) \
{ \
/* Return label */ \
return enumName; \
} \
} \
\
/* Label not found, return unknown */ \
return "?"; \
}
class SettingsDialogImpl class SettingsDialogImpl
{ {
public: public:
@ -104,6 +124,9 @@ public:
&antiAliasingEnabled_, &antiAliasingEnabled_,
&updateNotificationsEnabled_, &updateNotificationsEnabled_,
&debugEnabled_, &debugEnabled_,
&alertAudioLocationMethod_,
&alertAudioLatitude_,
&alertAudioLongitude_,
&hoverTextWrap_, &hoverTextWrap_,
&tooltipMethod_, &tooltipMethod_,
&placefileTextDropShadowEnabled_}} &placefileTextDropShadowEnabled_}}
@ -136,6 +159,7 @@ public:
void SetupGeneralTab(); void SetupGeneralTab();
void SetupPalettesColorTablesTab(); void SetupPalettesColorTablesTab();
void SetupPalettesAlertsTab(); void SetupPalettesAlertsTab();
void SetupAudioTab();
void SetupTextTab(); void SetupTextTab();
void ShowColorDialog(QLineEdit* lineEdit, QFrame* frame = nullptr); void ShowColorDialog(QLineEdit* lineEdit, QFrame* frame = nullptr);
@ -191,6 +215,13 @@ public:
settings::SettingsInterface<std::string>> settings::SettingsInterface<std::string>>
inactiveAlertColors_ {}; inactiveAlertColors_ {};
settings::SettingsInterface<std::string> alertAudioLocationMethod_ {};
settings::SettingsInterface<double> alertAudioLatitude_ {};
settings::SettingsInterface<double> alertAudioLongitude_ {};
std::unordered_map<awips::Phenomenon, settings::SettingsInterface<bool>>
alertAudioEnabled_ {};
std::unordered_map<types::FontCategory, std::unordered_map<types::FontCategory,
settings::SettingsInterface<std::string>> settings::SettingsInterface<std::string>>
fontFamilies_ {}; fontFamilies_ {};
@ -223,6 +254,9 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
// Palettes > Alerts // Palettes > Alerts
p->SetupPalettesAlertsTab(); p->SetupPalettesAlertsTab();
// Audio
p->SetupAudioTab();
// Text // Text
p->SetupTextTab(); p->SetupTextTab();
@ -766,6 +800,70 @@ void SettingsDialogImpl::SetupPalettesAlertsTab()
} }
} }
void SettingsDialogImpl::SetupAudioTab()
{
settings::AudioSettings& audioSettings = settings::AudioSettings::Instance();
for (const auto& locationMethod : types::LocationMethodIterator())
{
self_->ui->alertAudioLocationMethodComboBox->addItem(
QString::fromStdString(types::GetLocationMethodName(locationMethod)));
}
alertAudioLocationMethod_.SetSettingsVariable(
audioSettings.alert_location_method());
alertAudioLocationMethod_.SetMapFromValueFunction(
SCWX_ENUM_MAP_FROM_VALUE(types::LocationMethod,
types::LocationMethodIterator(),
types::GetLocationMethodName));
alertAudioLocationMethod_.SetMapToValueFunction(
[](std::string text) -> std::string
{
// Convert label to lower case and return
boost::to_lower(text);
return text;
});
alertAudioLocationMethod_.SetEditWidget(
self_->ui->alertAudioLocationMethodComboBox);
alertAudioLocationMethod_.SetResetButton(
self_->ui->resetAlertAudioLocationMethodButton);
alertAudioLatitude_.SetSettingsVariable(audioSettings.alert_latitude());
alertAudioLatitude_.SetEditWidget(self_->ui->alertAudioLatitudeSpinBox);
alertAudioLatitude_.SetResetButton(self_->ui->resetAlertAudioLatitudeButton);
alertAudioLongitude_.SetSettingsVariable(audioSettings.alert_longitude());
alertAudioLongitude_.SetEditWidget(self_->ui->alertAudioLongitudeSpinBox);
alertAudioLongitude_.SetResetButton(
self_->ui->resetAlertAudioLongitudeButton);
auto alertAudioLayout =
static_cast<QGridLayout*>(self_->ui->alertAudioGroupBox->layout());
for (const auto& phenomenon : types::GetAlertAudioPhenomena())
{
QCheckBox* alertAudioCheckbox = new QCheckBox(self_);
alertAudioCheckbox->setText(
QString::fromStdString(awips::GetPhenomenonText(phenomenon)));
static_cast<QGridLayout*>(self_->ui->alertAudioGroupBox->layout())
->addWidget(
alertAudioCheckbox, alertAudioLayout->rowCount(), 0, 1, -1);
// Create settings interface
auto result = alertAudioEnabled_.emplace(
phenomenon, settings::SettingsInterface<bool> {});
auto& alertAudioEnabled = result.first->second;
// Add to settings list
settings_.push_back(&alertAudioEnabled);
alertAudioEnabled.SetSettingsVariable(
audioSettings.alert_enabled(phenomenon));
alertAudioEnabled.SetEditWidget(alertAudioCheckbox);
}
}
void SettingsDialogImpl::SetupTextTab() void SettingsDialogImpl::SetupTextTab()
{ {
settings::TextSettings& textSettings = settings::TextSettings::Instance(); settings::TextSettings& textSettings = settings::TextSettings::Instance();

View file

@ -77,6 +77,15 @@
<normaloff>:/res/icons/font-awesome-6/palette-solid.svg</normaloff>:/res/icons/font-awesome-6/palette-solid.svg</iconset> <normaloff>:/res/icons/font-awesome-6/palette-solid.svg</normaloff>:/res/icons/font-awesome-6/palette-solid.svg</iconset>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>Audio</string>
</property>
<property name="icon">
<iconset resource="../../../../scwx-qt.qrc">
<normaloff>:/res/icons/font-awesome-6/volume-high-solid.svg</normaloff>:/res/icons/font-awesome-6/volume-high-solid.svg</iconset>
</property>
</item>
<item> <item>
<property name="text"> <property name="text">
<string>Text</string> <string>Text</string>
@ -364,8 +373,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>63</width> <width>508</width>
<height>18</height> <height>383</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
@ -436,6 +445,128 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="alertAudioGroupBox">
<property name="title">
<string>Alerts</string>
</property>
<layout class="QGridLayout" name="gridLayout_10">
<item row="1" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Latitude</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="alertAudioLatitudeSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="minimum">
<double>-90.000000000000000</double>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="resetAlertAudioLatitudeButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../scwx-qt.qrc">
<normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Longitude</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="resetAlertAudioLongitudeButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../scwx-qt.qrc">
<normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="resetAlertAudioLocationMethodButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../../scwx-qt.qrc">
<normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</normaloff>:/res/icons/font-awesome-6/rotate-left-solid.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Location Method</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="alertAudioLongitudeSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="minimum">
<double>-180.000000000000000</double>
</property>
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="alertAudioLocationMethodComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>309</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="text"> <widget class="QWidget" name="text">
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
<item> <item>