From: Flavio Tordini Date: Sun, 2 Aug 2015 19:55:21 +0000 (+0200) Subject: Simpler active overlay X-Git-Tag: 2.5~63 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=29125c101dbe4bc9d61a2a19e80a5b571f20d11c;p=minitube Simpler active overlay --- diff --git a/src/playlistitemdelegate.cpp b/src/playlistitemdelegate.cpp index d29d973..7639a50 100644 --- a/src/playlistitemdelegate.cpp +++ b/src/playlistitemdelegate.cpp @@ -25,6 +25,7 @@ $END_LICENSE */ #include "iconutils.h" #include "videodefinition.h" #include "video.h" +#include "datautils.h" const int PlaylistItemDelegate::THUMB_HEIGHT = 90; const int PlaylistItemDelegate::THUMB_WIDTH = 160; @@ -115,13 +116,19 @@ void PlaylistItemDelegate::paintBody( QPainter* painter, const bool isActive = index.data( ActiveTrackRole ).toBool(); const bool isSelected = option.state & QStyle::State_Selected; + // get the video metadata + const Video *video = index.data(VideoRole).value().data(); + // draw the "current track" highlight underneath the text if (isActive && !isSelected) - paintActiveOverlay(painter, line); + paintActiveOverlay(painter, option, line); - // get the video metadata - const VideoPointer videoPointer = index.data( VideoRole ).value(); - const Video *video = videoPointer.data(); + // separator + painter->setPen(option.palette.color(QPalette::Midlight)); + painter->drawLine(THUMB_WIDTH, THUMB_HEIGHT, option.rect.width(), THUMB_HEIGHT); + if (!video->thumbnail().isNull()) + painter->setPen(Qt::black); + painter->drawLine(0, THUMB_HEIGHT, THUMB_WIDTH-1, THUMB_HEIGHT); // thumb painter->drawPixmap(0, 0, video->thumbnail()); @@ -134,13 +141,6 @@ void PlaylistItemDelegate::paintBody( QPainter* painter, if (video->duration() > 0) drawTime(painter, video->formattedDuration(), line); - // separator - painter->setPen(option.palette.color(QPalette::Midlight)); - painter->drawLine(THUMB_WIDTH, THUMB_HEIGHT, option.rect.width(), THUMB_HEIGHT); - if (!video->thumbnail().isNull()) - painter->setPen(Qt::black); - painter->drawLine(0, THUMB_HEIGHT, THUMB_WIDTH-1, THUMB_HEIGHT); - if (line.width() > THUMB_WIDTH + 60) { // if (isActive) painter->setFont(boldFont); @@ -168,7 +168,7 @@ void PlaylistItemDelegate::paintBody( QPainter* painter, painter->setFont(smallerFont); // published date - QString publishedString = video->published().date().toString(Qt::DefaultLocaleShortDate); + QString publishedString = DataUtils::formatDateTime(video->published()); QSize stringSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, publishedString ) ); QPoint textLoc(PADDING+THUMB_WIDTH, PADDING*2 + textBox.height()); QRect publishedTextBox(textLoc , stringSize); @@ -193,7 +193,7 @@ void PlaylistItemDelegate::paintBody( QPainter* painter, else painter->setOpacity(.5); } - QString authorString = video->channelTitle(); + const QString &authorString = video->channelTitle(); textLoc.setX(textLoc.x() + stringSize.width() + PADDING); stringSize = QSize(QFontMetrics(painter->font()).size( Qt::TextSingleLine, authorString ) ); QRect authorTextBox(textLoc , stringSize); @@ -254,35 +254,11 @@ void PlaylistItemDelegate::paintBody( QPainter* painter, } -void PlaylistItemDelegate::paintActiveOverlay(QPainter *painter, const QRect &line) const { - static QLinearGradient linearGradient; - static bool initialized = false; - - if (!initialized) { - QPalette palette; - QColor highlightColor = palette.color(QPalette::Highlight); - QColor backgroundColor = palette.color(QPalette::Base); - const float animation = 0.4; - const int gradientRange = 16; - - QColor color2 = QColor::fromHsv( - highlightColor.hue(), - (int) (backgroundColor.saturation() * (1.0f - animation) + highlightColor.saturation() * animation), - (int) (backgroundColor.value() * (1.0f - animation) + highlightColor.value() * animation) - ); - QColor color1 = QColor::fromHsv( - color2.hue(), - qMax(color2.saturation() - gradientRange, 0), - qMin(color2.value() + gradientRange, 255) - ); - - linearGradient = QLinearGradient(0, 0, 0, THUMB_HEIGHT); - linearGradient.setColorAt(0.0, color1); - linearGradient.setColorAt(1.0, color2); - initialized = true; - } - - painter->fillRect(line, linearGradient); +void PlaylistItemDelegate::paintActiveOverlay(QPainter *painter, const QStyleOptionViewItem& option, const QRect &line) const { + painter->save(); + painter->setOpacity(.1); + painter->fillRect(line, option.palette.highlight()); + painter->restore(); } void PlaylistItemDelegate::drawTime(QPainter *painter, const QString &time, const QRect &line) const { diff --git a/src/playlistitemdelegate.h b/src/playlistitemdelegate.h index 0bbd77f..b2f693b 100644 --- a/src/playlistitemdelegate.h +++ b/src/playlistitemdelegate.h @@ -45,11 +45,7 @@ private: void paintDownloadInfo( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - - // active track painting - void paintActiveOverlay(QPainter *painter, const QRect &line) const; - - // Paints the video duration + void paintActiveOverlay(QPainter *painter, const QStyleOptionViewItem& option, const QRect &line) const; void drawTime(QPainter *painter, const QString &time, const QRect &line) const; static const int THUMB_WIDTH;