1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtDocGallery module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | // |
43 | // W A R N I N G |
44 | // ------------- |
45 | // |
46 | // This file is not part of the Qt API. It exists purely as an |
47 | // implementation detail. This header file may change from version to |
48 | // version without notice, or even be removed. |
49 | // |
50 | // We mean it. |
51 | // |
52 | |
53 | #ifndef QDECLARATIVEGALLERYITEM_H |
54 | #define QDECLARATIVEGALLERYITEM_H |
55 | |
56 | #include <qgalleryitemrequest.h> |
57 | |
58 | #include "qdeclarativedocumentgallery.h" |
59 | |
60 | #include <QtCore/qpointer.h> |
61 | #include <QtCore/qurl.h> |
62 | #include <QtQml/qqml.h> |
63 | #include <QtQml/qqmlpropertymap.h> |
64 | |
65 | QT_BEGIN_NAMESPACE_DOCGALLERY |
66 | |
67 | class QDeclarativeGalleryItem : public QObject, public QQmlParserStatus |
68 | { |
69 | Q_OBJECT |
70 | Q_INTERFACES(QQmlParserStatus) |
71 | Q_ENUMS(Status) |
72 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
73 | Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) |
74 | Q_PROPERTY(QStringList properties READ propertyNames WRITE setPropertyNames NOTIFY propertyNamesChanged) |
75 | Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged) |
76 | Q_PROPERTY(QVariant item READ itemId WRITE setItemId NOTIFY itemIdChanged) |
77 | Q_PROPERTY(bool available READ available NOTIFY availableChanged) |
78 | Q_PROPERTY(QUrl itemUrl READ itemUrl NOTIFY availableChanged) |
79 | Q_PROPERTY(QObject *metaData READ metaData NOTIFY metaDataChanged) |
80 | public: |
81 | enum Status |
82 | { |
83 | Null = QGalleryAbstractRequest::Inactive, |
84 | Active = QGalleryAbstractRequest::Active, |
85 | Canceling = QGalleryAbstractRequest::Canceling, |
86 | Canceled = QGalleryAbstractRequest::Canceled, |
87 | Idle = QGalleryAbstractRequest::Idle, |
88 | Finished = QGalleryAbstractRequest::Finished, |
89 | Error = QGalleryAbstractRequest::Error |
90 | }; |
91 | |
92 | ~QDeclarativeGalleryItem(); |
93 | |
94 | Status status() const { return m_status; } |
95 | |
96 | qreal progress() const; |
97 | |
98 | QStringList propertyNames() { return m_request.propertyNames(); } |
99 | void setPropertyNames(const QStringList &names); |
100 | |
101 | bool autoUpdate() const { return m_request.autoUpdate(); } |
102 | void setAutoUpdate(bool enabled); |
103 | |
104 | QVariant itemId() const { return m_request.itemId(); } |
105 | void setItemId(const QVariant &itemId); |
106 | |
107 | bool available() const { return m_request.isValid(); } |
108 | |
109 | QUrl itemUrl() const { return m_request.itemUrl(); } |
110 | |
111 | QObject *metaData() const { return m_metaData; } |
112 | |
113 | void componentComplete(); |
114 | |
115 | public Q_SLOTS: |
116 | void reload(); |
117 | void cancel(); |
118 | void clear(); |
119 | |
120 | Q_SIGNALS: |
121 | void statusChanged(); |
122 | void progressChanged(); |
123 | void availableChanged(); |
124 | void metaDataChanged(); |
125 | |
126 | void galleryChanged(); |
127 | void propertyNamesChanged(); |
128 | void autoUpdateChanged(); |
129 | void itemIdChanged(); |
130 | |
131 | protected: |
132 | enum UpdateStatus |
133 | { |
134 | Incomplete, |
135 | NoUpdate, |
136 | PendingUpdate, |
137 | CanceledUpdate |
138 | }; |
139 | |
140 | explicit QDeclarativeGalleryItem(QObject *parent = Q_NULLPTR); |
141 | |
142 | void deferredExecute(); |
143 | |
144 | bool event(QEvent *event); |
145 | |
146 | QGalleryItemRequest m_request; |
147 | QQmlPropertyMap *m_metaData; |
148 | QHash<int, QString> m_propertyKeys; |
149 | Status m_status; |
150 | UpdateStatus m_updateStatus; |
151 | |
152 | private Q_SLOTS: |
153 | void _q_stateChanged(); |
154 | void _q_itemChanged(); |
155 | void _q_metaDataChanged(const QList<int> &keys); |
156 | void _q_valueChanged(const QString &key, const QVariant &value) { |
157 | m_request.setMetaData(property: key, value); } |
158 | }; |
159 | |
160 | class QDeclarativeDocumentGalleryItem : public QDeclarativeGalleryItem |
161 | { |
162 | Q_OBJECT |
163 | Q_PROPERTY(QDocGallery::QDeclarativeDocumentGallery::ItemType itemType READ itemType NOTIFY itemTypeChanged) |
164 | public: |
165 | explicit QDeclarativeDocumentGalleryItem(QObject *parent = Q_NULLPTR); |
166 | ~QDeclarativeDocumentGalleryItem(); |
167 | |
168 | void classBegin(); |
169 | |
170 | QDeclarativeDocumentGallery::ItemType itemType() const; |
171 | |
172 | Q_SIGNALS: |
173 | void itemTypeChanged(); |
174 | }; |
175 | |
176 | QT_END_NAMESPACE_DOCGALLERY |
177 | |
178 | QML_DECLARE_TYPE(QT_DOCGALLERY_PREPEND_NAMESPACE(QDeclarativeDocumentGalleryItem)) |
179 | |
180 | #endif |
181 | |