Draw alert boxes using colors from settings

This commit is contained in:
Dan Paulat 2022-12-25 21:55:27 -06:00
parent 3289f98638
commit 14f825d896
3 changed files with 34 additions and 15 deletions

View file

@ -1,5 +1,7 @@
#include <scwx/qt/map/alert_layer.hpp>
#include <scwx/qt/manager/settings_manager.hpp>
#include <scwx/qt/manager/text_event_manager.hpp>
#include <scwx/qt/util/color.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/threads.hpp>
@ -43,18 +45,6 @@ static const std::vector<awips::Phenomenon> kAlertPhenomena_ {
awips::Phenomenon::SnowSquall,
awips::Phenomenon::Tornado};
static const std::map<
awips::Phenomenon,
std::pair<boost::gil::rgba8_pixel_t, boost::gil::rgba8_pixel_t>>
kAlertColors_ {
{awips::Phenomenon::Marine, {{255, 127, 0, 255}, {127, 63, 0, 255}}},
{awips::Phenomenon::FlashFlood, {{0, 255, 0, 255}, {0, 127, 0, 255}}},
{awips::Phenomenon::SevereThunderstorm,
{{255, 255, 0, 255}, {127, 127, 0, 255}}},
{awips::Phenomenon::SnowSquall,
{{127, 127, 255, 255}, {63, 63, 127, 255}}},
{awips::Phenomenon::Tornado, {{255, 0, 0, 255}, {127, 0, 0, 255}}}};
template<class Key>
struct AlertTypeHash;
@ -69,7 +59,7 @@ class AlertLayerHandler : public QObject
Q_OBJECT public :
explicit AlertLayerHandler() :
textEventManager_ {manager::TextEventManager::Instance()},
alertUpdateTimer_ {util::io_context()},
alertUpdateTimer_ {scwx::util::io_context()},
alertSourceMap_ {},
featureMap_ {}
{
@ -403,10 +393,13 @@ static void AddAlertLayer(std::shared_ptr<QMapLibreGL::Map> map,
bool alertActive,
const QString& beforeLayer)
{
settings::PaletteSettings& paletteSettings =
manager::SettingsManager::palette_settings();
QString sourceId = GetSourceId(phenomenon, alertActive);
QString idSuffix = GetSuffix(phenomenon, alertActive);
auto& outlineColor = (alertActive) ? kAlertColors_.at(phenomenon).first :
kAlertColors_.at(phenomenon).second;
auto outlineColor = util::color::ToRgba8PixelT(
paletteSettings.alert_color(phenomenon, alertActive).GetValue());
QString bgLayerId = QString("alertPolygonLayerBg-%1").arg(idSuffix);
QString fgLayerId = QString("alertPolygonLayerFg-%1").arg(idSuffix);

View file

@ -1,6 +1,7 @@
#include <scwx/qt/util/color.hpp>
#include <format>
#include <QColor>
namespace scwx
{
@ -19,6 +20,15 @@ std::string ToArgbString(const boost::gil::rgba8_pixel_t& color)
"#{:02x}{:02x}{:02x}{:02x}", color[3], color[0], color[1], color[2]);
}
boost::gil::rgba8_pixel_t ToRgba8PixelT(const std::string& argbString)
{
QRgb color = QColor(QString::fromStdString(argbString)).rgba();
return boost::gil::rgba8_pixel_t {static_cast<uint8_t>(qRed(color)),
static_cast<uint8_t>(qGreen(color)),
static_cast<uint8_t>(qBlue(color)),
static_cast<uint8_t>(qAlpha(color))};
}
} // namespace color
} // namespace util
} // namespace qt

View file

@ -11,8 +11,24 @@ namespace util
namespace color
{
/**
* Converts a Boost.GIL 8-bit RGBA pixel to an ARGB string used by Qt libraries.
*
* @param color RGBA8 pixel
*
* @return ARGB string in the format #AARRGGBB
*/
std::string ToArgbString(const boost::gil::rgba8_pixel_t& color);
/**
* Converts an ARGB string used by Qt libraries to a Boost.GIL 8-bit RGBA pixel.
*
* @param argbString ARGB string in the format #AARRGGBB
*
* @return RGBA8 pixel
*/
boost::gil::rgba8_pixel_t ToRgba8PixelT(const std::string& argbString);
} // namespace color
} // namespace util
} // namespace qt