Plasma-framework

tooltip.h
1/*
2 SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2011 Artur Duque de Souza <asouza@kde.org>
4 SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#ifndef TOOLTIPOBJECT_H
10#define TOOLTIPOBJECT_H
11
12#include <Plasma/Plasma>
13#include <QPointer>
14#include <QQuickItem>
15#include <QVariant>
16
17class QQuickItem;
18class ToolTipDialog;
19
20/**
21 * An Item managing a Plasma-themed tooltip. It is rendered in its own window.
22 * You can either specify icon, mainText and subText, or a custom Component
23 * that will be put inside the tooltip. By default the tooltip will be
24 * rendered when hovering over the parent item.
25 *
26 * The item inside the ToolTipArea is loaded on demand and will be destroyed when the
27 * tooltip is being hidden.
28 *
29 * Example usage:
30 * @code
31 * import org.kde.plasma.core as PlasmaCore
32 * import org.kde.kirigami 2.20 as Kirigami
33 *
34 * Kirigami.Icon {
35 * PlasmaCore.ToolTipArea {
36 * mainText: i18n("Tooltip Title")
37 * subText: i18n("Some explanation.")
38 * icon: "plasma"
39 * // alternatively, you can specify your own component
40 * // to be loaded when the tooltip shows
41 * mainItem: YourCustomItem { }
42 * }
43 * }
44 * @endcode
45 *
46 * <b>Import Statement</b>
47 * @code import org.kde.plasma.core @endcode
48 * @version 2.0
49 */
50class ToolTip : public QQuickItem
51{
53
54 /**
55 * The item shown inside the tooltip.
56 */
57 Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
58
59 /**
60 * The main text of this tooltip
61 */
62 Q_PROPERTY(QString mainText READ mainText WRITE setMainText NOTIFY mainTextChanged)
63
64 /**
65 * The description of this tooltip
66 */
67 Q_PROPERTY(QString subText READ subText WRITE setSubText NOTIFY subTextChanged)
68
69 /**
70 * how to handle the text format of the tooltip subtext:
71 * * Text.AutoText (default)
72 * * Text.PlainText
73 * * Text.StyledText
74 * * Text.RichText
75 * Note: in the default implementation the main text is always plain text
76 */
77 Q_PROPERTY(int textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
78
79 /**
80 * An icon for this tooltip, accepted values are an icon name, a QIcon, QImage or QPixmap
81 */
82 Q_PROPERTY(QVariant icon READ icon WRITE setIcon NOTIFY iconChanged)
83
84 /**
85 * Returns whether the mouse is inside the item
86 */
87 Q_PROPERTY(bool containsMouse READ containsMouse NOTIFY containsMouseChanged)
88
89 /**
90 * Plasma Location of the dialog window. Useful if this dialog is a popup for a panel
91 */
92 Q_PROPERTY(Plasma::Types::Location location READ location WRITE setLocation NOTIFY locationChanged)
93
94 /**
95 * TODO: single property for images?
96 * An image for this tooltip, accepted values are an icon name, a QIcon, QImage or QPixmap
97 */
98 Q_PROPERTY(QVariant image READ image WRITE setImage NOTIFY imageChanged)
99
100 /**
101 * Property that controls if a tooltips will show on mouse over.
102 * The default is true.
103 */
104 Q_PROPERTY(bool active MEMBER m_active WRITE setActive NOTIFY activeChanged)
105
106 /**
107 * If interactive is false (default), the tooltip will automatically hide
108 * itself as soon as the mouse leaves the tooltiparea, if is true, if the
109 * mouse leaves tooltiparea and goes over the tooltip itself, the tooltip
110 * won't hide, so it will be possible to interact with tooltip contents.
111 */
112 Q_PROPERTY(bool interactive MEMBER m_interactive WRITE setInteractive NOTIFY interactiveChanged)
113
114 /**
115 * Timeout in milliseconds after which the tooltip will hide itself.
116 * Set this value to -1 to never hide the tooltip automatically.
117 */
118 Q_PROPERTY(int timeout MEMBER m_timeout WRITE setTimeout)
119
120public:
121 /// @cond INTERNAL_DOCS
122 explicit ToolTip(QQuickItem *parent = nullptr);
123 ~ToolTip() override;
124
125 QQuickItem *mainItem() const;
126 void setMainItem(QQuickItem *mainItem);
127
128 QString mainText() const;
129 void setMainText(const QString &mainText);
130
131 QString subText() const;
132 void setSubText(const QString &subText);
133
134 int textFormat() const;
135 void setTextFormat(int format);
136
137 QVariant icon() const;
138 void setIcon(const QVariant &icon);
139
140 QVariant image() const;
141 void setImage(const QVariant &image);
142
143 Plasma::Types::Location location() const;
144 void setLocation(Plasma::Types::Location location);
145
146 bool containsMouse() const;
147 void setContainsMouse(bool contains);
148
149 void setActive(bool active);
150
151 void setInteractive(bool interactive);
152
153 void setTimeout(int timeout);
154 /// @endcond
155
156public Q_SLOTS:
157
158 /**
159 * Shows the tooltip.
160 * @since 5.73
161 */
162 void showToolTip();
163
164 /**
165 * Hides the tooltip after a grace period if shown. Does not affect whether the tooltip area is active.
166 */
167 void hideToolTip();
168
169 /**
170 * Hides the tooltip immediately, in comparison to hideToolTip.
171 * @since 5.84
172 */
173 void hideImmediately();
174
175protected:
176 /// @cond INTERNAL_DOCS
177 bool childMouseEventFilter(QQuickItem *item, QEvent *event) override;
178 void hoverEnterEvent(QHoverEvent *event) override;
179 void hoverLeaveEvent(QHoverEvent *event) override;
180
181 ToolTipDialog *tooltipDialogInstance();
182 /// @endcond
183
185 void mainItemChanged();
186 void mainTextChanged();
187 void subTextChanged();
188 void textFormatChanged();
189 void iconChanged();
190 void imageChanged();
191 void containsMouseChanged();
192 void locationChanged();
193 void activeChanged();
194 void interactiveChanged();
195 /**
196 * Emitted just before the tooltip dialog is shown.
197 *
198 * @since 5.45
199 */
201 /**
202 * Emitted when the tooltip's visibility changes.
203 *
204 * @since 5.88
205 */
206 void toolTipVisibleChanged(bool toolTipVisible);
207
208private Q_SLOTS:
209 void settingsChanged(const QString &file);
210
211private:
212 bool isValid() const;
213
214 void loadSettings();
215 bool m_tooltipsEnabledGlobally;
216 bool m_containsMouse;
217 Plasma::Types::Location m_location;
218 QPointer<QQuickItem> m_mainItem;
219 QTimer *m_showTimer;
220 QString m_mainText;
221 QString m_subText;
222 int m_textFormat;
223 QVariant m_image;
224 QVariant m_icon;
225 bool m_active;
226 bool m_interactive;
227 int m_interval;
228 int m_timeout;
229
230 // ToolTipDialog is not a Q_GLOBAL_STATIC because QQuickwindows as global static
231 // are deleted too later after some stuff in the qml runtime has already been deleted,
232 // causing a crash on exit
233 bool m_usingDialog : 1;
234 static ToolTipDialog *s_dialog;
235 static int s_dialogUsers;
236};
237
238#endif
An Item managing a Plasma-themed tooltip.
Definition tooltip.h:51
int timeout
Timeout in milliseconds after which the tooltip will hide itself.
Definition tooltip.h:118
QString subText
The description of this tooltip.
Definition tooltip.h:67
bool interactive
If interactive is false (default), the tooltip will automatically hide itself as soon as the mouse le...
Definition tooltip.h:112
void toolTipVisibleChanged(bool toolTipVisible)
Emitted when the tooltip's visibility changes.
void hideImmediately()
Hides the tooltip immediately, in comparison to hideToolTip.
Definition tooltip.cpp:294
QQuickItem * mainItem
The item shown inside the tooltip.
Definition tooltip.h:57
QVariant icon
An icon for this tooltip, accepted values are an icon name, a QIcon, QImage or QPixmap.
Definition tooltip.h:82
QString mainText
The main text of this tooltip.
Definition tooltip.h:62
bool containsMouse
Returns whether the mouse is inside the item.
Definition tooltip.h:87
void hideToolTip()
Hides the tooltip after a grace period if shown.
Definition tooltip.cpp:288
void aboutToShow()
Emitted just before the tooltip dialog is shown.
QVariant image
TODO: single property for images? An image for this tooltip, accepted values are an icon name,...
Definition tooltip.h:98
int textFormat
how to handle the text format of the tooltip subtext:
Definition tooltip.h:77
void showToolTip()
Shows the tooltip.
Definition tooltip.cpp:117
Plasma::Types::Location location
Plasma Location of the dialog window.
Definition tooltip.h:92
bool active
Property that controls if a tooltips will show on mouse over.
Definition tooltip.h:104
Namespace for everything in libplasma.
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
virtual bool childMouseEventFilter(QQuickItem *item, QEvent *event)
virtual bool contains(const QPointF &point) const const
virtual bool event(QEvent *ev) override
virtual void hoverEnterEvent(QHoverEvent *event)
virtual void hoverLeaveEvent(QHoverEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:48:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.