File indexing completed on 2025-01-05 03:51:11
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-02-06 0007 * Description : thumbnail bar for items - the delegate 0008 * 0009 * SPDX-FileCopyrightText: 2002-2005 by Renchi Raju <renchi dot raju at gmail dot com> 0010 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0011 * SPDX-FileCopyrightText: 2002-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0012 * SPDX-FileCopyrightText: 2009-2011 by Andi Clemens <andi dot clemens at gmail dot com> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #include "itemthumbnaildelegate.h" 0019 #include "itemthumbnaildelegate_p.h" 0020 0021 // Local includes 0022 0023 #include "digikam_debug.h" 0024 #include "applicationsettings.h" 0025 #include "itemcategorizedview.h" 0026 #include "itemdelegateoverlay.h" 0027 #include "itemmodel.h" 0028 #include "itemfiltermodel.h" 0029 #include "thumbnailloadthread.h" 0030 0031 namespace Digikam 0032 { 0033 0034 void ItemThumbnailDelegatePrivate::init(ItemThumbnailDelegate* const q) 0035 { 0036 QObject::connect(ApplicationSettings::instance(), SIGNAL(setupChanged()), 0037 q, SLOT(slotSetupChanged())); 0038 } 0039 0040 ItemThumbnailDelegate::ItemThumbnailDelegate(ItemCategorizedView* parent) 0041 : ItemDelegate(*new ItemThumbnailDelegatePrivate, parent) 0042 { 0043 Q_D(ItemThumbnailDelegate); 0044 d->init(this); 0045 } 0046 0047 ItemThumbnailDelegate::~ItemThumbnailDelegate() 0048 { 0049 } 0050 0051 void ItemThumbnailDelegate::setFlow(QListView::Flow flow) 0052 { 0053 Q_D(ItemThumbnailDelegate); 0054 d->flow = flow; 0055 } 0056 0057 void ItemThumbnailDelegate::setDefaultViewOptions(const QStyleOptionViewItem& option) 0058 { 0059 Q_D(ItemThumbnailDelegate); 0060 0061 // store before calling parent class 0062 0063 d->viewSize = option.rect; 0064 ItemDelegate::setDefaultViewOptions(option); 0065 } 0066 0067 int ItemThumbnailDelegate::maximumSize() const 0068 { 0069 Q_D(const ItemThumbnailDelegate); 0070 0071 return ThumbnailLoadThread::maximumThumbnailPixmapSize(true) + 2*d->radius + 2*d->margin; 0072 } 0073 0074 int ItemThumbnailDelegate::minimumSize() const 0075 { 0076 Q_D(const ItemThumbnailDelegate); 0077 0078 return (ThumbnailSize::Small + 2*d->radius + 2*d->margin); 0079 } 0080 0081 bool ItemThumbnailDelegate::acceptsActivation(const QPoint& pos, const QRect& visualRect, 0082 const QModelIndex& index, QRect* activationRect) const 0083 { 0084 // reuse implementation from grandparent 0085 0086 return ItemViewDelegate::acceptsActivation(pos, visualRect, index, activationRect); // clazy:exclude=skipped-base-method 0087 } 0088 0089 void ItemThumbnailDelegate::updateContentWidth() 0090 { 0091 Q_D(ItemThumbnailDelegate); 0092 int maxSize; 0093 0094 if (d->flow == QListView::LeftToRight) 0095 { 0096 maxSize = d->viewSize.height(); 0097 } 0098 else 0099 { 0100 maxSize = d->viewSize.width(); 0101 } 0102 0103 d->thumbSize = ThumbnailSize(ThumbnailLoadThread::thumbnailToPixmapSize(true, maxSize - 2*d->radius - 2*d->margin)); 0104 0105 ItemDelegate::updateContentWidth(); 0106 } 0107 0108 void ItemThumbnailDelegate::updateRects() 0109 { 0110 Q_D(ItemThumbnailDelegate); 0111 0112 d->rect = QRect(0, 0, d->contentWidth + 2*d->margin, d->contentWidth + 2*d->margin); 0113 d->pixmapRect = QRect(d->margin, d->margin, d->contentWidth, d->contentWidth); 0114 const int iconSize = qBound(16, (d->contentWidth + 2*d->margin) / 8 - 2, 48); 0115 d->coordinatesRect = QRect(d->contentWidth - iconSize+2, d->pixmapRect.top(), iconSize, iconSize); 0116 d->pickLabelRect = QRect(d->margin+2, d->rect.bottom() - d->margin - 18, 16, 16); 0117 d->drawCoordinates = ApplicationSettings::instance()->getIconShowCoordinates(); 0118 d->drawImageFormat = ApplicationSettings::instance()->getIconShowImageFormat(); 0119 d->drawImageFormatTop = true; 0120 0121 if (ApplicationSettings::instance()->getIconShowRating()) 0122 { 0123 int top = d->rect.bottom() - d->margin - d->starPolygonSize.height() - 2; 0124 d->ratingRect = QRect(d->margin, top, d->contentWidth, d->starPolygonSize.height()); 0125 } 0126 0127 if (d->flow == QListView::LeftToRight) 0128 { 0129 d->gridSize = QSize(d->rect.width() + d->spacing, d->rect.height()); 0130 } 0131 else 0132 { 0133 d->gridSize = QSize(d->rect.width(), d->rect.height() + d->spacing); 0134 } 0135 } 0136 0137 } // namespace Digikam 0138 0139 #include "moc_itemthumbnaildelegate.cpp"