]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/tooltips/tooltipmanager.h
Add clang-format and format code as in Frameworks
[dolphin.git] / src / views / tooltips / tooltipmanager.h
1 /*
2 * SPDX-FileCopyrightText: 2008 Konstantin Heil <konst.heil@stud.uni-heidelberg.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef TOOLTIPMANAGER_H
8 #define TOOLTIPMANAGER_H
9
10 #include <KFileItem>
11
12 #include <QObject>
13 #include <QRect>
14
15 class DolphinFileMetaDataWidget;
16 class KToolTipWidget;
17 class QTimer;
18 class QWindow;
19
20 /**
21 * @brief Manages the tooltips for an item view.
22 *
23 * When hovering an item, a tooltip is shown after
24 * a short timeout. The tooltip is hidden again when the
25 * viewport is hovered or the item view has been left.
26 */
27 class ToolTipManager : public QObject
28 {
29 Q_OBJECT
30
31 public:
32 enum class HideBehavior { Instantly, Later };
33
34 explicit ToolTipManager(QWidget *parent);
35 ~ToolTipManager() override;
36
37 /**
38 * Triggers the showing of the tooltip for the item \p item
39 * where the item has the maximum boundaries of \p itemRect.
40 * The tooltip manager takes care that the tooltip is shown
41 * slightly delayed and with a proper \p transientParent.
42 */
43 void showToolTip(const KFileItem &item, const QRectF &itemRect, QWindow *transientParent);
44
45 /**
46 * Hides the currently shown tooltip.
47 */
48 void hideToolTip(const HideBehavior behavior = HideBehavior::Later);
49
50 Q_SIGNALS:
51 /**
52 * Is emitted when the user clicks a tag or a link
53 * in the metadata widget.
54 */
55 void urlActivated(const QUrl &url);
56
57 private Q_SLOTS:
58 void startContentRetrieval();
59 void setPreviewPix(const KFileItem &item, const QPixmap &pix);
60 void previewFailed();
61 void slotMetaDataRequestFinished();
62 void showToolTip();
63
64 private:
65 /// Timeout from requesting a tooltip until the tooltip
66 /// should be shown
67 QTimer *m_showToolTipTimer;
68
69 /// Timeout from requesting a tooltip until the retrieving of
70 /// the tooltip content like preview and meta data gets started.
71 QTimer *m_contentRetrievalTimer;
72
73 /// Transient parent of the tooltip, mandatory on Wayland.
74 QWindow *m_transientParent;
75
76 QScopedPointer<KToolTipWidget> m_tooltipWidget;
77 DolphinFileMetaDataWidget *m_fileMetaDataWidget = nullptr;
78
79 /// Whether ownership of the metadata widget was transferred
80 /// over to the KToolTipWidget (i.e. we should not delete it
81 /// anymore)
82 bool m_fileMetaDatWidgetOwnershipTransferred = false;
83
84 bool m_toolTipRequested;
85 bool m_metaDataRequested;
86 bool m_appliedWaitCursor;
87 int m_margin;
88 KFileItem m_item;
89 QRect m_itemRect;
90 };
91
92 #endif