From 3ceee7cddb27fc6b5237328684d799f27cf6623a Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Wed, 30 Sep 2020 16:25:42 +0200 Subject: [PATCH] change hints for progress bars --- .../iot-dashboard/CircularProgressBar.cpp | 19 ++++++++++++------- examples/iot-dashboard/CircularProgressBar.h | 9 +++++++++ examples/iot-dashboard/PieChartPainted.cpp | 12 ++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/examples/iot-dashboard/CircularProgressBar.cpp b/examples/iot-dashboard/CircularProgressBar.cpp index c961b213..c9999716 100644 --- a/examples/iot-dashboard/CircularProgressBar.cpp +++ b/examples/iot-dashboard/CircularProgressBar.cpp @@ -7,6 +7,17 @@ CircularProgressBar::CircularProgressBar( const QGradient& gradient, int progres , m_gradient( gradient ) , m_progress( progress ) { + connect( this, &QQuickPaintedItem::contentsSizeChanged, [this]() + { + auto size = contentsSize(); + QRadialGradient ringGradient( size.width() / 2, size.height() / 2, 45 ); + QGradientStop stop1( 0.0, "#c0c0c0" ); + QGradientStop stop2( 0.5, "#f0f0f0" ); + QGradientStop stop3( 1.0, "#c0c0c0" ); + ringGradient.setStops( {stop1, stop2, stop3} ); + + m_ringGradient = ringGradient; + } ); } void CircularProgressBar::paint( QPainter* painter ) @@ -16,13 +27,7 @@ void CircularProgressBar::paint( QPainter* painter ) painter->setRenderHint( QPainter::Antialiasing, true ); - QRadialGradient gradient( size.width() / 2, size.height() / 2, 45 ); - QGradientStop stop1( 0.0, "#c0c0c0" ); - QGradientStop stop2( 0.5, "#f0f0f0" ); - QGradientStop stop3( 1.0, "#c0c0c0" ); - gradient.setStops( {stop1, stop2, stop3} ); - - painter->setBrush( gradient ); + painter->setBrush( m_ringGradient ); painter->setPen( m_backgroundColor ); painter->drawEllipse( outerRect ); diff --git a/examples/iot-dashboard/CircularProgressBar.h b/examples/iot-dashboard/CircularProgressBar.h index 78489492..c5ee14b0 100644 --- a/examples/iot-dashboard/CircularProgressBar.h +++ b/examples/iot-dashboard/CircularProgressBar.h @@ -26,11 +26,20 @@ class CircularProgressBar : public QQuickPaintedItem m_backgroundColor = color; } + QRadialGradient ringGradient() const + { + return m_ringGradient; + } + void setRingGradient( const QRadialGradient& gradient ) + { + m_ringGradient = gradient; + } private: QGradient m_gradient; QColor m_backgroundColor; + QRadialGradient m_ringGradient; double m_width = 20; int m_progress; }; diff --git a/examples/iot-dashboard/PieChartPainted.cpp b/examples/iot-dashboard/PieChartPainted.cpp index bdf863c8..744f3ef5 100644 --- a/examples/iot-dashboard/PieChartPainted.cpp +++ b/examples/iot-dashboard/PieChartPainted.cpp @@ -33,6 +33,18 @@ PieChartPainted::PieChartPainted( const QColor& color, const QGradient& gradient { const QColor c = this->color( Panel ); m_progressBar->setBackgroundColor( c ); + + QRadialGradient gradient = m_progressBar->ringGradient(); + QRadialGradient newGradient = gradient; + + for( const QGradientStop& stop : gradient.stops() ) + { + QColor s = stop.second; + QColor newColor = { 255 - s.red(), 255 - s.green(), 255 - s.blue()}; + newGradient.setColorAt( stop.first, newColor ); + } + + m_progressBar->setRingGradient( newGradient ); } ); }