mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-24 01:39:42 +01:00
* Offer inverted gauge animations.
This commit is contained in:
parent
e5b4caee2f
commit
7557696d48
@ -33,6 +33,7 @@
|
||||
|
||||
StatsGauge::StatsGauge( QWidget* parent )
|
||||
: QProgressBar( parent )
|
||||
, m_inverted( false )
|
||||
{
|
||||
QProgressBar::setValue( 0 );
|
||||
QProgressBar::setMaximum( 0 );
|
||||
@ -57,7 +58,9 @@ StatsGauge::paintEvent( QPaintEvent* event )
|
||||
p.setPen( pen );
|
||||
|
||||
int fullCircle = 16 * 360;
|
||||
p.drawArc( QRect( 12, 12, gaugeSize.width() - 24, gaugeSize.height() - 24 ), 4*360, (int)( -1.0 * (float)fullCircle * ( 1.0 - (float)value() / (float)maximum() ) ) );
|
||||
float pct = m_inverted ? ( 1.0 - (float)value() / (float)maximum() ) : (float)value() / (float)maximum();
|
||||
|
||||
p.drawArc( QRect( 12, 12, gaugeSize.width() - 24, gaugeSize.height() - 24 ), 4*360, (int)( -1.0 * (float)fullCircle * pct ) );
|
||||
|
||||
pen = QPen( TomahawkStyle::NOW_PLAYING_ITEM.darker() );
|
||||
pen.setWidth( 6 );
|
||||
@ -85,7 +88,7 @@ StatsGauge::paintEvent( QPaintEvent* event )
|
||||
p.setFont( font );
|
||||
|
||||
textRect = QRect( 0, gaugeSize.height() / 2 - 32, gaugeSize.width(), 20 );
|
||||
p.drawText( textRect, Qt::AlignCenter, maximum() > 0 ? QString( "out of %1" ).arg( maximum() ) : "-" );
|
||||
p.drawText( textRect, Qt::AlignCenter, maximum() > 0 ? tr( "out of %1" ).arg( maximum() ) : "-" );
|
||||
|
||||
if ( !m_text.isEmpty() )
|
||||
{
|
||||
@ -111,7 +114,7 @@ StatsGauge::paintEvent( QPaintEvent* event )
|
||||
void
|
||||
StatsGauge::setValue( int v )
|
||||
{
|
||||
if ( maximum() == 0 )
|
||||
if ( maximum() == 0 || v == 0 )
|
||||
return;
|
||||
|
||||
QPropertyAnimation* a = new QPropertyAnimation( (QProgressBar*)this, "value" );
|
||||
@ -130,4 +133,12 @@ StatsGauge::setText( const QString& text )
|
||||
{
|
||||
m_text = text;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StatsGauge::setInvertedGauge( bool inverted )
|
||||
{
|
||||
m_inverted = inverted;
|
||||
repaint();
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ public:
|
||||
virtual QSize sizeHint() const { return m_sizeHint; }
|
||||
QString text() const { return m_text; }
|
||||
|
||||
void setInvertedGauge( bool inverted );
|
||||
|
||||
public slots:
|
||||
void setValue( int value );
|
||||
void setText( const QString& text );
|
||||
@ -44,6 +46,7 @@ protected:
|
||||
private:
|
||||
QSize m_sizeHint;
|
||||
QString m_text;
|
||||
bool m_inverted;
|
||||
};
|
||||
|
||||
#endif //STATS_GAUGE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user