Changeset View
Changeset View
Standalone View
Standalone View
lib/thumbnailview/previewitemdelegate.cpp
Show First 20 Lines • Show All 317 Lines • ▼ Show 20 Line(s) | 317 | { | |||
---|---|---|---|---|---|
318 | const QPoint shadowOffset(-SHADOW_SIZE, -SHADOW_SIZE + 1); | 318 | const QPoint shadowOffset(-SHADOW_SIZE, -SHADOW_SIZE + 1); | ||
319 | 319 | | |||
320 | int key = rect.height() * 1000 + rect.width(); | 320 | int key = rect.height() * 1000 + rect.width(); | ||
321 | 321 | | |||
322 | ShadowCache::Iterator it = mShadowCache.find(key); | 322 | ShadowCache::Iterator it = mShadowCache.find(key); | ||
323 | if (it == mShadowCache.end()) { | 323 | if (it == mShadowCache.end()) { | ||
324 | QSize size = QSize(rect.width() + 2 * SHADOW_SIZE, rect.height() + 2 * SHADOW_SIZE); | 324 | QSize size = QSize(rect.width() + 2 * SHADOW_SIZE, rect.height() + 2 * SHADOW_SIZE); | ||
325 | QColor color(0, 0, 0, SHADOW_STRENGTH); | 325 | QColor color(0, 0, 0, SHADOW_STRENGTH); | ||
326 | QPixmap shadow = PaintUtils::generateFuzzyRect(size, color, SHADOW_SIZE); | 326 | const auto dpr = qApp->devicePixelRatio(); | ||
327 | QPixmap shadow = PaintUtils::generateFuzzyRect(size * dpr, color, SHADOW_SIZE * dpr); | ||||
328 | shadow.setDevicePixelRatio(dpr); | ||||
327 | it = mShadowCache.insert(key, shadow); | 329 | it = mShadowCache.insert(key, shadow); | ||
328 | } | 330 | } | ||
329 | painter->drawPixmap(rect.topLeft() + shadowOffset, it.value()); | 331 | painter->drawPixmap(rect.topLeft() + shadowOffset, it.value()); | ||
330 | } | 332 | } | ||
331 | 333 | | |||
332 | void drawText(QPainter* painter, const QRect& rect, const QColor& fgColor, const QString& fullText) const | 334 | void drawText(QPainter* painter, const QRect& rect, const QColor& fgColor, const QString& fullText) const | ||
333 | { | 335 | { | ||
334 | QFontMetrics fm = mView->fontMetrics(); | 336 | QFontMetrics fm = mView->fontMetrics(); | ||
▲ Show 20 Lines • Show All 348 Lines • ▼ Show 20 Line(s) | 664 | { | |||
683 | } | 685 | } | ||
684 | } | 686 | } | ||
685 | 687 | | |||
686 | void PreviewItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const | 688 | void PreviewItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const | ||
687 | { | 689 | { | ||
688 | int thumbnailHeight = d->mThumbnailSize.height(); | 690 | int thumbnailHeight = d->mThumbnailSize.height(); | ||
689 | QSize fullSize; | 691 | QSize fullSize; | ||
690 | QPixmap thumbnailPix = d->mView->thumbnailForIndex(index, &fullSize); | 692 | QPixmap thumbnailPix = d->mView->thumbnailForIndex(index, &fullSize); | ||
693 | QSize thumbnailSize = thumbnailPix.size() / thumbnailPix.devicePixelRatio(); | ||||
691 | const KFileItem fileItem = fileItemForIndex(index); | 694 | const KFileItem fileItem = fileItemForIndex(index); | ||
692 | const bool opaque = !thumbnailPix.hasAlphaChannel(); | 695 | const bool opaque = !thumbnailPix.hasAlphaChannel(); | ||
693 | const bool isDirOrArchive = ArchiveUtils::fileItemIsDirOrArchive(fileItem); | 696 | const bool isDirOrArchive = ArchiveUtils::fileItemIsDirOrArchive(fileItem); | ||
694 | QRect rect = option.rect; | 697 | QRect rect = option.rect; | ||
695 | const bool selected = option.state & QStyle::State_Selected; | 698 | const bool selected = option.state & QStyle::State_Selected; | ||
696 | const bool underMouse = option.state & QStyle::State_MouseOver; | 699 | const bool underMouse = option.state & QStyle::State_MouseOver; | ||
697 | const bool hasFocus = option.state & QStyle::State_HasFocus; | 700 | const bool hasFocus = option.state & QStyle::State_HasFocus; | ||
698 | 701 | | |||
Show All 35 Lines | 736 | if (hasFocus) { | |||
734 | borderColor = fgColor; | 737 | borderColor = fgColor; | ||
735 | } else { | 738 | } else { | ||
736 | borderColor = bgColor.lighter(200); | 739 | borderColor = bgColor.lighter(200); | ||
737 | } | 740 | } | ||
738 | } | 741 | } | ||
739 | 742 | | |||
740 | // Compute thumbnailRect | 743 | // Compute thumbnailRect | ||
741 | QRect thumbnailRect = QRect( | 744 | QRect thumbnailRect = QRect( | ||
742 | rect.left() + (rect.width() - thumbnailPix.width()) / 2, | 745 | rect.left() + (rect.width() - thumbnailSize.width()) / 2, | ||
743 | rect.top() + (thumbnailHeight - thumbnailPix.height()) + ITEM_MARGIN, | 746 | rect.top() + (thumbnailHeight - thumbnailSize.height()) + ITEM_MARGIN, | ||
744 | thumbnailPix.width(), | 747 | thumbnailSize.width(), | ||
745 | thumbnailPix.height()); | 748 | thumbnailSize.height()); | ||
746 | 749 | | |||
747 | // Draw background | 750 | // Draw background | ||
748 | const QRect backgroundRect = thumbnailRect.adjusted(-ITEM_MARGIN, -ITEM_MARGIN, ITEM_MARGIN, ITEM_MARGIN); | 751 | const QRect backgroundRect = thumbnailRect.adjusted(-ITEM_MARGIN, -ITEM_MARGIN, ITEM_MARGIN, ITEM_MARGIN); | ||
749 | if (selected) { | 752 | if (selected) { | ||
750 | d->drawBackground(painter, backgroundRect, bgColor, borderColor); | 753 | d->drawBackground(painter, backgroundRect, bgColor, borderColor); | ||
751 | } else if (underMouse) { | 754 | } else if (underMouse) { | ||
752 | painter->setOpacity(0.2); | 755 | painter->setOpacity(0.2); | ||
753 | d->drawBackground(painter, backgroundRect, bgColor, borderColor); | 756 | d->drawBackground(painter, backgroundRect, bgColor, borderColor); | ||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |