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

KDE's Doxygen guidelines are available online.