painter->drawText(textBox, 0, elidedText);
return elidedText.length() < text.length();
}
-}
+} // namespace
PlaylistItemDelegate::PlaylistItemDelegate(QObject *parent, bool downloadInfo)
- : QStyledItemDelegate(parent), downloadInfo(downloadInfo), progressBar(0) {
+ : QStyledItemDelegate(parent), downloadInfo(downloadInfo), progressBar(nullptr) {
listView = qobject_cast<PlaylistView *>(parent);
smallerBoldFont = FontUtils::smallBold();
}
void PlaylistItemDelegate::createPlayIcon() {
- qreal maxRatio = IconUtils::maxSupportedPixelRatio();
+ qreal maxRatio = 2.0;
playIcon = QPixmap(thumbWidth * maxRatio, thumbHeight * maxRatio);
playIcon.setDevicePixelRatio(maxRatio);
playIcon.fill(Qt::transparent);
QSize PlaylistItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/,
const QModelIndex & /*index*/) const {
- return QSize(thumbWidth, thumbHeight + 1);
+ return QSize(thumbWidth, thumbHeight);
}
void PlaylistItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const {
int itemType = index.data(ItemTypeRole).toInt();
- if (itemType == ItemTypeVideo) {
- QStyleOptionViewItem opt = QStyleOptionViewItem(option);
- initStyleOption(&opt, index);
- opt.text.clear();
- opt.widget->style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
- paintBody(painter, opt, index);
- } else
+ if (itemType == ItemTypeVideo)
+ paintBody(painter, option, index);
+ else
QStyledItemDelegate::paint(painter, option, index);
}
void PlaylistItemDelegate::paintBody(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const {
+ const bool isSelected = option.state & QStyle::State_Selected;
+ if (isSelected)
+ QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
+
painter->save();
painter->translate(option.rect.topLeft());
if (downloadInfo) line.setWidth(line.width() / 2);
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<VideoPointer>().data();
// draw the "current track" highlight underneath the text
if (isActive && !isSelected) paintActiveOverlay(painter, option, line);
- // separator
- painter->setPen(option.palette.color(QPalette::Midlight));
- painter->drawLine(thumbWidth, thumbHeight, option.rect.width(), thumbHeight);
- if (!video->getThumbnail().isNull()) painter->setPen(Qt::black);
- painter->drawLine(0, thumbHeight, thumbWidth - 1, thumbHeight);
-
// thumb
- painter->drawPixmap(0, 0, video->getThumbnail());
+ const QPixmap &thumb = video->getThumbnail();
+ if (!thumb.isNull()) {
+ painter->drawPixmap(0, 0, thumb);
+ if (video->getDuration() > 0) drawTime(painter, video->getFormattedDuration(), line);
+ }
const bool thumbsOnly = line.width() <= thumbWidth + 60;
const bool isHovered = index.data(HoveredItemRole).toBool();
// play icon overlayed on the thumb
- if (isActive && (!isHovered && thumbsOnly)) painter->drawPixmap(0, 0, playIcon);
-
- // time
- if (video->getDuration() > 0) drawTime(painter, video->getFormattedDuration(), line);
+ bool needPlayIcon = isActive;
+ if (thumbsOnly) needPlayIcon = needPlayIcon && !isHovered;
+ if (needPlayIcon) painter->drawPixmap(0, 0, playIcon);
if (!thumbsOnly) {
// text color
QStringRef title(&video->getTitle());
QString elidedTitle = video->getTitle();
static const int titleFlags = Qt::AlignTop | Qt::TextWordWrap;
- QRect textBox = line.adjusted(padding + thumbWidth, padding, 0, 0);
+ QRect textBox = line.adjusted(padding + thumbWidth, padding, -padding, 0);
textBox = painter->boundingRect(textBox, titleFlags, elidedTitle);
while (textBox.height() > 55 && elidedTitle.length() > 10) {
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
textSize = QSize(painter->fontMetrics().size(Qt::TextSingleLine, author));
textBox = QRect(textPoint, textSize);
authorRects.insert(index.row(), textBox);
- if (textBox.right() > line.width()) {
+ if (textBox.right() > line.width() - padding) {
textBox.setRight(line.width());
elided = drawElidedText(painter, textBox, flags, author);
} else {
// view count
if (video->getViewCount() > 0) {
- QLocale locale;
- const QString viewCount = tr("%1 views").arg(locale.toString(video->getViewCount()));
+ const QString &viewCount = video->getFormattedViewCount();
textPoint.setX(textBox.right() + padding);
textSize = QSize(fontMetrics.size(Qt::TextSingleLine, viewCount));
- if (elided || textPoint.x() + textSize.width() > line.width()) {
+ if (elided || textPoint.x() + textSize.width() > line.width() - padding) {
textPoint.setX(thumbWidth + padding);
textPoint.setY(textPoint.y() + textSize.height() + padding);
}