]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/tooltips/tooltipmanager.h
[Places Panel] Support drag and drop from Ark
[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 {
33 Instantly,
34 Later
35 };
36
37 explicit ToolTipManager(QWidget* parent);
38 ~ToolTipManager() override;
39
40 /**
41 * Triggers the showing of the tooltip for the item \p item
42 * where the item has the maximum boundaries of \p itemRect.
43 * The tooltip manager takes care that the tooltip is shown
44 * slightly delayed and with a proper \p transientParent.
45 */
46 void showToolTip(const KFileItem& item, const QRectF& itemRect, QWindow *transientParent);
47
48 /**
49 * Hides the currently shown tooltip.
50 */
51 void hideToolTip(const HideBehavior behavior = HideBehavior::Later);
52
53 Q_SIGNALS:
54 /**
55 * Is emitted when the user clicks a tag or a link
56 * in the metadata widget.
57 */
58 void urlActivated(const QUrl& url);
59
60 private Q_SLOTS:
61 void startContentRetrieval();
62 void setPreviewPix(const KFileItem& item, const QPixmap& pix);
63 void previewFailed();
64 void slotMetaDataRequestFinished();
65 void showToolTip();
66
67 private:
68 /// Timeout from requesting a tooltip until the tooltip
69 /// should be shown
70 QTimer* m_showToolTipTimer;
71
72 /// Timeout from requesting a tooltip until the retrieving of
73 /// the tooltip content like preview and meta data gets started.
74 QTimer* m_contentRetrievalTimer;
75
76 /// Transient parent of the tooltip, mandatory on Wayland.
77 QWindow* m_transientParent;
78
79 QScopedPointer<KToolTipWidget> m_tooltipWidget;
80 QScopedPointer<DolphinFileMetaDataWidget> m_fileMetaDataWidget;
81
82 bool m_toolTipRequested;
83 bool m_metaDataRequested;
84 bool m_appliedWaitCursor;
85 int m_margin;
86 KFileItem m_item;
87 QRect m_itemRect;
88 };
89
90 #endif