1 | // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu> |
2 | // SPDX-License-Identifier: LGPL-2.0-or-later |
3 | |
4 | #ifndef SPELLCHECKATTACHED_H |
5 | #define SPELLCHECKATTACHED_H |
6 | |
7 | #include <QObject> |
8 | #include <QQmlEngine> |
9 | |
10 | #include <qqmlregistration.h> |
11 | |
12 | /*! |
13 | * \qmltype SpellCheck |
14 | * \inqmlmodule org.kde.kirigami |
15 | * |
16 | * \brief This attached property contains hints for spell checker. |
17 | * |
18 | * \warning Kirigami doesn't provide any spell checker per se, this is just a |
19 | * hint for QQC2 style implementation and other downstream components. If you |
20 | * want to add spell checking to your custom application theme check out Sonnet. |
21 | * |
22 | * \code |
23 | * import QtQuick.Controls as QQC2 |
24 | * import org.kde.kirigami as Kirigami |
25 | * |
26 | * QQC2.TextArea { |
27 | * Kirigami.SpellCheck.enabled: true |
28 | * } |
29 | * \endcode |
30 | * |
31 | * \since 2.18 |
32 | */ |
33 | class SpellCheckAttached : public QObject |
34 | { |
35 | Q_OBJECT |
36 | QML_ELEMENT |
37 | QML_NAMED_ELEMENT(SpellCheck) |
38 | QML_UNCREATABLE("Attached property only" ) |
39 | QML_ATTACHED(SpellCheckAttached) |
40 | |
41 | /*! |
42 | * \qmlattachedproperty bool SpellCheck::enabled |
43 | * |
44 | * This property holds whether the spell checking should be enabled on the |
45 | * TextField/TextArea. |
46 | * |
47 | * \note By default, false. This might change in KF6, so if you don't want |
48 | * spellcheck in your application, explicitly set it to false. |
49 | * |
50 | * \since 2.18 |
51 | */ |
52 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
53 | public: |
54 | explicit SpellCheckAttached(QObject *parent = nullptr); |
55 | ~SpellCheckAttached() override; |
56 | |
57 | void setEnabled(bool enabled); |
58 | bool enabled() const; |
59 | |
60 | // QML attached property |
61 | static SpellCheckAttached *qmlAttachedProperties(QObject *object); |
62 | |
63 | Q_SIGNALS: |
64 | void enabledChanged(); |
65 | |
66 | private: |
67 | bool m_enabled = false; |
68 | }; |
69 | |
70 | QML_DECLARE_TYPEINFO(SpellCheckAttached, QML_HAS_ATTACHED_PROPERTIES) |
71 | |
72 | #endif // SPELLCHECKATTACHED_H |
73 | |