mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:50:05 +00:00 
			
		
		
		
	Connect line label to alert palette settings
- Line label will initialize to settings value - Changes to the line label will stage settings
This commit is contained in:
		
							parent
							
								
									9f4a798d67
								
							
						
					
					
						commit
						8212d24d34
					
				
					 3 changed files with 96 additions and 10 deletions
				
			
		|  | @ -1,4 +1,5 @@ | ||||||
| #include <scwx/qt/ui/line_label.hpp> | #include <scwx/qt/ui/line_label.hpp> | ||||||
|  | #include <scwx/qt/util/color.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
| #include <QEvent> | #include <QEvent> | ||||||
|  | @ -20,6 +21,8 @@ public: | ||||||
|    explicit Impl() {}; |    explicit Impl() {}; | ||||||
|    ~Impl() = default; |    ~Impl() = default; | ||||||
| 
 | 
 | ||||||
|  |    void ResetLineSettings(); | ||||||
|  | 
 | ||||||
|    QImage GenerateImage() const; |    QImage GenerateImage() const; | ||||||
| 
 | 
 | ||||||
|    std::size_t borderWidth_ {1}; |    std::size_t borderWidth_ {1}; | ||||||
|  | @ -30,6 +33,8 @@ public: | ||||||
|    boost::gil::rgba8_pixel_t highlightColor_ {255, 255, 0, 255}; |    boost::gil::rgba8_pixel_t highlightColor_ {255, 255, 0, 255}; | ||||||
|    boost::gil::rgba8_pixel_t lineColor_ {0, 0, 255, 255}; |    boost::gil::rgba8_pixel_t lineColor_ {0, 0, 255, 255}; | ||||||
| 
 | 
 | ||||||
|  |    settings::LineSettings* lineSettings_ {nullptr}; | ||||||
|  | 
 | ||||||
|    QPixmap pixmap_ {}; |    QPixmap pixmap_ {}; | ||||||
|    bool    pixmapDirty_ {true}; |    bool    pixmapDirty_ {true}; | ||||||
| }; | }; | ||||||
|  | @ -39,7 +44,15 @@ LineLabel::LineLabel(QWidget* parent) : | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| LineLabel::~LineLabel() {} | LineLabel::~LineLabel() | ||||||
|  | { | ||||||
|  |    p->ResetLineSettings(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void LineLabel::Impl::ResetLineSettings() | ||||||
|  | { | ||||||
|  |    lineSettings_ = nullptr; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| boost::gil::rgba8_pixel_t LineLabel::border_color() const | boost::gil::rgba8_pixel_t LineLabel::border_color() const | ||||||
| { | { | ||||||
|  | @ -77,6 +90,11 @@ void LineLabel::set_border_width(std::size_t width) | ||||||
|    p->pixmapDirty_ = true; |    p->pixmapDirty_ = true; | ||||||
|    updateGeometry(); |    updateGeometry(); | ||||||
|    update(); |    update(); | ||||||
|  | 
 | ||||||
|  |    if (p->lineSettings_ != nullptr) | ||||||
|  |    { | ||||||
|  |       p->lineSettings_->border_width().StageValue(width); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LineLabel::set_highlight_width(std::size_t width) | void LineLabel::set_highlight_width(std::size_t width) | ||||||
|  | @ -85,6 +103,11 @@ void LineLabel::set_highlight_width(std::size_t width) | ||||||
|    p->pixmapDirty_    = true; |    p->pixmapDirty_    = true; | ||||||
|    updateGeometry(); |    updateGeometry(); | ||||||
|    update(); |    update(); | ||||||
|  | 
 | ||||||
|  |    if (p->lineSettings_ != nullptr) | ||||||
|  |    { | ||||||
|  |       p->lineSettings_->highlight_width().StageValue(width); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LineLabel::set_line_width(std::size_t width) | void LineLabel::set_line_width(std::size_t width) | ||||||
|  | @ -93,6 +116,11 @@ void LineLabel::set_line_width(std::size_t width) | ||||||
|    p->pixmapDirty_ = true; |    p->pixmapDirty_ = true; | ||||||
|    updateGeometry(); |    updateGeometry(); | ||||||
|    update(); |    update(); | ||||||
|  | 
 | ||||||
|  |    if (p->lineSettings_ != nullptr) | ||||||
|  |    { | ||||||
|  |       p->lineSettings_->line_width().StageValue(width); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LineLabel::set_border_color(boost::gil::rgba8_pixel_t color) | void LineLabel::set_border_color(boost::gil::rgba8_pixel_t color) | ||||||
|  | @ -100,6 +128,12 @@ void LineLabel::set_border_color(boost::gil::rgba8_pixel_t color) | ||||||
|    p->borderColor_ = color; |    p->borderColor_ = color; | ||||||
|    p->pixmapDirty_ = true; |    p->pixmapDirty_ = true; | ||||||
|    update(); |    update(); | ||||||
|  | 
 | ||||||
|  |    if (p->lineSettings_ != nullptr) | ||||||
|  |    { | ||||||
|  |       p->lineSettings_->border_color().StageValue( | ||||||
|  |          util::color::ToArgbString(color)); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LineLabel::set_highlight_color(boost::gil::rgba8_pixel_t color) | void LineLabel::set_highlight_color(boost::gil::rgba8_pixel_t color) | ||||||
|  | @ -107,6 +141,12 @@ void LineLabel::set_highlight_color(boost::gil::rgba8_pixel_t color) | ||||||
|    p->highlightColor_ = color; |    p->highlightColor_ = color; | ||||||
|    p->pixmapDirty_    = true; |    p->pixmapDirty_    = true; | ||||||
|    update(); |    update(); | ||||||
|  | 
 | ||||||
|  |    if (p->lineSettings_ != nullptr) | ||||||
|  |    { | ||||||
|  |       p->lineSettings_->highlight_color().StageValue( | ||||||
|  |          util::color::ToArgbString(color)); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LineLabel::set_line_color(boost::gil::rgba8_pixel_t color) | void LineLabel::set_line_color(boost::gil::rgba8_pixel_t color) | ||||||
|  | @ -114,6 +154,30 @@ void LineLabel::set_line_color(boost::gil::rgba8_pixel_t color) | ||||||
|    p->lineColor_   = color; |    p->lineColor_   = color; | ||||||
|    p->pixmapDirty_ = true; |    p->pixmapDirty_ = true; | ||||||
|    update(); |    update(); | ||||||
|  | 
 | ||||||
|  |    if (p->lineSettings_ != nullptr) | ||||||
|  |    { | ||||||
|  |       p->lineSettings_->line_color().StageValue( | ||||||
|  |          util::color::ToArgbString(color)); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void LineLabel::set_line_settings(settings::LineSettings& lineSettings) | ||||||
|  | { | ||||||
|  |    p->ResetLineSettings(); | ||||||
|  | 
 | ||||||
|  |    set_border_color(util::color::ToRgba8PixelT( | ||||||
|  |       lineSettings.border_color().GetStagedOrValue())); | ||||||
|  |    set_highlight_color(util::color::ToRgba8PixelT( | ||||||
|  |       lineSettings.highlight_color().GetStagedOrValue())); | ||||||
|  |    set_line_color( | ||||||
|  |       util::color::ToRgba8PixelT(lineSettings.line_color().GetStagedOrValue())); | ||||||
|  | 
 | ||||||
|  |    set_border_width(lineSettings.border_width().GetStagedOrValue()); | ||||||
|  |    set_highlight_width(lineSettings.highlight_width().GetStagedOrValue()); | ||||||
|  |    set_line_width(lineSettings.line_width().GetStagedOrValue()); | ||||||
|  | 
 | ||||||
|  |    p->lineSettings_ = &lineSettings; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QSize LineLabel::minimumSizeHint() const | QSize LineLabel::minimumSizeHint() const | ||||||
|  |  | ||||||
|  | @ -1,5 +1,7 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include <scwx/qt/settings/line_settings.hpp> | ||||||
|  | 
 | ||||||
| #include <QFrame> | #include <QFrame> | ||||||
| 
 | 
 | ||||||
| #include <boost/gil/typedefs.hpp> | #include <boost/gil/typedefs.hpp> | ||||||
|  | @ -36,6 +38,8 @@ public: | ||||||
|    void set_highlight_width(std::size_t width); |    void set_highlight_width(std::size_t width); | ||||||
|    void set_line_width(std::size_t width); |    void set_line_width(std::size_t width); | ||||||
| 
 | 
 | ||||||
|  |    void set_line_settings(settings::LineSettings& lineSettings); | ||||||
|  | 
 | ||||||
| protected: | protected: | ||||||
|    QSize minimumSizeHint() const override; |    QSize minimumSizeHint() const override; | ||||||
|    QSize sizeHint() const override; |    QSize sizeHint() const override; | ||||||
|  |  | ||||||
|  | @ -37,8 +37,10 @@ public: | ||||||
|    } |    } | ||||||
|    ~Impl() = default; |    ~Impl() = default; | ||||||
| 
 | 
 | ||||||
|    void |    void     AddPhenomenonLine(const std::string&      name, | ||||||
|    AddPhenomenonLine(const std::string& name, QGridLayout* layout, int row); |                               settings::LineSettings& lineSettings, | ||||||
|  |                               QGridLayout*            layout, | ||||||
|  |                               int                     row); | ||||||
|    QWidget* CreateStackedWidgetPage(awips::Phenomenon phenomenon); |    QWidget* CreateStackedWidgetPage(awips::Phenomenon phenomenon); | ||||||
|    void     ConnectSignals(); |    void     ConnectSignals(); | ||||||
|    void     SelectPhenomenon(awips::Phenomenon phenomenon); |    void     SelectPhenomenon(awips::Phenomenon phenomenon); | ||||||
|  | @ -181,21 +183,31 @@ QWidget* AlertPaletteSettingsWidget::Impl::CreateStackedWidgetPage( | ||||||
|    const auto& impactBasedWarningInfo = |    const auto& impactBasedWarningInfo = | ||||||
|       awips::ibw::GetImpactBasedWarningInfo(phenomenon); |       awips::ibw::GetImpactBasedWarningInfo(phenomenon); | ||||||
| 
 | 
 | ||||||
|  |    auto& alertPalette = | ||||||
|  |       settings::PaletteSettings::Instance().alert_palette(phenomenon); | ||||||
|  | 
 | ||||||
|    int row = 0; |    int row = 0; | ||||||
| 
 | 
 | ||||||
|    // Add a blank label to align left and right widgets
 |    // Add a blank label to align left and right widgets
 | ||||||
|    gridLayout->addWidget(new QLabel(self_), row++, 0); |    gridLayout->addWidget(new QLabel(self_), row++, 0); | ||||||
| 
 | 
 | ||||||
|    AddPhenomenonLine("Active", gridLayout, row++); |    AddPhenomenonLine( | ||||||
|  |       "Active", | ||||||
|  |       alertPalette.threat_category(awips::ibw::ThreatCategory::Base), | ||||||
|  |       gridLayout, | ||||||
|  |       row++); | ||||||
| 
 | 
 | ||||||
|    if (impactBasedWarningInfo.hasObservedTag_) |    if (impactBasedWarningInfo.hasObservedTag_) | ||||||
|    { |    { | ||||||
|       AddPhenomenonLine("Observed", gridLayout, row++); |       AddPhenomenonLine("Observed", alertPalette.observed(), gridLayout, row++); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    if (impactBasedWarningInfo.hasTornadoPossibleTag_) |    if (impactBasedWarningInfo.hasTornadoPossibleTag_) | ||||||
|    { |    { | ||||||
|       AddPhenomenonLine("Tornado Possible", gridLayout, row++); |       AddPhenomenonLine("Tornado Possible", | ||||||
|  |                         alertPalette.tornado_possible(), | ||||||
|  |                         gridLayout, | ||||||
|  |                         row++); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    for (auto& category : impactBasedWarningInfo.threatCategories_) |    for (auto& category : impactBasedWarningInfo.threatCategories_) | ||||||
|  | @ -205,11 +217,13 @@ QWidget* AlertPaletteSettingsWidget::Impl::CreateStackedWidgetPage( | ||||||
|          continue; |          continue; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       AddPhenomenonLine( |       AddPhenomenonLine(awips::ibw::GetThreatCategoryName(category), | ||||||
|          awips::ibw::GetThreatCategoryName(category), gridLayout, row++); |                         alertPalette.threat_category(category), | ||||||
|  |                         gridLayout, | ||||||
|  |                         row++); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    AddPhenomenonLine("Inactive", gridLayout, row++); |    AddPhenomenonLine("Inactive", alertPalette.inactive(), gridLayout, row++); | ||||||
| 
 | 
 | ||||||
|    QSpacerItem* spacer = |    QSpacerItem* spacer = | ||||||
|       new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); |       new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | ||||||
|  | @ -219,12 +233,16 @@ QWidget* AlertPaletteSettingsWidget::Impl::CreateStackedWidgetPage( | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AlertPaletteSettingsWidget::Impl::AddPhenomenonLine( | void AlertPaletteSettingsWidget::Impl::AddPhenomenonLine( | ||||||
|    const std::string& name, QGridLayout* layout, int row) |    const std::string&      name, | ||||||
|  |    settings::LineSettings& lineSettings, | ||||||
|  |    QGridLayout*            layout, | ||||||
|  |    int                     row) | ||||||
| { | { | ||||||
|    QToolButton* toolButton = new QToolButton(self_); |    QToolButton* toolButton = new QToolButton(self_); | ||||||
|    toolButton->setText(tr("...")); |    toolButton->setText(tr("...")); | ||||||
| 
 | 
 | ||||||
|    LineLabel* lineLabel = new LineLabel(self_); |    LineLabel* lineLabel = new LineLabel(self_); | ||||||
|  |    lineLabel->set_line_settings(lineSettings); | ||||||
| 
 | 
 | ||||||
|    layout->addWidget(new QLabel(tr(name.c_str()), self_), row, 0); |    layout->addWidget(new QLabel(tr(name.c_str()), self_), row, 0); | ||||||
|    layout->addWidget(lineLabel, row, 1); |    layout->addWidget(lineLabel, row, 1); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat