mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +02:00
* Made StatsGauge animation smooth and use QProgressBar's own inverted state handling.
This commit is contained in:
@@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
StatsGauge::StatsGauge( QWidget* parent )
|
StatsGauge::StatsGauge( QWidget* parent )
|
||||||
: QProgressBar( parent )
|
: QProgressBar( parent )
|
||||||
, m_inverted( false )
|
, m_percentage( 0 )
|
||||||
|
, m_targetValue( 0 )
|
||||||
{
|
{
|
||||||
QProgressBar::setValue( 0 );
|
QProgressBar::setValue( 0 );
|
||||||
QProgressBar::setMaximum( 0 );
|
QProgressBar::setMaximum( 0 );
|
||||||
@@ -58,9 +59,8 @@ StatsGauge::paintEvent( QPaintEvent* event )
|
|||||||
p.setPen( pen );
|
p.setPen( pen );
|
||||||
|
|
||||||
int fullCircle = 16 * 360;
|
int fullCircle = 16 * 360;
|
||||||
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 * ( invertedAppearance() ? ( 1.0 - m_percentage ) : m_percentage ) ) );
|
||||||
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 );
|
||||||
@@ -116,7 +116,11 @@ StatsGauge::setValue( int v )
|
|||||||
{
|
{
|
||||||
if ( maximum() == 0 || v == 0 )
|
if ( maximum() == 0 || v == 0 )
|
||||||
return;
|
return;
|
||||||
|
if ( v == m_targetValue )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_targetValue = v;
|
||||||
|
{
|
||||||
QPropertyAnimation* a = new QPropertyAnimation( (QProgressBar*)this, "value" );
|
QPropertyAnimation* a = new QPropertyAnimation( (QProgressBar*)this, "value" );
|
||||||
a->setEasingCurve( QEasingCurve( QEasingCurve::OutQuad ) );
|
a->setEasingCurve( QEasingCurve( QEasingCurve::OutQuad ) );
|
||||||
a->setStartValue( value() > 0 ? value() : 1 );
|
a->setStartValue( value() > 0 ? value() : 1 );
|
||||||
@@ -126,6 +130,17 @@ StatsGauge::setValue( int v )
|
|||||||
connect( a, SIGNAL( finished() ), a, SLOT( deleteLater() ) );
|
connect( a, SIGNAL( finished() ), a, SLOT( deleteLater() ) );
|
||||||
a->start();
|
a->start();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
QPropertyAnimation* a = new QPropertyAnimation( (QProgressBar*)this, "percentage" );
|
||||||
|
a->setEasingCurve( QEasingCurve( QEasingCurve::OutQuad ) );
|
||||||
|
a->setStartValue( (float)0 );
|
||||||
|
a->setEndValue( (float)v / (float)maximum() );
|
||||||
|
a->setDuration( 2000 );
|
||||||
|
|
||||||
|
connect( a, SIGNAL( finished() ), a, SLOT( deleteLater() ) );
|
||||||
|
a->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -137,8 +152,8 @@ StatsGauge::setText( const QString& text )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
StatsGauge::setInvertedGauge( bool inverted )
|
StatsGauge::setPercentage( float percentage )
|
||||||
{
|
{
|
||||||
m_inverted = inverted;
|
m_percentage = percentage;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
class DLLEXPORT StatsGauge : public QProgressBar
|
class DLLEXPORT StatsGauge : public QProgressBar
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY( float percentage READ percentage WRITE setPercentage )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** this pixmap becomes the rest state pixmap and defines the size of the eventual widget */
|
/** this pixmap becomes the rest state pixmap and defines the size of the eventual widget */
|
||||||
@@ -34,11 +35,12 @@ 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 );
|
float percentage() const { return m_percentage; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setValue( int value );
|
void setValue( int value );
|
||||||
void setText( const QString& text );
|
void setText( const QString& text );
|
||||||
|
void setPercentage( float percentage );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent( QPaintEvent* event );
|
virtual void paintEvent( QPaintEvent* event );
|
||||||
@@ -46,7 +48,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QSize m_sizeHint;
|
QSize m_sizeHint;
|
||||||
QString m_text;
|
QString m_text;
|
||||||
bool m_inverted;
|
float m_percentage;
|
||||||
|
int m_targetValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //STATS_GAUGE_H
|
#endif //STATS_GAUGE_H
|
||||||
|
@@ -108,7 +108,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
|
|||||||
QHBoxLayout* l = new QHBoxLayout( ui->statsWidget );
|
QHBoxLayout* l = new QHBoxLayout( ui->statsWidget );
|
||||||
m_playStatsGauge = new StatsGauge( ui->statsWidget );
|
m_playStatsGauge = new StatsGauge( ui->statsWidget );
|
||||||
m_playStatsGauge->setText( tr( "CHART #" ) );
|
m_playStatsGauge->setText( tr( "CHART #" ) );
|
||||||
m_playStatsGauge->setInvertedGauge( true );
|
m_playStatsGauge->setInvertedAppearance( true );
|
||||||
|
|
||||||
l->addSpacerItem( new QSpacerItem( 0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding ) );
|
l->addSpacerItem( new QSpacerItem( 0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding ) );
|
||||||
l->addWidget( m_playStatsGauge );
|
l->addWidget( m_playStatsGauge );
|
||||||
|
Reference in New Issue
Block a user