diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 8ec12c389..7fdec0a56 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -128,6 +128,7 @@ set( libGuiSources widgets/CheckDirTree.cpp widgets/QueryLabel.cpp widgets/ImageButton.cpp + widgets/StatsGauge.cpp widgets/AnimatedSplitter.cpp widgets/ElidedLabel.cpp widgets/NewPlaylistWidget.cpp @@ -246,6 +247,7 @@ list(APPEND libSources database/DatabaseCommand_SourceOffline.cpp database/DatabaseCommand_CollectionStats.cpp database/DatabaseCommand_TrackStats.cpp + database/DatabaseCommand_ArtistStats.cpp database/DatabaseCommand_LoadPlaylistEntries.cpp database/DatabaseCommand_LoadInboxEntries.cpp database/DatabaseCommand_ModifyPlaylist.cpp diff --git a/src/libtomahawk/widgets/StatsGauge.cpp b/src/libtomahawk/widgets/StatsGauge.cpp new file mode 100644 index 000000000..64b308c91 --- /dev/null +++ b/src/libtomahawk/widgets/StatsGauge.cpp @@ -0,0 +1,129 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "StatsGauge.h" + +#include "utils/TomahawkStyle.h" +#include "utils/TomahawkUtilsGui.h" +#include "utils/Logger.h" + +#include +#include +#include +#include +#include +#include + + +StatsGauge::StatsGauge( QWidget* parent ) + : QProgressBar( parent ) +{ + QProgressBar::setValue( 0 ); + QProgressBar::setMaximum( 0 ); + + m_sizeHint = QSize( 200, 240 ); + resize( m_sizeHint ); + setFixedSize( m_sizeHint ); +} + + +void +StatsGauge::paintEvent( QPaintEvent* event ) +{ + QPainter p( this ); + p.setRenderHint( QPainter::Antialiasing ); + p.setClipRect( event->rect() ); + + QSize gaugeSize = m_sizeHint - QSize( 0, 40 ); + + QPen pen( TomahawkStyle::NOW_PLAYING_ITEM.lighter() ); + pen.setWidth( 16 ); + 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() ) ) ); + + pen = QPen( TomahawkStyle::NOW_PLAYING_ITEM.darker() ); + pen.setWidth( 6 ); + p.setPen( pen ); + + QBrush brush( QColor( "#252020" ) ); + p.setBrush( brush ); + p.drawEllipse( QRect( 28, 28, gaugeSize.width() - 56, gaugeSize.height() - 56 ) ); + + pen = QPen( Qt::white ); + p.setPen( pen ); + QFont font = p.font(); + font.setWeight( QFont::Black ); + font.setPixelSize( 60 ); + p.setFont( font ); + + QRect textRect( 0, gaugeSize.height() / 2 - 14, gaugeSize.width(), 62 ); + p.drawText( textRect, Qt::AlignCenter, value() > 0 ? QString::number( value() ) : "-" ); + + pen = QPen( QColor( "#8b8b8b" ) ); + p.setPen( pen ); + font = p.font(); + font.setWeight( QFont::Black ); + font.setPixelSize( 16 ); + 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() ) : "-" ); + + if ( !m_text.isEmpty() ) + { + pen = QPen( Qt::white ); + p.setPen( pen ); + font = p.font(); + font.setWeight( QFont::Black ); + font.setPixelSize( 18 ); + p.setFont( font ); + + QColor figColor( "#3e3e3e" ); + p.setBrush( figColor ); + + QFontMetrics fm( font ); + int textWidth = fm.width( m_text ); + textRect = QRect( m_sizeHint.width() / 2 - ( textWidth / 2 + 12 ), m_sizeHint.height() - 32, textWidth + 24, 28 ); + + TomahawkUtils::drawBackgroundAndNumbers( &p, m_text, textRect ); + } +} + + +void +StatsGauge::setValue( int v ) +{ + QPropertyAnimation* a = new QPropertyAnimation( (QProgressBar*)this, "value" ); + a->setEasingCurve( QEasingCurve( QEasingCurve::InOutQuad ) ); + a->setStartValue( value() ); + a->setEndValue( v ); + a->setDuration( 2000 ); + + connect( a, SIGNAL( finished() ), a, SLOT( deleteLater() ) ); + a->start(); +} + + +void +StatsGauge::setText( const QString& text ) +{ + m_text = text; + repaint(); +} \ No newline at end of file diff --git a/src/libtomahawk/widgets/StatsGauge.h b/src/libtomahawk/widgets/StatsGauge.h new file mode 100644 index 000000000..dc7720d75 --- /dev/null +++ b/src/libtomahawk/widgets/StatsGauge.h @@ -0,0 +1,49 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef STATS_GAUGE_H +#define STATS_GAUGE_H + +#include "DllMacro.h" + +#include + +class DLLEXPORT StatsGauge : public QProgressBar +{ +Q_OBJECT + +public: + /** this pixmap becomes the rest state pixmap and defines the size of the eventual widget */ + explicit StatsGauge( QWidget* parent = 0 ); + + virtual QSize sizeHint() const { return m_sizeHint; } + QString text() const { return m_text; } + +public slots: + void setValue( int value ); + void setText( const QString& text ); + +protected: + virtual void paintEvent( QPaintEvent* event ); + +private: + QSize m_sizeHint; + QString m_text; +}; + +#endif //STATS_GAUGE_H