From 0a87348723006b9ded168bdc51fd0e5119178813 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Fri, 14 Aug 2009 19:16:02 +0200 Subject: [PATCH] Play icon overlay --- src/playlist/PrettyItemDelegate.cpp | 41 ++++++++++++++++++++++++----- src/playlist/PrettyItemDelegate.h | 21 +++++---------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/playlist/PrettyItemDelegate.cpp b/src/playlist/PrettyItemDelegate.cpp index efc9e0c..d70dfd5 100644 --- a/src/playlist/PrettyItemDelegate.cpp +++ b/src/playlist/PrettyItemDelegate.cpp @@ -6,13 +6,31 @@ const qreal PrettyItemDelegate::THUMB_HEIGHT = 90.0; const qreal PrettyItemDelegate::THUMB_WIDTH = 120.0; -const qreal PrettyItemDelegate::MARGIN = 0.0; -const qreal PrettyItemDelegate::MARGINH = 0.0; -const qreal PrettyItemDelegate::MARGINBODY = 0.0; const qreal PrettyItemDelegate::PADDING = 10.0; PrettyItemDelegate::PrettyItemDelegate( QObject* parent ) : QStyledItemDelegate( parent ) { + createPlayIcon(); +} +void PrettyItemDelegate::createPlayIcon() { + playIcon = QPixmap(THUMB_WIDTH, THUMB_HEIGHT); + playIcon.fill(Qt::transparent); + QPainter painter(&playIcon); + QPolygon polygon; + polygon << QPoint(PADDING*4, PADDING*2) + << QPoint(THUMB_WIDTH-PADDING*4, THUMB_HEIGHT/2) + << QPoint(PADDING*4, THUMB_HEIGHT-PADDING*2); + painter.setRenderHints(QPainter::Antialiasing, true); + painter.setBrush(Qt::white); + QPen pen; + pen.setColor(Qt::white); + pen.setWidth(10); + pen.setJoinStyle(Qt::RoundJoin); + pen.setCapStyle(Qt::RoundCap); + painter.setPen(pen); + painter.setOpacity(1); + painter.drawPolygon(polygon); + painter.end(); } PrettyItemDelegate::~PrettyItemDelegate() { } @@ -67,6 +85,10 @@ void PrettyItemDelegate::paintBody( QPainter* painter, // thumb painter->drawImage(QRect(0, 0, THUMB_WIDTH, THUMB_HEIGHT), video->thumbnail()); + // play icon overlayed on the thumb + if (isActive) + paintPlayIcon(painter); + // time QString timeString; int duration = video->duration(); @@ -163,11 +185,11 @@ QPointF PrettyItemDelegate::centerImage( const QPixmap& pixmap, const QRectF& re void PrettyItemDelegate::paintActiveOverlay( QPainter *painter, qreal x, qreal y, qreal w, qreal h ) const { QPalette palette; - QColor color2 = palette.color( QPalette::Highlight); - QColor backgroundColor = palette.color( QPalette::Base); + QColor color2 = palette.color(QPalette::Highlight); + QColor backgroundColor = palette.color(QPalette::Base); float animation = 0.5; color2 = QColor::fromHsv( - animation == 0.0 ? backgroundColor.hue() : color2.hue(), + color2.hue(), (int)(backgroundColor.saturation()*(1.0f-animation)+color2.saturation()*animation), (int)(backgroundColor.value()*(1.0f-animation)+color2.value()*animation) ); @@ -187,6 +209,13 @@ void PrettyItemDelegate::paintActiveOverlay( QPainter *painter, qreal x, qreal y painter->restore(); } +void PrettyItemDelegate::paintPlayIcon(QPainter *painter) const { + painter->save(); + painter->setOpacity(.5); + painter->drawPixmap(playIcon.rect(), playIcon); + painter->restore(); +} + void PrettyItemDelegate::drawTime(QPainter *painter, QString time, QRectF line) const { static const int timePadding = 4; QRectF textBox = painter->boundingRect(line, Qt::AlignLeft | Qt::AlignTop, time); diff --git a/src/playlist/PrettyItemDelegate.h b/src/playlist/PrettyItemDelegate.h index 941f397..723dcaa 100644 --- a/src/playlist/PrettyItemDelegate.h +++ b/src/playlist/PrettyItemDelegate.h @@ -6,9 +6,6 @@ class QPainter; - - - class PrettyItemDelegate : public QStyledItemDelegate { Q_OBJECT @@ -21,28 +18,22 @@ public: void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const; private: + void createPlayIcon(); void paintBody( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const; - QPointF centerImage( const QPixmap&, const QRectF& ) const; - /** - * Paints a marker indicating the track is active - */ + // active track painting void paintActiveOverlay( QPainter *painter, qreal x, qreal y, qreal w, qreal h ) const; - /** - * Paints the video duration - */ + void paintPlayIcon(QPainter *painter) const; + + // Paints the video duration void drawTime(QPainter *painter, QString time, QRectF line) const; static const qreal THUMB_WIDTH; static const qreal THUMB_HEIGHT; - static const qreal MARGIN; - static const qreal MARGINH; - static const qreal MARGINBODY; static const qreal PADDING; + QPixmap playIcon; }; - #endif - -- 2.39.5