File indexing completed on 2025-03-09 03:58:42

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-01-19
0007  * Description : free space widget tool tip
0008  *
0009  * SPDX-FileCopyrightText: 2009-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 "freespacetooltip.h"
0016 
0017 // Qt includes
0018 
0019 #include <QWidget>
0020 #include <QString>
0021 #include <QRect>
0022 
0023 namespace Digikam
0024 {
0025 
0026 class Q_DECL_HIDDEN FreeSpaceToolTip::Private
0027 {
0028 public:
0029 
0030     explicit Private()
0031       : parent(nullptr)
0032     {
0033     }
0034 
0035     QString  tip;
0036 
0037     QWidget* parent;
0038 };
0039 
0040 FreeSpaceToolTip::FreeSpaceToolTip(QWidget* const parent)
0041     : DItemToolTip(),
0042       d           (new Private)
0043 {
0044     d->parent = parent;
0045 }
0046 
0047 FreeSpaceToolTip::~FreeSpaceToolTip()
0048 {
0049     delete d;
0050 }
0051 
0052 void FreeSpaceToolTip::setToolTip(const QString& tip)
0053 {
0054     d->tip = tip;
0055 }
0056 
0057 void FreeSpaceToolTip::show()
0058 {
0059     updateToolTip();
0060     reposition();
0061 
0062     if (isHidden() && !toolTipIsEmpty())
0063     {
0064         DItemToolTip::show();
0065     }
0066 }
0067 
0068 QRect FreeSpaceToolTip::repositionRect()
0069 {
0070     if (!d->parent)
0071     {
0072         return QRect();
0073     }
0074 
0075     QRect rect = d->parent->rect();
0076     rect.moveTopLeft(d->parent->mapToGlobal(rect.topLeft()));
0077 
0078     return rect;
0079 }
0080 
0081 QString FreeSpaceToolTip::tipContents()
0082 {
0083     return d->tip;
0084 }
0085 
0086 } // namespace Digikam
0087 
0088 #include "moc_freespacetooltip.cpp"