Libplasma

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

KDE's Doxygen guidelines are available online.