change hints for progress bars
This commit is contained in:
parent
4a4d7259d4
commit
3ceee7cddb
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 );
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue