File indexing completed on 2025-01-19 03:53:52
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-03-13 0007 * Description : Image files selection dialog - List view tooltip. 0008 * 0009 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "imagedialog_p.h" 0016 0017 namespace Digikam 0018 { 0019 0020 class Q_DECL_HIDDEN ImageDialogToolTip::Private 0021 { 0022 public: 0023 0024 explicit Private() 0025 : view (nullptr), 0026 catcher (nullptr), 0027 thread (nullptr) 0028 { 0029 } 0030 0031 QAbstractItemView* view; 0032 QModelIndex index; 0033 QUrl url; 0034 QImage preview; 0035 ThumbnailImageCatcher* catcher; 0036 ThumbnailLoadThread* thread; 0037 }; 0038 0039 ImageDialogToolTip::ImageDialogToolTip() 0040 : DItemToolTip(), 0041 d (new Private) 0042 { 0043 d->thread = new ThumbnailLoadThread; 0044 d->thread->setThumbnailSize(64); 0045 d->thread->setPixmapRequested(false); 0046 d->catcher = new ThumbnailImageCatcher(d->thread); 0047 } 0048 0049 ImageDialogToolTip::~ImageDialogToolTip() 0050 { 0051 d->catcher->thread()->stopAllTasks(); 0052 d->catcher->cancel(); 0053 0054 delete d->catcher->thread(); 0055 delete d->catcher; 0056 delete d; 0057 } 0058 0059 void ImageDialogToolTip::setData(QAbstractItemView* const view, 0060 const QModelIndex& index, 0061 const QUrl& url) 0062 { 0063 d->view = view; 0064 d->index = index; 0065 d->url = url; 0066 0067 d->catcher->setActive(true); 0068 d->catcher->thread()->find(ThumbnailIdentifier(d->url.toLocalFile())); 0069 d->catcher->enqueue(); 0070 QList<QImage> images = d->catcher->waitForThumbnails(); 0071 0072 if (!images.isEmpty()) 0073 { 0074 d->preview = images.first(); 0075 } 0076 else 0077 { 0078 d->preview = QImage(); 0079 } 0080 0081 d->catcher->setActive(false); 0082 0083 if (!d->index.isValid()) 0084 { 0085 hide(); 0086 } 0087 else 0088 { 0089 updateToolTip(); 0090 reposition(); 0091 0092 if (isHidden() && !toolTipIsEmpty()) 0093 { 0094 show(); 0095 } 0096 } 0097 } 0098 0099 QRect ImageDialogToolTip::repositionRect() 0100 { 0101 if (!d->index.isValid()) 0102 { 0103 return QRect(); 0104 } 0105 0106 QRect rect = d->view->visualRect(d->index); 0107 rect.moveTopLeft(d->view->viewport()->mapToGlobal(rect.topLeft())); 0108 0109 return rect; 0110 } 0111 0112 QString ImageDialogToolTip::tipContents() 0113 { 0114 if (!d->index.isValid()) 0115 { 0116 return QString(); 0117 } 0118 0119 QString identify = ImageDialogPreview::identifyItem(d->url, d->preview); 0120 0121 return identify; 0122 } 0123 0124 } // namespace Digikam