File indexing completed on 2025-01-19 03:55:42
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-05-21 0007 * Description : widget to display a list of items 0008 * 0009 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2008-2010 by Andi Clemens <andi dot clemens at googlemail dot com> 0011 * SPDX-FileCopyrightText: 2009-2010 by Luka Renko <lure at kubuntu dot org> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "ditemslist_p.h" 0018 0019 namespace Digikam 0020 { 0021 0022 class Q_DECL_HIDDEN DItemsListViewItem::Private 0023 { 0024 public: 0025 0026 explicit Private() 0027 : hasThumb (false), 0028 rating (-1), 0029 view (nullptr), 0030 state (Waiting) 0031 { 0032 } 0033 0034 bool hasThumb; ///< True if thumbnails is a real photo thumbs 0035 0036 int rating; ///< Image Rating from host. 0037 QString comments; ///< Image comments from host. 0038 QStringList tags; ///< List of keywords from host. 0039 QUrl url; ///< Image url provided by host. 0040 QPixmap thumb; ///< Image thumbnail. 0041 DItemsListView* view; 0042 State state; 0043 }; 0044 0045 DItemsListViewItem::DItemsListViewItem(DItemsListView* const view, const QUrl& url) 0046 : QTreeWidgetItem(view), 0047 d (new Private) 0048 { 0049 setUrl(url); 0050 setRating(-1); 0051 setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsSelectable); 0052 0053 d->view = view; 0054 int iconSize = d->view->iconSize().width(); 0055 setThumb(QIcon::fromTheme(QLatin1String("view-preview")).pixmap(iconSize, iconSize, QIcon::Disabled), false); 0056 /* 0057 qCDebug(DIGIKAM_GENERAL_LOG) << "Creating new ImageListViewItem with url " << d->url 0058 << " for list view " << d->view; 0059 */ 0060 } 0061 0062 DItemsListViewItem::~DItemsListViewItem() 0063 { 0064 delete d; 0065 } 0066 0067 bool DItemsListViewItem::hasValidThumbnail() const 0068 { 0069 return d->hasThumb; 0070 } 0071 0072 void DItemsListViewItem::updateInformation() 0073 { 0074 if (d->view->iface()) 0075 { 0076 DItemInfo info(d->view->iface()->itemInfo(d->url)); 0077 0078 setComments(info.comment()); 0079 setTags(info.keywords()); 0080 setRating(info.rating()); 0081 } 0082 } 0083 0084 void DItemsListViewItem::setUrl(const QUrl& url) 0085 { 0086 d->url = url; 0087 setText(DItemsListView::Filename, d->url.fileName()); 0088 } 0089 0090 QUrl DItemsListViewItem::url() const 0091 { 0092 return d->url; 0093 } 0094 0095 void DItemsListViewItem::setComments(const QString& comments) 0096 { 0097 d->comments = comments; 0098 } 0099 0100 QString DItemsListViewItem::comments() const 0101 { 0102 return d->comments; 0103 } 0104 0105 void DItemsListViewItem::setTags(const QStringList& tags) 0106 { 0107 d->tags = tags; 0108 } 0109 0110 QStringList DItemsListViewItem::tags() const 0111 { 0112 return d->tags; 0113 } 0114 0115 void DItemsListViewItem::setRating(int rating) 0116 { 0117 d->rating = rating; 0118 } 0119 0120 int DItemsListViewItem::rating() const 0121 { 0122 return d->rating; 0123 } 0124 0125 void DItemsListViewItem::setPixmap(const QPixmap& pix) 0126 { 0127 QIcon icon = QIcon(pix); 0128 0129 // We make sure the preview icon stays the same regardless of the role. 0130 0131 icon.addPixmap(pix, QIcon::Selected, QIcon::On); 0132 icon.addPixmap(pix, QIcon::Selected, QIcon::Off); 0133 icon.addPixmap(pix, QIcon::Active, QIcon::On); 0134 icon.addPixmap(pix, QIcon::Active, QIcon::Off); 0135 icon.addPixmap(pix, QIcon::Normal, QIcon::On); 0136 icon.addPixmap(pix, QIcon::Normal, QIcon::Off); 0137 setIcon(DItemsListView::Thumbnail, icon); 0138 } 0139 0140 void DItemsListViewItem::setThumb(const QPixmap& pix, bool hasThumb) 0141 { 0142 /* 0143 qCDebug(DIGIKAM_GENERAL_LOG) << "Received new thumbnail for url " << d->url 0144 << ". My view is " << d->view; 0145 */ 0146 if (!d->view) 0147 { 0148 qCCritical(DIGIKAM_GENERAL_LOG) << "This item do not have a tree view. " 0149 << "This should never happen!"; 0150 return; 0151 } 0152 0153 int iconSize = qMax<int>(d->view->iconSize().width(), d->view->iconSize().height()); 0154 QPixmap pixmap(iconSize + 2, iconSize + 2); 0155 pixmap.fill(Qt::transparent); 0156 QPainter p(&pixmap); 0157 p.drawPixmap((pixmap.width() / 2) - (pix.width() / 2), 0158 (pixmap.height() / 2) - (pix.height() / 2), pix); 0159 d->thumb = pixmap; 0160 setPixmap(d->thumb); 0161 0162 d->hasThumb = hasThumb; 0163 } 0164 0165 void DItemsListViewItem::setProgressAnimation(const QPixmap& pix) 0166 { 0167 QPixmap overlay = d->thumb; 0168 QPixmap mask(overlay.size()); 0169 mask.fill(QColor(128, 128, 128, 192)); 0170 QPainter p(&overlay); 0171 p.drawPixmap(0, 0, mask); 0172 p.drawPixmap((overlay.width() / 2) - (pix.width() / 2), 0173 (overlay.height() / 2) - (pix.height() / 2), pix); 0174 setPixmap(overlay); 0175 } 0176 0177 void DItemsListViewItem::setProcessedIcon(const QIcon& icon) 0178 { 0179 setIcon(DItemsListView::Filename, icon); 0180 0181 // reset thumbnail back to no animation pix. 0182 0183 setPixmap(d->thumb); 0184 } 0185 0186 void DItemsListViewItem::setState(State state) 0187 { 0188 d->state = state; 0189 } 0190 0191 DItemsListViewItem::State DItemsListViewItem::state() const 0192 { 0193 return d->state; 0194 } 0195 0196 DItemsListView* DItemsListViewItem::view() const 0197 { 0198 return d->view; 0199 } 0200 0201 bool DItemsListViewItem::operator<(const QTreeWidgetItem& other) const 0202 { 0203 if (d->view->isLessThanHandler()) 0204 { 0205 return d->view->isLessThanHandler()(this, other); 0206 } 0207 0208 return QTreeWidgetItem::operator<(other); 0209 } 0210 0211 } // namespace Digikam