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