1 | // Copyright (C) 2022 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICKIMAGESELECTOR_P_H |
5 | #define QQUICKIMAGESELECTOR_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/qurl.h> |
19 | #include <QtCore/qobject.h> |
20 | #include <QtCore/qvariant.h> |
21 | #include <QtQml/qqmlproperty.h> |
22 | #include <QtQml/qqmlparserstatus.h> |
23 | #include <QtQml/private/qqmlpropertyvalueinterceptor_p.h> |
24 | #include <QtQml/qqmlproperty.h> |
25 | #include <QtQml/qqml.h> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QQuickImageSelector : public QObject, public QQmlParserStatus, public QQmlPropertyValueInterceptor |
30 | { |
31 | Q_OBJECT |
32 | Q_PROPERTY(QUrl source READ source NOTIFY sourceChanged FINAL) |
33 | Q_PROPERTY(QString name READ name WRITE setName FINAL) |
34 | Q_PROPERTY(QString path READ path WRITE setPath FINAL) |
35 | Q_PROPERTY(QVariantList states READ states WRITE setStates FINAL) |
36 | Q_PROPERTY(QString separator READ separator WRITE setSeparator FINAL) |
37 | Q_PROPERTY(bool cache READ cache WRITE setCache FINAL) |
38 | Q_INTERFACES(QQmlParserStatus QQmlPropertyValueInterceptor) |
39 | QML_NAMED_ELEMENT(ImageSelector) |
40 | QML_ADDED_IN_VERSION(2, 3) |
41 | |
42 | public: |
43 | explicit QQuickImageSelector(QObject *parent = nullptr); |
44 | |
45 | QUrl source() const; |
46 | void setSource(const QUrl &source); |
47 | |
48 | QString name() const; |
49 | void setName(const QString &name); |
50 | |
51 | QString path() const; |
52 | void setPath(const QString &path); |
53 | |
54 | QVariantList states() const; |
55 | void setStates(const QVariantList &states); |
56 | |
57 | QString separator() const; |
58 | void setSeparator(const QString &separator); |
59 | |
60 | bool cache() const; |
61 | void setCache(bool cache); |
62 | |
63 | void write(const QVariant &value) override; |
64 | void setTarget(const QQmlProperty &property) override; |
65 | |
66 | Q_SIGNALS: |
67 | void sourceChanged(); |
68 | |
69 | protected: |
70 | void classBegin() override; |
71 | void componentComplete() override; |
72 | |
73 | virtual QStringList fileExtensions() const; |
74 | |
75 | QString cacheKey() const; |
76 | void updateSource(); |
77 | void setUrl(const QUrl &url); |
78 | bool updateActiveStates(); |
79 | int calculateScore(const QStringList &states) const; |
80 | |
81 | private: |
82 | bool m_cache = false; |
83 | bool m_complete = false; |
84 | QUrl m_source; |
85 | QString m_path; |
86 | QString m_name; |
87 | QString m_separator = QLatin1String("-"); |
88 | QVariantList m_allStates; |
89 | QStringList m_activeStates; |
90 | QQmlProperty m_property; |
91 | }; |
92 | |
93 | class QQuickNinePatchImageSelector : public QQuickImageSelector |
94 | { |
95 | Q_OBJECT |
96 | QML_NAMED_ELEMENT(NinePatchImageSelector) |
97 | QML_ADDED_IN_VERSION(2, 3) |
98 | |
99 | public: |
100 | explicit QQuickNinePatchImageSelector(QObject *parent = nullptr); |
101 | |
102 | protected: |
103 | QStringList fileExtensions() const override; |
104 | }; |
105 | |
106 | class QQuickAnimatedImageSelector : public QQuickImageSelector |
107 | { |
108 | Q_OBJECT |
109 | QML_NAMED_ELEMENT(AnimatedImageSelector) |
110 | QML_ADDED_IN_VERSION(2, 3) |
111 | |
112 | public: |
113 | explicit QQuickAnimatedImageSelector(QObject *parent = nullptr); |
114 | |
115 | protected: |
116 | QStringList fileExtensions() const override; |
117 | }; |
118 | |
119 | QT_END_NAMESPACE |
120 | |
121 | QML_DECLARE_TYPE(QQuickImageSelector) |
122 | QML_DECLARE_TYPE(QQuickAnimatedImageSelector) |
123 | |
124 | #endif // QQUICKIMAGESELECTOR_P_H |
125 |