File indexing completed on 2025-01-19 03:57:29

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2021-08-27
0007  * Description : Tool tip for Showfoto folder-view item.
0008  *
0009  * SPDX-FileCopyrightText: 2021-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 "showfotofolderviewtooltip.h"
0016 
0017 // Qt includes
0018 
0019 #include <QDateTime>
0020 #include <QPainter>
0021 #include <QScopedPointer>
0022 #include <QPixmap>
0023 #include <QFileInfo>
0024 #include <QTextDocument>
0025 
0026 // Local includes
0027 
0028 #include "digikam_debug.h"
0029 #include "digikam_globals.h"
0030 #include "showfotosettings.h"
0031 #include "showfotoiteminfo.h"
0032 #include "showfotofolderviewlist.h"
0033 #include "showfotofolderviewmodel.h"
0034 #include "showfototooltipfiller.h"
0035 
0036 namespace ShowFoto
0037 {
0038 
0039 class Q_DECL_HIDDEN ShowfotoFolderViewToolTip::Private
0040 {
0041 public:
0042 
0043     explicit Private()
0044       : view        (nullptr)
0045     {
0046     }
0047 
0048     ShowfotoFolderViewList* view;
0049     QModelIndex             index;
0050 };
0051 
0052 ShowfotoFolderViewToolTip::ShowfotoFolderViewToolTip(ShowfotoFolderViewList* const view)
0053     : DItemToolTip(),
0054       d           (new Private)
0055 {
0056     d->view = view;
0057 }
0058 
0059 ShowfotoFolderViewToolTip::~ShowfotoFolderViewToolTip()
0060 {
0061     delete d;
0062 }
0063 
0064 void ShowfotoFolderViewToolTip::setIndex(const QModelIndex& index)
0065 {
0066     d->index = index;
0067 
0068     if (!d->index.isValid() || !ShowfotoSettings::instance()->getShowToolTip())
0069     {
0070         hide();
0071     }
0072     else
0073     {
0074         updateToolTip();
0075         reposition();
0076 
0077         if (isHidden() && !toolTipIsEmpty())
0078         {
0079             show();
0080         }
0081     }
0082 }
0083 
0084 QRect ShowfotoFolderViewToolTip::repositionRect()
0085 {
0086     if (!d->index.isValid())
0087     {
0088         return QRect();
0089     }
0090 
0091     QRect rect = d->view->visualRect(d->index);
0092     rect.moveTopLeft(d->view->viewport()->mapToGlobal(rect.topLeft()));
0093 
0094     return rect;
0095 }
0096 
0097 QString ShowfotoFolderViewToolTip::tipContents()
0098 {
0099     if (!d->index.isValid())
0100     {
0101         return QString();
0102     }
0103 
0104     ShowfotoFolderViewModel* const model = dynamic_cast<ShowfotoFolderViewModel*>(d->view->model());
0105 
0106     if (!model)
0107     {
0108         return QString();
0109     }
0110 
0111     QString path              = model->filePath(d->index);
0112     ShowfotoItemInfo iteminfo = ShowfotoItemInfo::itemInfoFromFile(QFileInfo(path));
0113 
0114     return ShowfotoToolTipFiller::ShowfotoItemInfoTipContents(iteminfo);
0115 }
0116 
0117 } // namespace ShowFoto
0118 
0119 #include "moc_showfotofolderviewtooltip.cpp"