QmlMaterial 0.1.0
Loading...
Searching...
No Matches
tool_tip.hpp
1#pragma once
2
3#include <QObject>
4#include <QPointer>
5#include <QString>
6#include <qqmlregistration.h>
7
8#include "qml_material/export.hpp"
9
10class QQuickItem;
11
12namespace qml_material
13{
14
15class ToolTipManager;
16
17class QML_MATERIAL_API ToolTipAttached final : public QObject {
18 Q_OBJECT
19
20 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
21 Q_PROPERTY(int delay READ delay WRITE setDelay NOTIFY delayChanged FINAL)
22 Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged FINAL)
23 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged FINAL)
24 Q_PROPERTY(QObject* toolTip READ toolTip CONSTANT FINAL)
25
26public:
27 explicit ToolTipAttached(QObject* parent = nullptr);
28 ~ToolTipAttached() override;
29
30 QString text() const;
31 void setText(const QString& text);
32
33 int delay() const;
34 void setDelay(int delay);
35
36 int timeout() const;
37 void setTimeout(int timeout);
38
39 bool visible() const;
40 void setVisible(bool visible);
41
42 QObject* toolTip() const;
43
44 Q_INVOKABLE void show(const QString& text, int timeout = -1);
45 Q_INVOKABLE void hide();
46
47 Q_SIGNAL void textChanged();
48 Q_SIGNAL void delayChanged();
49 Q_SIGNAL void timeoutChanged();
50 Q_SIGNAL void visibleChanged();
51
52private:
53 friend class ToolTipManager;
54
55 ToolTipManager* manager(bool create) const;
56 QQuickItem* target() const;
57 void notifyVisibleChanged();
58
59 QString m_text;
60 int m_delay { 500 };
61 int m_timeout { -1 };
62};
63
68class QML_MATERIAL_API ToolTip : public QObject {
69 Q_OBJECT
70
71 QML_NAMED_ELEMENT(ToolTip)
72 QML_UNCREATABLE("ToolTip is only available as an attached property")
73 QML_ATTACHED(ToolTipAttached)
74
75public:
76 explicit ToolTip(QObject* parent = nullptr);
77
78 static ToolTipAttached* qmlAttachedProperties(QObject* object);
79};
80
81} // namespace qml_material
Definition tool_tip.hpp:68