diff --git a/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml b/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml index 31a98a980c..b0e82f1bf4 100644 --- a/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml +++ b/src/context/applets/currenttrack/package/contents/ui/StatsItem.qml @@ -1,100 +1,116 @@ /**************************************************************************************** * Copyright (c) 2017 Malte Veerman * * * * This program 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 2 of the License, or (at your option) any later * * version. * * * * This program 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 * * this program. If not, see . * ****************************************************************************************/ 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 } } } SystemPalette { id: palette } } diff --git a/src/context/applets/currenttrack/package/contents/ui/main.qml b/src/context/applets/currenttrack/package/contents/ui/main.qml index 55665136da..bd25c24aaa 100644 --- a/src/context/applets/currenttrack/package/contents/ui/main.qml +++ b/src/context/applets/currenttrack/package/contents/ui/main.qml @@ -1,98 +1,109 @@ /**************************************************************************************** * Copyright (c) 2017 Malte Veerman * * * * This program 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 2 of the License, or (at your option) any later * * version. * * * * This program 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 * * this program. If not, see . * ****************************************************************************************/ 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.qml 1.0 as AmarokQml import org.kde.amarok.currenttrack 1.0 AmarokQml.Applet { 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 leftMargin: applet.spacing right: parent.right top: parent.top bottom: parent.bottom } RowLayout { Layout.fillWidth: true Layout.fillHeight: true Layout.alignment: Qt.AlignTop InfoItem { id: infoItem Layout.fillHeight: true Layout.fillWidth: true Layout.alignment: Qt.AlignLeft } 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 } } StatsItem { id: statsItem 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.cpp b/src/context/applets/currenttrack/plugin/CurrentEngine.cpp index 81cd04f7e7..98906fd78a 100644 --- a/src/context/applets/currenttrack/plugin/CurrentEngine.cpp +++ b/src/context/applets/currenttrack/plugin/CurrentEngine.cpp @@ -1,284 +1,270 @@ /**************************************************************************************** * Copyright (c) 2007 Leo Franchi * * * * This program 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 2 of the License, or (at your option) any later * * version. * * * * This program 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 * * this program. If not, see . * ****************************************************************************************/ #define DEBUG_PREFIX "CurrentEngine" #include "CurrentEngine.h" #include "EngineController.h" #include "core/support/Debug.h" #include "core/capabilities/SourceInfoCapability.h" #include "core/collections/Collection.h" #include "core/collections/QueryMaker.h" #include "core/meta/support/MetaUtility.h" #include "core/meta/Statistics.h" #include "core/support/Amarok.h" #include "core-impl/collections/support/CollectionManager.h" #include "covermanager/CoverCache.h" #include #include #include CurrentEngine::CurrentEngine( QObject* parent ) : QObject( parent ) - , m_coverWidth( 0 ) , m_lastQueryMaker( Q_NULLPTR ) { EngineController* engine = The::engineController(); // Connect queued to reduce interface stuttering. connect( engine, &EngineController::trackPlaying, this, &CurrentEngine::slotTrackChanged, Qt::QueuedConnection ); connect( engine, &EngineController::stopped, this, &CurrentEngine::stopped, Qt::QueuedConnection ); connect( engine, &EngineController::trackMetadataChanged, this, &CurrentEngine::slotTrackMetadataChanged, Qt::QueuedConnection ); connect( engine, &EngineController::albumMetadataChanged, this, &CurrentEngine::slotAlbumMetadataChanged, Qt::QueuedConnection ); } CurrentEngine::~CurrentEngine() { } void CurrentEngine::slotAlbumMetadataChanged( Meta::AlbumPtr album ) { DEBUG_BLOCK // disregard changes for other albums (BR: 306735) if( !m_currentTrack || m_currentTrack->album() != album ) return; QPixmap cover; if( album ) - cover = The::coverCache()->getCover( album, m_coverWidth ); + cover = The::coverCache()->getCover( album, 1 ); if( m_cover.cacheKey() != cover.cacheKey() ) { m_cover = cover; emit albumChanged(); } } void CurrentEngine::slotTrackMetadataChanged( Meta::TrackPtr track ) { if( !track ) return; update( track->album() ); emit trackChanged(); } void CurrentEngine::slotTrackChanged(Meta::TrackPtr track) { DEBUG_BLOCK if( !track || track == m_currentTrack ) return; m_currentTrack = track; slotTrackMetadataChanged( track ); } void CurrentEngine::stopped() { m_currentTrack.clear(); emit trackChanged(); m_cover = QPixmap(); // Collect data for the recently added albums m_albums.clear(); emit albumChanged(); Collections::QueryMaker *qm = CollectionManager::instance()->queryMaker(); qm->setAutoDelete( true ); qm->setQueryType( Collections::QueryMaker::Album ); qm->excludeFilter( Meta::valAlbum, QString(), true, true ); qm->orderBy( Meta::valCreateDate, true ); qm->limitMaxResultSize( Amarok::config("Albums Applet").readEntry("RecentlyAdded", 5) ); connect( qm, &Collections::QueryMaker::newAlbumsReady, this, &CurrentEngine::resultReady, Qt::QueuedConnection ); m_lastQueryMaker = qm; qm->run(); } void CurrentEngine::update( Meta::AlbumPtr album ) { m_lastQueryMaker = Q_NULLPTR; if( !album ) return; slotAlbumMetadataChanged( album ); Meta::TrackPtr track = The::engineController()->currentTrack(); if( !track ) return; Meta::ArtistPtr artist = track->artist(); // Prefer track artist to album artist BUG: 266682 if( !artist ) artist = album->albumArtist(); if( artist && !artist->name().isEmpty() ) { m_albums.clear(); // -- search the collection for albums with the same artist Collections::QueryMaker *qm = CollectionManager::instance()->queryMaker(); qm->setAutoDelete( true ); qm->addFilter( Meta::valArtist, artist->name(), true, true ); qm->setAlbumQueryMode( Collections::QueryMaker::AllAlbums ); qm->setQueryType( Collections::QueryMaker::Album ); connect( qm, &Collections::QueryMaker::newAlbumsReady, this, &CurrentEngine::resultReady, Qt::QueuedConnection ); m_lastQueryMaker = qm; qm->run(); } } void CurrentEngine::resultReady( const Meta::AlbumList &albums ) { if( sender() == m_lastQueryMaker ) m_albums << albums; } QString CurrentEngine::artist() const { if( !m_currentTrack ) return QString(); return m_currentTrack->artist()->prettyName(); } QString CurrentEngine::track() const { if( !m_currentTrack ) return QString(); return m_currentTrack->prettyName(); } QString CurrentEngine::album() const { if( !m_currentTrack ) return QString(); return m_currentTrack->album()->prettyName(); } int CurrentEngine::rating() const { if( !m_currentTrack ) return 0; return m_currentTrack->statistics()->rating(); } void CurrentEngine::setRating(int rating) { DEBUG_BLOCK debug() << "New rating:" << rating; if( !m_currentTrack ) return; if( rating == m_currentTrack->statistics()->rating() ) return; m_currentTrack->statistics()->setRating( rating ); emit trackChanged(); } int CurrentEngine::score() const { if( !m_currentTrack ) return 0; return m_currentTrack->statistics()->score(); } int CurrentEngine::length() const { if( !m_currentTrack ) return 0; return m_currentTrack->length(); } QString CurrentEngine::lastPlayed() const { if( !m_currentTrack ) return QString(); auto lastPlayed = m_currentTrack->statistics()->lastPlayed(); QString lastPlayedString; if( lastPlayed.isValid() ) lastPlayedString = KFormat().formatRelativeDateTime( lastPlayed, QLocale::ShortFormat ); else lastPlayedString = i18n( "Never" ); return lastPlayedString; } int CurrentEngine::timesPlayed() const { if( !m_currentTrack ) return 0; 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/applets/currenttrack/plugin/CurrentEngine.h b/src/context/applets/currenttrack/plugin/CurrentEngine.h index 9a9420bfb2..69d05253de 100644 --- a/src/context/applets/currenttrack/plugin/CurrentEngine.h +++ b/src/context/applets/currenttrack/plugin/CurrentEngine.h @@ -1,92 +1,90 @@ /**************************************************************************************** * Copyright (c) 2007 Leo Franchi * * * * This program 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 2 of the License, or (at your option) any later * * version. * * * * This program 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 * * this program. If not, see . * ****************************************************************************************/ #ifndef AMAROK_CURRENT_ENGINE #define AMAROK_CURRENT_ENGINE #include "core/meta/Meta.h" #include #include #include namespace Collections { class QueryMaker; } class CurrentEngine : public QObject { Q_OBJECT Q_PROPERTY(QString artist READ artist NOTIFY trackChanged) Q_PROPERTY(QString track READ track NOTIFY trackChanged) Q_PROPERTY(QString album READ album NOTIFY trackChanged) Q_PROPERTY(int rating READ rating WRITE setRating NOTIFY trackChanged) Q_PROPERTY(int score READ score NOTIFY trackChanged) Q_PROPERTY(int length READ length NOTIFY trackChanged) 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 ); virtual ~CurrentEngine(); QString artist() const; QString track() const; QString album() const; int rating() const; void setRating( int rating ); int score() const; int length() const; 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(); void albumChanged(); void coverWidthChanged(); private Q_SLOTS: void slotAlbumMetadataChanged( Meta::AlbumPtr album ); void slotTrackMetadataChanged( Meta::TrackPtr track ); void slotTrackChanged( Meta::TrackPtr track ); void stopped(); private: void update( Meta::TrackPtr track ); void update( Meta::AlbumPtr album ); - int m_coverWidth; QPixmap m_cover; Meta::AlbumList m_albums; Meta::TrackPtr m_currentTrack; /** The address of the query maker used for the albums query. This is only used to check if the query results are from the latest started query maker. */ Collections::QueryMaker *m_lastQueryMaker; private Q_SLOTS: void resultReady( const Meta::AlbumList &albums ); }; #endif diff --git a/src/context/qml_plugin/src/RatingItem.cpp b/src/context/qml_plugin/src/RatingItem.cpp index 68073b541d..ffbe52510c 100644 --- a/src/context/qml_plugin/src/RatingItem.cpp +++ b/src/context/qml_plugin/src/RatingItem.cpp @@ -1,275 +1,252 @@ /**************************************************************************************** * Copyright (c) 2008 William Viana Soarjs * * Copyright (c) 2010 Mark Kretschmann * * * * This program 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 2 of the License, or (at your option) any later * * version. * * * * This program 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 * * this program. If not, see . * ****************************************************************************************/ /* Significant parts of this code is inspired and/or copied from KDE Nepomuk sources, available at kdelibs/nepomuk */ #include "RatingItem.h" #include "core/support/Debug.h" #include #include #include #include #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 ); connect( qApp, &QGuiApplication::paletteChanged, this, &QQuickItem::update ); } RatingItem::~RatingItem() { - delete d; + delete m_ratingPainter; } void RatingItem::setIcon( const QString& iconName ) { if( iconName == icon() ) return; - d->ratingPainter.setIcon( QIcon::fromTheme( iconName ) ); + m_ratingPainter->setIcon( QIcon::fromTheme( iconName ) ); emit iconChanged(); update(); } 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(); } 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(); } 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(); } 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(); update(); } 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(); } 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(); } void RatingItem::mousePressEvent( QMouseEvent* e ) { DEBUG_BLOCK 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 ); } diff --git a/src/context/qml_plugin/src/RatingItem.h b/src/context/qml_plugin/src/RatingItem.h index ad3a5e941c..300620a2f8 100644 --- a/src/context/qml_plugin/src/RatingItem.h +++ b/src/context/qml_plugin/src/RatingItem.h @@ -1,158 +1,163 @@ /**************************************************************************************** * Copyright (c) 2008 William Viana Soares * * Copyright (c) 2010 Mark Kretschmann * * * * This program 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 2 of the License, or (at your option) any later * * version. * * * * This program 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 * * this program. If not, see . * ****************************************************************************************/ #ifndef AMAROK_RATING_ITEM_H #define AMAROK_RATING_ITEM_H #include + +class KRatingPainter; + class RatingItem : public QQuickPaintedItem { Q_OBJECT Q_PROPERTY( int rating READ rating WRITE setRating NOTIFY ratingChanged ) Q_PROPERTY( int hoverRating READ hoverRating NOTIFY hoverRatingChanged ) Q_PROPERTY( int maxRating READ maxRating WRITE setMaxRating NOTIFY maxRatingChanged ) Q_PROPERTY( int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged ) Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged ) Q_PROPERTY( Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged ) Q_PROPERTY( bool halfStepsEnabled READ halfStepsEnabled WRITE setHalfStepsEnabled NOTIFY halfStepsEnabledChanged ) Q_PROPERTY( QString icon READ icon WRITE setIcon NOTIFY iconChanged ) public: /** * Creates a new rating widget. */ explicit RatingItem( QQuickItem* parent = Q_NULLPTR ); /** * Destructor */ ~RatingItem(); /** * @return The current rating. */ unsigned int rating() const; /** * @return the maximum possible rating. */ int maxRating() const; /** * @return the rating that corresponds to the cursor position while hovering. * Returns -1 if the cursor is outside of the item. */ int hoverRating() const; /** * The alignment of the stars. */ Qt::Alignment alignment() const; /** * The layout direction. If RTL the stars * representing the rating value will be drawn from the * right. */ Qt::LayoutDirection layoutDirection() const; /** * The spacing between the rating stars. */ int spacing() const; /** * If half steps are enabled one star equals to 2 rating * points and uneven rating values result in half-stars being * drawn. */ bool halfStepsEnabled() const; /** * The icon name used to draw a star. */ QString icon() const; Q_SIGNALS: void ratingChanged(); void hoverRatingChanged(); void maxRatingChanged(); void spacingChanged(); void layoutDirectionChanged(); void alignmentChanged(); void halfStepsEnabledChanged(); void iconChanged(); void clicked( int newRating ); public Q_SLOTS: /** * Set the current rating. */ void setRating( int rating ); /** * Set the maximum allowed rating value. The default is 10 which means * that a rating from 1 to 10 is selectable. If \a max is uneven steps * are automatically only allowed full. */ void setMaxRating( int max ); /** * If half steps are enabled (the default) then * one rating step corresponds to half a star. */ void setHalfStepsEnabled( bool enabled ); /** * Set the spacing between the pixmaps. The default is 0. */ void setSpacing( int ); /** * The alignment of the stars in the drawing rect. * All alignment flags are supported. */ void setAlignment( Qt::Alignment align ); /** * LTR or RTL */ void setLayoutDirection( Qt::LayoutDirection direction ); /** * Set a custom icon. Defaults to "rating". */ void setIcon( const QString& iconName ); protected: virtual void mousePressEvent( QMouseEvent* e ) override; virtual void hoverMoveEvent( QHoverEvent* e ) override; virtual void hoverEnterEvent( QHoverEvent* e ) override; virtual void hoverLeaveEvent( QHoverEvent* e ) override; virtual void paint( QPainter* painter ) override; private: - class Private; - Private* const d; + int m_rating; + int m_hoverRating; + + KRatingPainter *m_ratingPainter; }; #endif