#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) {
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 );
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();
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();
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);
16,
16);
}
+
+QRect PrettyItemDelegate::authorRect(const QModelIndex& index) const {
+ return authorRects.value(index.row());
+}