]> git.sur5r.net Git - minitube/blobdiff - src/playlist/PrettyItemDelegate.cpp
Imported Upstream version 1.7
[minitube] / src / playlist / PrettyItemDelegate.cpp
index 3454572e11fbb92640e9e58e776c3bda41133f55..6cdac51014805cdb6efc823740a9419996ee9f28 100644 (file)
@@ -6,11 +6,15 @@
 
 #include <QFontMetricsF>
 #include <QPainter>
+#include <QHash>
 
 const qreal PrettyItemDelegate::THUMB_HEIGHT = 90.0;
 const qreal PrettyItemDelegate::THUMB_WIDTH = 120.0;
 const qreal PrettyItemDelegate::PADDING = 10.0;
 
+QRect lastAuthorRect;
+QHash<int, QRect> authorRects;
+
 PrettyItemDelegate::PrettyItemDelegate(QObject* parent, bool downloadInfo)
     : QStyledItemDelegate(parent),
     downloadInfo(downloadInfo) {
@@ -58,8 +62,11 @@ void PrettyItemDelegate::paint( QPainter* painter,
 
     int itemType = index.data(ItemTypeRole).toInt();
     if (itemType == ItemTypeVideo) {
-        QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter );
-        paintBody( painter, option, index );
+        QStyleOptionViewItemV4 opt = QStyleOptionViewItemV4(option);
+        initStyleOption(&opt, index);
+        opt.text = "";
+        opt.widget->style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
+        paintBody(painter, opt, index);
     } else
         QStyledItemDelegate::paint( painter, option, index );
 
@@ -85,12 +92,6 @@ void PrettyItemDelegate::paintBody( QPainter* painter,
         paintActiveOverlay(painter, line.x(), line.y(), line.width(), line.height());
     }
 
-#if defined(APP_MAC) | defined(APP_WIN)
-    if (isSelected) {
-        paintSelectedOverlay(painter, line.x(), line.y(), line.width(), line.height());
-    }
-#endif
-
     // get the video metadata
     const VideoPointer videoPointer = index.data( VideoRole ).value<VideoPointer>();
     const Video *video = videoPointer.data();
@@ -138,14 +139,27 @@ void PrettyItemDelegate::paintBody( QPainter* painter,
     painter->drawText(publishedTextBox, Qt::AlignLeft | Qt::AlignTop, publishedString);
 
     // author
+    bool authorHovered = false;
+    bool authorPressed = false;
+    const bool isHovered = index.data(HoveredItemRole).toBool();
+    if (isHovered) {
+        authorHovered = index.data(AuthorHoveredRole).toBool();
+        authorPressed = index.data(AuthorPressedRole).toBool();
+    }
+
     painter->save();
     painter->setFont(smallerBoldFont);
-    if (!isSelected && !isActive)
-        painter->setPen(QPen(option.palette.brush(QPalette::Mid), 0));
+    if (!isSelected) {
+        if (authorHovered)
+            painter->setPen(QPen(option.palette.brush(QPalette::Highlight), 0));
+        else
+            painter->setPen(QPen(option.palette.brush(QPalette::Mid), 0));
+    }
     QString authorString = video->author();
     QSizeF authorStringSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, authorString ) );
     textLoc.setX(textLoc.x() + publishedStringSize.width() + PADDING);
     QRectF authorTextBox( textLoc , authorStringSize);
+    authorRects.insert(index.row(), authorTextBox.toRect());
     painter->drawText(authorTextBox, Qt::AlignLeft | Qt::AlignTop, authorString);
     painter->restore();
 
@@ -217,20 +231,6 @@ void PrettyItemDelegate::paintActiveOverlay( QPainter *painter, qreal x, qreal y
     painter->restore();
 }
 
-void PrettyItemDelegate::paintSelectedOverlay( QPainter *painter, qreal x, qreal y, qreal w, qreal h ) const {
-    QColor color1 = QColor::fromRgb(0x69, 0xa6, 0xd9);
-    QColor color2 = QColor::fromRgb(0x14, 0x6b, 0xd4);
-    QRect rect((int) x, (int) y, (int) w, (int) h);
-    painter->save();
-    painter->setPen(Qt::NoPen);
-    QLinearGradient linearGradient(0, 0, 0, rect.height());
-    linearGradient.setColorAt(0.0, color1);
-    linearGradient.setColorAt(1.0, color2);
-    painter->setBrush(linearGradient);
-    painter->drawRect(rect);
-    painter->restore();
-}
-
 void PrettyItemDelegate::paintPlayIcon(QPainter *painter) const {
     painter->save();
     painter->setOpacity(.5);
@@ -375,3 +375,7 @@ QRect PrettyItemDelegate::downloadButtonRect(QRect line) const {
             16,
             16);
 }
+
+QRect PrettyItemDelegate::authorRect(const QModelIndex& index) const {
+    return authorRects.value(index.row());
+}