1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QDECLARATIVEITEM_P_H
|
---|
43 | #define QDECLARATIVEITEM_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "qdeclarativeitem.h"
|
---|
57 |
|
---|
58 | #include "private/qdeclarativeanchors_p.h"
|
---|
59 | #include "private/qdeclarativeanchors_p_p.h"
|
---|
60 | #include "private/qdeclarativeitemchangelistener_p.h"
|
---|
61 | #include <private/qpodvector_p.h>
|
---|
62 |
|
---|
63 | #include <private/qdeclarativestate_p.h>
|
---|
64 | #include <private/qdeclarativenullablevalue_p_p.h>
|
---|
65 | #include <private/qdeclarativenotifier_p.h>
|
---|
66 | #include <private/qdeclarativeglobal_p.h>
|
---|
67 |
|
---|
68 | #include <qdeclarative.h>
|
---|
69 | #include <qdeclarativecontext.h>
|
---|
70 |
|
---|
71 | #include <QtCore/qlist.h>
|
---|
72 | #include <QtCore/qdebug.h>
|
---|
73 |
|
---|
74 | #include <private/qgraphicsitem_p.h>
|
---|
75 |
|
---|
76 | QT_BEGIN_NAMESPACE
|
---|
77 |
|
---|
78 | class QNetworkReply;
|
---|
79 | class QDeclarativeItemKeyFilter;
|
---|
80 |
|
---|
81 | //### merge into private?
|
---|
82 | class QDeclarativeContents : public QObject, public QDeclarativeItemChangeListener
|
---|
83 | {
|
---|
84 | Q_OBJECT
|
---|
85 | public:
|
---|
86 | QDeclarativeContents(QDeclarativeItem *item);
|
---|
87 | ~QDeclarativeContents();
|
---|
88 |
|
---|
89 | QRectF rectF() const;
|
---|
90 |
|
---|
91 | void childRemoved(QDeclarativeItem *item);
|
---|
92 | void childAdded(QDeclarativeItem *item);
|
---|
93 |
|
---|
94 | void calcGeometry() { calcWidth(); calcHeight(); }
|
---|
95 | void complete();
|
---|
96 |
|
---|
97 | Q_SIGNALS:
|
---|
98 | void rectChanged(QRectF);
|
---|
99 |
|
---|
100 | protected:
|
---|
101 | void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
|
---|
102 | void itemDestroyed(QDeclarativeItem *item);
|
---|
103 | //void itemVisibilityChanged(QDeclarativeItem *item)
|
---|
104 |
|
---|
105 | private:
|
---|
106 | void calcHeight(QDeclarativeItem *changed = 0);
|
---|
107 | void calcWidth(QDeclarativeItem *changed = 0);
|
---|
108 |
|
---|
109 | QDeclarativeItem *m_item;
|
---|
110 | qreal m_x;
|
---|
111 | qreal m_y;
|
---|
112 | qreal m_width;
|
---|
113 | qreal m_height;
|
---|
114 | };
|
---|
115 |
|
---|
116 | class Q_DECLARATIVE_EXPORT QDeclarativeItemPrivate : public QGraphicsItemPrivate
|
---|
117 | {
|
---|
118 | Q_DECLARE_PUBLIC(QDeclarativeItem)
|
---|
119 |
|
---|
120 | public:
|
---|
121 | QDeclarativeItemPrivate()
|
---|
122 | : _anchors(0), _contents(0),
|
---|
123 | baselineOffset(0),
|
---|
124 | _anchorLines(0),
|
---|
125 | _stateGroup(0), origin(QDeclarativeItem::Center),
|
---|
126 | widthValid(false), heightValid(false),
|
---|
127 | componentComplete(true), keepMouse(false),
|
---|
128 | smooth(false), transformOriginDirty(true), doneEventPreHandler(false), keyHandler(0),
|
---|
129 | mWidth(0), mHeight(0), implicitWidth(0), implicitHeight(0), hadSubFocusItem(false)
|
---|
130 | {
|
---|
131 | QGraphicsItemPrivate::acceptedMouseButtons = 0;
|
---|
132 | isDeclarativeItem = 1;
|
---|
133 | QGraphicsItemPrivate::flags = QGraphicsItem::GraphicsItemFlags(
|
---|
134 | QGraphicsItem::ItemHasNoContents
|
---|
135 | | QGraphicsItem::ItemIsFocusable
|
---|
136 | | QGraphicsItem::ItemNegativeZStacksBehindParent);
|
---|
137 |
|
---|
138 | }
|
---|
139 |
|
---|
140 | void init(QDeclarativeItem *parent)
|
---|
141 | {
|
---|
142 | Q_Q(QDeclarativeItem);
|
---|
143 | if (parent) {
|
---|
144 | QDeclarative_setParent_noEvent(q, parent);
|
---|
145 | q->setParentItem(parent);
|
---|
146 | }
|
---|
147 | baselineOffset.invalidate();
|
---|
148 | mouseSetsFocus = false;
|
---|
149 | }
|
---|
150 |
|
---|
151 | // Private Properties
|
---|
152 | qreal width() const;
|
---|
153 | void setWidth(qreal);
|
---|
154 | void resetWidth();
|
---|
155 |
|
---|
156 | qreal height() const;
|
---|
157 | void setHeight(qreal);
|
---|
158 | void resetHeight();
|
---|
159 |
|
---|
160 | QDeclarativeListProperty<QObject> data();
|
---|
161 | QDeclarativeListProperty<QObject> resources();
|
---|
162 |
|
---|
163 | QDeclarativeListProperty<QDeclarativeState> states();
|
---|
164 | QDeclarativeListProperty<QDeclarativeTransition> transitions();
|
---|
165 |
|
---|
166 | QString state() const;
|
---|
167 | void setState(const QString &);
|
---|
168 |
|
---|
169 | QDeclarativeAnchorLine left() const;
|
---|
170 | QDeclarativeAnchorLine right() const;
|
---|
171 | QDeclarativeAnchorLine horizontalCenter() const;
|
---|
172 | QDeclarativeAnchorLine top() const;
|
---|
173 | QDeclarativeAnchorLine bottom() const;
|
---|
174 | QDeclarativeAnchorLine verticalCenter() const;
|
---|
175 | QDeclarativeAnchorLine baseline() const;
|
---|
176 |
|
---|
177 | // data property
|
---|
178 | static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
|
---|
179 | static int data_count(QDeclarativeListProperty<QObject> *);
|
---|
180 | static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
|
---|
181 | static void data_clear(QDeclarativeListProperty<QObject> *);
|
---|
182 |
|
---|
183 | // resources property
|
---|
184 | static QObject *resources_at(QDeclarativeListProperty<QObject> *, int);
|
---|
185 | static void resources_append(QDeclarativeListProperty<QObject> *, QObject *);
|
---|
186 | static int resources_count(QDeclarativeListProperty<QObject> *);
|
---|
187 | static void resources_clear(QDeclarativeListProperty<QObject> *);
|
---|
188 |
|
---|
189 | // transform property
|
---|
190 | static int transform_count(QDeclarativeListProperty<QGraphicsTransform> *list);
|
---|
191 | static void transform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *);
|
---|
192 | static QGraphicsTransform *transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int);
|
---|
193 | static void transform_clear(QDeclarativeListProperty<QGraphicsTransform> *list);
|
---|
194 |
|
---|
195 | static QDeclarativeItemPrivate* get(QDeclarativeItem *item)
|
---|
196 | {
|
---|
197 | return item->d_func();
|
---|
198 | }
|
---|
199 |
|
---|
200 | // Accelerated property accessors
|
---|
201 | QDeclarativeNotifier parentNotifier;
|
---|
202 | static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e);
|
---|
203 |
|
---|
204 | QDeclarativeAnchors *anchors() {
|
---|
205 | if (!_anchors) {
|
---|
206 | Q_Q(QDeclarativeItem);
|
---|
207 | _anchors = new QDeclarativeAnchors(q);
|
---|
208 | if (!componentComplete)
|
---|
209 | _anchors->classBegin();
|
---|
210 | }
|
---|
211 | return _anchors;
|
---|
212 | }
|
---|
213 | QDeclarativeAnchors *_anchors;
|
---|
214 | QDeclarativeContents *_contents;
|
---|
215 |
|
---|
216 | QDeclarativeNullableValue<qreal> baselineOffset;
|
---|
217 |
|
---|
218 | struct AnchorLines {
|
---|
219 | AnchorLines(QGraphicsObject *);
|
---|
220 | QDeclarativeAnchorLine left;
|
---|
221 | QDeclarativeAnchorLine right;
|
---|
222 | QDeclarativeAnchorLine hCenter;
|
---|
223 | QDeclarativeAnchorLine top;
|
---|
224 | QDeclarativeAnchorLine bottom;
|
---|
225 | QDeclarativeAnchorLine vCenter;
|
---|
226 | QDeclarativeAnchorLine baseline;
|
---|
227 | };
|
---|
228 | mutable AnchorLines *_anchorLines;
|
---|
229 | AnchorLines *anchorLines() const {
|
---|
230 | Q_Q(const QDeclarativeItem);
|
---|
231 | if (!_anchorLines) _anchorLines =
|
---|
232 | new AnchorLines(const_cast<QDeclarativeItem *>(q));
|
---|
233 | return _anchorLines;
|
---|
234 | }
|
---|
235 |
|
---|
236 | enum ChangeType {
|
---|
237 | Geometry = 0x01,
|
---|
238 | SiblingOrder = 0x02,
|
---|
239 | Visibility = 0x04,
|
---|
240 | Opacity = 0x08,
|
---|
241 | Destroyed = 0x10
|
---|
242 | };
|
---|
243 |
|
---|
244 | Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
|
---|
245 |
|
---|
246 | struct ChangeListener {
|
---|
247 | ChangeListener(QDeclarativeItemChangeListener *l, QDeclarativeItemPrivate::ChangeTypes t) : listener(l), types(t) {}
|
---|
248 | QDeclarativeItemChangeListener *listener;
|
---|
249 | QDeclarativeItemPrivate::ChangeTypes types;
|
---|
250 | bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
|
---|
251 | };
|
---|
252 |
|
---|
253 | void addItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types) {
|
---|
254 | changeListeners.append(ChangeListener(listener, types));
|
---|
255 | }
|
---|
256 | void removeItemChangeListener(QDeclarativeItemChangeListener *, ChangeTypes types);
|
---|
257 | QPODVector<ChangeListener,4> changeListeners;
|
---|
258 |
|
---|
259 | QDeclarativeStateGroup *_states();
|
---|
260 | QDeclarativeStateGroup *_stateGroup;
|
---|
261 |
|
---|
262 | QDeclarativeItem::TransformOrigin origin:5;
|
---|
263 | bool widthValid:1;
|
---|
264 | bool heightValid:1;
|
---|
265 | bool componentComplete:1;
|
---|
266 | bool keepMouse:1;
|
---|
267 | bool smooth:1;
|
---|
268 | bool transformOriginDirty : 1;
|
---|
269 | bool doneEventPreHandler : 1;
|
---|
270 |
|
---|
271 | QDeclarativeItemKeyFilter *keyHandler;
|
---|
272 |
|
---|
273 | qreal mWidth;
|
---|
274 | qreal mHeight;
|
---|
275 | qreal implicitWidth;
|
---|
276 | qreal implicitHeight;
|
---|
277 |
|
---|
278 | bool hadSubFocusItem;
|
---|
279 |
|
---|
280 | QPointF computeTransformOrigin() const;
|
---|
281 |
|
---|
282 | virtual void setPosHelper(const QPointF &pos)
|
---|
283 | {
|
---|
284 | Q_Q(QDeclarativeItem);
|
---|
285 | QRectF oldGeometry(this->pos.x(), this->pos.y(), mWidth, mHeight);
|
---|
286 | QGraphicsItemPrivate::setPosHelper(pos);
|
---|
287 | q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), mWidth, mHeight), oldGeometry);
|
---|
288 | }
|
---|
289 |
|
---|
290 | // Reimplemented from QGraphicsItemPrivate
|
---|
291 | virtual void subFocusItemChange()
|
---|
292 | {
|
---|
293 | bool hasSubFocusItem = subFocusItem != 0;
|
---|
294 | if (((flags & QGraphicsItem::ItemIsFocusScope) || !parent) && hasSubFocusItem != hadSubFocusItem)
|
---|
295 | emit q_func()->activeFocusChanged(hasSubFocusItem);
|
---|
296 | //see also QDeclarativeItemPrivate::focusChanged
|
---|
297 | hadSubFocusItem = hasSubFocusItem;
|
---|
298 | }
|
---|
299 |
|
---|
300 | // Reimplemented from QGraphicsItemPrivate
|
---|
301 | virtual void focusScopeItemChange(bool isSubFocusItem)
|
---|
302 | {
|
---|
303 | emit q_func()->focusChanged(isSubFocusItem);
|
---|
304 | }
|
---|
305 |
|
---|
306 |
|
---|
307 | // Reimplemented from QGraphicsItemPrivate
|
---|
308 | virtual void siblingOrderChange()
|
---|
309 | {
|
---|
310 | Q_Q(QDeclarativeItem);
|
---|
311 | for(int ii = 0; ii < changeListeners.count(); ++ii) {
|
---|
312 | const QDeclarativeItemPrivate::ChangeListener &change = changeListeners.at(ii);
|
---|
313 | if (change.types & QDeclarativeItemPrivate::SiblingOrder) {
|
---|
314 | change.listener->itemSiblingOrderChanged(q);
|
---|
315 | }
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 | // Reimplemented from QGraphicsItemPrivate
|
---|
320 | virtual void transformChanged();
|
---|
321 |
|
---|
322 | virtual void focusChanged(bool);
|
---|
323 |
|
---|
324 | static qint64 consistentTime;
|
---|
325 | static void setConsistentTime(qint64 t);
|
---|
326 | static void start(QElapsedTimer &);
|
---|
327 | static qint64 elapsed(QElapsedTimer &);
|
---|
328 | static qint64 restart(QElapsedTimer &);
|
---|
329 | };
|
---|
330 |
|
---|
331 | /*
|
---|
332 | Key filters can be installed on a QDeclarativeItem, but not removed. Currently they
|
---|
333 | are only used by attached objects (which are only destroyed on Item
|
---|
334 | destruction), so this isn't a problem. If in future this becomes any form
|
---|
335 | of public API, they will have to support removal too.
|
---|
336 | */
|
---|
337 | class QDeclarativeItemKeyFilter
|
---|
338 | {
|
---|
339 | public:
|
---|
340 | QDeclarativeItemKeyFilter(QDeclarativeItem * = 0);
|
---|
341 | virtual ~QDeclarativeItemKeyFilter();
|
---|
342 |
|
---|
343 | virtual void keyPressed(QKeyEvent *event, bool post);
|
---|
344 | virtual void keyReleased(QKeyEvent *event, bool post);
|
---|
345 | virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
|
---|
346 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
|
---|
347 | virtual void componentComplete();
|
---|
348 |
|
---|
349 | bool m_processPost;
|
---|
350 |
|
---|
351 | private:
|
---|
352 | QDeclarativeItemKeyFilter *m_next;
|
---|
353 | };
|
---|
354 |
|
---|
355 | class QDeclarativeKeyNavigationAttachedPrivate : public QObjectPrivate
|
---|
356 | {
|
---|
357 | public:
|
---|
358 | QDeclarativeKeyNavigationAttachedPrivate()
|
---|
359 | : QObjectPrivate(), left(0), right(0), up(0), down(0), tab(0), backtab(0) {}
|
---|
360 |
|
---|
361 | QDeclarativeItem *left;
|
---|
362 | QDeclarativeItem *right;
|
---|
363 | QDeclarativeItem *up;
|
---|
364 | QDeclarativeItem *down;
|
---|
365 | QDeclarativeItem *tab;
|
---|
366 | QDeclarativeItem *backtab;
|
---|
367 | };
|
---|
368 |
|
---|
369 | class QDeclarativeKeyNavigationAttached : public QObject, public QDeclarativeItemKeyFilter
|
---|
370 | {
|
---|
371 | Q_OBJECT
|
---|
372 | Q_DECLARE_PRIVATE(QDeclarativeKeyNavigationAttached)
|
---|
373 |
|
---|
374 | Q_PROPERTY(QDeclarativeItem *left READ left WRITE setLeft NOTIFY leftChanged)
|
---|
375 | Q_PROPERTY(QDeclarativeItem *right READ right WRITE setRight NOTIFY rightChanged)
|
---|
376 | Q_PROPERTY(QDeclarativeItem *up READ up WRITE setUp NOTIFY upChanged)
|
---|
377 | Q_PROPERTY(QDeclarativeItem *down READ down WRITE setDown NOTIFY downChanged)
|
---|
378 | Q_PROPERTY(QDeclarativeItem *tab READ tab WRITE setTab NOTIFY tabChanged)
|
---|
379 | Q_PROPERTY(QDeclarativeItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged)
|
---|
380 | Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
|
---|
381 |
|
---|
382 | Q_ENUMS(Priority)
|
---|
383 |
|
---|
384 | public:
|
---|
385 | QDeclarativeKeyNavigationAttached(QObject * = 0);
|
---|
386 |
|
---|
387 | QDeclarativeItem *left() const;
|
---|
388 | void setLeft(QDeclarativeItem *);
|
---|
389 | QDeclarativeItem *right() const;
|
---|
390 | void setRight(QDeclarativeItem *);
|
---|
391 | QDeclarativeItem *up() const;
|
---|
392 | void setUp(QDeclarativeItem *);
|
---|
393 | QDeclarativeItem *down() const;
|
---|
394 | void setDown(QDeclarativeItem *);
|
---|
395 | QDeclarativeItem *tab() const;
|
---|
396 | void setTab(QDeclarativeItem *);
|
---|
397 | QDeclarativeItem *backtab() const;
|
---|
398 | void setBacktab(QDeclarativeItem *);
|
---|
399 |
|
---|
400 | enum Priority { BeforeItem, AfterItem };
|
---|
401 | Priority priority() const;
|
---|
402 | void setPriority(Priority);
|
---|
403 |
|
---|
404 | static QDeclarativeKeyNavigationAttached *qmlAttachedProperties(QObject *);
|
---|
405 |
|
---|
406 | Q_SIGNALS:
|
---|
407 | void leftChanged();
|
---|
408 | void rightChanged();
|
---|
409 | void upChanged();
|
---|
410 | void downChanged();
|
---|
411 | void tabChanged();
|
---|
412 | void backtabChanged();
|
---|
413 | void priorityChanged();
|
---|
414 |
|
---|
415 | private:
|
---|
416 | virtual void keyPressed(QKeyEvent *event, bool post);
|
---|
417 | virtual void keyReleased(QKeyEvent *event, bool post);
|
---|
418 | };
|
---|
419 |
|
---|
420 | class QDeclarativeKeysAttachedPrivate : public QObjectPrivate
|
---|
421 | {
|
---|
422 | public:
|
---|
423 | QDeclarativeKeysAttachedPrivate()
|
---|
424 | : QObjectPrivate(), inPress(false), inRelease(false)
|
---|
425 | , inIM(false), enabled(true), imeItem(0), item(0)
|
---|
426 | {}
|
---|
427 |
|
---|
428 | bool isConnected(const char *signalName);
|
---|
429 |
|
---|
430 | QGraphicsItem *finalFocusProxy(QGraphicsItem *item) const
|
---|
431 | {
|
---|
432 | QGraphicsItem *fp;
|
---|
433 | while ((fp = item->focusProxy()))
|
---|
434 | item = fp;
|
---|
435 | return item;
|
---|
436 | }
|
---|
437 |
|
---|
438 | //loop detection
|
---|
439 | bool inPress:1;
|
---|
440 | bool inRelease:1;
|
---|
441 | bool inIM:1;
|
---|
442 |
|
---|
443 | bool enabled : 1;
|
---|
444 |
|
---|
445 | QGraphicsItem *imeItem;
|
---|
446 | QList<QDeclarativeItem *> targets;
|
---|
447 | QDeclarativeItem *item;
|
---|
448 | };
|
---|
449 |
|
---|
450 | class QDeclarativeKeysAttached : public QObject, public QDeclarativeItemKeyFilter
|
---|
451 | {
|
---|
452 | Q_OBJECT
|
---|
453 | Q_DECLARE_PRIVATE(QDeclarativeKeysAttached)
|
---|
454 |
|
---|
455 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
---|
456 | Q_PROPERTY(QDeclarativeListProperty<QDeclarativeItem> forwardTo READ forwardTo)
|
---|
457 | Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
|
---|
458 |
|
---|
459 | Q_ENUMS(Priority)
|
---|
460 |
|
---|
461 | public:
|
---|
462 | QDeclarativeKeysAttached(QObject *parent=0);
|
---|
463 | ~QDeclarativeKeysAttached();
|
---|
464 |
|
---|
465 | bool enabled() const { Q_D(const QDeclarativeKeysAttached); return d->enabled; }
|
---|
466 | void setEnabled(bool enabled) {
|
---|
467 | Q_D(QDeclarativeKeysAttached);
|
---|
468 | if (enabled != d->enabled) {
|
---|
469 | d->enabled = enabled;
|
---|
470 | emit enabledChanged();
|
---|
471 | }
|
---|
472 | }
|
---|
473 |
|
---|
474 | enum Priority { BeforeItem, AfterItem};
|
---|
475 | Priority priority() const;
|
---|
476 | void setPriority(Priority);
|
---|
477 |
|
---|
478 | QDeclarativeListProperty<QDeclarativeItem> forwardTo() {
|
---|
479 | Q_D(QDeclarativeKeysAttached);
|
---|
480 | return QDeclarativeListProperty<QDeclarativeItem>(this, d->targets);
|
---|
481 | }
|
---|
482 |
|
---|
483 | virtual void componentComplete();
|
---|
484 |
|
---|
485 | static QDeclarativeKeysAttached *qmlAttachedProperties(QObject *);
|
---|
486 |
|
---|
487 | Q_SIGNALS:
|
---|
488 | void enabledChanged();
|
---|
489 | void priorityChanged();
|
---|
490 | void pressed(QDeclarativeKeyEvent *event);
|
---|
491 | void released(QDeclarativeKeyEvent *event);
|
---|
492 | void digit0Pressed(QDeclarativeKeyEvent *event);
|
---|
493 | void digit1Pressed(QDeclarativeKeyEvent *event);
|
---|
494 | void digit2Pressed(QDeclarativeKeyEvent *event);
|
---|
495 | void digit3Pressed(QDeclarativeKeyEvent *event);
|
---|
496 | void digit4Pressed(QDeclarativeKeyEvent *event);
|
---|
497 | void digit5Pressed(QDeclarativeKeyEvent *event);
|
---|
498 | void digit6Pressed(QDeclarativeKeyEvent *event);
|
---|
499 | void digit7Pressed(QDeclarativeKeyEvent *event);
|
---|
500 | void digit8Pressed(QDeclarativeKeyEvent *event);
|
---|
501 | void digit9Pressed(QDeclarativeKeyEvent *event);
|
---|
502 |
|
---|
503 | void leftPressed(QDeclarativeKeyEvent *event);
|
---|
504 | void rightPressed(QDeclarativeKeyEvent *event);
|
---|
505 | void upPressed(QDeclarativeKeyEvent *event);
|
---|
506 | void downPressed(QDeclarativeKeyEvent *event);
|
---|
507 | void tabPressed(QDeclarativeKeyEvent *event);
|
---|
508 | void backtabPressed(QDeclarativeKeyEvent *event);
|
---|
509 |
|
---|
510 | void asteriskPressed(QDeclarativeKeyEvent *event);
|
---|
511 | void numberSignPressed(QDeclarativeKeyEvent *event);
|
---|
512 | void escapePressed(QDeclarativeKeyEvent *event);
|
---|
513 | void returnPressed(QDeclarativeKeyEvent *event);
|
---|
514 | void enterPressed(QDeclarativeKeyEvent *event);
|
---|
515 | void deletePressed(QDeclarativeKeyEvent *event);
|
---|
516 | void spacePressed(QDeclarativeKeyEvent *event);
|
---|
517 | void backPressed(QDeclarativeKeyEvent *event);
|
---|
518 | void cancelPressed(QDeclarativeKeyEvent *event);
|
---|
519 | void selectPressed(QDeclarativeKeyEvent *event);
|
---|
520 | void yesPressed(QDeclarativeKeyEvent *event);
|
---|
521 | void noPressed(QDeclarativeKeyEvent *event);
|
---|
522 | void context1Pressed(QDeclarativeKeyEvent *event);
|
---|
523 | void context2Pressed(QDeclarativeKeyEvent *event);
|
---|
524 | void context3Pressed(QDeclarativeKeyEvent *event);
|
---|
525 | void context4Pressed(QDeclarativeKeyEvent *event);
|
---|
526 | void callPressed(QDeclarativeKeyEvent *event);
|
---|
527 | void hangupPressed(QDeclarativeKeyEvent *event);
|
---|
528 | void flipPressed(QDeclarativeKeyEvent *event);
|
---|
529 | void menuPressed(QDeclarativeKeyEvent *event);
|
---|
530 | void volumeUpPressed(QDeclarativeKeyEvent *event);
|
---|
531 | void volumeDownPressed(QDeclarativeKeyEvent *event);
|
---|
532 |
|
---|
533 | private:
|
---|
534 | virtual void keyPressed(QKeyEvent *event, bool post);
|
---|
535 | virtual void keyReleased(QKeyEvent *event, bool post);
|
---|
536 | virtual void inputMethodEvent(QInputMethodEvent *, bool post);
|
---|
537 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
|
---|
538 |
|
---|
539 | const QByteArray keyToSignal(int key) {
|
---|
540 | QByteArray keySignal;
|
---|
541 | if (key >= Qt::Key_0 && key <= Qt::Key_9) {
|
---|
542 | keySignal = "digit0Pressed";
|
---|
543 | keySignal[5] = '0' + (key - Qt::Key_0);
|
---|
544 | } else {
|
---|
545 | int i = 0;
|
---|
546 | while (sigMap[i].key && sigMap[i].key != key)
|
---|
547 | ++i;
|
---|
548 | keySignal = sigMap[i].sig;
|
---|
549 | }
|
---|
550 | return keySignal;
|
---|
551 | }
|
---|
552 |
|
---|
553 | struct SigMap {
|
---|
554 | int key;
|
---|
555 | const char *sig;
|
---|
556 | };
|
---|
557 |
|
---|
558 | static const SigMap sigMap[];
|
---|
559 | };
|
---|
560 |
|
---|
561 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeItemPrivate::ChangeTypes);
|
---|
562 |
|
---|
563 | QT_END_NAMESPACE
|
---|
564 |
|
---|
565 | QML_DECLARE_TYPE(QDeclarativeKeysAttached)
|
---|
566 | QML_DECLARE_TYPEINFO(QDeclarativeKeysAttached, QML_HAS_ATTACHED_PROPERTIES)
|
---|
567 | QML_DECLARE_TYPE(QDeclarativeKeyNavigationAttached)
|
---|
568 | QML_DECLARE_TYPEINFO(QDeclarativeKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES)
|
---|
569 |
|
---|
570 | #endif // QDECLARATIVEITEM_P_H
|
---|