mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Switch to stars, and show on-hover star animation when rating
This commit is contained in:
BIN
data/images/star-hover.png
Normal file
BIN
data/images/star-hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
data/images/star-unstarred.png
Normal file
BIN
data/images/star-unstarred.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
data/images/starred.png
Normal file
BIN
data/images/starred.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#define PADDING 4
|
#define PADDING 4
|
||||||
#define PADDING_BETWEEN_STARS 2
|
#define PADDING_BETWEEN_STARS 2
|
||||||
|
#define STAR_SIZE 12
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
#define SIZEHINT_HEIGHT 70
|
#define SIZEHINT_HEIGHT 70
|
||||||
@@ -41,11 +42,14 @@ GetNewStuffDelegate::GetNewStuffDelegate( QObject* parent )
|
|||||||
, m_widestTextWidth( 0 )
|
, m_widestTextWidth( 0 )
|
||||||
{
|
{
|
||||||
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
|
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
|
||||||
m_ratingStarPositive.load( RESPATH "images/loved.png" );
|
m_ratingStarPositive.load( RESPATH "images/starred.png" );
|
||||||
m_ratingStarNegative.load( RESPATH "images/not-loved.png" );
|
m_ratingStarNegative.load( RESPATH "images/star-unstarred.png" );
|
||||||
|
m_onHoverStar.load( RESPATH "images/star-hover.png" );
|
||||||
|
|
||||||
|
m_ratingStarPositive = m_ratingStarPositive.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
m_ratingStarNegative = m_ratingStarNegative.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
m_onHoverStar = m_onHoverStar.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
|
||||||
m_ratingStarPositive = m_ratingStarPositive.scaled( 8, 8, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
|
||||||
m_ratingStarNegative = m_ratingStarNegative.scaled( 8, 8, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
|
||||||
const int w = SIZEHINT_HEIGHT - 2*PADDING;
|
const int w = SIZEHINT_HEIGHT - 2*PADDING;
|
||||||
m_defaultCover = m_defaultCover.scaled( w, w, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
m_defaultCover = m_defaultCover.scaled( w, w, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
|
||||||
@@ -175,6 +179,7 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio
|
|||||||
painter->drawText( btnRect, Qt::AlignCenter, actionText );
|
painter->drawText( btnRect, Qt::AlignCenter, actionText );
|
||||||
|
|
||||||
painter->setPen( saved );
|
painter->setPen( saved );
|
||||||
|
|
||||||
// rating stars
|
// rating stars
|
||||||
int rating = index.data( GetNewStuffModel::RatingRole ).toInt();
|
int rating = index.data( GetNewStuffModel::RatingRole ).toInt();
|
||||||
const int ratingWidth = 5 * ( m_ratingStarPositive.width() + PADDING_BETWEEN_STARS );
|
const int ratingWidth = 5 * ( m_ratingStarPositive.width() + PADDING_BETWEEN_STARS );
|
||||||
@@ -185,10 +190,21 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio
|
|||||||
if ( i == 1 )
|
if ( i == 1 )
|
||||||
m_cachedStarRects[ QPair<int, int>(index.row(), index.column()) ] = r;
|
m_cachedStarRects[ QPair<int, int>(index.row(), index.column()) ] = r;
|
||||||
|
|
||||||
|
QPixmap pm;
|
||||||
|
if ( m_hoveringOver > -1 )
|
||||||
|
{
|
||||||
|
if ( i <= m_hoveringOver ) // positive star
|
||||||
|
painter->drawPixmap( r, m_onHoverStar );
|
||||||
|
else
|
||||||
|
painter->drawPixmap( r, m_ratingStarNegative );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if ( i <= rating ) // positive star
|
if ( i <= rating ) // positive star
|
||||||
painter->drawPixmap( r, m_ratingStarPositive );
|
painter->drawPixmap( r, m_ratingStarPositive );
|
||||||
else
|
else
|
||||||
painter->drawPixmap( r, m_ratingStarNegative );
|
painter->drawPixmap( r, m_ratingStarNegative );
|
||||||
|
}
|
||||||
runningEdge += m_ratingStarPositive.width() + PADDING_BETWEEN_STARS;
|
runningEdge += m_ratingStarPositive.width() + PADDING_BETWEEN_STARS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,10 +258,13 @@ bool
|
|||||||
GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
||||||
{
|
{
|
||||||
Q_UNUSED( option );
|
Q_UNUSED( option );
|
||||||
if ( event->type() != QEvent::MouseButtonRelease )
|
m_hoveringOver = -1;
|
||||||
|
|
||||||
|
if ( event->type() != QEvent::MouseButtonRelease &&
|
||||||
|
event->type() != QEvent::MouseMove )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( m_cachedButtonRects.contains( QPair<int, int>( index.row(), index.column() ) ) )
|
if ( event->type() == QEvent::MouseButtonRelease && m_cachedButtonRects.contains( QPair<int, int>( index.row(), index.column() ) ) )
|
||||||
{
|
{
|
||||||
QRect rect = m_cachedButtonRects[ QPair<int, int>( index.row(), index.column() ) ];
|
QRect rect = m_cachedButtonRects[ QPair<int, int>( index.row(), index.column() ) ];
|
||||||
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
||||||
@@ -273,8 +292,17 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons
|
|||||||
const int eachStar = starsWidth / 5;
|
const int eachStar = starsWidth / 5;
|
||||||
const int clickOffset = me->pos().x() - fullStars.x();
|
const int clickOffset = me->pos().x() - fullStars.x();
|
||||||
const int whichStar = (clickOffset / eachStar) + 1;
|
const int whichStar = (clickOffset / eachStar) + 1;
|
||||||
|
|
||||||
|
if ( event->type() == QEvent::MouseButtonRelease )
|
||||||
|
{
|
||||||
tDebug() << "Clicked on:" << whichStar;
|
tDebug() << "Clicked on:" << whichStar;
|
||||||
model->setData( index, whichStar, GetNewStuffModel::RatingRole );
|
model->setData( index, whichStar, GetNewStuffModel::RatingRole );
|
||||||
|
}
|
||||||
|
else if ( event->type() == QEvent::MouseMove )
|
||||||
|
{
|
||||||
|
// 0-indexed
|
||||||
|
m_hoveringOver = whichStar;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -35,11 +35,10 @@ protected:
|
|||||||
virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap m_defaultCover;
|
QPixmap m_defaultCover, m_onHoverStar, m_ratingStarPositive, m_ratingStarNegative;
|
||||||
QPixmap m_ratingStarPositive;
|
|
||||||
QPixmap m_ratingStarNegative;
|
|
||||||
|
|
||||||
int m_widestTextWidth;
|
int m_widestTextWidth;
|
||||||
|
int m_hoveringOver;
|
||||||
mutable QHash< QPair<int, int>, QRect > m_cachedButtonRects;
|
mutable QHash< QPair<int, int>, QRect > m_cachedButtonRects;
|
||||||
mutable QHash< QPair<int, int>, QRect > m_cachedStarRects;
|
mutable QHash< QPair<int, int>, QRect > m_cachedStarRects;
|
||||||
};
|
};
|
||||||
|
@@ -33,6 +33,8 @@ GetNewStuffDialog::GetNewStuffDialog( QWidget *parent, Qt::WindowFlags f )
|
|||||||
ui->listView->setItemDelegate( new GetNewStuffDelegate( ui->listView ) );
|
ui->listView->setItemDelegate( new GetNewStuffDelegate( ui->listView ) );
|
||||||
ui->listView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
ui->listView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
||||||
|
|
||||||
|
ui->listView->setMouseTracking( true );
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
setMinimumSize( 510, 350 );
|
setMinimumSize( 510, 350 );
|
||||||
setMaximumSize( 510, 350 );
|
setMaximumSize( 510, 350 );
|
||||||
|
Reference in New Issue
Block a user