change hints for dimmer
This commit is contained in:
parent
17e4582f85
commit
4a4d7259d4
|
@ -12,6 +12,17 @@ QSK_SUBCONTROL( LightDisplay, Panel )
|
||||||
LightDimmer::LightDimmer( QQuickItem* parent )
|
LightDimmer::LightDimmer( QQuickItem* parent )
|
||||||
: QQuickPaintedItem( parent )
|
: QQuickPaintedItem( parent )
|
||||||
{
|
{
|
||||||
|
connect( this, &QQuickPaintedItem::contentsSizeChanged, [this]()
|
||||||
|
{
|
||||||
|
auto size = contentsSize();
|
||||||
|
QRadialGradient ringGradient( size.width() / 2, size.height() / 2, 110 );
|
||||||
|
QGradientStop stop1( 0.0, "#c0c0c0" );
|
||||||
|
QGradientStop stop2( 0.5, "#f0f0f0" );
|
||||||
|
QGradientStop stop3( 1.0, "#c0c0c0" );
|
||||||
|
ringGradient.setStops( {stop1, stop2, stop3} );
|
||||||
|
|
||||||
|
m_ringGradient = ringGradient;
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightDimmer::paint( QPainter* painter )
|
void LightDimmer::paint( QPainter* painter )
|
||||||
|
@ -24,13 +35,7 @@ void LightDimmer::paint( QPainter* painter )
|
||||||
auto size = contentsSize();
|
auto size = contentsSize();
|
||||||
QRectF outerRect( {0, offset}, size );
|
QRectF outerRect( {0, offset}, size );
|
||||||
|
|
||||||
QRadialGradient gradient( size.width() / 2, size.height() / 2, 110 );
|
painter->setBrush( m_ringGradient );
|
||||||
QGradientStop stop1( 0.0, "#c0c0c0" );
|
|
||||||
QGradientStop stop2( 0.5, "#f0f0f0" );
|
|
||||||
QGradientStop stop3( 1.0, "#c0c0c0" );
|
|
||||||
gradient.setStops( {stop1, stop2, stop3} );
|
|
||||||
|
|
||||||
painter->setBrush( gradient );
|
|
||||||
|
|
||||||
painter->setPen( m_backgroundColor );
|
painter->setPen( m_backgroundColor );
|
||||||
painter->drawEllipse( outerRect );
|
painter->drawEllipse( outerRect );
|
||||||
|
@ -87,6 +92,18 @@ LightDisplay::LightDisplay( QQuickItem* parent )
|
||||||
{
|
{
|
||||||
const QColor c = color( Panel );
|
const QColor c = color( Panel );
|
||||||
m_dimmer->setBackgroundColor( c );
|
m_dimmer->setBackgroundColor( c );
|
||||||
|
|
||||||
|
QRadialGradient gradient = m_dimmer->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_dimmer->setRingGradient( newGradient );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "Box.h"
|
#include "Box.h"
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
#include <QQuickPaintedItem>
|
||||||
|
#include <QRadialGradient>
|
||||||
|
|
||||||
class QskTextLabel;
|
class QskTextLabel;
|
||||||
|
|
||||||
|
@ -29,9 +30,20 @@ class LightDimmer: public QQuickPaintedItem
|
||||||
m_backgroundColor = color;
|
m_backgroundColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRadialGradient ringGradient() const
|
||||||
|
{
|
||||||
|
return m_ringGradient;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRingGradient( const QRadialGradient& gradient )
|
||||||
|
{
|
||||||
|
m_ringGradient = gradient;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_thickness = 17.57;
|
double m_thickness = 17.57;
|
||||||
QColor m_backgroundColor;
|
QColor m_backgroundColor;
|
||||||
|
QRadialGradient m_ringGradient;
|
||||||
|
|
||||||
virtual void paint( QPainter* painter ) override;
|
virtual void paint( QPainter* painter ) override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue