Qt 4.8
qdeclarativeitem_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative 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 #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 
77 
78 class QNetworkReply;
81 
82 //### merge into private?
84 {
85  Q_OBJECT
86 public:
89 
90  QRectF rectF() const;
91 
92  void childRemoved(QDeclarativeItem *item);
93  void childAdded(QDeclarativeItem *item);
94 
96  void complete();
97 
98 Q_SIGNALS:
99  void rectChanged(QRectF);
100 
101 protected:
102  void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
103  void itemDestroyed(QDeclarativeItem *item);
104  //void itemVisibilityChanged(QDeclarativeItem *item)
105 
106 private:
107  void calcHeight(QDeclarativeItem *changed = 0);
108  void calcWidth(QDeclarativeItem *changed = 0);
109 
115 };
116 
118 {
120 
121 public:
123  : _anchors(0), _contents(0),
124  baselineOffset(0),
125  _anchorLines(0),
126  _stateGroup(0), origin(QDeclarativeItem::Center),
127  widthValid(false), heightValid(false),
128  componentComplete(true), keepMouse(false),
129  smooth(false), transformOriginDirty(true), doneEventPreHandler(false),
130  inheritedLayoutMirror(false), effectiveLayoutMirror(false), isMirrorImplicit(true),
131  inheritMirrorFromParent(false), inheritMirrorFromItem(false), hadFocus(false), hadActiveFocus(false), keyHandler(0),
132  mWidth(0), mHeight(0), mImplicitWidth(0), mImplicitHeight(0), attachedLayoutDirection(0)
133  {
135  isDeclarativeItem = 1;
136  QGraphicsItemPrivate::flags = QGraphicsItem::GraphicsItemFlags(
140  }
141 
143  {
145  if (parent) {
147  q->setParentItem(parent);
148  QDeclarativeItemPrivate *parentPrivate = QDeclarativeItemPrivate::get(parent);
149  setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
150  }
151  baselineOffset.invalidate();
152  mouseSetsFocus = false;
153  }
154 
155  bool isMirrored() const {
156  return effectiveLayoutMirror;
157  }
158 
159  // Private Properties
160  qreal width() const;
161  void setWidth(qreal);
162  void resetWidth();
163 
164  qreal height() const;
165  void setHeight(qreal);
166  void resetHeight();
167 
168  virtual qreal implicitWidth() const;
169  virtual qreal implicitHeight() const;
170  virtual void implicitWidthChanged();
171  virtual void implicitHeightChanged();
172 
173  void resolveLayoutMirror();
174  void setImplicitLayoutMirror(bool mirror, bool inherit);
175  void setLayoutMirror(bool mirror);
176 
179 
182 
183  QString state() const;
184  void setState(const QString &);
185 
188  QDeclarativeAnchorLine horizontalCenter() const;
189  QDeclarativeAnchorLine top() const;
190  QDeclarativeAnchorLine bottom() const;
191  QDeclarativeAnchorLine verticalCenter() const;
192  QDeclarativeAnchorLine baseline() const;
193 
194  // data property
195  static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
196  static int data_count(QDeclarativeListProperty<QObject> *);
197  static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
198  static void data_clear(QDeclarativeListProperty<QObject> *);
199 
200  // resources property
201  static QObject *resources_at(QDeclarativeListProperty<QObject> *, int);
202  static void resources_append(QDeclarativeListProperty<QObject> *, QObject *);
203  static int resources_count(QDeclarativeListProperty<QObject> *);
204  static void resources_clear(QDeclarativeListProperty<QObject> *);
205 
206  // transform property
207  static int transform_count(QDeclarativeListProperty<QGraphicsTransform> *list);
208  static void transform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *);
209  static QGraphicsTransform *transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int);
210  static void transform_clear(QDeclarativeListProperty<QGraphicsTransform> *list);
211 
213  {
214  return item->d_func();
215  }
216 
217  // Accelerated property accessors
219  static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e);
220 
222  if (!_anchors) {
224  _anchors = new QDeclarativeAnchors(q);
225  if (!componentComplete)
226  _anchors->classBegin();
227  }
228  return _anchors;
229  }
232 
234 
235  struct AnchorLines {
244  };
247  Q_Q(const QDeclarativeItem);
248  if (!_anchorLines) _anchorLines =
249  new AnchorLines(const_cast<QDeclarativeItem *>(q));
250  return _anchorLines;
251  }
252 
253  enum ChangeType {
254  Geometry = 0x01,
255  SiblingOrder = 0x02,
256  Visibility = 0x04,
257  Opacity = 0x08,
258  Destroyed = 0x10
259  };
260 
261  Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
262 
263  struct ChangeListener {
264  ChangeListener(QDeclarativeItemChangeListener *l, QDeclarativeItemPrivate::ChangeTypes t) : listener(l), types(t) {}
266  QDeclarativeItemPrivate::ChangeTypes types;
267  bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
268  };
269 
271  changeListeners.append(ChangeListener(listener, types));
272  }
273  void removeItemChangeListener(QDeclarativeItemChangeListener *, ChangeTypes types);
275 
276  QDeclarativeStateGroup *_states();
278 
280  bool widthValid:1;
281  bool heightValid:1;
283  bool keepMouse:1;
284  bool smooth:1;
292  bool hadFocus:1;
294 
296 
301 
303 
304 
305  QPointF computeTransformOrigin() const;
306 
307  virtual void setPosHelper(const QPointF &pos)
308  {
310  QRectF oldGeometry(this->pos.x(), this->pos.y(), mWidth, mHeight);
312  q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), mWidth, mHeight), oldGeometry);
313  }
314 
315  // Reimplemented from QGraphicsItemPrivate
316  virtual void focusScopeItemChange(bool isSubFocusItem)
317  {
318  if (hadFocus != isSubFocusItem) {
319  hadFocus = isSubFocusItem;
320  emit q_func()->focusChanged(isSubFocusItem);
321  }
322  }
323 
324  // Reimplemented from QGraphicsItemPrivate
325  virtual void siblingOrderChange()
326  {
328  for(int ii = 0; ii < changeListeners.count(); ++ii) {
329  const QDeclarativeItemPrivate::ChangeListener &change = changeListeners.at(ii);
332  }
333  }
334  }
335 
336  // Reimplemented from QGraphicsItemPrivate
337  virtual void transformChanged();
338 
339  virtual void focusChanged(bool);
340 
341  virtual void mirrorChange() {};
342 
343  static qint64 consistentTime;
344  static void setConsistentTime(qint64 t);
345  static void start(QElapsedTimer &);
346  static qint64 elapsed(QElapsedTimer &);
347  static qint64 restart(QElapsedTimer &);
348 };
349 
350 /*
351  Key filters can be installed on a QDeclarativeItem, but not removed. Currently they
352  are only used by attached objects (which are only destroyed on Item
353  destruction), so this isn't a problem. If in future this becomes any form
354  of public API, they will have to support removal too.
355 */
357 {
358 public:
360  virtual ~QDeclarativeItemKeyFilter();
361 
362  virtual void keyPressed(QKeyEvent *event, bool post);
363  virtual void keyReleased(QKeyEvent *event, bool post);
364  virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
365  virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
366  virtual void componentComplete();
367 
369 
370 private:
372 };
373 
375 {
376 public:
378  : QObjectPrivate(), left(0), right(0), up(0), down(0), tab(0), backtab(0) {}
379 
386 };
387 
389 {
390  Q_OBJECT
392 
399  Priority priority;
400 
402 
403 public:
405 
406  QDeclarativeItem *left() const;
407  void setLeft(QDeclarativeItem *);
408  QDeclarativeItem *right() const;
409  void setRight(QDeclarativeItem *);
410  QDeclarativeItem *up() const;
411  void setUp(QDeclarativeItem *);
412  QDeclarativeItem *down() const;
413  void setDown(QDeclarativeItem *);
414  QDeclarativeItem *tab() const;
415  void setTab(QDeclarativeItem *);
416  QDeclarativeItem *backtab() const;
417  void setBacktab(QDeclarativeItem *);
418 
419  enum Priority { BeforeItem, AfterItem };
420  Priority priority() const;
421  void setPriority(Priority);
422 
423  static QDeclarativeKeyNavigationAttached *qmlAttachedProperties(QObject *);
424 
425 Q_SIGNALS:
426  void leftChanged();
427  void rightChanged();
428  void upChanged();
429  void downChanged();
430  void tabChanged();
431  void backtabChanged();
432  void priorityChanged();
433 
434 private:
435  virtual void keyPressed(QKeyEvent *event, bool post);
436  virtual void keyReleased(QKeyEvent *event, bool post);
437  void setFocusNavigation(QDeclarativeItem *currentItem, const char *dir);
438 };
439 
441 {
442  Q_OBJECT
443  bool enabled;
445 
446 public:
448 
449  bool enabled() const;
450  void setEnabled(bool);
451  void resetEnabled();
452 
453  bool childrenInherit() const;
454  void setChildrenInherit(bool);
455 
456  static QDeclarativeLayoutMirroringAttached *qmlAttachedProperties(QObject *);
457 Q_SIGNALS:
458  void enabledChanged();
459  void childrenInheritChanged();
460 private:
463 };
464 
466 {
467 public:
469  : QObjectPrivate(), inPress(false), inRelease(false)
470  , inIM(false), enabled(true), imeItem(0), item(0)
471  {}
472 
473  bool isConnected(const char *signalName);
474 
476  {
477  QGraphicsItem *fp;
478  while ((fp = item->focusProxy()))
479  item = fp;
480  return item;
481  }
482 
483  //loop detection
484  bool inPress:1;
485  bool inRelease:1;
486  bool inIM:1;
487 
488  bool enabled : 1;
489 
493 };
494 
496 {
497  Q_OBJECT
499 
500  bool enabled;
502  Priority priority;
503 
505 
506 public:
509 
510  bool enabled() const { Q_D(const QDeclarativeKeysAttached); return d->enabled; }
511  void setEnabled(bool enabled) {
513  if (enabled != d->enabled) {
514  d->enabled = enabled;
515  emit enabledChanged();
516  }
517  }
518 
519  enum Priority { BeforeItem, AfterItem};
520  Priority priority() const;
521  void setPriority(Priority);
522 
525  return QDeclarativeListProperty<QDeclarativeItem>(this, d->targets);
526  }
527 
528  virtual void componentComplete();
529 
530  static QDeclarativeKeysAttached *qmlAttachedProperties(QObject *);
531 
532 Q_SIGNALS:
533  void enabledChanged();
534  void priorityChanged();
535  void pressed(QDeclarativeKeyEvent *event);
536  void released(QDeclarativeKeyEvent *event);
537  void digit0Pressed(QDeclarativeKeyEvent *event);
538  void digit1Pressed(QDeclarativeKeyEvent *event);
539  void digit2Pressed(QDeclarativeKeyEvent *event);
540  void digit3Pressed(QDeclarativeKeyEvent *event);
541  void digit4Pressed(QDeclarativeKeyEvent *event);
542  void digit5Pressed(QDeclarativeKeyEvent *event);
543  void digit6Pressed(QDeclarativeKeyEvent *event);
544  void digit7Pressed(QDeclarativeKeyEvent *event);
545  void digit8Pressed(QDeclarativeKeyEvent *event);
546  void digit9Pressed(QDeclarativeKeyEvent *event);
547 
548  void leftPressed(QDeclarativeKeyEvent *event);
549  void rightPressed(QDeclarativeKeyEvent *event);
550  void upPressed(QDeclarativeKeyEvent *event);
551  void downPressed(QDeclarativeKeyEvent *event);
552  void tabPressed(QDeclarativeKeyEvent *event);
553  void backtabPressed(QDeclarativeKeyEvent *event);
554 
555  void asteriskPressed(QDeclarativeKeyEvent *event);
556  void numberSignPressed(QDeclarativeKeyEvent *event);
557  void escapePressed(QDeclarativeKeyEvent *event);
558  void returnPressed(QDeclarativeKeyEvent *event);
559  void enterPressed(QDeclarativeKeyEvent *event);
560  void deletePressed(QDeclarativeKeyEvent *event);
561  void spacePressed(QDeclarativeKeyEvent *event);
562  void backPressed(QDeclarativeKeyEvent *event);
563  void cancelPressed(QDeclarativeKeyEvent *event);
564  void selectPressed(QDeclarativeKeyEvent *event);
565  void yesPressed(QDeclarativeKeyEvent *event);
566  void noPressed(QDeclarativeKeyEvent *event);
567  void context1Pressed(QDeclarativeKeyEvent *event);
568  void context2Pressed(QDeclarativeKeyEvent *event);
569  void context3Pressed(QDeclarativeKeyEvent *event);
570  void context4Pressed(QDeclarativeKeyEvent *event);
571  void callPressed(QDeclarativeKeyEvent *event);
572  void hangupPressed(QDeclarativeKeyEvent *event);
573  void flipPressed(QDeclarativeKeyEvent *event);
574  void menuPressed(QDeclarativeKeyEvent *event);
575  void volumeUpPressed(QDeclarativeKeyEvent *event);
576  void volumeDownPressed(QDeclarativeKeyEvent *event);
577 
578 private:
579  virtual void keyPressed(QKeyEvent *event, bool post);
580  virtual void keyReleased(QKeyEvent *event, bool post);
581  virtual void inputMethodEvent(QInputMethodEvent *, bool post);
582  virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
583 
585  QByteArray keySignal;
586  if (key >= Qt::Key_0 && key <= Qt::Key_9) {
587  keySignal = "digit0Pressed";
588  keySignal[5] = '0' + (key - Qt::Key_0);
589  } else {
590  int i = 0;
591  while (sigMap[i].key && sigMap[i].key != key)
592  ++i;
593  keySignal = sigMap[i].sig;
594  }
595  return keySignal;
596  }
597 
598  struct SigMap {
599  int key;
600  const char *sig;
601  };
602 
603  static const SigMap sigMap[];
604 };
605 
606 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeItemPrivate::ChangeTypes);
607 
609 
616 
617 #endif // QDECLARATIVEITEM_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
const T & at(int idx) const
Definition: qpodvector_p.h:69
double d
Definition: qnumeric_p.h:62
QGraphicsItem * finalFocusProxy(QGraphicsItem *item) const
The QKeyEvent class describes a key event.
Definition: qevent.h:224
double qreal
Definition: qglobal.h:1193
static double elapsed(qint64 after, qint64 before)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void calcHeight(QDeclarativeItem *changed=0)
QDeclarativeItemKeyFilter * m_next
#define QML_DECLARE_TYPE(TYPE)
Definition: qdeclarative.h:56
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
virtual void siblingOrderChange()
Subclasses can reimplement this function to be notified when its siblingIndex order is changed...
QDeclarativeAnchors * anchors()
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QDeclarativeItem * m_item
QDeclarativeListProperty< QDeclarativeItem > forwardTo()
QGraphicsItem * focusProxy() const
Returns this item&#39;s focus proxy, or 0 if this item has no focus proxy.
void childAdded(QDeclarativeItem *item)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDeclarativeItemPrivate * itemPrivate
void rectChanged(QRectF)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_D(Class)
Definition: qglobal.h:2482
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
virtual void setPosHelper(const QPointF &pos)
Sets the position pos.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void init(QDeclarativeItem *parent)
QDeclarativeContents(QDeclarativeItem *item)
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QDeclarativeItem * > targets
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
QDeclarativeAnchors * _anchors
#define QML_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition: qdeclarative.h:73
virtual void itemSiblingOrderChanged(QDeclarativeItem *)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDeclarativeItemPrivate::ChangeTypes types
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool operator==(const ChangeListener &other) const
The QDeclarativeItem class provides the most basic of all visual items in QML.
void addItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types)
void calcWidth(QDeclarativeItem *changed=0)
#define emit
Definition: qobjectdefs.h:76
static QDeclarativeItemPrivate * get(QDeclarativeItem *item)
static const char * data(const QByteArray &arr)
void childRemoved(QDeclarativeItem *item)
QDeclarativeLayoutMirroringAttached * attachedLayoutDirection
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry)
__int64 qint64
Definition: qglobal.h:942
QDeclarativeItem::TransformOrigin origin
#define Q_OBJECT
Definition: qobjectdefs.h:157
QPODVector< ChangeListener, 4 > changeListeners
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
#define Q_DECLARATIVE_EXPORT
Definition: qglobal.h:1454
TransformOrigin
Controls the point about which simple transforms like scale apply.
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
static const struct @32 types[]
QDeclarativeNullableValue< qreal > baselineOffset
void QDeclarative_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
int key
QDeclarativeNotifier parentNotifier
ChangeListener(QDeclarativeItemChangeListener *l, QDeclarativeItemPrivate::ChangeTypes t)
QFactoryLoader * l
int count() const
Definition: qpodvector_p.h:148
AnchorLines * anchorLines() const
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QDeclarativeItemKeyFilter * keyHandler
void setEnabled(bool enabled)
virtual void focusScopeItemChange(bool isSubFocusItem)
Subclasses can reimplement this function to be notified when an item becomes a focusScopeItem (or is ...
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
QDeclarativeStateGroup * _stateGroup
static QNSListener * listener
Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeItemPrivate::ChangeTypes)
const QByteArray keyToSignal(int key)
The QGraphicsObject class provides a base class for all graphics items that require signals...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void itemDestroyed(QDeclarativeItem *item)
QDeclarativeItemChangeListener * listener
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...
#define enabled
virtual void setPosHelper(const QPointF &pos)
Sets the position pos.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QDeclarativeContents * _contents