src/declarative/graphicsitems/qdeclarativeitem.cpp
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "private/qdeclarativeitem_p.h"
       
    43 #include "qdeclarativeitem.h"
       
    44 
       
    45 #include "private/qdeclarativeevents_p_p.h"
       
    46 #include <private/qdeclarativeengine_p.h>
       
    47 
       
    48 #include <qdeclarativeengine.h>
       
    49 #include <qdeclarativeopenmetaobject_p.h>
       
    50 #include <qdeclarativestate_p.h>
       
    51 #include <qdeclarativeview.h>
       
    52 #include <qdeclarativestategroup_p.h>
       
    53 #include <qdeclarativecomponent.h>
       
    54 #include <qdeclarativeinfo.h>
       
    55 
       
    56 #include <QDebug>
       
    57 #include <QPen>
       
    58 #include <QFile>
       
    59 #include <QEvent>
       
    60 #include <QGraphicsSceneMouseEvent>
       
    61 #include <QtCore/qnumeric.h>
       
    62 #include <QtScript/qscriptengine.h>
       
    63 #include <QtGui/qgraphicstransform.h>
       
    64 #include <qlistmodelinterface_p.h>
       
    65 
       
    66 QT_BEGIN_NAMESPACE
       
    67 
       
    68 #ifndef FLT_MAX
       
    69 #define FLT_MAX 1E+37
       
    70 #endif
       
    71 
       
    72 /*!
       
    73     \qmlclass Transform QGraphicsTransform
       
    74     \since 4.7
       
    75     \brief The Transform elements provide a way of building advanced transformations on Items.
       
    76 
       
    77     The Transform element is a base type which cannot be instantiated directly.
       
    78     The following concrete Transform types are available:
       
    79 
       
    80     \list
       
    81     \o \l Rotation
       
    82     \o \l Scale
       
    83     \o \l Translate
       
    84     \endlist
       
    85 
       
    86     The Transform elements let you create and control advanced transformations that can be configured
       
    87     independently using specialized properties.
       
    88 
       
    89     You can assign any number of Transform elements to an Item. Each Transform is applied in order,
       
    90     one at a time, to the Item it's assigned to.
       
    91 */
       
    92 
       
    93 /*!
       
    94     \qmlclass Translate QGraphicsTranslate
       
    95     \since 4.7
       
    96     \brief The Translate object provides a way to move an Item without changing its x or y properties.
       
    97 
       
    98     The Translate object provides independent control over position in addition to the Item's x and y properties.
       
    99 
       
   100     The following example moves the Y axis of the Rectangles while still allowing the Row element
       
   101     to lay the items out as if they had not been transformed:
       
   102     \qml
       
   103     Row {
       
   104         Rectangle {
       
   105             width: 100; height: 100
       
   106             color: "blue"
       
   107             transform: Translate { y: 20 }
       
   108         }
       
   109         Rectangle {
       
   110             width: 100; height: 100
       
   111             color: "red"
       
   112             transform: Translate { y: -20 }
       
   113         }
       
   114     }
       
   115     \endqml
       
   116 */
       
   117 
       
   118 /*!
       
   119     \qmlproperty real Translate::x
       
   120 
       
   121     The translation along the X axis.
       
   122 */
       
   123 
       
   124 /*!
       
   125     \qmlproperty real Translate::y
       
   126 
       
   127     The translation along the Y axis.
       
   128 */
       
   129 
       
   130 /*!
       
   131     \qmlclass Scale QGraphicsScale
       
   132     \since 4.7
       
   133     \brief The Scale object provides a way to scale an Item.
       
   134 
       
   135     The Scale object gives more control over scaling than using Item's scale property. Specifically,
       
   136     it allows a different scale for the x and y axes, and allows the scale to be relative to an
       
   137     arbitrary point.
       
   138 
       
   139     The following example scales the X axis of the Rectangle, relative to its interior point 25, 25:
       
   140     \qml
       
   141     Rectangle {
       
   142         width: 100; height: 100
       
   143         color: "blue"
       
   144         transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}
       
   145     }
       
   146     \endqml
       
   147 */
       
   148 
       
   149 /*!
       
   150     \qmlproperty real Scale::origin.x
       
   151     \qmlproperty real Scale::origin.y
       
   152 
       
   153     The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as
       
   154     the rest of the item grows). By default the origin is 0, 0.
       
   155 */
       
   156 
       
   157 /*!
       
   158     \qmlproperty real Scale::xScale
       
   159 
       
   160     The scaling factor for the X axis.
       
   161 */
       
   162 
       
   163 /*!
       
   164     \qmlproperty real Scale::yScale
       
   165 
       
   166     The scaling factor for the Y axis.
       
   167 */
       
   168 
       
   169 /*!
       
   170     \qmlclass Rotation QGraphicsRotation
       
   171     \since 4.7
       
   172     \brief The Rotation object provides a way to rotate an Item.
       
   173 
       
   174     The Rotation object gives more control over rotation than using Item's rotation property.
       
   175     Specifically, it allows (z axis) rotation to be relative to an arbitrary point.
       
   176 
       
   177     The following example rotates a Rectangle around its interior point 25, 25:
       
   178     \qml
       
   179     Rectangle {
       
   180         width: 100; height: 100
       
   181         color: "blue"
       
   182         transform: Rotation { origin.x: 25; origin.y: 25; angle: 45}
       
   183     }
       
   184     \endqml
       
   185 
       
   186     Rotation also provides a way to specify 3D-like rotations for Items. For these types of
       
   187     rotations you must specify the axis to rotate around in addition to the origin point.
       
   188 
       
   189     The following example shows various 3D-like rotations applied to an \l Image.
       
   190     \snippet doc/src/snippets/declarative/rotation.qml 0
       
   191 
       
   192     \image axisrotation.png
       
   193 */
       
   194 
       
   195 /*!
       
   196     \qmlproperty real Rotation::origin.x
       
   197     \qmlproperty real Rotation::origin.y
       
   198 
       
   199     The origin point of the rotation (i.e., the point that stays fixed relative to the parent as
       
   200     the rest of the item rotates). By default the origin is 0, 0.
       
   201 */
       
   202 
       
   203 /*!
       
   204     \qmlproperty real Rotation::axis.x
       
   205     \qmlproperty real Rotation::axis.y
       
   206     \qmlproperty real Rotation::axis.z
       
   207 
       
   208     The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis,
       
   209     as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 1 } }).
       
   210 
       
   211     For a typical 3D-like rotation you will usually specify both the origin and the axis.
       
   212 
       
   213     \image 3d-rotation-axis.png
       
   214 */
       
   215 
       
   216 /*!
       
   217     \qmlproperty real Rotation::angle
       
   218 
       
   219     The angle to rotate, in degrees clockwise.
       
   220 */
       
   221 
       
   222 /*!
       
   223     \internal
       
   224     \class QDeclarativeContents
       
   225     \brief The QDeclarativeContents class gives access to the height and width of an item's contents.
       
   226 
       
   227 */
       
   228 
       
   229 QDeclarativeContents::QDeclarativeContents() : m_x(0), m_y(0), m_width(0), m_height(0)
       
   230 {
       
   231 }
       
   232 
       
   233 QDeclarativeContents::~QDeclarativeContents()
       
   234 {
       
   235     QList<QGraphicsItem *> children = m_item->childItems();
       
   236     for (int i = 0; i < children.count(); ++i) {
       
   237         QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
       
   238         if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
       
   239             continue;
       
   240         QDeclarativeItemPrivate::get(child)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
       
   241     }
       
   242 }
       
   243 
       
   244 QRectF QDeclarativeContents::rectF() const
       
   245 {
       
   246     return QRectF(m_x, m_y, m_width, m_height);
       
   247 }
       
   248 
       
   249 void QDeclarativeContents::calcHeight(QDeclarativeItem *changed)
       
   250 {
       
   251     qreal oldy = m_y;
       
   252     qreal oldheight = m_height;
       
   253 
       
   254     if (changed) {
       
   255         qreal top = oldy;
       
   256         qreal bottom = oldy + oldheight;
       
   257         qreal y = changed->y();
       
   258         if (y + changed->height() > bottom)
       
   259             bottom = y + changed->height();
       
   260         if (y < top)
       
   261             top = y;
       
   262         m_y = top;
       
   263         m_height = bottom - top;
       
   264     } else {
       
   265         qreal top = FLT_MAX;
       
   266         qreal bottom = 0;
       
   267         QList<QGraphicsItem *> children = m_item->childItems();
       
   268         for (int i = 0; i < children.count(); ++i) {
       
   269             QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
       
   270             if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
       
   271                 continue;
       
   272             qreal y = child->y();
       
   273             if (y + child->height() > bottom)
       
   274                 bottom = y + child->height();
       
   275             if (y < top)
       
   276                 top = y;
       
   277         }
       
   278         if (!children.isEmpty())
       
   279             m_y = top;
       
   280         m_height = qMax(bottom - top, qreal(0.0));
       
   281     }
       
   282 
       
   283     if (m_height != oldheight || m_y != oldy)
       
   284         emit rectChanged(rectF());
       
   285 }
       
   286 
       
   287 void QDeclarativeContents::calcWidth(QDeclarativeItem *changed)
       
   288 {
       
   289     qreal oldx = m_x;
       
   290     qreal oldwidth = m_width;
       
   291 
       
   292     if (changed) {
       
   293         qreal left = oldx;
       
   294         qreal right = oldx + oldwidth;
       
   295         qreal x = changed->x();
       
   296         if (x + changed->width() > right)
       
   297             right = x + changed->width();
       
   298         if (x < left)
       
   299             left = x;
       
   300         m_x = left;
       
   301         m_width = right - left;
       
   302     } else {
       
   303         qreal left = FLT_MAX;
       
   304         qreal right = 0;
       
   305         QList<QGraphicsItem *> children = m_item->childItems();
       
   306         for (int i = 0; i < children.count(); ++i) {
       
   307             QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
       
   308             if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
       
   309                 continue;
       
   310             qreal x = child->x();
       
   311             if (x + child->width() > right)
       
   312                 right = x + child->width();
       
   313             if (x < left)
       
   314                 left = x;
       
   315         }
       
   316         if (!children.isEmpty())
       
   317             m_x = left;
       
   318         m_width = qMax(right - left, qreal(0.0));
       
   319     }
       
   320 
       
   321     if (m_width != oldwidth || m_x != oldx)
       
   322         emit rectChanged(rectF());
       
   323 }
       
   324 
       
   325 void QDeclarativeContents::setItem(QDeclarativeItem *item)
       
   326 {
       
   327     m_item = item;
       
   328     //### optimize
       
   329     connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF)));
       
   330 
       
   331     QList<QGraphicsItem *> children = m_item->childItems();
       
   332     for (int i = 0; i < children.count(); ++i) {
       
   333         QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
       
   334         if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
       
   335             continue;
       
   336         QDeclarativeItemPrivate::get(child)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
       
   337         //###what about changes to visibility?
       
   338     }
       
   339 
       
   340     //### defer until componentComplete
       
   341     calcHeight();
       
   342     calcWidth();
       
   343 }
       
   344 
       
   345 void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry)
       
   346 {
       
   347     if (newGeometry.width() != oldGeometry.width())
       
   348         calcWidth(changed);
       
   349     if (newGeometry.height() != oldGeometry.height())
       
   350         calcHeight(changed);
       
   351 }
       
   352 
       
   353 void QDeclarativeContents::itemDestroyed(QDeclarativeItem *item)
       
   354 {
       
   355     if (item)
       
   356         QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
       
   357     calcWidth();
       
   358     calcHeight();
       
   359 }
       
   360 
       
   361 void QDeclarativeContents::childRemoved(QDeclarativeItem *item)
       
   362 {
       
   363     if (item)
       
   364         QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
       
   365     calcWidth();
       
   366     calcHeight();
       
   367 }
       
   368 
       
   369 void QDeclarativeContents::childAdded(QDeclarativeItem *item)
       
   370 {
       
   371     if (item)
       
   372         QDeclarativeItemPrivate::get(item)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
       
   373     calcWidth(item);
       
   374     calcHeight(item);
       
   375 }
       
   376 
       
   377 QDeclarativeItemKeyFilter::QDeclarativeItemKeyFilter(QDeclarativeItem *item)
       
   378 : m_processPost(false), m_next(0)
       
   379 {
       
   380     QDeclarativeItemPrivate *p =
       
   381         item?static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(item)):0;
       
   382     if (p) {
       
   383         m_next = p->keyHandler;
       
   384         p->keyHandler = this;
       
   385     }
       
   386 }
       
   387 
       
   388 QDeclarativeItemKeyFilter::~QDeclarativeItemKeyFilter()
       
   389 {
       
   390 }
       
   391 
       
   392 void QDeclarativeItemKeyFilter::keyPressed(QKeyEvent *event, bool post)
       
   393 {
       
   394     if (m_next) m_next->keyPressed(event, post);
       
   395 }
       
   396 
       
   397 void QDeclarativeItemKeyFilter::keyReleased(QKeyEvent *event, bool post)
       
   398 {
       
   399     if (m_next) m_next->keyReleased(event, post);
       
   400 }
       
   401 
       
   402 void QDeclarativeItemKeyFilter::inputMethodEvent(QInputMethodEvent *event, bool post)
       
   403 {
       
   404     if (m_next) m_next->inputMethodEvent(event, post);
       
   405 }
       
   406 
       
   407 QVariant QDeclarativeItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const
       
   408 {
       
   409     if (m_next) return m_next->inputMethodQuery(query);
       
   410     return QVariant();
       
   411 }
       
   412 
       
   413 void QDeclarativeItemKeyFilter::componentComplete()
       
   414 {
       
   415     if (m_next) m_next->componentComplete();
       
   416 }
       
   417 
       
   418 
       
   419 /*!
       
   420     \qmlclass KeyNavigation
       
   421     \since 4.7
       
   422     \brief The KeyNavigation attached property supports key navigation by arrow keys.
       
   423 
       
   424     It is common in key-based UIs to use arrow keys to navigate
       
   425     between focussed items.  The KeyNavigation property provides a
       
   426     convenient way of specifying which item will gain focus
       
   427     when an arrow key is pressed.  The following example provides
       
   428     key navigation for a 2x2 grid of items.
       
   429 
       
   430     \code
       
   431     Grid {
       
   432         columns: 2
       
   433         width: 100; height: 100
       
   434         Rectangle {
       
   435             id: item1
       
   436             focus: true
       
   437             width: 50; height: 50
       
   438             color: focus ? "red" : "lightgray"
       
   439             KeyNavigation.right: item2
       
   440             KeyNavigation.down: item3
       
   441         }
       
   442         Rectangle {
       
   443             id: item2
       
   444             width: 50; height: 50
       
   445             color: focus ? "red" : "lightgray"
       
   446             KeyNavigation.left: item1
       
   447             KeyNavigation.down: item4
       
   448         }
       
   449         Rectangle {
       
   450             id: item3
       
   451             width: 50; height: 50
       
   452             color: focus ? "red" : "lightgray"
       
   453             KeyNavigation.right: item4
       
   454             KeyNavigation.up: item1
       
   455         }
       
   456         Rectangle {
       
   457             id: item4
       
   458             width: 50; height: 50
       
   459             color: focus ? "red" : "lightgray"
       
   460             KeyNavigation.left: item3
       
   461             KeyNavigation.up: item2
       
   462         }
       
   463     }
       
   464     \endcode
       
   465 
       
   466     By default KeyNavigation receives key events after the item it is attached to.
       
   467     If the item accepts an arrow key event, the KeyNavigation
       
   468     attached property will not receive an event for that key.  Setting the
       
   469     \l priority property to KeyNavigation.BeforeItem allows handling
       
   470     of the key events before normal item processing.
       
   471 
       
   472     If an item has been set for a direction and the KeyNavigation
       
   473     attached property receives the corresponding
       
   474     key press and release events, the events will be accepted by
       
   475     KeyNavigation and will not propagate any further.
       
   476 
       
   477     \sa {Keys}{Keys attached property}
       
   478 */
       
   479 
       
   480 /*!
       
   481     \qmlproperty Item KeyNavigation::left
       
   482     \qmlproperty Item KeyNavigation::right
       
   483     \qmlproperty Item KeyNavigation::up
       
   484     \qmlproperty Item KeyNavigation::down
       
   485 
       
   486     These properties hold the item to assign focus to
       
   487     when Key_Left, Key_Right, Key_Up or Key_Down are
       
   488     pressed.
       
   489 */
       
   490 
       
   491 QDeclarativeKeyNavigationAttached::QDeclarativeKeyNavigationAttached(QObject *parent)
       
   492 : QObject(*(new QDeclarativeKeyNavigationAttachedPrivate), parent),
       
   493   QDeclarativeItemKeyFilter(qobject_cast<QDeclarativeItem*>(parent))
       
   494 {
       
   495     m_processPost = true;
       
   496 }
       
   497 
       
   498 QDeclarativeKeyNavigationAttached *
       
   499 QDeclarativeKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
       
   500 {
       
   501     return new QDeclarativeKeyNavigationAttached(obj);
       
   502 }
       
   503 
       
   504 QDeclarativeItem *QDeclarativeKeyNavigationAttached::left() const
       
   505 {
       
   506     Q_D(const QDeclarativeKeyNavigationAttached);
       
   507     return d->left;
       
   508 }
       
   509 
       
   510 void QDeclarativeKeyNavigationAttached::setLeft(QDeclarativeItem *i)
       
   511 {
       
   512     Q_D(QDeclarativeKeyNavigationAttached);
       
   513     d->left = i;
       
   514     emit changed();
       
   515 }
       
   516 
       
   517 QDeclarativeItem *QDeclarativeKeyNavigationAttached::right() const
       
   518 {
       
   519     Q_D(const QDeclarativeKeyNavigationAttached);
       
   520     return d->right;
       
   521 }
       
   522 
       
   523 void QDeclarativeKeyNavigationAttached::setRight(QDeclarativeItem *i)
       
   524 {
       
   525     Q_D(QDeclarativeKeyNavigationAttached);
       
   526     d->right = i;
       
   527     emit changed();
       
   528 }
       
   529 
       
   530 QDeclarativeItem *QDeclarativeKeyNavigationAttached::up() const
       
   531 {
       
   532     Q_D(const QDeclarativeKeyNavigationAttached);
       
   533     return d->up;
       
   534 }
       
   535 
       
   536 void QDeclarativeKeyNavigationAttached::setUp(QDeclarativeItem *i)
       
   537 {
       
   538     Q_D(QDeclarativeKeyNavigationAttached);
       
   539     d->up = i;
       
   540     emit changed();
       
   541 }
       
   542 
       
   543 QDeclarativeItem *QDeclarativeKeyNavigationAttached::down() const
       
   544 {
       
   545     Q_D(const QDeclarativeKeyNavigationAttached);
       
   546     return d->down;
       
   547 }
       
   548 
       
   549 void QDeclarativeKeyNavigationAttached::setDown(QDeclarativeItem *i)
       
   550 {
       
   551     Q_D(QDeclarativeKeyNavigationAttached);
       
   552     d->down = i;
       
   553     emit changed();
       
   554 }
       
   555 
       
   556 QDeclarativeItem *QDeclarativeKeyNavigationAttached::tab() const
       
   557 {
       
   558     Q_D(const QDeclarativeKeyNavigationAttached);
       
   559     return d->tab;
       
   560 }
       
   561 
       
   562 void QDeclarativeKeyNavigationAttached::setTab(QDeclarativeItem *i)
       
   563 {
       
   564     Q_D(QDeclarativeKeyNavigationAttached);
       
   565     d->tab = i;
       
   566     emit changed();
       
   567 }
       
   568 
       
   569 QDeclarativeItem *QDeclarativeKeyNavigationAttached::backtab() const
       
   570 {
       
   571     Q_D(const QDeclarativeKeyNavigationAttached);
       
   572     return d->backtab;
       
   573 }
       
   574 
       
   575 void QDeclarativeKeyNavigationAttached::setBacktab(QDeclarativeItem *i)
       
   576 {
       
   577     Q_D(QDeclarativeKeyNavigationAttached);
       
   578     d->backtab = i;
       
   579     emit changed();
       
   580 }
       
   581 
       
   582 /*!
       
   583     \qmlproperty enumeration KeyNavigation::priority
       
   584 
       
   585     This property determines whether the keys are processed before
       
   586     or after the attached item's own key handling.
       
   587 
       
   588     \list
       
   589     \o KeyNavigation.BeforeItem - process the key events before normal
       
   590     item key processing.  If the event is accepted it will not
       
   591     be passed on to the item.
       
   592     \o KeyNavigation.AfterItem (default) - process the key events after normal item key
       
   593     handling.  If the item accepts the key event it will not be
       
   594     handled by the KeyNavigation attached property handler.
       
   595     \endlist
       
   596 */
       
   597 QDeclarativeKeyNavigationAttached::Priority QDeclarativeKeyNavigationAttached::priority() const
       
   598 {
       
   599     return m_processPost ? AfterItem : BeforeItem;
       
   600 }
       
   601 
       
   602 void QDeclarativeKeyNavigationAttached::setPriority(Priority order)
       
   603 {
       
   604     bool processPost = order == AfterItem;
       
   605     if (processPost != m_processPost) {
       
   606         m_processPost = processPost;
       
   607         emit priorityChanged();
       
   608     }
       
   609 }
       
   610 
       
   611 void QDeclarativeKeyNavigationAttached::keyPressed(QKeyEvent *event, bool post)
       
   612 {
       
   613     Q_D(QDeclarativeKeyNavigationAttached);
       
   614     event->ignore();
       
   615 
       
   616     if (post != m_processPost) {
       
   617         QDeclarativeItemKeyFilter::keyPressed(event, post);
       
   618         return;
       
   619     }
       
   620 
       
   621     switch(event->key()) {
       
   622     case Qt::Key_Left:
       
   623         if (d->left) {
       
   624             d->left->setFocus(true);
       
   625             event->accept();
       
   626         }
       
   627         break;
       
   628     case Qt::Key_Right:
       
   629         if (d->right) {
       
   630             d->right->setFocus(true);
       
   631             event->accept();
       
   632         }
       
   633         break;
       
   634     case Qt::Key_Up:
       
   635         if (d->up) {
       
   636             d->up->setFocus(true);
       
   637             event->accept();
       
   638         }
       
   639         break;
       
   640     case Qt::Key_Down:
       
   641         if (d->down) {
       
   642             d->down->setFocus(true);
       
   643             event->accept();
       
   644         }
       
   645         break;
       
   646     case Qt::Key_Tab:
       
   647         if (d->tab) {
       
   648             d->tab->setFocus(true);
       
   649             event->accept();
       
   650         }
       
   651         break;
       
   652     case Qt::Key_Backtab:
       
   653         if (d->backtab) {
       
   654             d->backtab->setFocus(true);
       
   655             event->accept();
       
   656         }
       
   657         break;
       
   658     default:
       
   659         break;
       
   660     }
       
   661 
       
   662     if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyPressed(event, post);
       
   663 }
       
   664 
       
   665 void QDeclarativeKeyNavigationAttached::keyReleased(QKeyEvent *event, bool post)
       
   666 {
       
   667     Q_D(QDeclarativeKeyNavigationAttached);
       
   668     event->ignore();
       
   669 
       
   670     if (post != m_processPost) {
       
   671         QDeclarativeItemKeyFilter::keyReleased(event, post);
       
   672         return;
       
   673     }
       
   674 
       
   675     switch(event->key()) {
       
   676     case Qt::Key_Left:
       
   677         if (d->left) {
       
   678             event->accept();
       
   679         }
       
   680         break;
       
   681     case Qt::Key_Right:
       
   682         if (d->right) {
       
   683             event->accept();
       
   684         }
       
   685         break;
       
   686     case Qt::Key_Up:
       
   687         if (d->up) {
       
   688             event->accept();
       
   689         }
       
   690         break;
       
   691     case Qt::Key_Down:
       
   692         if (d->down) {
       
   693             event->accept();
       
   694         }
       
   695         break;
       
   696     case Qt::Key_Tab:
       
   697         if (d->tab) {
       
   698             event->accept();
       
   699         }
       
   700         break;
       
   701     case Qt::Key_Backtab:
       
   702         if (d->backtab) {
       
   703             event->accept();
       
   704         }
       
   705         break;
       
   706     default:
       
   707         break;
       
   708     }
       
   709 
       
   710     if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post);
       
   711 }
       
   712 
       
   713 /*!
       
   714     \qmlclass Keys
       
   715     \since 4.7
       
   716     \brief The Keys attached property provides key handling to Items.
       
   717 
       
   718     All visual primitives support key handling via the \e Keys
       
   719     attached property.  Keys can be handled via the \e onPressed
       
   720     and \e onReleased signal properties.
       
   721 
       
   722     The signal properties have a \l KeyEvent parameter, named
       
   723     \e event which contains details of the event.  If a key is
       
   724     handled \e event.accepted should be set to true to prevent the
       
   725     event from propagating up the item heirarchy.
       
   726 
       
   727     \code
       
   728     Item {
       
   729         focus: true
       
   730         Keys.onPressed: {
       
   731             if (event.key == Qt.Key_Left) {
       
   732                 console.log("move left");
       
   733                 event.accepted = true;
       
   734             }
       
   735         }
       
   736     }
       
   737     \endcode
       
   738 
       
   739     Some keys may alternatively be handled via specific signal properties,
       
   740     for example \e onSelectPressed.  These handlers automatically set
       
   741     \e event.accepted to true.
       
   742 
       
   743     \code
       
   744     Item {
       
   745         focus: true
       
   746         Keys.onLeftPressed: console.log("move left")
       
   747     }
       
   748     \endcode
       
   749 
       
   750     See \l {Qt::Key}{Qt.Key} for the list of keyboard codes.
       
   751 
       
   752     If priority is Keys.BeforeItem (default) the order of key event processing is:
       
   753 
       
   754     \list 1
       
   755     \o Items specified in \c forwardTo
       
   756     \o specific key handlers, e.g. onReturnPressed
       
   757     \o onKeyPress, onKeyRelease handlers
       
   758     \o Item specific key handling, e.g. TextInput key handling
       
   759     \o parent item
       
   760     \endlist
       
   761 
       
   762     If priority is Keys.AfterItem the order of key event processing is:
       
   763     \list 1
       
   764     \o Item specific key handling, e.g. TextInput key handling
       
   765     \o Items specified in \c forwardTo
       
   766     \o specific key handlers, e.g. onReturnPressed
       
   767     \o onKeyPress, onKeyRelease handlers
       
   768     \o parent item
       
   769     \endlist
       
   770 
       
   771     If the event is accepted during any of the above steps, key
       
   772     propagation stops.
       
   773 
       
   774     \sa KeyEvent, {KeyNavigation}{KeyNavigation attached property}
       
   775 */
       
   776 
       
   777 /*!
       
   778     \qmlproperty bool Keys::enabled
       
   779 
       
   780     This flags enables key handling if true (default); otherwise
       
   781     no key handlers will be called.
       
   782 */
       
   783 
       
   784 /*!
       
   785     \qmlproperty enumeration Keys::priority
       
   786 
       
   787     This property determines whether the keys are processed before
       
   788     or after the attached item's own key handling.
       
   789 
       
   790     \list
       
   791     \o Keys.BeforeItem (default) - process the key events before normal
       
   792     item key processing.  If the event is accepted it will not
       
   793     be passed on to the item.
       
   794     \o Keys.AfterItem - process the key events after normal item key
       
   795     handling.  If the item accepts the key event it will not be
       
   796     handled by the Keys attached property handler.
       
   797     \endlist
       
   798 */
       
   799 
       
   800 /*!
       
   801     \qmlproperty list<Object> Keys::forwardTo
       
   802 
       
   803     This property provides a way to forward key presses, key releases, and keyboard input
       
   804     coming from input methods to other items. This can be useful when you want
       
   805     one item to handle some keys (e.g. the up and down arrow keys), and another item to
       
   806     handle other keys (e.g. the left and right arrow keys).  Once an item that has been
       
   807     forwarded keys accepts the event it is no longer forwarded to items later in the
       
   808     list.
       
   809 
       
   810     This example forwards key events to two lists:
       
   811     \qml
       
   812     ListView { id: list1 ... }
       
   813     ListView { id: list2 ... }
       
   814     Keys.forwardTo: [list1, list2]
       
   815     focus: true
       
   816     \endqml
       
   817 */
       
   818 
       
   819 /*!
       
   820     \qmlsignal Keys::onPressed(event)
       
   821 
       
   822     This handler is called when a key has been pressed. The \a event
       
   823     parameter provides information about the event.
       
   824 */
       
   825 
       
   826 /*!
       
   827     \qmlsignal Keys::onReleased(event)
       
   828 
       
   829     This handler is called when a key has been released. The \a event
       
   830     parameter provides information about the event.
       
   831 */
       
   832 
       
   833 /*!
       
   834     \qmlsignal Keys::onDigit0Pressed(event)
       
   835 
       
   836     This handler is called when the digit '0' has been pressed. The \a event
       
   837     parameter provides information about the event.
       
   838 */
       
   839 
       
   840 /*!
       
   841     \qmlsignal Keys::onDigit1Pressed(event)
       
   842 
       
   843     This handler is called when the digit '1' has been pressed. The \a event
       
   844     parameter provides information about the event.
       
   845 */
       
   846 
       
   847 /*!
       
   848     \qmlsignal Keys::onDigit2Pressed(event)
       
   849 
       
   850     This handler is called when the digit '2' has been pressed. The \a event
       
   851     parameter provides information about the event.
       
   852 */
       
   853 
       
   854 /*!
       
   855     \qmlsignal Keys::onDigit3Pressed(event)
       
   856 
       
   857     This handler is called when the digit '3' has been pressed. The \a event
       
   858     parameter provides information about the event.
       
   859 */
       
   860 
       
   861 /*!
       
   862     \qmlsignal Keys::onDigit4Pressed(event)
       
   863 
       
   864     This handler is called when the digit '4' has been pressed. The \a event
       
   865     parameter provides information about the event.
       
   866 */
       
   867 
       
   868 /*!
       
   869     \qmlsignal Keys::onDigit5Pressed(event)
       
   870 
       
   871     This handler is called when the digit '5' has been pressed. The \a event
       
   872     parameter provides information about the event.
       
   873 */
       
   874 
       
   875 /*!
       
   876     \qmlsignal Keys::onDigit6Pressed(event)
       
   877 
       
   878     This handler is called when the digit '6' has been pressed. The \a event
       
   879     parameter provides information about the event.
       
   880 */
       
   881 
       
   882 /*!
       
   883     \qmlsignal Keys::onDigit7Pressed(event)
       
   884 
       
   885     This handler is called when the digit '7' has been pressed. The \a event
       
   886     parameter provides information about the event.
       
   887 */
       
   888 
       
   889 /*!
       
   890     \qmlsignal Keys::onDigit8Pressed(event)
       
   891 
       
   892     This handler is called when the digit '8' has been pressed. The \a event
       
   893     parameter provides information about the event.
       
   894 */
       
   895 
       
   896 /*!
       
   897     \qmlsignal Keys::onDigit9Pressed(event)
       
   898 
       
   899     This handler is called when the digit '9' has been pressed. The \a event
       
   900     parameter provides information about the event.
       
   901 */
       
   902 
       
   903 /*!
       
   904     \qmlsignal Keys::onLeftPressed(event)
       
   905 
       
   906     This handler is called when the Left arrow has been pressed. The \a event
       
   907     parameter provides information about the event.
       
   908 */
       
   909 
       
   910 /*!
       
   911     \qmlsignal Keys::onRightPressed(event)
       
   912 
       
   913     This handler is called when the Right arrow has been pressed. The \a event
       
   914     parameter provides information about the event.
       
   915 */
       
   916 
       
   917 /*!
       
   918     \qmlsignal Keys::onUpPressed(event)
       
   919 
       
   920     This handler is called when the Up arrow has been pressed. The \a event
       
   921     parameter provides information about the event.
       
   922 */
       
   923 
       
   924 /*!
       
   925     \qmlsignal Keys::onDownPressed(event)
       
   926 
       
   927     This handler is called when the Down arrow has been pressed. The \a event
       
   928     parameter provides information about the event.
       
   929 */
       
   930 
       
   931 /*!
       
   932     \qmlsignal Keys::onAsteriskPressed(event)
       
   933 
       
   934     This handler is called when the Asterisk '*' has been pressed. The \a event
       
   935     parameter provides information about the event.
       
   936 */
       
   937 
       
   938 /*!
       
   939     \qmlsignal Keys::onEscapePressed(event)
       
   940 
       
   941     This handler is called when the Escape key has been pressed. The \a event
       
   942     parameter provides information about the event.
       
   943 */
       
   944 
       
   945 /*!
       
   946     \qmlsignal Keys::onReturnPressed(event)
       
   947 
       
   948     This handler is called when the Return key has been pressed. The \a event
       
   949     parameter provides information about the event.
       
   950 */
       
   951 
       
   952 /*!
       
   953     \qmlsignal Keys::onEnterPressed(event)
       
   954 
       
   955     This handler is called when the Enter key has been pressed. The \a event
       
   956     parameter provides information about the event.
       
   957 */
       
   958 
       
   959 /*!
       
   960     \qmlsignal Keys::onDeletePressed(event)
       
   961 
       
   962     This handler is called when the Delete key has been pressed. The \a event
       
   963     parameter provides information about the event.
       
   964 */
       
   965 
       
   966 /*!
       
   967     \qmlsignal Keys::onSpacePressed(event)
       
   968 
       
   969     This handler is called when the Space key has been pressed. The \a event
       
   970     parameter provides information about the event.
       
   971 */
       
   972 
       
   973 /*!
       
   974     \qmlsignal Keys::onBackPressed(event)
       
   975 
       
   976     This handler is called when the Back key has been pressed. The \a event
       
   977     parameter provides information about the event.
       
   978 */
       
   979 
       
   980 /*!
       
   981     \qmlsignal Keys::onCancelPressed(event)
       
   982 
       
   983     This handler is called when the Cancel key has been pressed. The \a event
       
   984     parameter provides information about the event.
       
   985 */
       
   986 
       
   987 /*!
       
   988     \qmlsignal Keys::onSelectPressed(event)
       
   989 
       
   990     This handler is called when the Select key has been pressed. The \a event
       
   991     parameter provides information about the event.
       
   992 */
       
   993 
       
   994 /*!
       
   995     \qmlsignal Keys::onYesPressed(event)
       
   996 
       
   997     This handler is called when the Yes key has been pressed. The \a event
       
   998     parameter provides information about the event.
       
   999 */
       
  1000 
       
  1001 /*!
       
  1002     \qmlsignal Keys::onNoPressed(event)
       
  1003 
       
  1004     This handler is called when the No key has been pressed. The \a event
       
  1005     parameter provides information about the event.
       
  1006 */
       
  1007 
       
  1008 /*!
       
  1009     \qmlsignal Keys::onContext1Pressed(event)
       
  1010 
       
  1011     This handler is called when the Context1 key has been pressed. The \a event
       
  1012     parameter provides information about the event.
       
  1013 */
       
  1014 
       
  1015 /*!
       
  1016     \qmlsignal Keys::onContext2Pressed(event)
       
  1017 
       
  1018     This handler is called when the Context2 key has been pressed. The \a event
       
  1019     parameter provides information about the event.
       
  1020 */
       
  1021 
       
  1022 /*!
       
  1023     \qmlsignal Keys::onContext3Pressed(event)
       
  1024 
       
  1025     This handler is called when the Context3 key has been pressed. The \a event
       
  1026     parameter provides information about the event.
       
  1027 */
       
  1028 
       
  1029 /*!
       
  1030     \qmlsignal Keys::onContext4Pressed(event)
       
  1031 
       
  1032     This handler is called when the Context4 key has been pressed. The \a event
       
  1033     parameter provides information about the event.
       
  1034 */
       
  1035 
       
  1036 /*!
       
  1037     \qmlsignal Keys::onCallPressed(event)
       
  1038 
       
  1039     This handler is called when the Call key has been pressed. The \a event
       
  1040     parameter provides information about the event.
       
  1041 */
       
  1042 
       
  1043 /*!
       
  1044     \qmlsignal Keys::onHangupPressed(event)
       
  1045 
       
  1046     This handler is called when the Hangup key has been pressed. The \a event
       
  1047     parameter provides information about the event.
       
  1048 */
       
  1049 
       
  1050 /*!
       
  1051     \qmlsignal Keys::onFlipPressed(event)
       
  1052 
       
  1053     This handler is called when the Flip key has been pressed. The \a event
       
  1054     parameter provides information about the event.
       
  1055 */
       
  1056 
       
  1057 /*!
       
  1058     \qmlsignal Keys::onMenuPressed(event)
       
  1059 
       
  1060     This handler is called when the Menu key has been pressed. The \a event
       
  1061     parameter provides information about the event.
       
  1062 */
       
  1063 
       
  1064 /*!
       
  1065     \qmlsignal Keys::onVolumeUpPressed(event)
       
  1066 
       
  1067     This handler is called when the VolumeUp key has been pressed. The \a event
       
  1068     parameter provides information about the event.
       
  1069 */
       
  1070 
       
  1071 /*!
       
  1072     \qmlsignal Keys::onVolumeDownPressed(event)
       
  1073 
       
  1074     This handler is called when the VolumeDown key has been pressed. The \a event
       
  1075     parameter provides information about the event.
       
  1076 */
       
  1077 
       
  1078 const QDeclarativeKeysAttached::SigMap QDeclarativeKeysAttached::sigMap[] = {
       
  1079     { Qt::Key_Left, "leftPressed" },
       
  1080     { Qt::Key_Right, "rightPressed" },
       
  1081     { Qt::Key_Up, "upPressed" },
       
  1082     { Qt::Key_Down, "downPressed" },
       
  1083     { Qt::Key_Tab, "tabPressed" },
       
  1084     { Qt::Key_Backtab, "backtabPressed" },
       
  1085     { Qt::Key_Asterisk, "asteriskPressed" },
       
  1086     { Qt::Key_NumberSign, "numberSignPressed" },
       
  1087     { Qt::Key_Escape, "escapePressed" },
       
  1088     { Qt::Key_Return, "returnPressed" },
       
  1089     { Qt::Key_Enter, "enterPressed" },
       
  1090     { Qt::Key_Delete, "deletePressed" },
       
  1091     { Qt::Key_Space, "spacePressed" },
       
  1092     { Qt::Key_Back, "backPressed" },
       
  1093     { Qt::Key_Cancel, "cancelPressed" },
       
  1094     { Qt::Key_Select, "selectPressed" },
       
  1095     { Qt::Key_Yes, "yesPressed" },
       
  1096     { Qt::Key_No, "noPressed" },
       
  1097     { Qt::Key_Context1, "context1Pressed" },
       
  1098     { Qt::Key_Context2, "context2Pressed" },
       
  1099     { Qt::Key_Context3, "context3Pressed" },
       
  1100     { Qt::Key_Context4, "context4Pressed" },
       
  1101     { Qt::Key_Call, "callPressed" },
       
  1102     { Qt::Key_Hangup, "hangupPressed" },
       
  1103     { Qt::Key_Flip, "flipPressed" },
       
  1104     { Qt::Key_Menu, "menuPressed" },
       
  1105     { Qt::Key_VolumeUp, "volumeUpPressed" },
       
  1106     { Qt::Key_VolumeDown, "volumeDownPressed" },
       
  1107     { 0, 0 }
       
  1108 };
       
  1109 
       
  1110 bool QDeclarativeKeysAttachedPrivate::isConnected(const char *signalName)
       
  1111 {
       
  1112     return isSignalConnected(signalIndex(signalName));
       
  1113 }
       
  1114 
       
  1115 QDeclarativeKeysAttached::QDeclarativeKeysAttached(QObject *parent)
       
  1116 : QObject(*(new QDeclarativeKeysAttachedPrivate), parent),
       
  1117   QDeclarativeItemKeyFilter(qobject_cast<QDeclarativeItem*>(parent))
       
  1118 {
       
  1119     Q_D(QDeclarativeKeysAttached);
       
  1120     m_processPost = false;
       
  1121     d->item = qobject_cast<QDeclarativeItem*>(parent);
       
  1122 }
       
  1123 
       
  1124 QDeclarativeKeysAttached::~QDeclarativeKeysAttached()
       
  1125 {
       
  1126 }
       
  1127 
       
  1128 QDeclarativeKeysAttached::Priority QDeclarativeKeysAttached::priority() const
       
  1129 {
       
  1130     return m_processPost ? AfterItem : BeforeItem;
       
  1131 }
       
  1132 
       
  1133 void QDeclarativeKeysAttached::setPriority(Priority order)
       
  1134 {
       
  1135     bool processPost = order == AfterItem;
       
  1136     if (processPost != m_processPost) {
       
  1137         m_processPost = processPost;
       
  1138         emit priorityChanged();
       
  1139     }
       
  1140 }
       
  1141 
       
  1142 void QDeclarativeKeysAttached::componentComplete()
       
  1143 {
       
  1144     Q_D(QDeclarativeKeysAttached);
       
  1145     if (d->item) {
       
  1146         for (int ii = 0; ii < d->targets.count(); ++ii) {
       
  1147             QGraphicsItem *targetItem = d->finalFocusProxy(d->targets.at(ii));
       
  1148             if (targetItem && (targetItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
       
  1149                 d->item->setFlag(QGraphicsItem::ItemAcceptsInputMethod);
       
  1150                 break;
       
  1151             }
       
  1152         }
       
  1153     }
       
  1154 }
       
  1155 
       
  1156 void QDeclarativeKeysAttached::keyPressed(QKeyEvent *event, bool post)
       
  1157 {
       
  1158     Q_D(QDeclarativeKeysAttached);
       
  1159     if (post != m_processPost || !d->enabled || d->inPress) {
       
  1160         event->ignore();
       
  1161         QDeclarativeItemKeyFilter::keyPressed(event, post);
       
  1162         return;
       
  1163     }
       
  1164 
       
  1165     // first process forwards
       
  1166     if (d->item && d->item->scene()) {
       
  1167         d->inPress = true;
       
  1168         for (int ii = 0; ii < d->targets.count(); ++ii) {
       
  1169             QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
       
  1170             if (i) {
       
  1171                 d->item->scene()->sendEvent(i, event);
       
  1172                 if (event->isAccepted()) {
       
  1173                     d->inPress = false;
       
  1174                     return;
       
  1175                 }
       
  1176             }
       
  1177         }
       
  1178         d->inPress = false;
       
  1179     }
       
  1180 
       
  1181     QDeclarativeKeyEvent ke(*event);
       
  1182     QByteArray keySignal = keyToSignal(event->key());
       
  1183     if (!keySignal.isEmpty()) {
       
  1184         keySignal += "(QDeclarativeKeyEvent*)";
       
  1185         if (d->isConnected(keySignal)) {
       
  1186             // If we specifically handle a key then default to accepted
       
  1187             ke.setAccepted(true);
       
  1188             int idx = QDeclarativeKeysAttached::staticMetaObject.indexOfSignal(keySignal);
       
  1189             metaObject()->method(idx).invoke(this, Qt::DirectConnection, Q_ARG(QDeclarativeKeyEvent*, &ke));
       
  1190         }
       
  1191     }
       
  1192     if (!ke.isAccepted())
       
  1193         emit pressed(&ke);
       
  1194     event->setAccepted(ke.isAccepted());
       
  1195 
       
  1196     if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyPressed(event, post);
       
  1197 }
       
  1198 
       
  1199 void QDeclarativeKeysAttached::keyReleased(QKeyEvent *event, bool post)
       
  1200 {
       
  1201     Q_D(QDeclarativeKeysAttached);
       
  1202     if (post != m_processPost || !d->enabled || d->inRelease) {
       
  1203         event->ignore();
       
  1204         QDeclarativeItemKeyFilter::keyReleased(event, post);
       
  1205         return;
       
  1206     }
       
  1207 
       
  1208     if (d->item && d->item->scene()) {
       
  1209         d->inRelease = true;
       
  1210         for (int ii = 0; ii < d->targets.count(); ++ii) {
       
  1211             QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
       
  1212             if (i) {
       
  1213                 d->item->scene()->sendEvent(i, event);
       
  1214                 if (event->isAccepted()) {
       
  1215                     d->inRelease = false;
       
  1216                     return;
       
  1217                 }
       
  1218             }
       
  1219         }
       
  1220         d->inRelease = false;
       
  1221     }
       
  1222 
       
  1223     QDeclarativeKeyEvent ke(*event);
       
  1224     emit released(&ke);
       
  1225     event->setAccepted(ke.isAccepted());
       
  1226 
       
  1227     if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post);
       
  1228 }
       
  1229 
       
  1230 void QDeclarativeKeysAttached::inputMethodEvent(QInputMethodEvent *event, bool post)
       
  1231 {
       
  1232     Q_D(QDeclarativeKeysAttached);
       
  1233     if (post == m_processPost && d->item && !d->inIM && d->item->scene()) {
       
  1234         d->inIM = true;
       
  1235         for (int ii = 0; ii < d->targets.count(); ++ii) {
       
  1236             QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
       
  1237             if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
       
  1238                 d->item->scene()->sendEvent(i, event);
       
  1239                 if (event->isAccepted()) {
       
  1240                     d->imeItem = i;
       
  1241                     d->inIM = false;
       
  1242                     return;
       
  1243                 }
       
  1244             }
       
  1245         }
       
  1246         d->inIM = false;
       
  1247     }
       
  1248     if (!event->isAccepted()) QDeclarativeItemKeyFilter::inputMethodEvent(event, post);
       
  1249 }
       
  1250 
       
  1251 class QDeclarativeItemAccessor : public QGraphicsItem
       
  1252 {
       
  1253 public:
       
  1254     QVariant doInputMethodQuery(Qt::InputMethodQuery query) const {
       
  1255         return QGraphicsItem::inputMethodQuery(query);
       
  1256     }
       
  1257 };
       
  1258 
       
  1259 QVariant QDeclarativeKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const
       
  1260 {
       
  1261     Q_D(const QDeclarativeKeysAttached);
       
  1262     if (d->item) {
       
  1263         for (int ii = 0; ii < d->targets.count(); ++ii) {
       
  1264                 QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
       
  1265             if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check?
       
  1266                 QVariant v = static_cast<QDeclarativeItemAccessor *>(i)->doInputMethodQuery(query);
       
  1267                 if (v.userType() == QVariant::RectF)
       
  1268                     v = d->item->mapRectFromItem(i, v.toRectF());  //### cost?
       
  1269                 return v;
       
  1270             }
       
  1271         }
       
  1272     }
       
  1273     return QDeclarativeItemKeyFilter::inputMethodQuery(query);
       
  1274 }
       
  1275 
       
  1276 QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObject *obj)
       
  1277 {
       
  1278     return new QDeclarativeKeysAttached(obj);
       
  1279 }
       
  1280 
       
  1281 /*!
       
  1282     \class QDeclarativeItem
       
  1283     \since 4.7
       
  1284     \brief The QDeclarativeItem class provides the most basic of all visual items in QML.
       
  1285 
       
  1286     All visual items in Qt Declarative inherit from QDeclarativeItem.  Although QDeclarativeItem
       
  1287     has no visual appearance, it defines all the properties that are
       
  1288     common across visual items - such as the x and y position, the
       
  1289     width and height, \l {anchor-layout}{anchoring} and key handling.
       
  1290 
       
  1291     You can subclass QDeclarativeItem to provide your own custom visual item that inherits
       
  1292     these features. Note that, because it does not draw anything, QDeclarativeItem sets the
       
  1293     QGraphicsItem::ItemHasNoContents flag. If you subclass QDeclarativeItem to create a visual
       
  1294     item, you will need to unset this flag.
       
  1295 
       
  1296 */
       
  1297 
       
  1298 /*!
       
  1299     \qmlclass Item QDeclarativeItem
       
  1300     \since 4.7
       
  1301     \brief The Item is the most basic of all visual items in QML.
       
  1302 
       
  1303     All visual items in Qt Declarative inherit from Item.  Although Item
       
  1304     has no visual appearance, it defines all the properties that are
       
  1305     common across visual items - such as the x and y position, the
       
  1306     width and height, \l {anchor-layout}{anchoring} and key handling.
       
  1307 
       
  1308     Item is also useful for grouping items together.
       
  1309 
       
  1310     \qml
       
  1311     Item {
       
  1312         Image {
       
  1313             source: "tile.png"
       
  1314         }
       
  1315         Image {
       
  1316             x: 80
       
  1317             width: 100
       
  1318             height: 100
       
  1319             source: "tile.png"
       
  1320         }
       
  1321         Image {
       
  1322             x: 190
       
  1323             width: 100
       
  1324             height: 100
       
  1325             fillMode: Image.Tile
       
  1326             source: "tile.png"
       
  1327         }
       
  1328     }
       
  1329     \endqml
       
  1330 
       
  1331     \section1 Identity
       
  1332 
       
  1333     Each item has an "id" - the identifier of the Item.
       
  1334 
       
  1335     The identifier can be used in bindings and other expressions to
       
  1336     refer to the item. For example:
       
  1337 
       
  1338     \qml
       
  1339     Text { id: myText; ... }
       
  1340     Text { text: myText.text }
       
  1341     \endqml
       
  1342 
       
  1343     The identifier is available throughout to the \l {components}{component}
       
  1344     where it is declared.  The identifier must be unique in the component.
       
  1345 
       
  1346     The id should not be thought of as a "property" - it makes no sense
       
  1347     to write \c myText.id, for example.
       
  1348 
       
  1349     \section1 Key Handling
       
  1350 
       
  1351     Key handling is available to all Item-based visual elements via the \l {Keys}{Keys}
       
  1352     attached property.  The \e Keys attached property provides basic handlers such
       
  1353     as \l {Keys::onPressed}{onPressed} and \l {Keys::onReleased}{onReleased},
       
  1354     as well as handlers for specific keys, such as
       
  1355     \l {Keys::onCancelPressed}{onCancelPressed}.  The example below
       
  1356     assigns \l {qmlfocus}{focus} to the item and handles
       
  1357     the Left key via the general \e onPressed handler and the Select key via the
       
  1358     onSelectPressed handler:
       
  1359 
       
  1360     \qml
       
  1361     Item {
       
  1362         focus: true
       
  1363         Keys.onPressed: {
       
  1364             if (event.key == Qt.Key_Left) {
       
  1365                 console.log("move left");
       
  1366                 event.accepted = true;
       
  1367             }
       
  1368         }
       
  1369         Keys.onSelectPressed: console.log("Selected");
       
  1370     }
       
  1371     \endqml
       
  1372 
       
  1373     See the \l {Keys}{Keys} attached property for detailed documentation.
       
  1374 
       
  1375     \section1 Property Change Signals
       
  1376 
       
  1377     Most properties on Item and Item derivatives have a signal
       
  1378     emitted when they change. By convention, the signals are
       
  1379     named <propertyName>Changed, e.g. xChanged will be emitted when an item's
       
  1380     x property changes. Note that these also have signal handers e.g.
       
  1381     the onXChanged signal handler will be called when an item's x property
       
  1382     changes. For many properties in Item or Item derivatives this can be used
       
  1383     to add a touch of imperative logic to your application (when absolutely
       
  1384     necessary).
       
  1385 */
       
  1386 
       
  1387 /*!
       
  1388     \property QDeclarativeItem::baseline
       
  1389     \internal
       
  1390 */
       
  1391 
       
  1392 /*!
       
  1393     \property QDeclarativeItem::focus
       
  1394     \internal
       
  1395 */
       
  1396 
       
  1397 /*!
       
  1398     \property QDeclarativeItem::wantsFocus
       
  1399     \internal
       
  1400 */
       
  1401 
       
  1402 /*!
       
  1403     \property QDeclarativeItem::transformOrigin
       
  1404     \internal
       
  1405 */
       
  1406 
       
  1407 /*!
       
  1408     \fn void QDeclarativeItem::childrenRectChanged(const QRectF &)
       
  1409     \internal
       
  1410 */
       
  1411 
       
  1412 /*!
       
  1413     \fn void QDeclarativeItem::baselineOffsetChanged(qreal)
       
  1414     \internal
       
  1415 */
       
  1416 
       
  1417 /*!
       
  1418     \fn void QDeclarativeItem::stateChanged(const QString &state)
       
  1419     \internal
       
  1420 */
       
  1421 
       
  1422 /*!
       
  1423     \fn void QDeclarativeItem::parentChanged(QDeclarativeItem *)
       
  1424     \internal
       
  1425 */
       
  1426 
       
  1427 /*!
       
  1428     \fn void QDeclarativeItem::smoothChanged(bool)
       
  1429     \internal
       
  1430 */
       
  1431 
       
  1432 /*!
       
  1433     \fn void QDeclarativeItem::clipChanged(bool)
       
  1434     \internal
       
  1435 */
       
  1436 
       
  1437 /*! \fn void QDeclarativeItem::transformOriginChanged(TransformOrigin)
       
  1438   \internal
       
  1439 */
       
  1440 
       
  1441 /*!
       
  1442     \fn void QDeclarativeItem::childrenChanged()
       
  1443     \internal
       
  1444 */
       
  1445 
       
  1446 /*!
       
  1447     \fn void QDeclarativeItem::focusChanged(bool)
       
  1448     \internal
       
  1449 */
       
  1450 
       
  1451 /*!
       
  1452     \fn void QDeclarativeItem::wantsFocusChanged(bool)
       
  1453     \internal
       
  1454 */
       
  1455 
       
  1456 // ### Must fix
       
  1457 struct RegisterAnchorLineAtStartup {
       
  1458     RegisterAnchorLineAtStartup() {
       
  1459         qRegisterMetaType<QDeclarativeAnchorLine>("QDeclarativeAnchorLine");
       
  1460     }
       
  1461 };
       
  1462 static RegisterAnchorLineAtStartup registerAnchorLineAtStartup;
       
  1463 
       
  1464 
       
  1465 /*!
       
  1466     \fn QDeclarativeItem::QDeclarativeItem(QDeclarativeItem *parent)
       
  1467 
       
  1468     Constructs a QDeclarativeItem with the given \a parent.
       
  1469 */
       
  1470 QDeclarativeItem::QDeclarativeItem(QDeclarativeItem* parent)
       
  1471   : QGraphicsObject(*(new QDeclarativeItemPrivate), parent, 0)
       
  1472 {
       
  1473     Q_D(QDeclarativeItem);
       
  1474     d->init(parent);
       
  1475 }
       
  1476 
       
  1477 /*! \internal
       
  1478 */
       
  1479 QDeclarativeItem::QDeclarativeItem(QDeclarativeItemPrivate &dd, QDeclarativeItem *parent)
       
  1480   : QGraphicsObject(dd, parent, 0)
       
  1481 {
       
  1482     Q_D(QDeclarativeItem);
       
  1483     d->init(parent);
       
  1484 }
       
  1485 
       
  1486 /*!
       
  1487     Destroys the QDeclarativeItem.
       
  1488 */
       
  1489 QDeclarativeItem::~QDeclarativeItem()
       
  1490 {
       
  1491     Q_D(QDeclarativeItem);
       
  1492     for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
       
  1493         QDeclarativeAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
       
  1494         if (anchor)
       
  1495             anchor->clearItem(this);
       
  1496     }
       
  1497     if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) {
       
  1498         for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
       
  1499             QDeclarativeAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
       
  1500             if (anchor && anchor->item && anchor->item->parentItem() != this) //child will be deleted anyway
       
  1501                 anchor->updateOnComplete();
       
  1502         }
       
  1503     }
       
  1504     for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
       
  1505         const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
       
  1506         if (change.types & QDeclarativeItemPrivate::Destroyed)
       
  1507             change.listener->itemDestroyed(this);
       
  1508     }
       
  1509     d->changeListeners.clear();
       
  1510     delete d->_anchorLines; d->_anchorLines = 0;
       
  1511     delete d->_anchors; d->_anchors = 0;
       
  1512     delete d->_stateGroup; d->_stateGroup = 0;
       
  1513     delete d->_contents; d->_contents = 0;
       
  1514 }
       
  1515 
       
  1516 /*!
       
  1517     \qmlproperty enumeration Item::transformOrigin
       
  1518     This property holds the origin point around which scale and rotation transform.
       
  1519 
       
  1520     Nine transform origins are available, as shown in the image below.
       
  1521 
       
  1522     \image declarative-transformorigin.png
       
  1523 
       
  1524     This example rotates an image around its bottom-right corner.
       
  1525     \qml
       
  1526     Image {
       
  1527         source: "myimage.png"
       
  1528         transformOrigin: Item.BottomRight
       
  1529         rotation: 45
       
  1530     }
       
  1531     \endqml
       
  1532 
       
  1533     The default transform origin is \c Item.Center.
       
  1534 */
       
  1535 
       
  1536 /*!
       
  1537     \qmlproperty Item Item::parent
       
  1538     This property holds the parent of the item.
       
  1539 */
       
  1540 
       
  1541 /*!
       
  1542     \property QDeclarativeItem::parent
       
  1543     This property holds the parent of the item.
       
  1544 */
       
  1545 void QDeclarativeItem::setParentItem(QDeclarativeItem *parent)
       
  1546 {
       
  1547     QGraphicsObject::setParentItem(parent);
       
  1548 }
       
  1549 
       
  1550 /*!
       
  1551     Returns the QDeclarativeItem parent of this item.
       
  1552 */
       
  1553 QDeclarativeItem *QDeclarativeItem::parentItem() const
       
  1554 {
       
  1555     return qobject_cast<QDeclarativeItem *>(QGraphicsObject::parentItem());
       
  1556 }
       
  1557 
       
  1558 /*!
       
  1559     \qmlproperty real Item::childrenRect.x
       
  1560     \qmlproperty real Item::childrenRect.y
       
  1561     \qmlproperty real Item::childrenRect.width
       
  1562     \qmlproperty real Item::childrenRect.height
       
  1563 
       
  1564     The childrenRect properties allow an item access to the geometry of its
       
  1565     children. This property is useful if you have an item that needs to be
       
  1566     sized to fit its children.
       
  1567 */
       
  1568 
       
  1569 
       
  1570 /*!
       
  1571     \qmlproperty list<Item> Item::children
       
  1572     \qmlproperty list<Object> Item::resources
       
  1573 
       
  1574     The children property contains the list of visual children of this item.
       
  1575     The resources property contains non-visual resources that you want to
       
  1576     reference by name.
       
  1577 
       
  1578     Generally you can rely on Item's default property to handle all this for
       
  1579     you, but it can come in handy in some cases.
       
  1580 
       
  1581     \qml
       
  1582     Item {
       
  1583         children: [
       
  1584             Text {},
       
  1585             Rectangle {}
       
  1586         ]
       
  1587         resources: [
       
  1588             Component {
       
  1589                 id: myComponent
       
  1590                 Text {}
       
  1591             }
       
  1592         ]
       
  1593     }
       
  1594     \endqml
       
  1595 */
       
  1596 
       
  1597 /*!
       
  1598     Returns true if construction of the QML component is complete; otherwise
       
  1599     returns false.
       
  1600 
       
  1601     It is often desireable to delay some processing until the component is
       
  1602     completed.
       
  1603 
       
  1604     \sa componentComplete()
       
  1605 */
       
  1606 bool QDeclarativeItem::isComponentComplete() const
       
  1607 {
       
  1608     Q_D(const QDeclarativeItem);
       
  1609     return d->_componentComplete;
       
  1610 }
       
  1611 
       
  1612 void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
       
  1613 {
       
  1614     if (!o)
       
  1615         return;
       
  1616 
       
  1617     QDeclarativeItem *that = static_cast<QDeclarativeItem *>(prop->object);
       
  1618 
       
  1619     // This test is measurably (albeit only slightly) faster than qobject_cast<>()
       
  1620     const QMetaObject *mo = o->metaObject();
       
  1621     while (mo && mo != &QGraphicsObject::staticMetaObject) mo = mo->d.superdata;
       
  1622 
       
  1623     if (mo) {
       
  1624         QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(o))->setParentItemHelper(that, 0, 0);
       
  1625     } else {
       
  1626         o->setParent(that);
       
  1627     }
       
  1628 }
       
  1629 
       
  1630 QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
       
  1631 {
       
  1632     QObjectList children = prop->object->children();
       
  1633     if (index < children.count())
       
  1634         return children.at(index);
       
  1635     else
       
  1636         return 0;
       
  1637 }
       
  1638 
       
  1639 void QDeclarativeItemPrivate::resources_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
       
  1640 {
       
  1641     o->setParent(prop->object);
       
  1642 }
       
  1643 
       
  1644 int QDeclarativeItemPrivate::resources_count(QDeclarativeListProperty<QObject> *prop)
       
  1645 {
       
  1646     return prop->object->children().count();
       
  1647 }
       
  1648 
       
  1649 int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform> *list)
       
  1650 {
       
  1651     QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
       
  1652     if (object) {
       
  1653         QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
       
  1654         return d->transformData ? d->transformData->graphicsTransforms.size() : 0;
       
  1655     } else {
       
  1656         return 0;
       
  1657     }
       
  1658 }
       
  1659 
       
  1660 void QDeclarativeItemPrivate::transform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *item)
       
  1661 {
       
  1662     QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
       
  1663     if (object) // QGraphicsItem applies the list in the wrong order, so we prepend.
       
  1664         QGraphicsItemPrivate::get(object)->prependGraphicsTransform(item);
       
  1665 }
       
  1666 
       
  1667 QGraphicsTransform *QDeclarativeItemPrivate::transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int idx)
       
  1668 {
       
  1669     QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
       
  1670     if (object) {
       
  1671         QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
       
  1672         if (!d->transformData)
       
  1673             return 0;
       
  1674         return d->transformData->graphicsTransforms.at(idx);
       
  1675     } else {
       
  1676         return 0;
       
  1677     }
       
  1678 }
       
  1679 
       
  1680 void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphicsTransform> *list)
       
  1681 {
       
  1682     QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
       
  1683     if (object) {
       
  1684         QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
       
  1685         if (!d->transformData)
       
  1686             return;
       
  1687         object->setTransformations(QList<QGraphicsTransform *>());
       
  1688     }
       
  1689 }
       
  1690 
       
  1691 void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e)
       
  1692 {
       
  1693     QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o);
       
  1694     if (e)
       
  1695         e->connect(&item->d_func()->parentNotifier);
       
  1696     *((QDeclarativeItem **)rv) = item->parentItem();
       
  1697 }
       
  1698 
       
  1699 /*!
       
  1700     \qmlproperty list<Object> Item::data
       
  1701     \default
       
  1702 
       
  1703     The data property is allows you to freely mix visual children and resources
       
  1704     of an item.  If you assign a visual item to the data list it becomes
       
  1705     a child and if you assign any other object type, it is added as a resource.
       
  1706 
       
  1707     So you can write:
       
  1708     \qml
       
  1709     Item {
       
  1710         Text {}
       
  1711         Rectangle {}
       
  1712         Timer {}
       
  1713     }
       
  1714     \endqml
       
  1715 
       
  1716     instead of:
       
  1717     \qml
       
  1718     Item {
       
  1719         children: [
       
  1720             Text {},
       
  1721             Rectangle {}
       
  1722         ]
       
  1723         resources: [
       
  1724             Timer {}
       
  1725         ]
       
  1726     }
       
  1727     \endqml
       
  1728 
       
  1729     data is a behind-the-scenes property: you should never need to explicitly
       
  1730     specify it.
       
  1731  */
       
  1732 
       
  1733 /*! \internal */
       
  1734 QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::data()
       
  1735 {
       
  1736     return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::data_append);
       
  1737 }
       
  1738 
       
  1739 /*!
       
  1740     \property QDeclarativeItem::childrenRect
       
  1741     \brief The geometry of an item's children.
       
  1742 
       
  1743     This property holds the (collective) position and size of the item's children.
       
  1744 */
       
  1745 QRectF QDeclarativeItem::childrenRect()
       
  1746 {
       
  1747     Q_D(QDeclarativeItem);
       
  1748     if (!d->_contents) {
       
  1749         d->_contents = new QDeclarativeContents;
       
  1750         d->_contents->setItem(this);
       
  1751     }
       
  1752     return d->_contents->rectF();
       
  1753 }
       
  1754 
       
  1755 bool QDeclarativeItem::clip() const
       
  1756 {
       
  1757     return flags() & ItemClipsChildrenToShape;
       
  1758 }
       
  1759 
       
  1760 void QDeclarativeItem::setClip(bool c)
       
  1761 {
       
  1762     if (clip() == c)
       
  1763         return;
       
  1764     setFlag(ItemClipsChildrenToShape, c);
       
  1765     emit clipChanged(c);
       
  1766 }
       
  1767 
       
  1768 /*!
       
  1769   \qmlproperty real Item::x
       
  1770   \qmlproperty real Item::y
       
  1771   \qmlproperty real Item::width
       
  1772   \qmlproperty real Item::height
       
  1773 
       
  1774   Defines the item's position and size relative to its parent.
       
  1775 
       
  1776   \qml
       
  1777   Item { x: 100; y: 100; width: 100; height: 100 }
       
  1778   \endqml
       
  1779  */
       
  1780 
       
  1781 /*!
       
  1782   \qmlproperty real Item::z
       
  1783 
       
  1784   Sets the stacking order of the item.  By default the stacking order is 0.
       
  1785 
       
  1786   Items with a higher stacking value are drawn on top of items with a
       
  1787   lower stacking order.  Items with the same stacking value are drawn
       
  1788   bottom up in the order they appear.  Items with a negative stacking
       
  1789   value are drawn under their parent's content.
       
  1790 
       
  1791   The following example shows the various effects of stacking order.
       
  1792 
       
  1793   \table
       
  1794   \row
       
  1795   \o \image declarative-item_stacking1.png
       
  1796   \o Same \c z - later children above earlier children:
       
  1797   \qml
       
  1798   Item {
       
  1799       Rectangle {
       
  1800           color: "red"
       
  1801           width: 100; height: 100
       
  1802       }
       
  1803       Rectangle {
       
  1804           color: "blue"
       
  1805           x: 50; y: 50; width: 100; height: 100
       
  1806       }
       
  1807   }
       
  1808   \endqml
       
  1809   \row
       
  1810   \o \image declarative-item_stacking2.png
       
  1811   \o Higher \c z on top:
       
  1812   \qml
       
  1813   Item {
       
  1814       Rectangle {
       
  1815           z: 1
       
  1816           color: "red"
       
  1817           width: 100; height: 100
       
  1818       }
       
  1819       Rectangle {
       
  1820           color: "blue"
       
  1821           x: 50; y: 50; width: 100; height: 100
       
  1822       }
       
  1823   }
       
  1824   \endqml
       
  1825   \row
       
  1826   \o \image declarative-item_stacking3.png
       
  1827   \o Same \c z - children above parents:
       
  1828   \qml
       
  1829   Item {
       
  1830       Rectangle {
       
  1831           color: "red"
       
  1832           width: 100; height: 100
       
  1833           Rectangle {
       
  1834               color: "blue"
       
  1835               x: 50; y: 50; width: 100; height: 100
       
  1836           }
       
  1837       }
       
  1838   }
       
  1839   \endqml
       
  1840   \row
       
  1841   \o \image declarative-item_stacking4.png
       
  1842   \o Lower \c z below:
       
  1843   \qml
       
  1844   Item {
       
  1845       Rectangle {
       
  1846           color: "red"
       
  1847           width: 100; height: 100
       
  1848           Rectangle {
       
  1849               z: -1
       
  1850               color: "blue"
       
  1851               x: 50; y: 50; width: 100; height: 100
       
  1852           }
       
  1853       }
       
  1854   }
       
  1855   \endqml
       
  1856   \endtable
       
  1857  */
       
  1858 
       
  1859 /*!
       
  1860     \qmlproperty bool Item::visible
       
  1861 
       
  1862     Whether the item is visible. By default this is true.
       
  1863 
       
  1864     \note visible is not linked to actual visibility; if an item
       
  1865     moves off screen, or the opacity changes to 0, this will
       
  1866     not affect the visible property.
       
  1867 */
       
  1868 
       
  1869 
       
  1870 /*!
       
  1871   This function is called to handle this item's changes in
       
  1872   geometry from \a oldGeometry to \a newGeometry. If the two
       
  1873   geometries are the same, it doesn't do anything.
       
  1874  */
       
  1875 void QDeclarativeItem::geometryChanged(const QRectF &newGeometry,
       
  1876                               const QRectF &oldGeometry)
       
  1877 {
       
  1878     Q_D(QDeclarativeItem);
       
  1879 
       
  1880     if (d->_anchors)
       
  1881         d->_anchors->d_func()->updateMe();
       
  1882 
       
  1883     if (transformOrigin() != QDeclarativeItem::TopLeft
       
  1884         && (newGeometry.width() != oldGeometry.width() || newGeometry.height() != oldGeometry.height())) {
       
  1885         if (d->transformData) {
       
  1886             QPointF origin = d->computeTransformOrigin();
       
  1887             if (transformOriginPoint() != origin)
       
  1888                 setTransformOriginPoint(origin);
       
  1889         } else {
       
  1890             d->transformOriginDirty = true;
       
  1891         }
       
  1892     }
       
  1893 
       
  1894     if (newGeometry.x() != oldGeometry.x())
       
  1895         emit xChanged();
       
  1896     if (newGeometry.width() != oldGeometry.width())
       
  1897         emit widthChanged();
       
  1898     if (newGeometry.y() != oldGeometry.y())
       
  1899         emit yChanged();
       
  1900     if (newGeometry.height() != oldGeometry.height())
       
  1901         emit heightChanged();
       
  1902 
       
  1903     for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
       
  1904         const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
       
  1905         if (change.types & QDeclarativeItemPrivate::Geometry)
       
  1906             change.listener->itemGeometryChanged(this, newGeometry, oldGeometry);
       
  1907     }
       
  1908 }
       
  1909 
       
  1910 void QDeclarativeItemPrivate::removeItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types)
       
  1911 {
       
  1912     ChangeListener change(listener, types);
       
  1913     changeListeners.removeOne(change);
       
  1914 }
       
  1915 
       
  1916 /*! \internal */
       
  1917 void QDeclarativeItem::keyPressEvent(QKeyEvent *event)
       
  1918 {
       
  1919     Q_D(QDeclarativeItem);
       
  1920     keyPressPreHandler(event);
       
  1921     if (event->isAccepted())
       
  1922         return;
       
  1923     if (d->keyHandler)
       
  1924         d->keyHandler->keyPressed(event, true);
       
  1925     else
       
  1926         event->ignore();
       
  1927 }
       
  1928 
       
  1929 /*! \internal */
       
  1930 void QDeclarativeItem::keyReleaseEvent(QKeyEvent *event)
       
  1931 {
       
  1932     Q_D(QDeclarativeItem);
       
  1933     keyReleasePreHandler(event);
       
  1934     if (event->isAccepted())
       
  1935         return;
       
  1936     if (d->keyHandler)
       
  1937         d->keyHandler->keyReleased(event, true);
       
  1938     else
       
  1939         event->ignore();
       
  1940 }
       
  1941 
       
  1942 /*! \internal */
       
  1943 void QDeclarativeItem::inputMethodEvent(QInputMethodEvent *event)
       
  1944 {
       
  1945     Q_D(QDeclarativeItem);
       
  1946     inputMethodPreHandler(event);
       
  1947     if (event->isAccepted())
       
  1948         return;
       
  1949     if (d->keyHandler)
       
  1950         d->keyHandler->inputMethodEvent(event, true);
       
  1951     else
       
  1952         event->ignore();
       
  1953 }
       
  1954 
       
  1955 /*! \internal */
       
  1956 QVariant QDeclarativeItem::inputMethodQuery(Qt::InputMethodQuery query) const
       
  1957 {
       
  1958     Q_D(const QDeclarativeItem);
       
  1959     QVariant v;
       
  1960     if (d->keyHandler)
       
  1961         v = d->keyHandler->inputMethodQuery(query);
       
  1962 
       
  1963     if (!v.isValid())
       
  1964         v = QGraphicsObject::inputMethodQuery(query);
       
  1965 
       
  1966     return v;
       
  1967 }
       
  1968 
       
  1969 void QDeclarativeItem::keyPressPreHandler(QKeyEvent *event)
       
  1970 {
       
  1971     Q_D(QDeclarativeItem);
       
  1972     if (d->keyHandler && !d->doneEventPreHandler)
       
  1973         d->keyHandler->keyPressed(event, false);
       
  1974     else
       
  1975         event->ignore();
       
  1976     d->doneEventPreHandler = true;
       
  1977 }
       
  1978 
       
  1979 void QDeclarativeItem::keyReleasePreHandler(QKeyEvent *event)
       
  1980 {
       
  1981     Q_D(QDeclarativeItem);
       
  1982     if (d->keyHandler && !d->doneEventPreHandler)
       
  1983         d->keyHandler->keyReleased(event, false);
       
  1984     else
       
  1985         event->ignore();
       
  1986     d->doneEventPreHandler = true;
       
  1987 }
       
  1988 
       
  1989 void QDeclarativeItem::inputMethodPreHandler(QInputMethodEvent *event)
       
  1990 {
       
  1991     Q_D(QDeclarativeItem);
       
  1992     if (d->keyHandler && !d->doneEventPreHandler)
       
  1993         d->keyHandler->inputMethodEvent(event, false);
       
  1994     else
       
  1995         event->ignore();
       
  1996     d->doneEventPreHandler = true;
       
  1997 }
       
  1998 
       
  1999 
       
  2000 /*!
       
  2001     \internal
       
  2002 */
       
  2003 QDeclarativeAnchorLine QDeclarativeItemPrivate::left() const
       
  2004 {
       
  2005     return anchorLines()->left;
       
  2006 }
       
  2007 
       
  2008 /*!
       
  2009     \internal
       
  2010 */
       
  2011 QDeclarativeAnchorLine QDeclarativeItemPrivate::right() const
       
  2012 {
       
  2013     return anchorLines()->right;
       
  2014 }
       
  2015 
       
  2016 /*!
       
  2017     \internal
       
  2018 */
       
  2019 QDeclarativeAnchorLine QDeclarativeItemPrivate::horizontalCenter() const
       
  2020 {
       
  2021     return anchorLines()->hCenter;
       
  2022 }
       
  2023 
       
  2024 /*!
       
  2025     \internal
       
  2026 */
       
  2027 QDeclarativeAnchorLine QDeclarativeItemPrivate::top() const
       
  2028 {
       
  2029     return anchorLines()->top;
       
  2030 }
       
  2031 
       
  2032 /*!
       
  2033     \internal
       
  2034 */
       
  2035 QDeclarativeAnchorLine QDeclarativeItemPrivate::bottom() const
       
  2036 {
       
  2037     return anchorLines()->bottom;
       
  2038 }
       
  2039 
       
  2040 /*!
       
  2041     \internal
       
  2042 */
       
  2043 QDeclarativeAnchorLine QDeclarativeItemPrivate::verticalCenter() const
       
  2044 {
       
  2045     return anchorLines()->vCenter;
       
  2046 }
       
  2047 
       
  2048 
       
  2049 /*!
       
  2050     \internal
       
  2051 */
       
  2052 QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const
       
  2053 {
       
  2054     return anchorLines()->baseline;
       
  2055 }
       
  2056 
       
  2057 /*!
       
  2058   \qmlproperty AnchorLine Item::top
       
  2059   \qmlproperty AnchorLine Item::bottom
       
  2060   \qmlproperty AnchorLine Item::left
       
  2061   \qmlproperty AnchorLine Item::right
       
  2062   \qmlproperty AnchorLine Item::horizontalCenter
       
  2063   \qmlproperty AnchorLine Item::verticalCenter
       
  2064   \qmlproperty AnchorLine Item::baseline
       
  2065 
       
  2066   The anchor lines of the item.
       
  2067 
       
  2068   For more information see \l {anchor-layout}{Anchor Layouts}.
       
  2069 */
       
  2070 
       
  2071 /*!
       
  2072   \qmlproperty AnchorLine Item::anchors.top
       
  2073   \qmlproperty AnchorLine Item::anchors.bottom
       
  2074   \qmlproperty AnchorLine Item::anchors.left
       
  2075   \qmlproperty AnchorLine Item::anchors.right
       
  2076   \qmlproperty AnchorLine Item::anchors.horizontalCenter
       
  2077   \qmlproperty AnchorLine Item::anchors.verticalCenter
       
  2078   \qmlproperty AnchorLine Item::anchors.baseline
       
  2079 
       
  2080   \qmlproperty Item Item::anchors.fill
       
  2081   \qmlproperty Item Item::anchors.centerIn
       
  2082 
       
  2083   \qmlproperty real Item::anchors.margins
       
  2084   \qmlproperty real Item::anchors.topMargin
       
  2085   \qmlproperty real Item::anchors.bottomMargin
       
  2086   \qmlproperty real Item::anchors.leftMargin
       
  2087   \qmlproperty real Item::anchors.rightMargin
       
  2088   \qmlproperty real Item::anchors.horizontalCenterOffset
       
  2089   \qmlproperty real Item::anchors.verticalCenterOffset
       
  2090   \qmlproperty real Item::anchors.baselineOffset
       
  2091 
       
  2092   Anchors provide a way to position an item by specifying its
       
  2093   relationship with other items.
       
  2094 
       
  2095   Margins apply to top, bottom, left, right, and fill anchors.
       
  2096   The margins property can be used to set all of the various margins at once, to the same value.
       
  2097 
       
  2098   Offsets apply for horizontal center, vertical center, and baseline anchors.
       
  2099 
       
  2100   \table
       
  2101   \row
       
  2102   \o \image declarative-anchors_example.png
       
  2103   \o Text anchored to Image, horizontally centered and vertically below, with a margin.
       
  2104   \qml
       
  2105   Image { id: pic; ... }
       
  2106   Text {
       
  2107       id: label
       
  2108       anchors.horizontalCenter: pic.horizontalCenter
       
  2109       anchors.top: pic.bottom
       
  2110       anchors.topMargin: 5
       
  2111       ...
       
  2112   }
       
  2113   \endqml
       
  2114   \row
       
  2115   \o \image declarative-anchors_example2.png
       
  2116   \o
       
  2117   Left of Text anchored to right of Image, with a margin. The y
       
  2118   property of both defaults to 0.
       
  2119 
       
  2120   \qml
       
  2121     Image { id: pic; ... }
       
  2122     Text {
       
  2123         id: label
       
  2124         anchors.left: pic.right
       
  2125         anchors.leftMargin: 5
       
  2126         ...
       
  2127     }
       
  2128   \endqml
       
  2129   \endtable
       
  2130 
       
  2131   anchors.fill provides a convenient way for one item to have the
       
  2132   same geometry as another item, and is equivalent to connecting all
       
  2133   four directional anchors.
       
  2134 
       
  2135   \note You can only anchor an item to siblings or a parent.
       
  2136 
       
  2137   For more information see \l {anchor-layout}{Anchor Layouts}.
       
  2138 */
       
  2139 
       
  2140 /*!
       
  2141   \property QDeclarativeItem::baselineOffset
       
  2142   \brief The position of the item's baseline in local coordinates.
       
  2143 
       
  2144   The baseline of a Text item is the imaginary line on which the text
       
  2145   sits. Controls containing text usually set their baseline to the
       
  2146   baseline of their text.
       
  2147 
       
  2148   For non-text items, a default baseline offset of 0 is used.
       
  2149 */
       
  2150 qreal QDeclarativeItem::baselineOffset() const
       
  2151 {
       
  2152     Q_D(const QDeclarativeItem);
       
  2153     if (!d->_baselineOffset.isValid()) {
       
  2154         return 0.0;
       
  2155     } else
       
  2156         return d->_baselineOffset;
       
  2157 }
       
  2158 
       
  2159 void QDeclarativeItem::setBaselineOffset(qreal offset)
       
  2160 {
       
  2161     Q_D(QDeclarativeItem);
       
  2162     if (offset == d->_baselineOffset)
       
  2163         return;
       
  2164 
       
  2165     d->_baselineOffset = offset;
       
  2166 
       
  2167     for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
       
  2168         const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
       
  2169         if (change.types & QDeclarativeItemPrivate::Geometry) {
       
  2170             QDeclarativeAnchorsPrivate *anchor = change.listener->anchorPrivate();
       
  2171             if (anchor)
       
  2172                 anchor->updateVerticalAnchors();
       
  2173         }
       
  2174     }
       
  2175     emit baselineOffsetChanged(offset);
       
  2176 }
       
  2177 
       
  2178 /*!
       
  2179   \qmlproperty real Item::rotation
       
  2180   This property holds the rotation of the item in degrees clockwise.
       
  2181 
       
  2182   This specifies how many degrees to rotate the item around its transformOrigin.
       
  2183   The default rotation is 0 degrees (i.e. not rotated at all).
       
  2184 
       
  2185   \table
       
  2186   \row
       
  2187   \o \image declarative-rotation.png
       
  2188   \o
       
  2189   \qml
       
  2190   Rectangle {
       
  2191       color: "blue"
       
  2192       width: 100; height: 100
       
  2193       Rectangle {
       
  2194           color: "red"
       
  2195           x: 25; y: 25; width: 50; height: 50
       
  2196           rotation: 30
       
  2197       }
       
  2198   }
       
  2199   \endqml
       
  2200   \endtable
       
  2201 */
       
  2202 
       
  2203 /*!
       
  2204   \qmlproperty real Item::scale
       
  2205   This property holds the scale of the item.
       
  2206 
       
  2207   A scale of less than 1 means the item will be displayed smaller than
       
  2208   normal, and a scale of greater than 1 means the item will be
       
  2209   displayed larger than normal.  A negative scale means the item will
       
  2210   be mirrored.
       
  2211 
       
  2212   By default, items are displayed at a scale of 1 (i.e. at their
       
  2213   normal size).
       
  2214 
       
  2215   Scaling is from the item's transformOrigin.
       
  2216 
       
  2217   \table
       
  2218   \row
       
  2219   \o \image declarative-scale.png
       
  2220   \o
       
  2221   \qml
       
  2222   Rectangle {
       
  2223       color: "blue"
       
  2224       width: 100; height: 100
       
  2225       Rectangle {
       
  2226           color: "green"
       
  2227           width: 25; height: 25
       
  2228       }
       
  2229       Rectangle {
       
  2230           color: "red"
       
  2231           x: 25; y: 25; width: 50; height: 50
       
  2232           scale: 1.4
       
  2233       }
       
  2234   }
       
  2235   \endqml
       
  2236   \endtable
       
  2237 */
       
  2238 
       
  2239 /*!
       
  2240   \qmlproperty real Item::opacity
       
  2241 
       
  2242   The opacity of the item.  Opacity is specified as a number between 0
       
  2243   (fully transparent) and 1 (fully opaque).  The default is 1.
       
  2244 
       
  2245   Opacity is an \e inherited attribute.  That is, the opacity is
       
  2246   also applied individually to child items.  In almost all cases this
       
  2247   is what you want, but in some cases (like the following example)
       
  2248   it may produce undesired results.
       
  2249 
       
  2250   \table
       
  2251   \row
       
  2252   \o \image declarative-item_opacity1.png
       
  2253   \o
       
  2254   \qml
       
  2255     Item {
       
  2256         Rectangle {
       
  2257             color: "red"
       
  2258             width: 100; height: 100
       
  2259             Rectangle {
       
  2260                 color: "blue"
       
  2261                 x: 50; y: 50; width: 100; height: 100
       
  2262             }
       
  2263         }
       
  2264     }
       
  2265   \endqml
       
  2266   \row
       
  2267   \o \image declarative-item_opacity2.png
       
  2268   \o
       
  2269   \qml
       
  2270     Item {
       
  2271         Rectangle {
       
  2272             opacity: 0.5
       
  2273             color: "red"
       
  2274             width: 100; height: 100
       
  2275             Rectangle {
       
  2276                 color: "blue"
       
  2277                 x: 50; y: 50; width: 100; height: 100
       
  2278             }
       
  2279         }
       
  2280     }
       
  2281   \endqml
       
  2282   \endtable
       
  2283 */
       
  2284 
       
  2285 /*!
       
  2286   Returns a value indicating whether mouse input should
       
  2287   remain with this item exclusively.
       
  2288 
       
  2289   \sa setKeepMouseGrab()
       
  2290  */
       
  2291 bool QDeclarativeItem::keepMouseGrab() const
       
  2292 {
       
  2293     Q_D(const QDeclarativeItem);
       
  2294     return d->_keepMouse;
       
  2295 }
       
  2296 
       
  2297 /*!
       
  2298   The flag indicating whether the mouse should remain
       
  2299   with this item is set to \a keep.
       
  2300 
       
  2301   This is useful for items that wish to grab and keep mouse
       
  2302   interaction following a predefined gesture.  For example,
       
  2303   an item that is interested in horizontal mouse movement
       
  2304   may set keepMouseGrab to true once a threshold has been
       
  2305   exceeded.  Once keepMouseGrab has been set to true, filtering
       
  2306   items will not react to mouse events.
       
  2307 
       
  2308   If the item does not indicate that it wishes to retain mouse grab,
       
  2309   a filtering item may steal the grab. For example, Flickable may attempt
       
  2310   to steal a mouse grab if it detects that the user has begun to
       
  2311   move the viewport.
       
  2312 
       
  2313   \sa keepMouseGrab()
       
  2314  */
       
  2315 void QDeclarativeItem::setKeepMouseGrab(bool keep)
       
  2316 {
       
  2317     Q_D(QDeclarativeItem);
       
  2318     d->_keepMouse = keep;
       
  2319 }
       
  2320 
       
  2321 /*!
       
  2322     \qmlmethod object Item::mapFromItem(Item item, real x, real y)
       
  2323 
       
  2324     Maps the point (\a x, \a y), which is in \a item's coordinate system, to
       
  2325     this item's coordinate system, and returns an object with \c x and \c y
       
  2326     properties matching the mapped cooordinate.
       
  2327 
       
  2328     If \a item is a \c null value, this maps the point from the coordinate
       
  2329     system of the root QML view.
       
  2330 */
       
  2331 QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qreal y) const
       
  2332 {
       
  2333     QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
       
  2334     QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
       
  2335     if (!itemObj && !item.isNull()) {
       
  2336         qmlInfo(this) << "mapFromItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
       
  2337         return 0;
       
  2338     }
       
  2339 
       
  2340     // If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene()
       
  2341     QPointF p = qobject_cast<QGraphicsItem*>(this)->mapFromItem(itemObj, x, y);
       
  2342     sv.setProperty(QLatin1String("x"), p.x());
       
  2343     sv.setProperty(QLatin1String("y"), p.y());
       
  2344     return sv;
       
  2345 }
       
  2346 
       
  2347 /*!
       
  2348     \qmlmethod object Item::mapToItem(Item item, real x, real y)
       
  2349 
       
  2350     Maps the point (\a x, \a y), which is in this item's coordinate system, to
       
  2351     \a item's coordinate system, and returns an object with \c x and \c y
       
  2352     properties matching the mapped cooordinate.
       
  2353 
       
  2354     If \a item is a \c null value, this maps \a x and \a y to the coordinate
       
  2355     system of the root QML view.
       
  2356 */
       
  2357 QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qreal y) const
       
  2358 {
       
  2359     QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
       
  2360     QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
       
  2361     if (!itemObj && !item.isNull()) {
       
  2362         qmlInfo(this) << "mapToItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
       
  2363         return 0;
       
  2364     }
       
  2365 
       
  2366     // If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene()
       
  2367     QPointF p = qobject_cast<QGraphicsItem*>(this)->mapToItem(itemObj, x, y);
       
  2368     sv.setProperty(QLatin1String("x"), p.x());
       
  2369     sv.setProperty(QLatin1String("y"), p.y());
       
  2370     return sv;
       
  2371 }
       
  2372 
       
  2373 /*!
       
  2374     \qmlmethod Item::forceFocus()
       
  2375 
       
  2376     Force the focus on the item.
       
  2377     This method sets the focus on the item and makes sure that all the focus scopes higher in the object hierarchy are given focus.
       
  2378 */
       
  2379 void QDeclarativeItem::forceFocus()
       
  2380 {
       
  2381     setFocus(true);
       
  2382     QGraphicsItem *parent = parentItem();
       
  2383     while (parent) {
       
  2384         if (parent->flags() & QGraphicsItem::ItemIsFocusScope)
       
  2385             parent->setFocus(Qt::OtherFocusReason);
       
  2386         parent = parent->parentItem();
       
  2387     }
       
  2388 }
       
  2389 
       
  2390 void QDeclarativeItemPrivate::focusChanged(bool flag)
       
  2391 {
       
  2392     Q_Q(QDeclarativeItem);
       
  2393     emit q->focusChanged(flag);
       
  2394 }
       
  2395 
       
  2396 /*! \internal */
       
  2397 QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::resources()
       
  2398 {
       
  2399     return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::resources_append,
       
  2400                                              QDeclarativeItemPrivate::resources_count,
       
  2401                                              QDeclarativeItemPrivate::resources_at);
       
  2402 }
       
  2403 
       
  2404 /*!
       
  2405   \qmlproperty list<State> Item::states
       
  2406   This property holds a list of states defined by the item.
       
  2407 
       
  2408   \qml
       
  2409   Item {
       
  2410     states: [
       
  2411       State { ... },
       
  2412       State { ... }
       
  2413       ...
       
  2414     ]
       
  2415   }
       
  2416   \endqml
       
  2417 
       
  2418   \sa {qmlstate}{States}
       
  2419 */
       
  2420 
       
  2421 /*! \internal */
       
  2422 QDeclarativeListProperty<QDeclarativeState> QDeclarativeItemPrivate::states()
       
  2423 {
       
  2424     return _states()->statesProperty();
       
  2425 }
       
  2426 
       
  2427 /*!
       
  2428   \qmlproperty list<Transition> Item::transitions
       
  2429   This property holds a list of transitions defined by the item.
       
  2430 
       
  2431   \qml
       
  2432   Item {
       
  2433     transitions: [
       
  2434       Transition { ... },
       
  2435       Transition { ... }
       
  2436       ...
       
  2437     ]
       
  2438   }
       
  2439   \endqml
       
  2440 
       
  2441   \sa {state-transitions}{Transitions}
       
  2442 */
       
  2443 
       
  2444 
       
  2445 /*! \internal */
       
  2446 QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItemPrivate::transitions()
       
  2447 {
       
  2448     return _states()->transitionsProperty();
       
  2449 }
       
  2450 
       
  2451 /*
       
  2452   \qmlproperty list<Filter> Item::filter
       
  2453   This property holds a list of graphical filters to be applied to the item.
       
  2454 
       
  2455   \l {Filter}{Filters} include things like \l {Blur}{blurring}
       
  2456   the item, or giving it a \l Reflection.  Some
       
  2457   filters may not be available on all canvases; if a filter is not
       
  2458   available on a certain canvas, it will simply not be applied for
       
  2459   that canvas (but the QML will still be considered valid).
       
  2460 
       
  2461   \qml
       
  2462   Item {
       
  2463     filter: [
       
  2464       Blur { ... },
       
  2465       Relection { ... }
       
  2466       ...
       
  2467     ]
       
  2468   }
       
  2469   \endqml
       
  2470 */
       
  2471 
       
  2472 /*!
       
  2473   \qmlproperty bool Item::clip
       
  2474   This property holds whether clipping is enabled.
       
  2475 
       
  2476   if clipping is enabled, an item will clip its own painting, as well
       
  2477   as the painting of its children, to its bounding rectangle.
       
  2478 
       
  2479   Non-rectangular clipping regions are not supported for performance reasons.
       
  2480 */
       
  2481 
       
  2482 /*!
       
  2483   \property QDeclarativeItem::clip
       
  2484   This property holds whether clipping is enabled.
       
  2485 
       
  2486   if clipping is enabled, an item will clip its own painting, as well
       
  2487   as the painting of its children, to its bounding rectangle.
       
  2488 
       
  2489   Non-rectangular clipping regions are not supported for performance reasons.
       
  2490 */
       
  2491 
       
  2492 /*!
       
  2493   \qmlproperty string Item::state
       
  2494 
       
  2495   This property holds the name of the current state of the item.
       
  2496 
       
  2497   This property is often used in scripts to change between states. For
       
  2498   example:
       
  2499 
       
  2500   \qml
       
  2501     function toggle() {
       
  2502         if (button.state == 'On')
       
  2503             button.state = 'Off';
       
  2504         else
       
  2505             button.state = 'On';
       
  2506     }
       
  2507   \endqml
       
  2508 
       
  2509   If the item is in its base state (i.e. no explicit state has been
       
  2510   set), \c state will be a blank string. Likewise, you can return an
       
  2511   item to its base state by setting its current state to \c ''.
       
  2512 
       
  2513   \sa {qmlstates}{States}
       
  2514 */
       
  2515 
       
  2516 /*!
       
  2517   \property QDeclarativeItem::state
       
  2518   \internal
       
  2519 */
       
  2520 
       
  2521 /*! \internal */
       
  2522 QString QDeclarativeItemPrivate::state() const
       
  2523 {
       
  2524     if (!_stateGroup)
       
  2525         return QString();
       
  2526     else
       
  2527         return _stateGroup->state();
       
  2528 }
       
  2529 
       
  2530 /*! \internal */
       
  2531 void QDeclarativeItemPrivate::setState(const QString &state)
       
  2532 {
       
  2533     _states()->setState(state);
       
  2534 }
       
  2535 
       
  2536 /*!
       
  2537   \qmlproperty list<Transform> Item::transform
       
  2538   This property holds the list of transformations to apply.
       
  2539 
       
  2540   For more information see \l Transform.
       
  2541 */
       
  2542 
       
  2543 /*!
       
  2544   \property QDeclarativeItem::transform
       
  2545   \internal
       
  2546 */
       
  2547 
       
  2548 /*! \internal */
       
  2549 QDeclarativeListProperty<QGraphicsTransform> QDeclarativeItem::transform()
       
  2550 {
       
  2551     Q_D(QDeclarativeItem);
       
  2552     return QDeclarativeListProperty<QGraphicsTransform>(this, 0, d->transform_append, d->transform_count,
       
  2553                                                d->transform_at, d->transform_clear);
       
  2554 }
       
  2555 
       
  2556 /*!
       
  2557   \internal
       
  2558 
       
  2559   classBegin() is called when the item is constructed, but its
       
  2560   properties have not yet been set.
       
  2561 
       
  2562   \sa componentComplete(), isComponentComplete()
       
  2563 */
       
  2564 void QDeclarativeItem::classBegin()
       
  2565 {
       
  2566     Q_D(QDeclarativeItem);
       
  2567     d->_componentComplete = false;
       
  2568     if (d->_stateGroup)
       
  2569         d->_stateGroup->classBegin();
       
  2570     if (d->_anchors)
       
  2571         d->_anchors->classBegin();
       
  2572 }
       
  2573 
       
  2574 /*!
       
  2575   \internal
       
  2576 
       
  2577   componentComplete() is called when all items in the component
       
  2578   have been constructed.  It is often desireable to delay some
       
  2579   processing until the component is complete an all bindings in the
       
  2580   component have been resolved.
       
  2581 */
       
  2582 void QDeclarativeItem::componentComplete()
       
  2583 {
       
  2584     Q_D(QDeclarativeItem);
       
  2585     d->_componentComplete = true;
       
  2586     if (d->_stateGroup)
       
  2587         d->_stateGroup->componentComplete();
       
  2588     if (d->_anchors) {
       
  2589         d->_anchors->componentComplete();
       
  2590         d->_anchors->d_func()->updateOnComplete();
       
  2591     }
       
  2592     if (d->keyHandler)
       
  2593         d->keyHandler->componentComplete();
       
  2594 }
       
  2595 
       
  2596 QDeclarativeStateGroup *QDeclarativeItemPrivate::_states()
       
  2597 {
       
  2598     Q_Q(QDeclarativeItem);
       
  2599     if (!_stateGroup) {
       
  2600         _stateGroup = new QDeclarativeStateGroup;
       
  2601         if (!_componentComplete)
       
  2602             _stateGroup->classBegin();
       
  2603         QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)),
       
  2604                          q, SIGNAL(stateChanged(QString)));
       
  2605     }
       
  2606 
       
  2607     return _stateGroup;
       
  2608 }
       
  2609 
       
  2610 QDeclarativeItemPrivate::AnchorLines::AnchorLines(QGraphicsObject *q)
       
  2611 {
       
  2612     left.item = q;
       
  2613     left.anchorLine = QDeclarativeAnchorLine::Left;
       
  2614     right.item = q;
       
  2615     right.anchorLine = QDeclarativeAnchorLine::Right;
       
  2616     hCenter.item = q;
       
  2617     hCenter.anchorLine = QDeclarativeAnchorLine::HCenter;
       
  2618     top.item = q;
       
  2619     top.anchorLine = QDeclarativeAnchorLine::Top;
       
  2620     bottom.item = q;
       
  2621     bottom.anchorLine = QDeclarativeAnchorLine::Bottom;
       
  2622     vCenter.item = q;
       
  2623     vCenter.anchorLine = QDeclarativeAnchorLine::VCenter;
       
  2624     baseline.item = q;
       
  2625     baseline.anchorLine = QDeclarativeAnchorLine::Baseline;
       
  2626 }
       
  2627 
       
  2628 QPointF QDeclarativeItemPrivate::computeTransformOrigin() const
       
  2629 {
       
  2630     Q_Q(const QDeclarativeItem);
       
  2631 
       
  2632     QRectF br = q->boundingRect();
       
  2633 
       
  2634     switch(origin) {
       
  2635     default:
       
  2636     case QDeclarativeItem::TopLeft:
       
  2637         return QPointF(0, 0);
       
  2638     case QDeclarativeItem::Top:
       
  2639         return QPointF(br.width() / 2., 0);
       
  2640     case QDeclarativeItem::TopRight:
       
  2641         return QPointF(br.width(), 0);
       
  2642     case QDeclarativeItem::Left:
       
  2643         return QPointF(0, br.height() / 2.);
       
  2644     case QDeclarativeItem::Center:
       
  2645         return QPointF(br.width() / 2., br.height() / 2.);
       
  2646     case QDeclarativeItem::Right:
       
  2647         return QPointF(br.width(), br.height() / 2.);
       
  2648     case QDeclarativeItem::BottomLeft:
       
  2649         return QPointF(0, br.height());
       
  2650     case QDeclarativeItem::Bottom:
       
  2651         return QPointF(br.width() / 2., br.height());
       
  2652     case QDeclarativeItem::BottomRight:
       
  2653         return QPointF(br.width(), br.height());
       
  2654     }
       
  2655 }
       
  2656 
       
  2657 /*! \internal */
       
  2658 bool QDeclarativeItem::sceneEvent(QEvent *event)
       
  2659 {
       
  2660     Q_D(QDeclarativeItem);
       
  2661     if (event->type() == QEvent::KeyPress) {
       
  2662         QKeyEvent *k = static_cast<QKeyEvent *>(event);
       
  2663         if ((k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) &&
       
  2664             !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
       
  2665             keyPressEvent(static_cast<QKeyEvent *>(event));
       
  2666             if (!event->isAccepted())
       
  2667                 return QGraphicsItem::sceneEvent(event);
       
  2668             else
       
  2669                 return true;
       
  2670         } else {
       
  2671             return QGraphicsItem::sceneEvent(event);
       
  2672         }
       
  2673     } else {
       
  2674         bool rv = QGraphicsItem::sceneEvent(event);
       
  2675 
       
  2676         if (event->type() == QEvent::FocusIn ||
       
  2677             event->type() == QEvent::FocusOut) {
       
  2678             d->focusChanged(hasFocus());
       
  2679         }
       
  2680         return rv;
       
  2681     }
       
  2682 }
       
  2683 
       
  2684 /*!
       
  2685     \reimp
       
  2686 
       
  2687     Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is \e not called
       
  2688     during initial widget polishing. Items wishing to optimize start-up construction
       
  2689     should instead consider using componentComplete().
       
  2690 */
       
  2691 QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
       
  2692                                        const QVariant &value)
       
  2693 {
       
  2694     Q_D(QDeclarativeItem);
       
  2695     switch (change) {
       
  2696     case ItemParentHasChanged:
       
  2697         emit parentChanged(parentItem());
       
  2698         d->parentNotifier.notify();
       
  2699         break;
       
  2700     case ItemVisibleHasChanged: {
       
  2701             for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
       
  2702                 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
       
  2703                 if (change.types & QDeclarativeItemPrivate::Visibility) {
       
  2704                     change.listener->itemVisibilityChanged(this);
       
  2705                 }
       
  2706             }
       
  2707         }
       
  2708         break;
       
  2709     case ItemOpacityHasChanged: {
       
  2710             for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
       
  2711                 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
       
  2712                 if (change.types & QDeclarativeItemPrivate::Opacity) {
       
  2713                     change.listener->itemOpacityChanged(this);
       
  2714                 }
       
  2715             }
       
  2716         }
       
  2717         break;
       
  2718     case ItemChildAddedChange:
       
  2719         if (d->_contents)
       
  2720             d->_contents->childAdded(qobject_cast<QDeclarativeItem*>(
       
  2721                     value.value<QGraphicsItem*>()));
       
  2722         break;
       
  2723     case ItemChildRemovedChange:
       
  2724         if (d->_contents)
       
  2725             d->_contents->childRemoved(qobject_cast<QDeclarativeItem*>(
       
  2726                     value.value<QGraphicsItem*>()));
       
  2727         break;
       
  2728     default:
       
  2729         break;
       
  2730     }
       
  2731 
       
  2732     return QGraphicsItem::itemChange(change, value);
       
  2733 }
       
  2734 
       
  2735 /*! \internal */
       
  2736 QRectF QDeclarativeItem::boundingRect() const
       
  2737 {
       
  2738     Q_D(const QDeclarativeItem);
       
  2739     return QRectF(0, 0, d->mWidth, d->mHeight);
       
  2740 }
       
  2741 
       
  2742 /*!
       
  2743     \enum QDeclarativeItem::TransformOrigin
       
  2744 
       
  2745     Controls the point about which simple transforms like scale apply.
       
  2746 
       
  2747     \value TopLeft The top-left corner of the item.
       
  2748     \value Top The center point of the top of the item.
       
  2749     \value TopRight The top-right corner of the item.
       
  2750     \value Left The left most point of the vertical middle.
       
  2751     \value Center The center of the item.
       
  2752     \value Right The right most point of the vertical middle.
       
  2753     \value BottomLeft The bottom-left corner of the item.
       
  2754     \value Bottom The center point of the bottom of the item.
       
  2755     \value BottomRight The bottom-right corner of the item.
       
  2756 */
       
  2757 
       
  2758 /*!
       
  2759     Returns the current transform origin.
       
  2760 */
       
  2761 QDeclarativeItem::TransformOrigin QDeclarativeItem::transformOrigin() const
       
  2762 {
       
  2763     Q_D(const QDeclarativeItem);
       
  2764     return d->origin;
       
  2765 }
       
  2766 
       
  2767 /*!
       
  2768     Set the transform \a origin.
       
  2769 */
       
  2770 void QDeclarativeItem::setTransformOrigin(TransformOrigin origin)
       
  2771 {
       
  2772     Q_D(QDeclarativeItem);
       
  2773     if (origin != d->origin) {
       
  2774         d->origin = origin;
       
  2775         if (d->transformData)
       
  2776             QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin());
       
  2777         else
       
  2778             d->transformOriginDirty = true;
       
  2779         emit transformOriginChanged(d->origin);
       
  2780     }
       
  2781 }
       
  2782 
       
  2783 void QDeclarativeItemPrivate::transformChanged()
       
  2784 {
       
  2785     Q_Q(QDeclarativeItem);
       
  2786     if (transformOriginDirty) {
       
  2787         q->QGraphicsItem::setTransformOriginPoint(computeTransformOrigin());
       
  2788         transformOriginDirty = false;
       
  2789     }
       
  2790 }
       
  2791 
       
  2792 /*!
       
  2793     \property QDeclarativeItem::smooth
       
  2794     \brief whether the item is smoothly transformed.
       
  2795 
       
  2796     This property is provided purely for the purpose of optimization. Turning
       
  2797     smooth transforms off is faster, but looks worse; turning smooth
       
  2798     transformations on is slower, but looks better.
       
  2799 
       
  2800     By default smooth transformations are off.
       
  2801 */
       
  2802 
       
  2803 /*!
       
  2804     Returns true if the item should be drawn with antialiasing and
       
  2805     smooth pixmap filtering, false otherwise.
       
  2806 
       
  2807     The default is false.
       
  2808 
       
  2809     \sa setSmooth()
       
  2810 */
       
  2811 bool QDeclarativeItem::smooth() const
       
  2812 {
       
  2813     Q_D(const QDeclarativeItem);
       
  2814     return d->smooth;
       
  2815 }
       
  2816 
       
  2817 /*!
       
  2818     Sets whether the item should be drawn with antialiasing and
       
  2819     smooth pixmap filtering to \a smooth.
       
  2820 
       
  2821     \sa smooth()
       
  2822 */
       
  2823 void QDeclarativeItem::setSmooth(bool smooth)
       
  2824 {
       
  2825     Q_D(QDeclarativeItem);
       
  2826     if (d->smooth == smooth)
       
  2827         return;
       
  2828     d->smooth = smooth;
       
  2829     emit smoothChanged(smooth);
       
  2830     update();
       
  2831 }
       
  2832 
       
  2833 /*!
       
  2834     \internal
       
  2835     Return the width of the item
       
  2836 */
       
  2837 qreal QDeclarativeItem::width() const
       
  2838 {
       
  2839     Q_D(const QDeclarativeItem);
       
  2840     return d->width();
       
  2841 }
       
  2842 
       
  2843 /*!
       
  2844     \internal
       
  2845     Set the width of the item
       
  2846 */
       
  2847 void QDeclarativeItem::setWidth(qreal w)
       
  2848 {
       
  2849     Q_D(QDeclarativeItem);
       
  2850     d->setWidth(w);
       
  2851 }
       
  2852 
       
  2853 /*!
       
  2854     \internal
       
  2855     Reset the width of the item
       
  2856 */
       
  2857 void QDeclarativeItem::resetWidth()
       
  2858 {
       
  2859     Q_D(QDeclarativeItem);
       
  2860     d->resetWidth();
       
  2861 }
       
  2862 
       
  2863 /*!
       
  2864     \internal
       
  2865     Return the width of the item
       
  2866 */
       
  2867 qreal QDeclarativeItemPrivate::width() const
       
  2868 {
       
  2869     return mWidth;
       
  2870 }
       
  2871 
       
  2872 /*!
       
  2873     \internal
       
  2874 */
       
  2875 void QDeclarativeItemPrivate::setWidth(qreal w)
       
  2876 {
       
  2877     Q_Q(QDeclarativeItem);
       
  2878     if (qIsNaN(w))
       
  2879         return;
       
  2880 
       
  2881     widthValid = true;
       
  2882     if (mWidth == w)
       
  2883         return;
       
  2884 
       
  2885     qreal oldWidth = mWidth;
       
  2886 
       
  2887     q->prepareGeometryChange();
       
  2888     mWidth = w;
       
  2889 
       
  2890     q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
       
  2891                     QRectF(q->x(), q->y(), oldWidth, height()));
       
  2892 }
       
  2893 
       
  2894 /*!
       
  2895     \internal
       
  2896 */
       
  2897 void QDeclarativeItemPrivate::resetWidth()
       
  2898 {
       
  2899     Q_Q(QDeclarativeItem);
       
  2900     widthValid = false;
       
  2901     q->setImplicitWidth(q->implicitWidth());
       
  2902 }
       
  2903 
       
  2904 /*!
       
  2905     Returns the width of the item that is implied by other properties that determine the content.
       
  2906 */
       
  2907 qreal QDeclarativeItem::implicitWidth() const
       
  2908 {
       
  2909     Q_D(const QDeclarativeItem);
       
  2910     return d->implicitWidth;
       
  2911 }
       
  2912 
       
  2913 /*!
       
  2914     Sets the implied width of the item to \a w.
       
  2915     This is the width implied by other properties that determine the content.
       
  2916 */
       
  2917 void QDeclarativeItem::setImplicitWidth(qreal w)
       
  2918 {
       
  2919     Q_D(QDeclarativeItem);
       
  2920     d->implicitWidth = w;
       
  2921     if (d->mWidth == w || widthValid())
       
  2922         return;
       
  2923 
       
  2924     qreal oldWidth = d->mWidth;
       
  2925 
       
  2926     prepareGeometryChange();
       
  2927     d->mWidth = w;
       
  2928 
       
  2929     geometryChanged(QRectF(x(), y(), width(), height()),
       
  2930                     QRectF(x(), y(), oldWidth, height()));
       
  2931 }
       
  2932 
       
  2933 /*!
       
  2934     Returns whether the width property has been set explicitly.
       
  2935 */
       
  2936 bool QDeclarativeItem::widthValid() const
       
  2937 {
       
  2938     Q_D(const QDeclarativeItem);
       
  2939     return d->widthValid;
       
  2940 }
       
  2941 
       
  2942 /*!
       
  2943     \internal
       
  2944     Return the height of the item
       
  2945 */
       
  2946 qreal QDeclarativeItem::height() const
       
  2947 {
       
  2948     Q_D(const QDeclarativeItem);
       
  2949     return d->height();
       
  2950 }
       
  2951 
       
  2952 /*!
       
  2953     \internal
       
  2954     Set the height of the item
       
  2955 */
       
  2956 void QDeclarativeItem::setHeight(qreal h)
       
  2957 {
       
  2958     Q_D(QDeclarativeItem);
       
  2959     d->setHeight(h);
       
  2960 }
       
  2961 
       
  2962 /*!
       
  2963     \internal
       
  2964     Reset the height of the item
       
  2965 */
       
  2966 void QDeclarativeItem::resetHeight()
       
  2967 {
       
  2968     Q_D(QDeclarativeItem);
       
  2969     d->resetHeight();
       
  2970 }
       
  2971 
       
  2972 /*!
       
  2973     \internal
       
  2974 */
       
  2975 qreal QDeclarativeItemPrivate::height() const
       
  2976 {
       
  2977     return mHeight;
       
  2978 }
       
  2979 
       
  2980 /*!
       
  2981     \internal
       
  2982 */
       
  2983 void QDeclarativeItemPrivate::setHeight(qreal h)
       
  2984 {
       
  2985     Q_Q(QDeclarativeItem);
       
  2986     if (qIsNaN(h))
       
  2987         return;
       
  2988 
       
  2989     heightValid = true;
       
  2990     if (mHeight == h)
       
  2991         return;
       
  2992 
       
  2993     qreal oldHeight = mHeight;
       
  2994 
       
  2995     q->prepareGeometryChange();
       
  2996     mHeight = h;
       
  2997 
       
  2998     q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
       
  2999                     QRectF(q->x(), q->y(), width(), oldHeight));
       
  3000 }
       
  3001 
       
  3002 /*!
       
  3003     \internal
       
  3004 */
       
  3005 void QDeclarativeItemPrivate::resetHeight()
       
  3006 {
       
  3007     Q_Q(QDeclarativeItem);
       
  3008     heightValid = false;
       
  3009     q->setImplicitHeight(q->implicitHeight());
       
  3010 }
       
  3011 
       
  3012 /*!
       
  3013     Returns the height of the item that is implied by other properties that determine the content.
       
  3014 */
       
  3015 qreal QDeclarativeItem::implicitHeight() const
       
  3016 {
       
  3017     Q_D(const QDeclarativeItem);
       
  3018     return d->implicitHeight;
       
  3019 }
       
  3020 
       
  3021 /*!
       
  3022     Sets the implied height of the item to \a h.
       
  3023     This is the height implied by other properties that determine the content.
       
  3024 */
       
  3025 void QDeclarativeItem::setImplicitHeight(qreal h)
       
  3026 {
       
  3027     Q_D(QDeclarativeItem);
       
  3028     d->implicitHeight = h;
       
  3029     if (d->mHeight == h || heightValid())
       
  3030         return;
       
  3031 
       
  3032     qreal oldHeight = d->mHeight;
       
  3033 
       
  3034     prepareGeometryChange();
       
  3035     d->mHeight = h;
       
  3036 
       
  3037     geometryChanged(QRectF(x(), y(), width(), height()),
       
  3038                     QRectF(x(), y(), width(), oldHeight));
       
  3039 }
       
  3040 
       
  3041 /*!
       
  3042     Returns whether the height property has been set explicitly.
       
  3043 */
       
  3044 bool QDeclarativeItem::heightValid() const
       
  3045 {
       
  3046     Q_D(const QDeclarativeItem);
       
  3047     return d->heightValid;
       
  3048 }
       
  3049 
       
  3050 /*! \internal */
       
  3051 void QDeclarativeItem::setSize(const QSizeF &size)
       
  3052 {
       
  3053     Q_D(QDeclarativeItem);
       
  3054     d->heightValid = true;
       
  3055     d->widthValid = true;
       
  3056 
       
  3057     if (d->height() == size.height() && d->width() == size.width())
       
  3058         return;
       
  3059 
       
  3060     qreal oldHeight = d->height();
       
  3061     qreal oldWidth = d->width();
       
  3062 
       
  3063     prepareGeometryChange();
       
  3064     d->setHeight(size.height());
       
  3065     d->setWidth(size.width());
       
  3066 
       
  3067     geometryChanged(QRectF(x(), y(), width(), height()),
       
  3068                     QRectF(x(), y(), oldWidth, oldHeight));
       
  3069 }
       
  3070 
       
  3071 /*!
       
  3072   \qmlproperty bool Item::wantsFocus
       
  3073 
       
  3074   This property indicates whether the item has has an active focus request.
       
  3075 
       
  3076   \sa {qmlfocus}{Keyboard Focus}
       
  3077 */
       
  3078 
       
  3079 /*! \internal */
       
  3080 bool QDeclarativeItem::wantsFocus() const
       
  3081 {
       
  3082     return focusItem() != 0;
       
  3083 }
       
  3084 
       
  3085 /*!
       
  3086   \qmlproperty bool Item::focus
       
  3087   This property indicates whether the item has keyboard input focus. Set this
       
  3088   property to true to request focus.
       
  3089 
       
  3090   \sa {qmlfocus}{Keyboard Focus}
       
  3091 */
       
  3092 
       
  3093 /*! \internal */
       
  3094 bool QDeclarativeItem::hasFocus() const
       
  3095 {
       
  3096     return QGraphicsItem::hasFocus();
       
  3097 }
       
  3098 
       
  3099 /*! \internal */
       
  3100 void QDeclarativeItem::setFocus(bool focus)
       
  3101 {
       
  3102     if (focus)
       
  3103         QGraphicsItem::setFocus(Qt::OtherFocusReason);
       
  3104     else
       
  3105         QGraphicsItem::clearFocus();
       
  3106 }
       
  3107 
       
  3108 /*!
       
  3109     \internal
       
  3110 */
       
  3111 void QDeclarativeItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
       
  3112 {
       
  3113 }
       
  3114 
       
  3115 /*!
       
  3116     \internal
       
  3117 */
       
  3118 bool QDeclarativeItem::event(QEvent *ev)
       
  3119 {
       
  3120     Q_D(QDeclarativeItem);
       
  3121     switch (ev->type()) {
       
  3122     case QEvent::KeyPress:
       
  3123     case QEvent::KeyRelease:
       
  3124     case QEvent::InputMethod:
       
  3125         d->doneEventPreHandler = false;
       
  3126         break;
       
  3127     default:
       
  3128         break;
       
  3129     }
       
  3130 
       
  3131     return QGraphicsObject::event(ev);
       
  3132 }
       
  3133 
       
  3134 QDebug operator<<(QDebug debug, QDeclarativeItem *item)
       
  3135 {
       
  3136     if (!item) {
       
  3137         debug << "QDeclarativeItem(0)";
       
  3138         return debug;
       
  3139     }
       
  3140 
       
  3141     debug << item->metaObject()->className() << "(this =" << ((void*)item)
       
  3142           << ", parent =" << ((void*)item->parentItem())
       
  3143           << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height()))
       
  3144           << ", z =" << item->zValue() << ')';
       
  3145     return debug;
       
  3146 }
       
  3147 
       
  3148 int QDeclarativeItemPrivate::consistentTime = -1;
       
  3149 void QDeclarativeItemPrivate::setConsistentTime(int t)
       
  3150 {
       
  3151     consistentTime = t;
       
  3152 }
       
  3153 
       
  3154 QTime QDeclarativeItemPrivate::currentTime()
       
  3155 {
       
  3156     if (consistentTime == -1)
       
  3157         return QTime::currentTime();
       
  3158     else
       
  3159         return QTime(0, 0).addMSecs(consistentTime);
       
  3160 }
       
  3161 
       
  3162 void QDeclarativeItemPrivate::start(QTime &t)
       
  3163 {
       
  3164     t = currentTime();
       
  3165 }
       
  3166 
       
  3167 int QDeclarativeItemPrivate::elapsed(QTime &t)
       
  3168 {
       
  3169     int n = t.msecsTo(currentTime());
       
  3170     if (n < 0)                                // passed midnight
       
  3171         n += 86400 * 1000;
       
  3172     return n;
       
  3173 }
       
  3174 
       
  3175 int QDeclarativeItemPrivate::restart(QTime &t)
       
  3176 {
       
  3177     QTime time = currentTime();
       
  3178     int n = t.msecsTo(time);
       
  3179     if (n < 0)                                // passed midnight
       
  3180         n += 86400*1000;
       
  3181     t = time;
       
  3182     return n;
       
  3183 }
       
  3184 
       
  3185 QT_END_NAMESPACE
       
  3186 
       
  3187 #include <moc_qdeclarativeitem.cpp>