File indexing completed on 2025-01-05 03:57:58
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2021-09-27 0007 * Description : Tool tip for Showfoto stack 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 "showfotostackviewtooltip.h" 0016 0017 // Local includes 0018 0019 #include "digikam_debug.h" 0020 #include "digikam_globals.h" 0021 #include "showfotosettings.h" 0022 #include "showfotostackviewlist.h" 0023 #include "showfototooltipfiller.h" 0024 #include "showfotostackviewitem.h" 0025 0026 namespace ShowFoto 0027 { 0028 0029 class Q_DECL_HIDDEN ShowfotoStackViewToolTip::Private 0030 { 0031 public: 0032 0033 explicit Private() 0034 : view (nullptr) 0035 { 0036 } 0037 0038 ShowfotoStackViewList* view; 0039 QModelIndex index; 0040 }; 0041 0042 ShowfotoStackViewToolTip::ShowfotoStackViewToolTip(ShowfotoStackViewList* const view) 0043 : DItemToolTip(), 0044 d (new Private) 0045 { 0046 d->view = view; 0047 } 0048 0049 ShowfotoStackViewToolTip::~ShowfotoStackViewToolTip() 0050 { 0051 delete d; 0052 } 0053 0054 void ShowfotoStackViewToolTip::setIndex(const QModelIndex& index) 0055 { 0056 d->index = index; 0057 0058 if (!d->index.isValid() || !ShowfotoSettings::instance()->getShowToolTip()) 0059 { 0060 hide(); 0061 } 0062 else 0063 { 0064 updateToolTip(); 0065 reposition(); 0066 0067 if (isHidden() && !toolTipIsEmpty()) 0068 { 0069 show(); 0070 } 0071 } 0072 } 0073 0074 QRect ShowfotoStackViewToolTip::repositionRect() 0075 { 0076 if (!d->index.isValid()) 0077 { 0078 return QRect(); 0079 } 0080 0081 QRect rect = d->view->visualRect(d->index); 0082 rect.moveTopLeft(d->view->viewport()->mapToGlobal(rect.topLeft())); 0083 0084 return rect; 0085 } 0086 0087 QString ShowfotoStackViewToolTip::tipContents() 0088 { 0089 if (!d->index.isValid()) 0090 { 0091 return QString(); 0092 } 0093 0094 ShowfotoItemInfo iteminfo = d->view->infoFromIndex(d->index); 0095 0096 if (iteminfo.isNull()) 0097 { 0098 return QString(); 0099 } 0100 0101 return ShowfotoToolTipFiller::ShowfotoItemInfoTipContents(iteminfo); 0102 } 0103 0104 } // namespace ShowFoto 0105 0106 #include "moc_showfotostackviewtooltip.cpp"