diff --git a/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml b/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml --- a/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml +++ b/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml @@ -16,78 +16,94 @@ import QtQuick 2.4 import QtQuick.Controls 2.0 -import QtQuick.Layouts 1.3 -import org.kde.kirigami 2.0 as Kirigami import org.kde.amarok.currenttrack 1.0 -Column { +Item { id: root - property real textSize: Kirigami.Units.largeSpacing property alias playCount: playCountLabel.text property alias score: scoreLabel.text property alias lastPlayed: lastPlayedLabel.text Row { - width: parent.width + height: parent.height / 2 Label { text: i18n("Play Count") - width: parent.width / 3 + width: root.width / 3 + height: parent.height horizontalAlignment: Text.AlignHCenter maximumLineCount: 1 - font.pixelSize: root.textSize + fontSizeMode: Text.Fit + font.pointSize: 32 + minimumPointSize: 9 } Label { text: i18n("Score") - width: parent.width / 3 + width: root.width / 3 + height: parent.height horizontalAlignment: Text.AlignHCenter maximumLineCount: 1 - font.pixelSize: root.textSize + fontSizeMode: Text.Fit + font.pointSize: 32 + minimumPointSize: 9 } Label { text: i18n("Last played") - width: parent.width / 3 + width: root.width / 3 + height: parent.height horizontalAlignment: Text.AlignHCenter maximumLineCount: 1 - font.pixelSize: root.textSize + fontSizeMode: Text.Fit + font.pointSize: 32 + minimumPointSize: 9 } } Rectangle { width: parent.width - height: childrenRect.height + height: parent.height / 2 + anchors.bottom: parent.bottom color: palette.base Row { - width: parent.width + height: parent.height Label { id: playCountLabel - width: parent.width / 3 + width: root.width / 3 + height: parent.height horizontalAlignment: Text.AlignHCenter maximumLineCount: 1 - font.pixelSize: root.textSize + fontSizeMode: Text.Fit + font.pointSize: 32 + minimumPointSize: 9 text: CurrentTrackEngine.timesPlayed elide: Text.ElideRight } Label { id: scoreLabel - width: parent.width / 3 + width: root.width / 3 + height: parent.height horizontalAlignment: Text.AlignHCenter maximumLineCount: 1 - font.pixelSize: root.textSize + fontSizeMode: Text.Fit + font.pointSize: 32 + minimumPointSize: 9 text: CurrentTrackEngine.score elide: Text.ElideRight } Label { id: lastPlayedLabel - width: parent.width / 3 + width: root.width / 3 + height: parent.height horizontalAlignment: Text.AlignHCenter maximumLineCount: 1 - font.pixelSize: root.textSize + fontSizeMode: Text.Fit + font.pointSize: 32 + minimumPointSize: 9 text: CurrentTrackEngine.lastPlayed elide: Text.ElideRight } diff --git a/src/context/applets/currenttrack/package/contents/ui/main.qml b/src/context/applets/currenttrack/package/contents/ui/main.qml --- a/src/context/applets/currenttrack/package/contents/ui/main.qml +++ b/src/context/applets/currenttrack/package/contents/ui/main.qml @@ -25,37 +25,15 @@ id: applet //album art - Rectangle { + Loader { id: cover - color: "white" - radius: Kirigami.Units.smallSpacing / 2 - border.width: 1 - border.color: applet.palette.light height: parent.height width: height - AmarokQml.PixmapItem { - id: iconItem - - anchors.fill: parent - anchors.margins: parent.radius - source: CurrentTrackEngine.cover - - onWidthChanged: CurrentTrackEngine.coverWidth = width - - //show standard empty cover if no data is available - AmarokQml.PixmapItem { - anchors.fill: parent - source: Svg.renderSvg("file://" + applet.packagePath + "images/amarok-currenttrack.svg", - "CurrentTrack", - width, - height, - "album_old"); - visible: !iconItem.valid - } - } + sourceComponent: CurrentTrackEngine.hasValidCover ? coverComponent : emptyComponent } + ColumnLayout { anchors { left: cover.right @@ -80,8 +58,8 @@ AmarokQml.RatingItem { id: ratingItem - height: Kirigami.Units.largeSpacing * 2 - width: height * 6 + Layout.preferredWidth: height * 6 + Layout.preferredHeight: parent.height / 5 Layout.alignment: Qt.AlignTop | Qt.AlignRight rating: CurrentTrackEngine.rating onClicked: CurrentTrackEngine.rating = newRating @@ -92,7 +70,40 @@ Layout.fillWidth: true Layout.alignment: Qt.AlignBottom - height: Kirigami.Units.largeSpacing * 3 + Layout.preferredHeight: parent.height / 5 + } + } + + Component { + id: coverComponent + + Rectangle { + id: cover + + color: "white" + radius: Kirigami.Units.smallSpacing / 2 + border.width: 1 + border.color: applet.palette.light + + + AmarokQml.PixmapItem { + id: iconItem + + anchors.fill: parent + anchors.margins: parent.radius + source: CurrentTrackEngine.cover + } + } + } + Component { + id: emptyComponent + + AmarokQml.PixmapItem { + source: Svg.renderSvg("file://" + applet.packagePath + "images/amarok-currenttrack.svg", + "CurrentTrack", + width, + height, + "album_old"); } } } diff --git a/src/context/applets/currenttrack/plugin/CurrentEngine.h b/src/context/applets/currenttrack/plugin/CurrentEngine.h --- a/src/context/applets/currenttrack/plugin/CurrentEngine.h +++ b/src/context/applets/currenttrack/plugin/CurrentEngine.h @@ -40,7 +40,7 @@ Q_PROPERTY(QString lastPlayed READ lastPlayed NOTIFY trackChanged) Q_PROPERTY(int timesPlayed READ timesPlayed NOTIFY trackChanged) Q_PROPERTY(QVariant cover READ cover NOTIFY albumChanged) - Q_PROPERTY(int coverWidth READ coverWidth WRITE setCoverWidth NOTIFY coverWidthChanged) + Q_PROPERTY(bool hasValidCover READ hasValidCover NOTIFY albumChanged) public: explicit CurrentEngine( QObject* parent = Q_NULLPTR ); @@ -56,8 +56,7 @@ QString lastPlayed() const; int timesPlayed() const; QVariant cover() const { return QVariant(m_cover); } - int coverWidth() { return m_coverWidth; } - void setCoverWidth( int width ); + bool hasValidCover() const { return !m_cover.isNull(); } signals: void trackChanged(); @@ -74,7 +73,6 @@ void update( Meta::TrackPtr track ); void update( Meta::AlbumPtr album ); - int m_coverWidth; QPixmap m_cover; Meta::AlbumList m_albums; Meta::TrackPtr m_currentTrack; diff --git a/src/context/applets/currenttrack/plugin/CurrentEngine.cpp b/src/context/applets/currenttrack/plugin/CurrentEngine.cpp --- a/src/context/applets/currenttrack/plugin/CurrentEngine.cpp +++ b/src/context/applets/currenttrack/plugin/CurrentEngine.cpp @@ -37,7 +37,6 @@ CurrentEngine::CurrentEngine( QObject* parent ) : QObject( parent ) - , m_coverWidth( 0 ) , m_lastQueryMaker( Q_NULLPTR ) { EngineController* engine = The::engineController(); @@ -69,7 +68,7 @@ QPixmap cover; if( album ) - cover = The::coverCache()->getCover( album, m_coverWidth ); + cover = The::coverCache()->getCover( album, 1 ); if( m_cover.cacheKey() != cover.cacheKey() ) { @@ -269,16 +268,3 @@ return m_currentTrack->statistics()->playCount(); } - -void -CurrentEngine::setCoverWidth(int width) -{ - if( m_coverWidth == width ) - return; - - m_coverWidth = width; - emit coverWidthChanged(); - - if( m_currentTrack ) - slotAlbumMetadataChanged( m_currentTrack->album() ); -} diff --git a/src/context/qml_plugin/src/RatingItem.h b/src/context/qml_plugin/src/RatingItem.h --- a/src/context/qml_plugin/src/RatingItem.h +++ b/src/context/qml_plugin/src/RatingItem.h @@ -23,6 +23,9 @@ #include + +class KRatingPainter; + class RatingItem : public QQuickPaintedItem { Q_OBJECT @@ -151,8 +154,10 @@ virtual void paint( QPainter* painter ) override; private: - class Private; - Private* const d; + int m_rating; + int m_hoverRating; + + KRatingPainter *m_ratingPainter; }; #endif diff --git a/src/context/qml_plugin/src/RatingItem.cpp b/src/context/qml_plugin/src/RatingItem.cpp --- a/src/context/qml_plugin/src/RatingItem.cpp +++ b/src/context/qml_plugin/src/RatingItem.cpp @@ -31,27 +31,10 @@ #include -class RatingItem::Private -{ -public: - Private() - : rating(0) - , hoverRating(-1) - , pixSize( 16 ) - { - } - - int rating; - int hoverRating; - int pixSize; - - KRatingPainter ratingPainter; -}; - RatingItem::RatingItem( QQuickItem* parent ) : QQuickPaintedItem( parent ) - , d( new Private() ) + , m_ratingPainter( new KRatingPainter ) { setAcceptedMouseButtons( Qt::LeftButton ); setAcceptHoverEvents( true ); @@ -62,7 +45,7 @@ RatingItem::~RatingItem() { - delete d; + delete m_ratingPainter; } @@ -72,7 +55,7 @@ if( iconName == icon() ) return; - d->ratingPainter.setIcon( QIcon::fromTheme( iconName ) ); + m_ratingPainter->setIcon( QIcon::fromTheme( iconName ) ); emit iconChanged(); update(); @@ -82,24 +65,24 @@ int RatingItem::spacing() const { - return d->ratingPainter.spacing(); + return m_ratingPainter->spacing(); } QString RatingItem::icon() const { - return d->ratingPainter.icon().name(); + return m_ratingPainter->icon().name(); } void RatingItem::setSpacing( int s ) { - if( s == d->ratingPainter.spacing() ) + if( s == m_ratingPainter->spacing() ) return; - d->ratingPainter.setSpacing( s ); + m_ratingPainter->setSpacing( s ); emit spacingChanged(); update(); @@ -109,17 +92,17 @@ Qt::Alignment RatingItem::alignment() const { - return d->ratingPainter.alignment(); + return m_ratingPainter->alignment(); } void RatingItem::setAlignment( Qt::Alignment align ) { - if( align == d->ratingPainter.alignment() ) + if( align == m_ratingPainter->alignment() ) return; - d->ratingPainter.setAlignment( align ); + m_ratingPainter->setAlignment( align ); emit alignmentChanged(); update(); @@ -129,17 +112,17 @@ Qt::LayoutDirection RatingItem::layoutDirection() const { - return d->ratingPainter.layoutDirection(); + return m_ratingPainter->layoutDirection(); } void RatingItem::setLayoutDirection( Qt::LayoutDirection direction ) { - if( direction == d->ratingPainter.layoutDirection() ) + if( direction == m_ratingPainter->layoutDirection() ) return; - d->ratingPainter.setLayoutDirection( direction ); + m_ratingPainter->setLayoutDirection( direction ); emit layoutDirectionChanged(); update(); @@ -149,37 +132,37 @@ unsigned int RatingItem::rating() const { - return d->rating; + return m_rating; } int RatingItem::maxRating() const { - return d->ratingPainter.maxRating(); + return m_ratingPainter->maxRating(); } int RatingItem::hoverRating() const { - return d->hoverRating; + return m_hoverRating; } bool RatingItem::halfStepsEnabled() const { - return d->ratingPainter.halfStepsEnabled(); + return m_ratingPainter->halfStepsEnabled(); } void RatingItem::setRating( int rating ) { - if( rating == d->rating ) + if( rating == m_rating ) return; - d->rating = rating; - d->hoverRating = rating; + m_rating = rating; + m_hoverRating = rating; emit ratingChanged(); emit hoverRatingChanged(); @@ -189,15 +172,15 @@ void RatingItem::setMaxRating( int max ) { - if( max == d->ratingPainter.maxRating() ) + if( max == m_ratingPainter->maxRating() ) return; - bool halfSteps = d->ratingPainter.halfStepsEnabled(); + bool halfSteps = m_ratingPainter->halfStepsEnabled(); - d->ratingPainter.setMaxRating( max ); + m_ratingPainter->setMaxRating( max ); emit maxRatingChanged(); - if( halfSteps != d->ratingPainter.halfStepsEnabled() ) + if( halfSteps != m_ratingPainter->halfStepsEnabled() ) emit halfStepsEnabledChanged(); update(); @@ -207,10 +190,10 @@ void RatingItem::setHalfStepsEnabled( bool enabled ) { - if( enabled == d->ratingPainter.halfStepsEnabled() ) + if( enabled == m_ratingPainter->halfStepsEnabled() ) return; - d->ratingPainter.setHalfStepsEnabled( enabled ); + m_ratingPainter->setHalfStepsEnabled( enabled ); emit halfStepsEnabledChanged(); update(); @@ -224,52 +207,46 @@ if ( e->button() == Qt::LeftButton ) { QRect rect( 0, 0, width(), height() ); - int ratingFromPos = d->ratingPainter.ratingFromPosition( rect, e->pos() ); + int ratingFromPos = m_ratingPainter->ratingFromPosition( rect, e->pos() ); debug() << "Rating item clicked. New rating:" << ratingFromPos; if ( ratingFromPos >= 0 ) - { - // setToolTip( i18n( "Track rating: %1", (float)d->rating / 2 ) ); emit clicked( ratingFromPos ); - } } } - void RatingItem::hoverMoveEvent( QHoverEvent* e ) { QRect rect( 0, 0, width(), height() ); - d->hoverRating = d->ratingPainter.ratingFromPosition( rect, e->pos() ); + m_hoverRating = m_ratingPainter->ratingFromPosition( rect, e->pos() ); update(); } - void RatingItem::hoverEnterEvent( QHoverEvent* e ) { QRect rect( 0, 0, width(), height() ); - d->hoverRating = d->ratingPainter.ratingFromPosition( rect, e->pos() ); - - // setToolTip( i18n( "Track rating: %1", (float)d->rating / 2 ) ); + m_hoverRating = m_ratingPainter->ratingFromPosition( rect, e->pos() ); update(); } void RatingItem::hoverLeaveEvent( QHoverEvent* ) { - d->hoverRating = -1; + m_hoverRating = -1; + update(); } void RatingItem::paint( QPainter* painter ) { - d->ratingPainter.setEnabled( isEnabled() ); + m_ratingPainter->setEnabled( isEnabled() ); QRect rect( 0, 0, width(), height() ); - d->ratingPainter.paint( painter, rect, d->rating, d->hoverRating ); + m_ratingPainter->paint( painter, rect, m_rating, m_hoverRating ); }