From bd0c40b24127c8419259fb30dd2c0af745d01199 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 25 Aug 2021 15:46:08 +0200 Subject: [PATCH] leftover code removed --- examples/iotdashboard/PieChartPainted.cpp | 136 +++++++--------------- examples/iotdashboard/PieChartPainted.h | 16 +-- examples/iotdashboard/Skin.cpp | 1 - examples/iotdashboard/Skin.h | 10 +- examples/iotdashboard/TopBar.cpp | 11 +- 5 files changed, 53 insertions(+), 121 deletions(-) diff --git a/examples/iotdashboard/PieChartPainted.cpp b/examples/iotdashboard/PieChartPainted.cpp index 1b4a3c50..4e1bfb13 100644 --- a/examples/iotdashboard/PieChartPainted.cpp +++ b/examples/iotdashboard/PieChartPainted.cpp @@ -4,6 +4,7 @@ *****************************************************************************/ #include "PieChartPainted.h" +#include "CircularProgressBar.h" #include #include @@ -13,112 +14,61 @@ #include #include -#include -#include -#include -#include - -QSK_SUBCONTROL( PieChartPainted, Panel ) - namespace { - QColor invertedColor( const QColor& c ) + class ProgressLabel : public QskTextLabel { - QColor ret = { 255 - c.red(), 255 - c.green(), 255 - c.blue()}; - return ret; - } -} - -// ### There must be an easier way to do this -class ProgressBarAnimator : public QskAnimator -{ - public: - ProgressBarAnimator( PieChartPainted* pieChart, CircularProgressBar* progressBar ) - : m_pieChart( pieChart ) - , m_progressBar( progressBar ) - { - QQuickWindow* w = static_cast< QQuickWindow* >( qGuiApp->allWindows().at( 0 ) ); - setWindow( w ); - setDuration( 500 ); - setEasingCurve( QEasingCurve::Linear ); - setAutoRepeat( false ); - } - - void setup() override - { - m_backgroundColor = m_pieChart->color( PieChartPainted::Panel ); - } - - void advance( qreal value ) override - { - const QColor c = m_backgroundColor; - const QColor c2 = invertedColor( c ); - const QColor newColor = QskRgb::interpolated( c2, c, value ); - m_progressBar->setBackgroundColor( newColor ); - - QRadialGradient gradient = m_ringGradient; - QRadialGradient newGradient = gradient; - - for( const QGradientStop& stop : gradient.stops() ) + public: + ProgressLabel( QQuickItem* parent ) + : QskTextLabel( parent ) { - QColor c = stop.second; - QColor c2 = invertedColor( c ); - const QColor newColor = QskRgb::interpolated( c, c2, value ); - newGradient.setColorAt( stop.first, newColor ); + initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); + setLayoutAlignmentHint( Qt::AlignCenter ); + setFontRole( QskSkin::SmallFont ); } - m_progressBar->update(); - } + void setValue( int value ) + { + setText( locale().toString( value ) + " " + locale().percent() ); + } + }; +} - private: - QColor m_backgroundColor; - QRadialGradient m_ringGradient; - PieChartPainted* m_pieChart; - CircularProgressBar* m_progressBar; -}; - -PieChartPainted::PieChartPainted( const QColor& color, const QskGradient& gradient, int progress, int /*value*/, QQuickItem* parent ) +PieChartPainted::PieChartPainted( const QColor& textColor, const QskGradient& gradient, + int progress, QQuickItem* parent ) : QskControl( parent ) - , m_color( color ) - , m_gradient( gradient ) - , m_progressBar( new CircularProgressBar( this ) ) - , m_progressLabel( new QskTextLabel( this ) ) - , m_animator( new ProgressBarAnimator( this, m_progressBar ) ) { setAutoLayoutChildren( true ); - setSubcontrolProxy( QskBox::Panel, PieChartPainted::Panel ); - m_progressBar->setGradientHint( CircularProgressBar::Bar, gradient ); - m_progressBar->setValue( progress ); + auto progressBar = new CircularProgressBar( this ); + progressBar->setGradientHint( CircularProgressBar::Bar, gradient ); + progressBar->setValue( progress ); - auto progressText = QString::number( progress ) + " %"; - m_progressLabel->setText( progressText ); - m_progressLabel->setFontRole( QskSkin::SmallFont ); - m_progressLabel->setTextColor( color ); - - const QColor c = this->color( Panel ); - m_progressBar->setBackgroundColor( c ); - - connect( qskSetup, &QskSetup::skinChanged, - [this]() { m_animator->start(); } ); + auto progressLabel = new ProgressLabel( this ); + progressLabel->setTextColor( textColor ); + progressLabel->setValue( progress ); } -QSizeF PieChartPainted::contentsSizeHint( Qt::SizeHint, const QSizeF& ) const +QSizeF PieChartPainted::contentsSizeHint( + Qt::SizeHint which, const QSizeF& constraint ) const { - return {57, 57}; -} - -void PieChartPainted::updateLayout() -{ - m_progressBar->update(); - - const auto rect = layoutRect(); - - QFontMetricsF fm( m_progressLabel->effectiveFont( QskTextLabel::Text ) ); - auto textWidth = qskHorizontalAdvance( fm, m_progressLabel->text() ); - auto posX = rect.width() / 2 - textWidth / 2; - auto posY = rect.height() / 2 - fm.height() / 2; - - m_progressLabel->setPosition( posX, posY ); - m_progressLabel->setFixedWidth( textWidth ); + if ( which != Qt::PreferredSize ) + return QSizeF(); + + qreal size; + + if ( constraint.width() > 0 ) + { + size = constraint.width(); + } + else if ( constraint.height() > 0 ) + { + size = constraint.height(); + } + else + { + size = 57; + } + + return QSizeF( size, size ); } diff --git a/examples/iotdashboard/PieChartPainted.h b/examples/iotdashboard/PieChartPainted.h index de3a059f..a3bfa596 100644 --- a/examples/iotdashboard/PieChartPainted.h +++ b/examples/iotdashboard/PieChartPainted.h @@ -6,27 +6,13 @@ #pragma once #include -#include "CircularProgressBar.h" - -class ProgressBarAnimator; -class QskTextLabel; class PieChartPainted : public QskControl { public: - QSK_SUBCONTROLS( Panel ) - PieChartPainted( const QColor&, const QskGradient&, - int progress, int value, QQuickItem* parent = nullptr ); + int progress, QQuickItem* parent = nullptr ); protected: QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const override; - void updateLayout() override; - - private: - QColor m_color; - QskGradient m_gradient; - CircularProgressBar* m_progressBar; - QskTextLabel* m_progressLabel; - ProgressBarAnimator* m_animator; }; diff --git a/examples/iotdashboard/Skin.cpp b/examples/iotdashboard/Skin.cpp index de524ade..0040518a 100644 --- a/examples/iotdashboard/Skin.cpp +++ b/examples/iotdashboard/Skin.cpp @@ -182,7 +182,6 @@ void Skin::initHints( const Palette& palette ) ed.setGradient( BoxWithButtons::Panel, palette.box ); ed.setGradient( UsageDiagramBox::Panel, palette.box ); ed.setColor( LightDisplay::Panel, palette.lightDisplay ); - ed.setColor( PieChartPainted::Panel, palette.pieChart ); ed.setGradient( RoundButton::Panel, palette.roundButton ); ed.setBoxBorderColors( UsageDiagramBox::DaysBox, palette.weekdayBox ); ed.setColor( QskTextLabel::Text, palette.text ); diff --git a/examples/iotdashboard/Skin.h b/examples/iotdashboard/Skin.h index ba3bf163..733d9818 100644 --- a/examples/iotdashboard/Skin.h +++ b/examples/iotdashboard/Skin.h @@ -15,7 +15,7 @@ class Skin : public QskSkin { public: Palette( const QskGradient& menuBar, const QskGradient& mainContent, - const QskGradient& box, const QColor& lightDisplay, const QColor& pieChart, + const QskGradient& box, const QColor& lightDisplay, const QskGradient& roundButton, const QColor& weekdayBox, const QColor& text, const QColor& shadow, const QskGradient& circularProgressBarGroove ) @@ -23,7 +23,6 @@ class Skin : public QskSkin , mainContent( mainContent ) , box( box ) , lightDisplay( lightDisplay ) - , pieChart( pieChart ) , roundButton( roundButton ) , weekdayBox( weekdayBox ) , text( text ) @@ -35,7 +34,6 @@ class Skin : public QskSkin QskGradient mainContent; QskGradient box; QColor lightDisplay; - QColor pieChart; QskGradient roundButton; QColor weekdayBox; QColor text; @@ -61,8 +59,7 @@ class DaytimeSkin : public Skin DaytimeSkin( QObject* parent = nullptr ) : Skin( Skin::Palette( {"#6D7BFB"}, {"#fbfbfb"}, {"#ffffff"}, - "#ffffff", "#ffffff", {"#f7f7f7"}, - {"#f4f4f4"}, Qt::black, Qt::black, + "#ffffff", {"#f7f7f7"}, {"#f4f4f4"}, Qt::black, Qt::black, { Qt::Horizontal, { { 0.0, 0xc4c4c4 }, { 0.5, 0xf8f8f8 }, { 1.0, 0xc4c4c4 } } } ) , parent ) { @@ -75,8 +72,7 @@ class NighttimeSkin : public Skin NighttimeSkin( QObject* parent = nullptr ) : Skin( Skin::Palette( {"#2937A7"}, {"#040404"}, {"#000000"}, - "#000000", "#000000", {"#0a0a0a"}, - {"#0c0c0c"}, Qt::white, Qt::white, + "#000000", {"#0a0a0a"}, {"#0c0c0c"}, Qt::white, Qt::white, { Qt::Horizontal, { { 0.0, 0x666666 }, { 0.5, 0x222222 }, { 1.0, 0x333333 } } } ) , parent ) { diff --git a/examples/iotdashboard/TopBar.cpp b/examples/iotdashboard/TopBar.cpp index c6939908..cd74d22b 100644 --- a/examples/iotdashboard/TopBar.cpp +++ b/examples/iotdashboard/TopBar.cpp @@ -51,8 +51,6 @@ TopBarItem::TopBarItem( { setSubcontrolProxy( QskLinearBox::Panel, Panel ); - setAutoLayoutChildren( true ); - setAutoAddChildren( true ); setSpacing( 15 ); auto* textLabel = new QskTextLabel( name, this ); @@ -61,9 +59,12 @@ TopBarItem::TopBarItem( auto* pieChartAndDisplay = new QskLinearBox( Qt::Horizontal, this ); pieChartAndDisplay->setSpacing( 10 ); - QskAspect::Subcontrol subcontrol = subcontrolForIndex( index ); - QColor textColor = color( subcontrol | QskAspect::TextColor ); - new PieChartPainted( textColor, gradient, progress, value, pieChartAndDisplay ); + const auto subcontrol = subcontrolForIndex( index ); + const auto textColor = color( subcontrol | QskAspect::TextColor ); + + auto pieChart = new PieChartPainted( + textColor, gradient, progress, pieChartAndDisplay ); + pieChart->setSizePolicy( Qt::Horizontal, QskSizePolicy::Constrained ); auto display = new QskLinearBox( Qt::Vertical, pieChartAndDisplay ); display->setSpacing( 0 );