]> git.sur5r.net Git - minitube/commitdiff
Play icon overlay
authorFlavio Tordini <flavio.tordini@gmail.com>
Fri, 14 Aug 2009 17:16:02 +0000 (19:16 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Fri, 14 Aug 2009 17:16:02 +0000 (19:16 +0200)
src/playlist/PrettyItemDelegate.cpp
src/playlist/PrettyItemDelegate.h

index efc9e0cbe64988e9e7d35045eb1098ca61784489..d70dfd5a76023938be0eed22486339f82dbe37e1 100644 (file)
@@ -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);
index 941f3978c530e45a159aa691c6f8ed3a216ce4aa..723dcaa4809a7e0106109a3da92a55270634956a 100644 (file)
@@ -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
-