1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qquickitem.h"
44 #include "qquickcanvas.h"
45 #include <QtDeclarative/qjsengine.h>
46 #include "qquickcanvas_p.h"
48 #include "qquickevents_p_p.h"
50 #include <QtDeclarative/qdeclarativeengine.h>
51 #include <QtDeclarative/qdeclarativecomponent.h>
52 #include <QtDeclarative/qdeclarativeinfo.h>
53 #include <QtGui/qpen.h>
54 #include <QtGui/qcursor.h>
55 #include <QtGui/qguiapplication.h>
56 #include <QtGui/qinputpanel.h>
57 #include <QtCore/qdebug.h>
58 #include <QtCore/qcoreevent.h>
59 #include <QtCore/qnumeric.h>
61 #include <private/qdeclarativeengine_p.h>
62 #include <QtQuick/private/qdeclarativestategroup_p.h>
63 #include <private/qdeclarativeopenmetaobject_p.h>
64 #include <QtQuick/private/qdeclarativestate_p.h>
65 #include <private/qlistmodelinterface_p.h>
66 #include <private/qquickitem_p.h>
70 // XXX todo Readd parentNotifier for faster parent bindings
71 // XXX todo Check that elements that create items handle memory correctly after visual ownership change
76 \qmlclass Transform QQuickTransform
77 \inqmlmodule QtQuick 2
78 \ingroup qml-transform-elements
79 \brief The Transform elements provide a way of building advanced transformations on Items.
81 The Transform element is a base type which cannot be instantiated directly.
82 The following concrete Transform types are available:
90 The Transform elements let you create and control advanced transformations that can be configured
91 independently using specialized properties.
93 You can assign any number of Transform elements to an \l Item. Each Transform is applied in order,
98 \qmlclass Translate QQuickTranslate
99 \inqmlmodule QtQuick 2
100 \ingroup qml-transform-elements
101 \brief The Translate object provides a way to move an Item without changing its x or y properties.
103 The Translate object provides independent control over position in addition to the Item's x and y properties.
105 The following example moves the Y axis of the \l Rectangle elements while still allowing the \l Row element
106 to lay the items out as if they had not been transformed:
112 width: 100; height: 100
114 transform: Translate { y: 20 }
117 width: 100; height: 100
119 transform: Translate { y: -20 }
128 \qmlproperty real QtQuick2::Translate::x
130 The translation along the X axis.
134 \qmlproperty real QtQuick2::Translate::y
136 The translation along the Y axis.
140 \qmlclass Scale QQuickScale
141 \inqmlmodule QtQuick 2
142 \ingroup qml-transform-elements
143 \brief The Scale element provides a way to scale an Item.
145 The Scale element gives more control over scaling than using \l Item's \l{Item::scale}{scale} property. Specifically,
146 it allows a different scale for the x and y axes, and allows the scale to be relative to an
149 The following example scales the X axis of the Rectangle, relative to its interior point 25, 25:
152 width: 100; height: 100
154 transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}
158 \sa Rotation, Translate
162 \qmlproperty real QtQuick2::Scale::origin.x
163 \qmlproperty real QtQuick2::Scale::origin.y
165 The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as
166 the rest of the item grows). By default the origin is 0, 0.
170 \qmlproperty real QtQuick2::Scale::xScale
172 The scaling factor for the X axis.
176 \qmlproperty real QtQuick2::Scale::yScale
178 The scaling factor for the Y axis.
182 \qmlclass Rotation QQuickRotation
183 \inqmlmodule QtQuick 2
184 \ingroup qml-transform-elements
185 \brief The Rotation object provides a way to rotate an Item.
187 The Rotation object gives more control over rotation than using \l Item's \l{Item::rotation}{rotation} property.
188 Specifically, it allows (z axis) rotation to be relative to an arbitrary point.
190 The following example rotates a Rectangle around its interior point 25, 25:
193 width: 100; height: 100
195 transform: Rotation { origin.x: 25; origin.y: 25; angle: 45}
199 Rotation also provides a way to specify 3D-like rotations for Items. For these types of
200 rotations you must specify the axis to rotate around in addition to the origin point.
202 The following example shows various 3D-like rotations applied to an \l Image.
203 \snippet doc/src/snippets/declarative/rotation.qml 0
205 \image axisrotation.png
207 \sa {declarative/ui-components/dialcontrol}{Dial Control example}, {declarative/toys/clocks}{Clocks example}
211 \qmlproperty real QtQuick2::Rotation::origin.x
212 \qmlproperty real QtQuick2::Rotation::origin.y
214 The origin point of the rotation (i.e., the point that stays fixed relative to the parent as
215 the rest of the item rotates). By default the origin is 0, 0.
219 \qmlproperty real QtQuick2::Rotation::axis.x
220 \qmlproperty real QtQuick2::Rotation::axis.y
221 \qmlproperty real QtQuick2::Rotation::axis.z
223 The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis,
224 as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 1 } }).
226 For a typical 3D-like rotation you will usually specify both the origin and the axis.
228 \image 3d-rotation-axis.png
232 \qmlproperty real QtQuick2::Rotation::angle
234 The angle to rotate, in degrees clockwise.
237 QQuickTransformPrivate::QQuickTransformPrivate()
241 QQuickTransform::QQuickTransform(QObject *parent)
242 : QObject(*(new QQuickTransformPrivate), parent)
246 QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent)
247 : QObject(dd, parent)
251 QQuickTransform::~QQuickTransform()
253 Q_D(QQuickTransform);
254 for (int ii = 0; ii < d->items.count(); ++ii) {
255 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
256 p->transforms.removeOne(this);
257 p->dirty(QQuickItemPrivate::Transform);
261 void QQuickTransform::update()
263 Q_D(QQuickTransform);
264 for (int ii = 0; ii < d->items.count(); ++ii) {
265 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
266 p->dirty(QQuickItemPrivate::Transform);
270 QQuickContents::QQuickContents(QQuickItem *item)
271 : m_item(item), m_x(0), m_y(0), m_width(0), m_height(0)
275 QQuickContents::~QQuickContents()
277 QList<QQuickItem *> children = m_item->childItems();
278 for (int i = 0; i < children.count(); ++i) {
279 QQuickItem *child = children.at(i);
280 QQuickItemPrivate::get(child)->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
284 bool QQuickContents::calcHeight(QQuickItem *changed)
287 qreal oldheight = m_height;
291 qreal bottom = oldy + oldheight;
292 qreal y = changed->y();
293 if (y + changed->height() > bottom)
294 bottom = y + changed->height();
298 m_height = bottom - top;
302 QList<QQuickItem *> children = m_item->childItems();
303 for (int i = 0; i < children.count(); ++i) {
304 QQuickItem *child = children.at(i);
305 qreal y = child->y();
306 if (y + child->height() > bottom)
307 bottom = y + child->height();
311 if (!children.isEmpty())
313 m_height = qMax(bottom - top, qreal(0.0));
316 return (m_height != oldheight || m_y != oldy);
319 bool QQuickContents::calcWidth(QQuickItem *changed)
322 qreal oldwidth = m_width;
326 qreal right = oldx + oldwidth;
327 qreal x = changed->x();
328 if (x + changed->width() > right)
329 right = x + changed->width();
333 m_width = right - left;
335 qreal left = FLT_MAX;
337 QList<QQuickItem *> children = m_item->childItems();
338 for (int i = 0; i < children.count(); ++i) {
339 QQuickItem *child = children.at(i);
340 qreal x = child->x();
341 if (x + child->width() > right)
342 right = x + child->width();
346 if (!children.isEmpty())
348 m_width = qMax(right - left, qreal(0.0));
351 return (m_width != oldwidth || m_x != oldx);
354 void QQuickContents::complete()
356 QQuickItemPrivate::get(m_item)->addItemChangeListener(this, QQuickItemPrivate::Children);
358 QList<QQuickItem *> children = m_item->childItems();
359 for (int i = 0; i < children.count(); ++i) {
360 QQuickItem *child = children.at(i);
361 QQuickItemPrivate::get(child)->addItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
362 //###what about changes to visibility?
367 void QQuickContents::updateRect()
369 QQuickItemPrivate::get(m_item)->emitChildrenRectChanged(rectF());
372 void QQuickContents::itemGeometryChanged(QQuickItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry)
375 bool wChanged = false;
376 bool hChanged = false;
377 //### we can only pass changed if the left edge has moved left, or the right edge has moved right
378 if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x())
379 wChanged = calcWidth(/*changed*/);
380 if (newGeometry.height() != oldGeometry.height() || newGeometry.y() != oldGeometry.y())
381 hChanged = calcHeight(/*changed*/);
382 if (wChanged || hChanged)
386 void QQuickContents::itemDestroyed(QQuickItem *item)
389 QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
393 void QQuickContents::itemChildRemoved(QQuickItem *, QQuickItem *item)
396 QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
400 void QQuickContents::itemChildAdded(QQuickItem *, QQuickItem *item)
403 QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
407 QQuickItemKeyFilter::QQuickItemKeyFilter(QQuickItem *item)
408 : m_processPost(false), m_next(0)
410 QQuickItemPrivate *p = item?QQuickItemPrivate::get(item):0;
412 m_next = p->keyHandler;
413 p->keyHandler = this;
417 QQuickItemKeyFilter::~QQuickItemKeyFilter()
421 void QQuickItemKeyFilter::keyPressed(QKeyEvent *event, bool post)
423 if (m_next) m_next->keyPressed(event, post);
426 void QQuickItemKeyFilter::keyReleased(QKeyEvent *event, bool post)
428 if (m_next) m_next->keyReleased(event, post);
431 void QQuickItemKeyFilter::inputMethodEvent(QInputMethodEvent *event, bool post)
434 m_next->inputMethodEvent(event, post);
439 QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const
441 if (m_next) return m_next->inputMethodQuery(query);
445 void QQuickItemKeyFilter::componentComplete()
447 if (m_next) m_next->componentComplete();
450 \qmlclass KeyNavigation QQuickKeyNavigationAttached
451 \inqmlmodule QtQuick 2
452 \ingroup qml-basic-interaction-elements
453 \brief The KeyNavigation attached property supports key navigation by arrow keys.
455 Key-based user interfaces commonly allow the use of arrow keys to navigate between
456 focusable items. The KeyNavigation attached property enables this behavior by providing a
457 convenient way to specify the item that should gain focus when an arrow or tab key is pressed.
459 The following example provides key navigation for a 2x2 grid of items:
461 \snippet doc/src/snippets/declarative/keynavigation.qml 0
463 The top-left item initially receives focus by setting \l {Item::}{focus} to
464 \c true. When an arrow key is pressed, the focus will move to the
465 appropriate item, as defined by the value that has been set for
466 the KeyNavigation \l left, \l right, \l up or \l down properties.
468 Note that if a KeyNavigation attached property receives the key press and release
469 events for a requested arrow or tab key, the event is accepted and does not
470 propagate any further.
472 By default, KeyNavigation receives key events after the item to which it is attached.
473 If the item accepts the key event, the KeyNavigation attached property will not
474 receive an event for that key. Setting the \l priority property to
475 \c KeyNavigation.BeforeItem allows the event to be used for key navigation
476 before the item, rather than after.
478 If item to which the focus is switching is not enabled or visible, an attempt will
479 be made to skip this item and focus on the next. This is possible if there are
480 a chain of items with the same KeyNavigation handler. If multiple items in a row are not enabled
481 or visible, they will also be skipped.
483 KeyNavigation will implicitly set the other direction to return focus to this item. So if you set
484 \l left to another item, \l right will be set on that item's KeyNavigation to set focus back to this
485 item. However, if that item's KeyNavigation has had right explicitly set then no change will occur.
486 This means that the above example could have been written, with the same behaviour, without specifing
487 KeyNavigation.right or KeyNavigation.down for any of the items.
489 \sa {Keys}{Keys attached property}
493 \qmlproperty Item QtQuick2::KeyNavigation::left
494 \qmlproperty Item QtQuick2::KeyNavigation::right
495 \qmlproperty Item QtQuick2::KeyNavigation::up
496 \qmlproperty Item QtQuick2::KeyNavigation::down
497 \qmlproperty Item QtQuick2::KeyNavigation::tab
498 \qmlproperty Item QtQuick2::KeyNavigation::backtab
500 These properties hold the item to assign focus to
501 when the left, right, up or down cursor keys, or the
506 \qmlproperty Item QtQuick2::KeyNavigation::tab
507 \qmlproperty Item QtQuick2::KeyNavigation::backtab
509 These properties hold the item to assign focus to
510 when the Tab key or Shift+Tab key combination (Backtab) are pressed.
513 QQuickKeyNavigationAttached::QQuickKeyNavigationAttached(QObject *parent)
514 : QObject(*(new QQuickKeyNavigationAttachedPrivate), parent),
515 QQuickItemKeyFilter(qobject_cast<QQuickItem*>(parent))
517 m_processPost = true;
520 QQuickKeyNavigationAttached *
521 QQuickKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
523 return new QQuickKeyNavigationAttached(obj);
526 QQuickItem *QQuickKeyNavigationAttached::left() const
528 Q_D(const QQuickKeyNavigationAttached);
532 void QQuickKeyNavigationAttached::setLeft(QQuickItem *i)
534 Q_D(QQuickKeyNavigationAttached);
539 QQuickKeyNavigationAttached* other =
540 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
541 if (other && !other->d_func()->rightSet){
542 other->d_func()->right = qobject_cast<QQuickItem*>(parent());
543 emit other->rightChanged();
548 QQuickItem *QQuickKeyNavigationAttached::right() const
550 Q_D(const QQuickKeyNavigationAttached);
554 void QQuickKeyNavigationAttached::setRight(QQuickItem *i)
556 Q_D(QQuickKeyNavigationAttached);
561 QQuickKeyNavigationAttached* other =
562 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
563 if (other && !other->d_func()->leftSet){
564 other->d_func()->left = qobject_cast<QQuickItem*>(parent());
565 emit other->leftChanged();
570 QQuickItem *QQuickKeyNavigationAttached::up() const
572 Q_D(const QQuickKeyNavigationAttached);
576 void QQuickKeyNavigationAttached::setUp(QQuickItem *i)
578 Q_D(QQuickKeyNavigationAttached);
583 QQuickKeyNavigationAttached* other =
584 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
585 if (other && !other->d_func()->downSet){
586 other->d_func()->down = qobject_cast<QQuickItem*>(parent());
587 emit other->downChanged();
592 QQuickItem *QQuickKeyNavigationAttached::down() const
594 Q_D(const QQuickKeyNavigationAttached);
598 void QQuickKeyNavigationAttached::setDown(QQuickItem *i)
600 Q_D(QQuickKeyNavigationAttached);
605 QQuickKeyNavigationAttached* other =
606 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
607 if (other && !other->d_func()->upSet) {
608 other->d_func()->up = qobject_cast<QQuickItem*>(parent());
609 emit other->upChanged();
614 QQuickItem *QQuickKeyNavigationAttached::tab() const
616 Q_D(const QQuickKeyNavigationAttached);
620 void QQuickKeyNavigationAttached::setTab(QQuickItem *i)
622 Q_D(QQuickKeyNavigationAttached);
627 QQuickKeyNavigationAttached* other =
628 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
629 if (other && !other->d_func()->backtabSet) {
630 other->d_func()->backtab = qobject_cast<QQuickItem*>(parent());
631 emit other->backtabChanged();
636 QQuickItem *QQuickKeyNavigationAttached::backtab() const
638 Q_D(const QQuickKeyNavigationAttached);
642 void QQuickKeyNavigationAttached::setBacktab(QQuickItem *i)
644 Q_D(QQuickKeyNavigationAttached);
648 d->backtabSet = true;
649 QQuickKeyNavigationAttached* other =
650 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
651 if (other && !other->d_func()->tabSet) {
652 other->d_func()->tab = qobject_cast<QQuickItem*>(parent());
653 emit other->tabChanged();
655 emit backtabChanged();
659 \qmlproperty enumeration QtQuick2::KeyNavigation::priority
661 This property determines whether the keys are processed before
662 or after the attached item's own key handling.
665 \o KeyNavigation.BeforeItem - process the key events before normal
666 item key processing. If the event is used for key navigation, it will be accepted and will not
667 be passed on to the item.
668 \o KeyNavigation.AfterItem (default) - process the key events after normal item key
669 handling. If the item accepts the key event it will not be
670 handled by the KeyNavigation attached property handler.
673 QQuickKeyNavigationAttached::Priority QQuickKeyNavigationAttached::priority() const
675 return m_processPost ? AfterItem : BeforeItem;
678 void QQuickKeyNavigationAttached::setPriority(Priority order)
680 bool processPost = order == AfterItem;
681 if (processPost != m_processPost) {
682 m_processPost = processPost;
683 emit priorityChanged();
687 void QQuickKeyNavigationAttached::keyPressed(QKeyEvent *event, bool post)
689 Q_D(QQuickKeyNavigationAttached);
692 if (post != m_processPost) {
693 QQuickItemKeyFilter::keyPressed(event, post);
698 switch (event->key()) {
700 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
701 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
702 QQuickItem* leftItem = mirror ? d->right : d->left;
704 setFocusNavigation(leftItem, mirror ? "right" : "left");
709 case Qt::Key_Right: {
710 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
711 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
712 QQuickItem* rightItem = mirror ? d->left : d->right;
714 setFocusNavigation(rightItem, mirror ? "left" : "right");
721 setFocusNavigation(d->up, "up");
727 setFocusNavigation(d->down, "down");
733 setFocusNavigation(d->tab, "tab");
737 case Qt::Key_Backtab:
739 setFocusNavigation(d->backtab, "backtab");
747 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
750 void QQuickKeyNavigationAttached::keyReleased(QKeyEvent *event, bool post)
752 Q_D(QQuickKeyNavigationAttached);
755 if (post != m_processPost) {
756 QQuickItemKeyFilter::keyReleased(event, post);
761 switch (event->key()) {
763 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
764 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
765 if (mirror ? d->right : d->left)
769 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
770 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
771 if (mirror ? d->left : d->right)
789 case Qt::Key_Backtab:
798 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
801 void QQuickKeyNavigationAttached::setFocusNavigation(QQuickItem *currentItem, const char *dir)
803 QQuickItem *initialItem = currentItem;
804 bool isNextItem = false;
807 if (currentItem->isVisible() && currentItem->isEnabled()) {
808 currentItem->setFocus(true);
811 qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(currentItem, false);
813 QQuickItem *tempItem = qvariant_cast<QQuickItem*>(attached->property(dir));
815 currentItem = tempItem;
821 while (currentItem != initialItem && isNextItem);
824 const QQuickKeysAttached::SigMap QQuickKeysAttached::sigMap[] = {
825 { Qt::Key_Left, "leftPressed" },
826 { Qt::Key_Right, "rightPressed" },
827 { Qt::Key_Up, "upPressed" },
828 { Qt::Key_Down, "downPressed" },
829 { Qt::Key_Tab, "tabPressed" },
830 { Qt::Key_Backtab, "backtabPressed" },
831 { Qt::Key_Asterisk, "asteriskPressed" },
832 { Qt::Key_NumberSign, "numberSignPressed" },
833 { Qt::Key_Escape, "escapePressed" },
834 { Qt::Key_Return, "returnPressed" },
835 { Qt::Key_Enter, "enterPressed" },
836 { Qt::Key_Delete, "deletePressed" },
837 { Qt::Key_Space, "spacePressed" },
838 { Qt::Key_Back, "backPressed" },
839 { Qt::Key_Cancel, "cancelPressed" },
840 { Qt::Key_Select, "selectPressed" },
841 { Qt::Key_Yes, "yesPressed" },
842 { Qt::Key_No, "noPressed" },
843 { Qt::Key_Context1, "context1Pressed" },
844 { Qt::Key_Context2, "context2Pressed" },
845 { Qt::Key_Context3, "context3Pressed" },
846 { Qt::Key_Context4, "context4Pressed" },
847 { Qt::Key_Call, "callPressed" },
848 { Qt::Key_Hangup, "hangupPressed" },
849 { Qt::Key_Flip, "flipPressed" },
850 { Qt::Key_Menu, "menuPressed" },
851 { Qt::Key_VolumeUp, "volumeUpPressed" },
852 { Qt::Key_VolumeDown, "volumeDownPressed" },
856 bool QQuickKeysAttachedPrivate::isConnected(const char *signalName)
858 return isSignalConnected(signalIndex(signalName));
862 \qmlclass Keys QQuickKeysAttached
863 \inqmlmodule QtQuick 2
864 \ingroup qml-basic-interaction-elements
865 \brief The Keys attached property provides key handling to Items.
867 All visual primitives support key handling via the Keys
868 attached property. Keys can be handled via the onPressed
869 and onReleased signal properties.
871 The signal properties have a \l KeyEvent parameter, named
872 \e event which contains details of the event. If a key is
873 handled \e event.accepted should be set to true to prevent the
874 event from propagating up the item hierarchy.
876 \section1 Example Usage
878 The following example shows how the general onPressed handler can
879 be used to test for a certain key; in this case, the left cursor
882 \snippet doc/src/snippets/declarative/keys/keys-pressed.qml key item
884 Some keys may alternatively be handled via specific signal properties,
885 for example \e onSelectPressed. These handlers automatically set
886 \e event.accepted to true.
888 \snippet doc/src/snippets/declarative/keys/keys-handler.qml key item
890 See \l{Qt::Key}{Qt.Key} for the list of keyboard codes.
892 \section1 Key Handling Priorities
894 The Keys attached property can be configured to handle key events
895 before or after the item it is attached to. This makes it possible
896 to intercept events in order to override an item's default behavior,
897 or act as a fallback for keys not handled by the item.
899 If \l priority is Keys.BeforeItem (default) the order of key event processing is:
902 \o Items specified in \c forwardTo
903 \o specific key handlers, e.g. onReturnPressed
904 \o onKeyPress, onKeyRelease handlers
905 \o Item specific key handling, e.g. TextInput key handling
909 If priority is Keys.AfterItem the order of key event processing is:
912 \o Item specific key handling, e.g. TextInput key handling
913 \o Items specified in \c forwardTo
914 \o specific key handlers, e.g. onReturnPressed
915 \o onKeyPress, onKeyRelease handlers
919 If the event is accepted during any of the above steps, key
922 \sa KeyEvent, {KeyNavigation}{KeyNavigation attached property}
926 \qmlproperty bool QtQuick2::Keys::enabled
928 This flags enables key handling if true (default); otherwise
929 no key handlers will be called.
933 \qmlproperty enumeration QtQuick2::Keys::priority
935 This property determines whether the keys are processed before
936 or after the attached item's own key handling.
939 \o Keys.BeforeItem (default) - process the key events before normal
940 item key processing. If the event is accepted it will not
941 be passed on to the item.
942 \o Keys.AfterItem - process the key events after normal item key
943 handling. If the item accepts the key event it will not be
944 handled by the Keys attached property handler.
949 \qmlproperty list<Object> QtQuick2::Keys::forwardTo
951 This property provides a way to forward key presses, key releases, and keyboard input
952 coming from input methods to other items. This can be useful when you want
953 one item to handle some keys (e.g. the up and down arrow keys), and another item to
954 handle other keys (e.g. the left and right arrow keys). Once an item that has been
955 forwarded keys accepts the event it is no longer forwarded to items later in the
958 This example forwards key events to two lists:
969 Keys.forwardTo: [list1, list2]
976 \qmlsignal QtQuick2::Keys::onPressed(KeyEvent event)
978 This handler is called when a key has been pressed. The \a event
979 parameter provides information about the event.
983 \qmlsignal QtQuick2::Keys::onReleased(KeyEvent event)
985 This handler is called when a key has been released. The \a event
986 parameter provides information about the event.
990 \qmlsignal QtQuick2::Keys::onDigit0Pressed(KeyEvent event)
992 This handler is called when the digit '0' has been pressed. The \a event
993 parameter provides information about the event.
997 \qmlsignal QtQuick2::Keys::onDigit1Pressed(KeyEvent event)
999 This handler is called when the digit '1' has been pressed. The \a event
1000 parameter provides information about the event.
1004 \qmlsignal QtQuick2::Keys::onDigit2Pressed(KeyEvent event)
1006 This handler is called when the digit '2' has been pressed. The \a event
1007 parameter provides information about the event.
1011 \qmlsignal QtQuick2::Keys::onDigit3Pressed(KeyEvent event)
1013 This handler is called when the digit '3' has been pressed. The \a event
1014 parameter provides information about the event.
1018 \qmlsignal QtQuick2::Keys::onDigit4Pressed(KeyEvent event)
1020 This handler is called when the digit '4' has been pressed. The \a event
1021 parameter provides information about the event.
1025 \qmlsignal QtQuick2::Keys::onDigit5Pressed(KeyEvent event)
1027 This handler is called when the digit '5' has been pressed. The \a event
1028 parameter provides information about the event.
1032 \qmlsignal QtQuick2::Keys::onDigit6Pressed(KeyEvent event)
1034 This handler is called when the digit '6' has been pressed. The \a event
1035 parameter provides information about the event.
1039 \qmlsignal QtQuick2::Keys::onDigit7Pressed(KeyEvent event)
1041 This handler is called when the digit '7' has been pressed. The \a event
1042 parameter provides information about the event.
1046 \qmlsignal QtQuick2::Keys::onDigit8Pressed(KeyEvent event)
1048 This handler is called when the digit '8' has been pressed. The \a event
1049 parameter provides information about the event.
1053 \qmlsignal QtQuick2::Keys::onDigit9Pressed(KeyEvent event)
1055 This handler is called when the digit '9' has been pressed. The \a event
1056 parameter provides information about the event.
1060 \qmlsignal QtQuick2::Keys::onLeftPressed(KeyEvent event)
1062 This handler is called when the Left arrow has been pressed. The \a event
1063 parameter provides information about the event.
1067 \qmlsignal QtQuick2::Keys::onRightPressed(KeyEvent event)
1069 This handler is called when the Right arrow has been pressed. The \a event
1070 parameter provides information about the event.
1074 \qmlsignal QtQuick2::Keys::onUpPressed(KeyEvent event)
1076 This handler is called when the Up arrow has been pressed. The \a event
1077 parameter provides information about the event.
1081 \qmlsignal QtQuick2::Keys::onDownPressed(KeyEvent event)
1083 This handler is called when the Down arrow has been pressed. The \a event
1084 parameter provides information about the event.
1088 \qmlsignal QtQuick2::Keys::onTabPressed(KeyEvent event)
1090 This handler is called when the Tab key has been pressed. The \a event
1091 parameter provides information about the event.
1095 \qmlsignal QtQuick2::Keys::onBacktabPressed(KeyEvent event)
1097 This handler is called when the Shift+Tab key combination (Backtab) has
1098 been pressed. The \a event parameter provides information about the event.
1102 \qmlsignal QtQuick2::Keys::onAsteriskPressed(KeyEvent event)
1104 This handler is called when the Asterisk '*' has been pressed. The \a event
1105 parameter provides information about the event.
1109 \qmlsignal QtQuick2::Keys::onEscapePressed(KeyEvent event)
1111 This handler is called when the Escape key has been pressed. The \a event
1112 parameter provides information about the event.
1116 \qmlsignal QtQuick2::Keys::onReturnPressed(KeyEvent event)
1118 This handler is called when the Return key has been pressed. The \a event
1119 parameter provides information about the event.
1123 \qmlsignal QtQuick2::Keys::onEnterPressed(KeyEvent event)
1125 This handler is called when the Enter key has been pressed. The \a event
1126 parameter provides information about the event.
1130 \qmlsignal QtQuick2::Keys::onDeletePressed(KeyEvent event)
1132 This handler is called when the Delete key has been pressed. The \a event
1133 parameter provides information about the event.
1137 \qmlsignal QtQuick2::Keys::onSpacePressed(KeyEvent event)
1139 This handler is called when the Space key has been pressed. The \a event
1140 parameter provides information about the event.
1144 \qmlsignal QtQuick2::Keys::onBackPressed(KeyEvent event)
1146 This handler is called when the Back key has been pressed. The \a event
1147 parameter provides information about the event.
1151 \qmlsignal QtQuick2::Keys::onCancelPressed(KeyEvent event)
1153 This handler is called when the Cancel key has been pressed. The \a event
1154 parameter provides information about the event.
1158 \qmlsignal QtQuick2::Keys::onSelectPressed(KeyEvent event)
1160 This handler is called when the Select key has been pressed. The \a event
1161 parameter provides information about the event.
1165 \qmlsignal QtQuick2::Keys::onYesPressed(KeyEvent event)
1167 This handler is called when the Yes key has been pressed. The \a event
1168 parameter provides information about the event.
1172 \qmlsignal QtQuick2::Keys::onNoPressed(KeyEvent event)
1174 This handler is called when the No key has been pressed. The \a event
1175 parameter provides information about the event.
1179 \qmlsignal QtQuick2::Keys::onContext1Pressed(KeyEvent event)
1181 This handler is called when the Context1 key has been pressed. The \a event
1182 parameter provides information about the event.
1186 \qmlsignal QtQuick2::Keys::onContext2Pressed(KeyEvent event)
1188 This handler is called when the Context2 key has been pressed. The \a event
1189 parameter provides information about the event.
1193 \qmlsignal QtQuick2::Keys::onContext3Pressed(KeyEvent event)
1195 This handler is called when the Context3 key has been pressed. The \a event
1196 parameter provides information about the event.
1200 \qmlsignal QtQuick2::Keys::onContext4Pressed(KeyEvent event)
1202 This handler is called when the Context4 key has been pressed. The \a event
1203 parameter provides information about the event.
1207 \qmlsignal QtQuick2::Keys::onCallPressed(KeyEvent event)
1209 This handler is called when the Call key has been pressed. The \a event
1210 parameter provides information about the event.
1214 \qmlsignal QtQuick2::Keys::onHangupPressed(KeyEvent event)
1216 This handler is called when the Hangup key has been pressed. The \a event
1217 parameter provides information about the event.
1221 \qmlsignal QtQuick2::Keys::onFlipPressed(KeyEvent event)
1223 This handler is called when the Flip key has been pressed. The \a event
1224 parameter provides information about the event.
1228 \qmlsignal QtQuick2::Keys::onMenuPressed(KeyEvent event)
1230 This handler is called when the Menu key has been pressed. The \a event
1231 parameter provides information about the event.
1235 \qmlsignal QtQuick2::Keys::onVolumeUpPressed(KeyEvent event)
1237 This handler is called when the VolumeUp key has been pressed. The \a event
1238 parameter provides information about the event.
1242 \qmlsignal QtQuick2::Keys::onVolumeDownPressed(KeyEvent event)
1244 This handler is called when the VolumeDown key has been pressed. The \a event
1245 parameter provides information about the event.
1248 QQuickKeysAttached::QQuickKeysAttached(QObject *parent)
1249 : QObject(*(new QQuickKeysAttachedPrivate), parent),
1250 QQuickItemKeyFilter(qobject_cast<QQuickItem*>(parent))
1252 Q_D(QQuickKeysAttached);
1253 m_processPost = false;
1254 d->item = qobject_cast<QQuickItem*>(parent);
1257 QQuickKeysAttached::~QQuickKeysAttached()
1261 QQuickKeysAttached::Priority QQuickKeysAttached::priority() const
1263 return m_processPost ? AfterItem : BeforeItem;
1266 void QQuickKeysAttached::setPriority(Priority order)
1268 bool processPost = order == AfterItem;
1269 if (processPost != m_processPost) {
1270 m_processPost = processPost;
1271 emit priorityChanged();
1275 void QQuickKeysAttached::componentComplete()
1277 Q_D(QQuickKeysAttached);
1279 for (int ii = 0; ii < d->targets.count(); ++ii) {
1280 QQuickItem *targetItem = d->targets.at(ii);
1281 if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1282 d->item->setFlag(QQuickItem::ItemAcceptsInputMethod);
1289 void QQuickKeysAttached::keyPressed(QKeyEvent *event, bool post)
1291 Q_D(QQuickKeysAttached);
1292 if (post != m_processPost || !d->enabled || d->inPress) {
1294 QQuickItemKeyFilter::keyPressed(event, post);
1298 // first process forwards
1299 if (d->item && d->item->canvas()) {
1301 for (int ii = 0; ii < d->targets.count(); ++ii) {
1302 QQuickItem *i = d->targets.at(ii);
1303 if (i && i->isVisible()) {
1304 d->item->canvas()->sendEvent(i, event);
1305 if (event->isAccepted()) {
1314 QQuickKeyEvent ke(*event);
1315 QByteArray keySignal = keyToSignal(event->key());
1316 if (!keySignal.isEmpty()) {
1317 keySignal += "(QQuickKeyEvent*)";
1318 if (d->isConnected(keySignal)) {
1319 // If we specifically handle a key then default to accepted
1320 ke.setAccepted(true);
1321 int idx = QQuickKeysAttached::staticMetaObject.indexOfSignal(keySignal);
1322 metaObject()->method(idx).invoke(this, Qt::DirectConnection, Q_ARG(QQuickKeyEvent*, &ke));
1325 if (!ke.isAccepted())
1327 event->setAccepted(ke.isAccepted());
1329 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
1332 void QQuickKeysAttached::keyReleased(QKeyEvent *event, bool post)
1334 Q_D(QQuickKeysAttached);
1335 if (post != m_processPost || !d->enabled || d->inRelease) {
1337 QQuickItemKeyFilter::keyReleased(event, post);
1341 if (d->item && d->item->canvas()) {
1342 d->inRelease = true;
1343 for (int ii = 0; ii < d->targets.count(); ++ii) {
1344 QQuickItem *i = d->targets.at(ii);
1345 if (i && i->isVisible()) {
1346 d->item->canvas()->sendEvent(i, event);
1347 if (event->isAccepted()) {
1348 d->inRelease = false;
1353 d->inRelease = false;
1356 QQuickKeyEvent ke(*event);
1358 event->setAccepted(ke.isAccepted());
1360 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
1363 void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event, bool post)
1365 Q_D(QQuickKeysAttached);
1366 if (post == m_processPost && d->item && !d->inIM && d->item->canvas()) {
1368 for (int ii = 0; ii < d->targets.count(); ++ii) {
1369 QQuickItem *i = d->targets.at(ii);
1370 if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1371 d->item->canvas()->sendEvent(i, event);
1372 if (event->isAccepted()) {
1381 QQuickItemKeyFilter::inputMethodEvent(event, post);
1384 QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const
1386 Q_D(const QQuickKeysAttached);
1388 for (int ii = 0; ii < d->targets.count(); ++ii) {
1389 QQuickItem *i = d->targets.at(ii);
1390 if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) {
1391 //### how robust is i == d->imeItem check?
1392 QVariant v = i->inputMethodQuery(query);
1393 if (v.userType() == QVariant::RectF)
1394 v = d->item->mapRectFromItem(i, v.toRectF()); //### cost?
1399 return QQuickItemKeyFilter::inputMethodQuery(query);
1402 QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj)
1404 return new QQuickKeysAttached(obj);
1408 \qmlclass LayoutMirroring QQuickLayoutMirroringAttached
1409 \inqmlmodule QtQuick 2
1410 \ingroup qml-utility-elements
1411 \brief The LayoutMirroring attached property is used to mirror layout behavior.
1413 The LayoutMirroring attached property is used to horizontally mirror \l {anchor-layout}{Item anchors},
1414 \l{Using QML Positioner and Repeater Items}{positioner} elements (such as \l Row and \l Grid)
1415 and views (such as \l GridView and horizontal \l ListView). Mirroring is a visual change: left
1416 anchors become right anchors, and positioner elements like \l Grid and \l Row reverse the
1417 horizontal layout of child items.
1419 Mirroring is enabled for an item by setting the \l enabled property to true. By default, this
1420 only affects the item itself; setting the \l childrenInherit property to true propagates the mirroring
1421 behavior to all child elements as well. If the \c LayoutMirroring attached property has not been defined
1422 for an item, mirroring is not enabled.
1424 The following example shows mirroring in action. The \l Row below is specified as being anchored
1425 to the left of its parent. However, since mirroring has been enabled, the anchor is horizontally
1426 reversed and it is now anchored to the right. Also, since items in a \l Row are positioned
1427 from left to right by default, they are now positioned from right to left instead, as demonstrated
1428 by the numbering and opacity of the items:
1430 \snippet doc/src/snippets/declarative/layoutmirroring.qml 0
1432 \image layoutmirroring.png
1434 Layout mirroring is useful when it is necessary to support both left-to-right and right-to-left
1435 layout versions of an application to target different language areas. The \l childrenInherit
1436 property allows layout mirroring to be applied without manually setting layout configurations
1437 for every item in an application. Keep in mind, however, that mirroring does not affect any
1438 positioning that is defined by the \l Item \l {Item::}{x} coordinate value, so even with
1439 mirroring enabled, it will often be necessary to apply some layout fixes to support the
1440 desired layout direction. Also, it may be necessary to disable the mirroring of individual
1441 child items (by setting \l {enabled}{LayoutMirroring.enabled} to false for such items) if
1442 mirroring is not the desired behavior, or if the child item already implements mirroring in
1445 See \l {QML Right-to-left User Interfaces} for further details on using \c LayoutMirroring and
1446 other related features to implement right-to-left support for an application.
1450 \qmlproperty bool QtQuick2::LayoutMirroring::enabled
1452 This property holds whether the item's layout is mirrored horizontally. Setting this to true
1453 horizontally reverses \l {anchor-layout}{anchor} settings such that left anchors become right,
1454 and right anchors become left. For \l{Using QML Positioner and Repeater Items}{positioner} elements
1455 (such as \l Row and \l Grid) and view elements (such as \l {GridView}{GridView} and \l {ListView}{ListView})
1456 this also mirrors the horizontal layout direction of the item.
1458 The default value is false.
1462 \qmlproperty bool QtQuick2::LayoutMirroring::childrenInherit
1464 This property holds whether the \l {enabled}{LayoutMirroring.enabled} value for this item
1465 is inherited by its children.
1467 The default value is false.
1471 QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(0)
1473 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1474 itemPrivate = QQuickItemPrivate::get(item);
1475 itemPrivate->attachedLayoutDirection = this;
1477 qmlInfo(parent) << tr("LayoutDirection attached property only works with Items");
1480 QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1482 return new QQuickLayoutMirroringAttached(object);
1485 bool QQuickLayoutMirroringAttached::enabled() const
1487 return itemPrivate ? itemPrivate->effectiveLayoutMirror : false;
1490 void QQuickLayoutMirroringAttached::setEnabled(bool enabled)
1495 itemPrivate->isMirrorImplicit = false;
1496 if (enabled != itemPrivate->effectiveLayoutMirror) {
1497 itemPrivate->setLayoutMirror(enabled);
1498 if (itemPrivate->inheritMirrorFromItem)
1499 itemPrivate->resolveLayoutMirror();
1503 void QQuickLayoutMirroringAttached::resetEnabled()
1505 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1506 itemPrivate->isMirrorImplicit = true;
1507 itemPrivate->resolveLayoutMirror();
1511 bool QQuickLayoutMirroringAttached::childrenInherit() const
1513 return itemPrivate ? itemPrivate->inheritMirrorFromItem : false;
1516 void QQuickLayoutMirroringAttached::setChildrenInherit(bool childrenInherit) {
1517 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1518 itemPrivate->inheritMirrorFromItem = childrenInherit;
1519 itemPrivate->resolveLayoutMirror();
1520 childrenInheritChanged();
1524 void QQuickItemPrivate::resolveLayoutMirror()
1527 if (QQuickItem *parentItem = q->parentItem()) {
1528 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1529 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1531 setImplicitLayoutMirror(isMirrorImplicit ? false : effectiveLayoutMirror, inheritMirrorFromItem);
1535 void QQuickItemPrivate::setImplicitLayoutMirror(bool mirror, bool inherit)
1537 inherit = inherit || inheritMirrorFromItem;
1538 if (!isMirrorImplicit && inheritMirrorFromItem)
1539 mirror = effectiveLayoutMirror;
1540 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1543 inheritMirrorFromParent = inherit;
1544 inheritedLayoutMirror = inheritMirrorFromParent ? mirror : false;
1546 if (isMirrorImplicit)
1547 setLayoutMirror(inherit ? inheritedLayoutMirror : false);
1548 for (int i = 0; i < childItems.count(); ++i) {
1549 if (QQuickItem *child = qobject_cast<QQuickItem *>(childItems.at(i))) {
1550 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1551 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1556 void QQuickItemPrivate::setLayoutMirror(bool mirror)
1558 if (mirror != effectiveLayoutMirror) {
1559 effectiveLayoutMirror = mirror;
1561 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1562 anchor_d->fillChanged();
1563 anchor_d->centerInChanged();
1564 anchor_d->updateHorizontalAnchors();
1565 emit _anchors->mirroredChanged();
1568 if (attachedLayoutDirection) {
1569 emit attachedLayoutDirection->enabledChanged();
1576 \brief The QQuickItem class provides the most basic of all visual items in QML.
1580 All visual items in Qt Declarative inherit from QQuickItem. Although QQuickItem
1581 has no visual appearance, it defines all the properties that are
1582 common across visual items - such as the x and y position, the
1583 width and height, \l {anchor-layout}{anchoring} and key handling.
1585 You can subclass QQuickItem to provide your own custom visual item that inherits
1586 these features. Note that, because it does not draw anything, QQuickItem sets the
1587 QGraphicsItem::ItemHasNoContents flag. If you subclass QQuickItem to create a visual
1588 item, you will need to unset this flag.
1593 \qmlclass Item QQuickItem
1594 \inqmlmodule QtQuick 2
1595 \ingroup qml-basic-visual-elements
1596 \brief The Item is the most basic of all visual items in QML.
1598 All visual items in Qt Declarative inherit from Item. Although Item
1599 has no visual appearance, it defines all the properties that are
1600 common across visual items - such as the x and y position, the
1601 width and height, \l {anchor-layout}{anchoring} and key handling.
1603 Item is also useful for grouping items together.
1620 fillMode: Image.Tile
1627 \section1 Key Handling
1629 Key handling is available to all Item-based visual elements via the \l {Keys}{Keys}
1630 attached property. The \e Keys attached property provides basic handlers such
1631 as \l {Keys::onPressed}{onPressed} and \l {Keys::onReleased}{onReleased},
1632 as well as handlers for specific keys, such as
1633 \l {Keys::onCancelPressed}{onCancelPressed}. The example below
1634 assigns \l {qmlfocus}{focus} to the item and handles
1635 the Left key via the general \e onPressed handler and the Select key via the
1636 onSelectPressed handler:
1642 if (event.key == Qt.Key_Left) {
1643 console.log("move left");
1644 event.accepted = true;
1647 Keys.onSelectPressed: console.log("Selected");
1651 See the \l {Keys}{Keys} attached property for detailed documentation.
1653 \section1 Layout Mirroring
1655 Item layouts can be mirrored using the \l {LayoutMirroring}{LayoutMirroring} attached property.
1660 \fn void QQuickItem::childrenRectChanged(const QRectF &)
1665 \fn void QQuickItem::baselineOffsetChanged(qreal)
1670 \fn void QQuickItem::stateChanged(const QString &state)
1675 \fn void QQuickItem::parentChanged(QQuickItem *)
1680 \fn void QQuickItem::smoothChanged(bool)
1685 \fn void QQuickItem::clipChanged(bool)
1689 /*! \fn void QQuickItem::transformOriginChanged(TransformOrigin)
1694 \fn void QQuickItem::focusChanged(bool)
1699 \fn void QQuickItem::activeFocusChanged(bool)
1703 \fn QQuickItem::QQuickItem(QQuickItem *parent)
1705 Constructs a QQuickItem with the given \a parent.
1707 QQuickItem::QQuickItem(QQuickItem* parent)
1708 : QObject(*(new QQuickItemPrivate), parent)
1716 QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
1717 : QObject(dd, parent)
1724 static int qt_item_count = 0;
1726 static void qt_print_item_count()
1728 qDebug("Number of leaked items: %i", qt_item_count);
1734 Destroys the QQuickItem.
1736 QQuickItem::~QQuickItem()
1740 if (qt_item_count < 0)
1741 qDebug("Item destroyed after qt_print_item_count() was called.");
1748 else if (d->canvas && d->itemNodeInstance)
1749 QQuickCanvasPrivate::get(d->canvas)->cleanup(d->itemNodeInstance); // cleanup root
1750 // XXX todo - optimize
1751 while (!d->childItems.isEmpty())
1752 d->childItems.first()->setParentItem(0);
1754 for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
1755 QQuickAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
1757 anchor->clearItem(this);
1761 update item anchors that depended on us unless they are our child (and will also be destroyed),
1762 or our sibling, and our parent is also being destroyed.
1764 for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
1765 QQuickAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
1766 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() != this)
1770 for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
1771 const QQuickItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
1772 if (change.types & QQuickItemPrivate::Destroyed)
1773 change.listener->itemDestroyed(this);
1775 d->changeListeners.clear();
1776 delete d->_anchorLines; d->_anchorLines = 0;
1777 delete d->_anchors; d->_anchors = 0;
1778 delete d->_stateGroup; d->_stateGroup = 0;
1779 delete d->_contents; d->_contents = 0;
1783 \qmlproperty enumeration QtQuick2::Item::transformOrigin
1784 This property holds the origin point around which scale and rotation transform.
1786 Nine transform origins are available, as shown in the image below.
1788 \image declarative-transformorigin.png
1790 This example rotates an image around its bottom-right corner.
1793 source: "myimage.png"
1794 transformOrigin: Item.BottomRight
1799 The default transform origin is \c Item.Center.
1801 To set an arbitrary transform origin point use the \l Scale or \l Rotation
1806 \qmlproperty Item QtQuick2::Item::parent
1807 This property holds the parent of the item.
1811 \property QQuickItem::parent
1812 This property holds the parent of the item.
1814 void QQuickItem::setParentItem(QQuickItem *parentItem)
1817 if (parentItem == d->parentItem)
1820 d->removeFromDirtyList();
1822 QQuickItem *oldParentItem = d->parentItem;
1823 QQuickItem *scopeFocusedItem = 0;
1825 if (oldParentItem) {
1826 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
1828 QQuickItem *scopeItem = 0;
1830 if (d->canvas && hasFocus()) {
1831 scopeItem = oldParentItem;
1832 while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem();
1833 scopeFocusedItem = this;
1834 } else if (d->canvas && !isFocusScope() && d->subFocusItem) {
1835 scopeItem = oldParentItem;
1836 while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem();
1837 scopeFocusedItem = d->subFocusItem;
1840 if (scopeFocusedItem)
1841 QQuickCanvasPrivate::get(d->canvas)->clearFocusInScope(scopeItem, scopeFocusedItem,
1842 QQuickCanvasPrivate::DontChangeFocusProperty);
1844 op->removeChild(this);
1847 d->parentItem = parentItem;
1849 QQuickCanvas *parentCanvas = parentItem?QQuickItemPrivate::get(parentItem)->canvas:0;
1850 if (d->canvas != parentCanvas) {
1851 QQuickItemPrivate::InitializationState initState;
1853 d->initCanvas(&initState, parentCanvas);
1856 d->dirty(QQuickItemPrivate::ParentChanged);
1859 QQuickItemPrivate::get(d->parentItem)->addChild(this);
1861 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
1862 d->setEffectiveEnableRecur(d->calcEffectiveEnable());
1864 if (scopeFocusedItem && d->parentItem && d->canvas) {
1865 // We need to test whether this item becomes scope focused
1866 QQuickItem *scopeItem = 0;
1867 scopeItem = d->parentItem;
1868 while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem();
1870 if (scopeItem->scopedFocusItem()) {
1871 QQuickItemPrivate::get(scopeFocusedItem)->focus = false;
1872 emit scopeFocusedItem->focusChanged(false);
1874 QQuickCanvasPrivate::get(d->canvas)->setFocusInScope(scopeItem, scopeFocusedItem,
1875 QQuickCanvasPrivate::DontChangeFocusProperty);
1879 d->resolveLayoutMirror();
1881 d->itemChange(ItemParentHasChanged, d->parentItem);
1883 emit parentChanged(d->parentItem);
1886 void QQuickItem::stackBefore(const QQuickItem *sibling)
1889 if (!sibling || sibling == this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
1890 qWarning("QQuickItem::stackBefore: Cannot stack before %p, which must be a sibling", sibling);
1894 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
1896 int myIndex = parentPrivate->childItems.indexOf(this);
1897 int siblingIndex = parentPrivate->childItems.indexOf(const_cast<QQuickItem *>(sibling));
1899 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
1901 if (myIndex == siblingIndex - 1)
1904 parentPrivate->childItems.removeAt(myIndex);
1906 if (myIndex < siblingIndex) --siblingIndex;
1908 parentPrivate->childItems.insert(siblingIndex, this);
1910 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
1911 parentPrivate->markSortedChildrenDirty(this);
1913 for (int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.count(); ++ii)
1914 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
1917 void QQuickItem::stackAfter(const QQuickItem *sibling)
1920 if (!sibling || sibling == this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
1921 qWarning("QQuickItem::stackAfter: Cannot stack after %p, which must be a sibling", sibling);
1925 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
1927 int myIndex = parentPrivate->childItems.indexOf(this);
1928 int siblingIndex = parentPrivate->childItems.indexOf(const_cast<QQuickItem *>(sibling));
1930 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
1932 if (myIndex == siblingIndex + 1)
1935 parentPrivate->childItems.removeAt(myIndex);
1937 if (myIndex < siblingIndex) --siblingIndex;
1939 parentPrivate->childItems.insert(siblingIndex + 1, this);
1941 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
1942 parentPrivate->markSortedChildrenDirty(this);
1944 for (int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.count(); ++ii)
1945 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
1949 Returns the QQuickItem parent of this item.
1951 QQuickItem *QQuickItem::parentItem() const
1953 Q_D(const QQuickItem);
1954 return d->parentItem;
1957 QSGEngine *QQuickItem::sceneGraphEngine() const
1959 return canvas()->sceneGraphEngine();
1962 QQuickCanvas *QQuickItem::canvas() const
1964 Q_D(const QQuickItem);
1968 static bool itemZOrder_sort(QQuickItem *lhs, QQuickItem *rhs)
1970 return lhs->z() < rhs->z();
1973 QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems() const
1975 if (sortedChildItems)
1976 return *sortedChildItems;
1978 // If none of the items have set Z then the paint order list is the same as
1979 // the childItems list. This is by far the most common case.
1981 for (int i = 0; i < childItems.count(); ++i) {
1982 if (QQuickItemPrivate::get(childItems.at(i))->z != 0.) {
1988 sortedChildItems = new QList<QQuickItem*>(childItems);
1989 qStableSort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
1990 return *sortedChildItems;
1993 sortedChildItems = const_cast<QList<QQuickItem*>*>(&childItems);
1998 void QQuickItemPrivate::addChild(QQuickItem *child)
2002 Q_ASSERT(!childItems.contains(child));
2004 childItems.append(child);
2006 markSortedChildrenDirty(child);
2007 dirty(QQuickItemPrivate::ChildrenChanged);
2009 itemChange(QQuickItem::ItemChildAddedChange, child);
2011 emit q->childrenChanged();
2014 void QQuickItemPrivate::removeChild(QQuickItem *child)
2019 Q_ASSERT(childItems.contains(child));
2020 childItems.removeOne(child);
2021 Q_ASSERT(!childItems.contains(child));
2023 markSortedChildrenDirty(child);
2024 dirty(QQuickItemPrivate::ChildrenChanged);
2026 itemChange(QQuickItem::ItemChildRemovedChange, child);
2028 emit q->childrenChanged();
2031 void QQuickItemPrivate::InitializationState::clear()
2036 void QQuickItemPrivate::InitializationState::clear(QQuickItem *fs)
2041 QQuickItem *QQuickItemPrivate::InitializationState::getFocusScope(QQuickItem *item)
2044 QQuickItem *fs = item->parentItem();
2045 while (!fs->isFocusScope())
2046 fs = fs->parentItem();
2052 void QQuickItemPrivate::initCanvas(InitializationState *state, QQuickCanvas *c)
2057 removeFromDirtyList();
2058 QQuickCanvasPrivate *c = QQuickCanvasPrivate::get(canvas);
2059 if (polishScheduled)
2060 c->itemsToPolish.remove(q);
2061 if (c->mouseGrabberItem == q)
2062 c->mouseGrabberItem = 0;
2064 c->hoverItems.removeAll(q);
2065 if (itemNodeInstance)
2066 c->cleanup(itemNodeInstance);
2071 if (canvas && polishScheduled)
2072 QQuickCanvasPrivate::get(canvas)->itemsToPolish.insert(q);
2074 itemNodeInstance = 0;
2080 beforePaintNode = 0;
2082 InitializationState _dummy;
2083 InitializationState *childState = state;
2085 if (c && q->isFocusScope()) {
2087 childState = &_dummy;
2090 for (int ii = 0; ii < childItems.count(); ++ii) {
2091 QQuickItem *child = childItems.at(ii);
2092 QQuickItemPrivate::get(child)->initCanvas(childState, c);
2097 if (state->getFocusScope(q)->scopedFocusItem()) {
2099 emit q->focusChanged(false);
2101 QQuickCanvasPrivate::get(canvas)->setFocusInScope(state->getFocusScope(q), q);
2107 itemChange(QQuickItem::ItemSceneChange, c);
2111 Returns a transform that maps points from canvas space into item space.
2113 QTransform QQuickItemPrivate::canvasToItemTransform() const
2115 // XXX todo - optimize
2116 return itemToCanvasTransform().inverted();
2120 Returns a transform that maps points from item space into canvas space.
2122 QTransform QQuickItemPrivate::itemToCanvasTransform() const
2125 QTransform rv = parentItem?QQuickItemPrivate::get(parentItem)->itemToCanvasTransform():QTransform();
2126 itemToParentTransform(rv);
2131 Motifies \a t with this items local transform relative to its parent.
2133 void QQuickItemPrivate::itemToParentTransform(QTransform &t) const
2138 if (!transforms.isEmpty()) {
2140 for (int ii = transforms.count() - 1; ii >= 0; --ii)
2141 transforms.at(ii)->applyTo(&m);
2142 t = m.toTransform();
2145 if (scale != 1. || rotation != 0.) {
2146 QPointF tp = computeTransformOrigin();
2147 t.translate(tp.x(), tp.y());
2148 t.scale(scale, scale);
2150 t.translate(-tp.x(), -tp.y());
2156 \qmlproperty real QtQuick2::Item::childrenRect.x
2157 \qmlproperty real QtQuick2::Item::childrenRect.y
2158 \qmlproperty real QtQuick2::Item::childrenRect.width
2159 \qmlproperty real QtQuick2::Item::childrenRect.height
2161 The childrenRect properties allow an item access to the geometry of its
2162 children. This property is useful if you have an item that needs to be
2163 sized to fit its children.
2168 \qmlproperty list<Item> QtQuick2::Item::children
2169 \qmlproperty list<Object> QtQuick2::Item::resources
2171 The children property contains the list of visual children of this item.
2172 The resources property contains non-visual resources that you want to
2175 Generally you can rely on Item's default property to handle all this for
2176 you, but it can come in handy in some cases.
2195 Returns true if construction of the QML component is complete; otherwise
2198 It is often desirable to delay some processing until the component is
2201 \sa componentComplete()
2203 bool QQuickItem::isComponentComplete() const
2205 Q_D(const QQuickItem);
2206 return d->componentComplete;
2209 QQuickItemPrivate::QQuickItemPrivate()
2210 : _anchors(0), _contents(0), baselineOffset(0), _anchorLines(0), _stateGroup(0), origin(QQuickItem::Center),
2212 flags(0), widthValid(false), heightValid(false), componentComplete(true),
2213 keepMouse(false), keepTouch(false), hoverEnabled(false), smooth(false), focus(false), activeFocus(false), notifiedFocus(false),
2214 notifiedActiveFocus(false), filtersChildMouseEvents(false), explicitVisible(true),
2215 effectiveVisible(true), explicitEnable(true), effectiveEnable(true), polishScheduled(false),
2216 inheritedLayoutMirror(false), effectiveLayoutMirror(false), isMirrorImplicit(true),
2217 inheritMirrorFromParent(false), inheritMirrorFromItem(false), childrenDoNotOverlap(false),
2219 canvas(0), parentItem(0), sortedChildItems(&childItems),
2223 x(0), y(0), width(0), height(0), implicitWidth(0), implicitHeight(0),
2224 z(0), scale(1), rotation(0), opacity(1),
2226 attachedLayoutDirection(0), acceptedMouseButtons(0),
2227 imHints(Qt::ImhMultiLine),
2231 dirtyAttributes(0), nextDirtyItem(0), prevDirtyItem(0),
2233 itemNodeInstance(0), opacityNode(0), clipNode(0), rootNode(0), groupNode(0), paintNode(0)
2234 , beforePaintNode(0), effectRefCount(0), hideRefCount(0)
2238 QQuickItemPrivate::~QQuickItemPrivate()
2240 if (sortedChildItems != &childItems)
2241 delete sortedChildItems;
2244 void QQuickItemPrivate::init(QQuickItem *parent)
2248 static bool atexit_registered = false;
2249 if (!atexit_registered) {
2250 atexit(qt_print_item_count);
2251 atexit_registered = true;
2256 baselineOffset.invalidate();
2259 q->setParentItem(parent);
2260 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
2261 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
2265 void QQuickItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
2270 QQuickItem *that = static_cast<QQuickItem *>(prop->object);
2272 // This test is measurably (albeit only slightly) faster than qobject_cast<>()
2273 const QMetaObject *mo = o->metaObject();
2274 while (mo && mo != &QQuickItem::staticMetaObject) {
2275 mo = mo->d.superdata;
2279 QQuickItem *item = static_cast<QQuickItem *>(o);
2280 item->setParentItem(that);
2282 if (o->inherits("QGraphicsItem"))
2283 qWarning("Cannot add a QtQuick 1.0 item (%s) into a QtQuick 2.0 scene!", o->metaObject()->className());
2285 // XXX todo - do we really want this behavior?
2291 \qmlproperty list<Object> QtQuick2::Item::data
2294 The data property allows you to freely mix visual children and resources
2295 in an item. If you assign a visual item to the data list it becomes
2296 a child and if you assign any other object type, it is added as a resource.
2320 data is a behind-the-scenes property: you should never need to explicitly
2324 int QQuickItemPrivate::data_count(QDeclarativeListProperty<QObject> *prop)
2331 QObject *QQuickItemPrivate::data_at(QDeclarativeListProperty<QObject> *prop, int i)
2339 void QQuickItemPrivate::data_clear(QDeclarativeListProperty<QObject> *prop)
2345 QObject *QQuickItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
2347 const QObjectList children = prop->object->children();
2348 if (index < children.count())
2349 return children.at(index);
2354 void QQuickItemPrivate::resources_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
2356 // XXX todo - do we really want this behavior?
2357 o->setParent(prop->object);
2360 int QQuickItemPrivate::resources_count(QDeclarativeListProperty<QObject> *prop)
2362 return prop->object->children().count();
2365 void QQuickItemPrivate::resources_clear(QDeclarativeListProperty<QObject> *prop)
2367 // XXX todo - do we really want this behavior?
2368 const QObjectList children = prop->object->children();
2369 for (int index = 0; index < children.count(); index++)
2370 children.at(index)->setParent(0);
2373 QQuickItem *QQuickItemPrivate::children_at(QDeclarativeListProperty<QQuickItem> *prop, int index)
2375 QQuickItemPrivate *p = QQuickItemPrivate::get(static_cast<QQuickItem *>(prop->object));
2376 if (index >= p->childItems.count() || index < 0)
2379 return p->childItems.at(index);
2382 void QQuickItemPrivate::children_append(QDeclarativeListProperty<QQuickItem> *prop, QQuickItem *o)
2387 QQuickItem *that = static_cast<QQuickItem *>(prop->object);
2388 if (o->parentItem() == that)
2389 o->setParentItem(0);
2391 o->setParentItem(that);
2394 int QQuickItemPrivate::children_count(QDeclarativeListProperty<QQuickItem> *prop)
2396 QQuickItemPrivate *p = QQuickItemPrivate::get(static_cast<QQuickItem *>(prop->object));
2397 return p->childItems.count();
2400 void QQuickItemPrivate::children_clear(QDeclarativeListProperty<QQuickItem> *prop)
2402 QQuickItem *that = static_cast<QQuickItem *>(prop->object);
2403 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
2404 while (!p->childItems.isEmpty())
2405 p->childItems.at(0)->setParentItem(0);
2408 int QQuickItemPrivate::transform_count(QDeclarativeListProperty<QQuickTransform> *prop)
2410 QQuickItem *that = static_cast<QQuickItem *>(prop->object);
2411 return QQuickItemPrivate::get(that)->transforms.count();
2414 void QQuickTransform::appendToItem(QQuickItem *item)
2416 Q_D(QQuickTransform);
2420 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
2422 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(this)) {
2423 p->transforms.removeOne(this);
2424 p->transforms.append(this);
2426 p->transforms.append(this);
2427 d->items.append(item);
2430 p->dirty(QQuickItemPrivate::Transform);
2433 void QQuickTransform::prependToItem(QQuickItem *item)
2435 Q_D(QQuickTransform);
2439 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
2441 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(this)) {
2442 p->transforms.removeOne(this);
2443 p->transforms.prepend(this);
2445 p->transforms.prepend(this);
2446 d->items.append(item);
2449 p->dirty(QQuickItemPrivate::Transform);
2452 void QQuickItemPrivate::transform_append(QDeclarativeListProperty<QQuickTransform> *prop, QQuickTransform *transform)
2457 QQuickItem *that = static_cast<QQuickItem *>(prop->object);
2458 transform->appendToItem(that);
2461 QQuickTransform *QQuickItemPrivate::transform_at(QDeclarativeListProperty<QQuickTransform> *prop, int idx)
2463 QQuickItem *that = static_cast<QQuickItem *>(prop->object);
2464 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
2466 if (idx < 0 || idx >= p->transforms.count())
2469 return p->transforms.at(idx);
2472 void QQuickItemPrivate::transform_clear(QDeclarativeListProperty<QQuickTransform> *prop)
2474 QQuickItem *that = static_cast<QQuickItem *>(prop->object);
2475 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
2477 for (int ii = 0; ii < p->transforms.count(); ++ii) {
2478 QQuickTransform *t = p->transforms.at(ii);
2479 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2480 tp->items.removeOne(that);
2483 p->transforms.clear();
2485 p->dirty(QQuickItemPrivate::Transform);
2489 \property QQuickItem::childrenRect
2490 \brief The geometry of an item's children.
2492 This property holds the (collective) position and size of the item's children.
2496 \qmlproperty real QtQuick2::Item::x
2497 \qmlproperty real QtQuick2::Item::y
2498 \qmlproperty real QtQuick2::Item::width
2499 \qmlproperty real QtQuick2::Item::height
2501 Defines the item's position and size relative to its parent.
2504 Item { x: 100; y: 100; width: 100; height: 100 }
2509 \qmlproperty real QtQuick2::Item::z
2511 Sets the stacking order of sibling items. By default the stacking order is 0.
2513 Items with a higher stacking value are drawn on top of siblings with a
2514 lower stacking order. Items with the same stacking value are drawn
2515 bottom up in the order they appear. Items with a negative stacking
2516 value are drawn under their parent's content.
2518 The following example shows the various effects of stacking order.
2522 \o \image declarative-item_stacking1.png
2523 \o Same \c z - later children above earlier children:
2528 width: 100; height: 100
2532 x: 50; y: 50; width: 100; height: 100
2537 \o \image declarative-item_stacking2.png
2538 \o Higher \c z on top:
2544 width: 100; height: 100
2548 x: 50; y: 50; width: 100; height: 100
2553 \o \image declarative-item_stacking3.png
2554 \o Same \c z - children above parents:
2559 width: 100; height: 100
2562 x: 50; y: 50; width: 100; height: 100
2568 \o \image declarative-item_stacking4.png
2569 \o Lower \c z below:
2574 width: 100; height: 100
2578 x: 50; y: 50; width: 100; height: 100
2587 \qmlproperty bool QtQuick2::Item::visible
2589 This property holds whether the item is visible. By default this is true.
2591 Setting this property directly affects the \c visible value of child
2592 items. When set to \c false, the \c visible values of all child items also
2593 become \c false. When set to \c true, the \c visible values of child items
2594 are returned to \c true, unless they have explicitly been set to \c false.
2596 (Because of this flow-on behavior, using the \c visible property may not
2597 have the intended effect if a property binding should only respond to
2598 explicit property changes. In such cases it may be better to use the
2599 \l opacity property instead.)
2601 Setting this property to \c false automatically causes \l focus to be set
2602 to \c false, and this item will longer receive mouse and keyboard events.
2603 (In contrast, setting the \l opacity to 0 does not affect the \l focus
2604 property and the receiving of key events.)
2606 \note This property's value is only affected by changes to this property or
2607 the parent's \c visible property. It does not change, for example, if this
2608 item moves off-screen, or if the \l opacity changes to 0.
2613 \qmlproperty AnchorLine QtQuick2::Item::anchors.top
2614 \qmlproperty AnchorLine QtQuick2::Item::anchors.bottom
2615 \qmlproperty AnchorLine QtQuick2::Item::anchors.left
2616 \qmlproperty AnchorLine QtQuick2::Item::anchors.right
2617 \qmlproperty AnchorLine QtQuick2::Item::anchors.horizontalCenter
2618 \qmlproperty AnchorLine QtQuick2::Item::anchors.verticalCenter
2619 \qmlproperty AnchorLine QtQuick2::Item::anchors.baseline
2621 \qmlproperty Item QtQuick2::Item::anchors.fill
2622 \qmlproperty Item QtQuick2::Item::anchors.centerIn
2624 \qmlproperty real QtQuick2::Item::anchors.margins
2625 \qmlproperty real QtQuick2::Item::anchors.topMargin
2626 \qmlproperty real QtQuick2::Item::anchors.bottomMargin
2627 \qmlproperty real QtQuick2::Item::anchors.leftMargin
2628 \qmlproperty real QtQuick2::Item::anchors.rightMargin
2629 \qmlproperty real QtQuick2::Item::anchors.horizontalCenterOffset
2630 \qmlproperty real QtQuick2::Item::anchors.verticalCenterOffset
2631 \qmlproperty real QtQuick2::Item::anchors.baselineOffset
2633 \qmlproperty bool QtQuick2::Item::anchors.mirrored
2635 Anchors provide a way to position an item by specifying its
2636 relationship with other items.
2638 Margins apply to top, bottom, left, right, and fill anchors.
2639 The \c anchors.margins property can be used to set all of the various margins at once, to the same value.
2640 Note that margins are anchor-specific and are not applied if an item does not
2643 Offsets apply for horizontal center, vertical center, and baseline anchors.
2647 \o \image declarative-anchors_example.png
2648 \o Text anchored to Image, horizontally centered and vertically below, with a margin.
2657 anchors.horizontalCenter: pic.horizontalCenter
2658 anchors.top: pic.bottom
2659 anchors.topMargin: 5
2665 \o \image declarative-anchors_example2.png
2667 Left of Text anchored to right of Image, with a margin. The y
2668 property of both defaults to 0.
2678 anchors.left: pic.right
2679 anchors.leftMargin: 5
2686 \c anchors.fill provides a convenient way for one item to have the
2687 same geometry as another item, and is equivalent to connecting all
2688 four directional anchors.
2690 To clear an anchor value, set it to \c undefined.
2692 \c anchors.mirrored returns true it the layout has been \l {LayoutMirroring}{mirrored}.
2694 \note You can only anchor an item to siblings or a parent.
2696 For more information see \l {anchor-layout}{Anchor Layouts}.
2700 \property QQuickItem::baselineOffset
2701 \brief The position of the item's baseline in local coordinates.
2703 The baseline of a \l Text item is the imaginary line on which the text
2704 sits. Controls containing text usually set their baseline to the
2705 baseline of their text.
2707 For non-text items, a default baseline offset of 0 is used.
2709 QQuickAnchors *QQuickItemPrivate::anchors() const
2712 Q_Q(const QQuickItem);
2713 _anchors = new QQuickAnchors(const_cast<QQuickItem *>(q));
2714 if (!componentComplete)
2715 _anchors->classBegin();
2720 QQuickItemPrivate::AnchorLines *QQuickItemPrivate::anchorLines() const
2722 Q_Q(const QQuickItem);
2723 if (!_anchorLines) _anchorLines =
2724 new AnchorLines(const_cast<QQuickItem *>(q));
2725 return _anchorLines;
2728 void QQuickItemPrivate::siblingOrderChanged()
2731 for (int ii = 0; ii < changeListeners.count(); ++ii) {
2732 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
2733 if (change.types & QQuickItemPrivate::SiblingOrder) {
2734 change.listener->itemSiblingOrderChanged(q);
2739 QDeclarativeListProperty<QObject> QQuickItemPrivate::data()
2741 return QDeclarativeListProperty<QObject>(q_func(), 0, QQuickItemPrivate::data_append,
2742 QQuickItemPrivate::data_count,
2743 QQuickItemPrivate::data_at,
2744 QQuickItemPrivate::data_clear);
2747 QRectF QQuickItem::childrenRect()
2750 if (!d->_contents) {
2751 d->_contents = new QQuickContents(this);
2752 if (d->componentComplete)
2753 d->_contents->complete();
2755 return d->_contents->rectF();
2758 QList<QQuickItem *> QQuickItem::childItems() const
2760 Q_D(const QQuickItem);
2761 return d->childItems;
2764 bool QQuickItem::clip() const
2766 return flags() & ItemClipsChildrenToShape;
2769 void QQuickItem::setClip(bool c)
2774 setFlag(ItemClipsChildrenToShape, c);
2776 emit clipChanged(c);
2781 This function is called to handle this item's changes in
2782 geometry from \a oldGeometry to \a newGeometry. If the two
2783 geometries are the same, it doesn't do anything.
2785 void QQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
2790 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
2792 bool xChange = (newGeometry.x() != oldGeometry.x());
2793 bool yChange = (newGeometry.y() != oldGeometry.y());
2794 bool widthChange = (newGeometry.width() != oldGeometry.width());
2795 bool heightChange = (newGeometry.height() != oldGeometry.height());
2797 for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
2798 const QQuickItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
2799 if (change.types & QQuickItemPrivate::Geometry) {
2800 if (change.gTypes == QQuickItemPrivate::GeometryChange) {
2801 change.listener->itemGeometryChanged(this, newGeometry, oldGeometry);
2802 } else if ((xChange && (change.gTypes & QQuickItemPrivate::XChange)) ||
2803 (yChange && (change.gTypes & QQuickItemPrivate::YChange)) ||
2804 (widthChange && (change.gTypes & QQuickItemPrivate::WidthChange)) ||
2805 (heightChange && (change.gTypes & QQuickItemPrivate::HeightChange))) {
2806 change.listener->itemGeometryChanged(this, newGeometry, oldGeometry);
2816 emit widthChanged();
2818 emit heightChanged();
2822 Called by the rendering thread when it is time to sync the state of the QML objects with the
2823 scene graph objects. The function should return the root of the scene graph subtree for
2824 this item. \a oldNode is the node that was returned the last time the function was called.
2826 The main thread is blocked while this function is executed so it is safe to read
2827 values from the QQuickItem instance and other objects in the main thread.
2829 \warning This is the only function in which it is allowed to make use of scene graph
2830 objects from the main thread. Use of scene graph objects outside this function will
2831 result in race conditions and potential crashes.
2834 QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
2840 QSGTransformNode *QQuickItemPrivate::createTransformNode()
2842 return new QSGTransformNode;
2845 void QQuickItem::updatePolish()
2849 void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
2851 ChangeListener change(listener, types);
2852 changeListeners.removeOne(change);
2855 void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types)
2857 ChangeListener change(listener, types);
2858 int index = changeListeners.find(change);
2860 changeListeners[index].gTypes = change.gTypes; //we may have different GeometryChangeTypes
2862 changeListeners.append(change);
2865 void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types)
2867 ChangeListener change(listener, types);
2868 if (types == NoChange) {
2869 changeListeners.removeOne(change);
2871 int index = changeListeners.find(change);
2873 changeListeners[index].gTypes = change.gTypes; //we may have different GeometryChangeTypes
2877 void QQuickItem::keyPressEvent(QKeyEvent *event)
2882 void QQuickItem::keyReleaseEvent(QKeyEvent *event)
2887 void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
2892 void QQuickItem::focusInEvent(QFocusEvent *)
2896 void QQuickItem::focusOutEvent(QFocusEvent *)
2900 void QQuickItem::mousePressEvent(QMouseEvent *event)
2905 void QQuickItem::mouseMoveEvent(QMouseEvent *event)
2910 void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
2915 void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
2917 mousePressEvent(event);
2920 void QQuickItem::mouseUngrabEvent()
2925 void QQuickItem::touchUngrabEvent()
2930 void QQuickItem::wheelEvent(QWheelEvent *event)
2935 void QQuickItem::touchEvent(QTouchEvent *event)
2940 void QQuickItem::hoverEnterEvent(QHoverEvent *event)
2945 void QQuickItem::hoverMoveEvent(QHoverEvent *event)
2950 void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
2955 void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
2960 void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
2966 void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
2972 void QQuickItem::dropEvent(QDropEvent *event)
2977 bool QQuickItem::childMouseEventFilter(QQuickItem *, QEvent *)
2982 void QQuickItem::windowDeactivateEvent()
2984 foreach (QQuickItem* item, childItems()) {
2985 item->windowDeactivateEvent();
2989 Qt::InputMethodHints QQuickItem::inputMethodHints() const
2991 Q_D(const QQuickItem);
2995 void QQuickItem::setInputMethodHints(Qt::InputMethodHints hints)
3000 if (!d->canvas || d->canvas->activeFocusItem() != this)
3003 QInputPanel *p = qApp->inputPanel();
3004 if (p->inputItem() == this)
3005 qApp->inputPanel()->update(Qt::ImHints);
3008 void QQuickItem::updateMicroFocus()
3010 QInputPanel *p = qApp->inputPanel();
3011 if (p->inputItem() == this)
3012 qApp->inputPanel()->update(Qt::ImQueryInput);
3015 QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query) const
3017 Q_D(const QQuickItem);
3022 v = (bool)(flags() & ItemAcceptsInputMethod);
3025 v = (int)inputMethodHints();
3027 case Qt::ImCursorRectangle:
3029 case Qt::ImCursorPosition:
3030 case Qt::ImSurroundingText:
3031 case Qt::ImCurrentSelection:
3032 case Qt::ImMaximumTextLength:
3033 case Qt::ImAnchorPosition:
3034 case Qt::ImPreferredLanguage:
3036 v = d->keyHandler->inputMethodQuery(query);
3044 QQuickAnchorLine QQuickItemPrivate::left() const
3046 return anchorLines()->left;
3049 QQuickAnchorLine QQuickItemPrivate::right() const
3051 return anchorLines()->right;
3054 QQuickAnchorLine QQuickItemPrivate::horizontalCenter() const
3056 return anchorLines()->hCenter;
3059 QQuickAnchorLine QQuickItemPrivate::top() const
3061 return anchorLines()->top;
3064 QQuickAnchorLine QQuickItemPrivate::bottom() const
3066 return anchorLines()->bottom;
3069 QQuickAnchorLine QQuickItemPrivate::verticalCenter() const
3071 return anchorLines()->vCenter;
3074 QQuickAnchorLine QQuickItemPrivate::baseline() const
3076 return anchorLines()->baseline;
3079 qreal QQuickItem::baselineOffset() const
3081 Q_D(const QQuickItem);
3082 if (!d->baselineOffset.isValid()) {
3085 return d->baselineOffset;
3088 void QQuickItem::setBaselineOffset(qreal offset)
3091 if (offset == d->baselineOffset)
3094 d->baselineOffset = offset;
3096 for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
3097 const QQuickItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
3098 if (change.types & QQuickItemPrivate::Geometry) {
3099 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
3101 anchor->updateVerticalAnchors();
3104 emit baselineOffsetChanged(offset);
3107 void QQuickItem::update()
3110 Q_ASSERT(flags() & ItemHasContents);
3111 d->dirty(QQuickItemPrivate::Content);
3114 void QQuickItem::polish()
3117 if (!d->polishScheduled) {
3118 d->polishScheduled = true;
3120 QQuickCanvasPrivate *p = QQuickCanvasPrivate::get(d->canvas);
3121 bool maybeupdate = p->itemsToPolish.isEmpty();
3122 p->itemsToPolish.insert(this);
3123 if (maybeupdate) d->canvas->maybeUpdate();
3128 void QQuickItem::mapFromItem(QDeclarativeV8Function *args) const
3130 if (args->Length() != 0) {
3131 v8::Local<v8::Value> item = (*args)[0];
3132 QV8Engine *engine = args->engine();
3134 QQuickItem *itemObj = 0;
3135 if (!item->IsNull())
3136 itemObj = qobject_cast<QQuickItem*>(engine->toQObject(item));
3138 if (!itemObj && !item->IsNull()) {
3139 qmlInfo(this) << "mapFromItem() given argument \"" << engine->toString(item->ToString())
3140 << "\" which is neither null nor an Item";
3144 v8::Local<v8::Object> rv = v8::Object::New();
3145 args->returnValue(rv);
3147 qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
3148 qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
3150 QPointF p = mapFromItem(itemObj, QPointF(x, y));
3152 rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
3153 rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
3157 QTransform QQuickItem::itemTransform(QQuickItem *other, bool *ok) const
3159 Q_D(const QQuickItem);
3161 // XXX todo - we need to be able to handle common parents better and detect
3165 QTransform t = d->itemToCanvasTransform();
3166 if (other) t *= QQuickItemPrivate::get(other)->canvasToItemTransform();
3171 void QQuickItem::mapToItem(QDeclarativeV8Function *args) const
3173 if (args->Length() != 0) {
3174 v8::Local<v8::Value> item = (*args)[0];
3175 QV8Engine *engine = args->engine();
3177 QQuickItem *itemObj = 0;
3178 if (!item->IsNull())
3179 itemObj = qobject_cast<QQuickItem*>(engine->toQObject(item));
3181 if (!itemObj && !item->IsNull()) {
3182 qmlInfo(this) << "mapToItem() given argument \"" << engine->toString(item->ToString())
3183 << "\" which is neither null nor an Item";
3187 v8::Local<v8::Object> rv = v8::Object::New();
3188 args->returnValue(rv);
3190 qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
3191 qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
3193 QPointF p = mapToItem(itemObj, QPointF(x, y));
3195 rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
3196 rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
3200 void QQuickItem::forceActiveFocus()
3203 QQuickItem *parent = parentItem();
3205 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
3206 parent->setFocus(true);
3208 parent = parent->parentItem();
3212 QQuickItem *QQuickItem::childAt(qreal x, qreal y) const
3214 // XXX todo - should this include transform etc.?
3215 const QList<QQuickItem *> children = childItems();
3216 for (int i = children.count()-1; i >= 0; --i) {
3217 QQuickItem *child = children.at(i);
3218 if (child->isVisible() && child->x() <= x
3219 && child->x() + child->width() >= x
3221 && child->y() + child->height() >= y)
3227 QDeclarativeListProperty<QObject> QQuickItemPrivate::resources()
3229 return QDeclarativeListProperty<QObject>(q_func(), 0, QQuickItemPrivate::resources_append,
3230 QQuickItemPrivate::resources_count,
3231 QQuickItemPrivate::resources_at,
3232 QQuickItemPrivate::resources_clear);
3235 QDeclarativeListProperty<QQuickItem> QQuickItemPrivate::children()
3237 return QDeclarativeListProperty<QQuickItem>(q_func(), 0, QQuickItemPrivate::children_append,
3238 QQuickItemPrivate::children_count,
3239 QQuickItemPrivate::children_at,
3240 QQuickItemPrivate::children_clear);
3244 QDeclarativeListProperty<QDeclarativeState> QQuickItemPrivate::states()
3246 return _states()->statesProperty();
3249 QDeclarativeListProperty<QDeclarativeTransition> QQuickItemPrivate::transitions()
3251 return _states()->transitionsProperty();
3254 QString QQuickItemPrivate::state() const
3259 return _stateGroup->state();
3262 void QQuickItemPrivate::setState(const QString &state)
3264 _states()->setState(state);
3267 QString QQuickItem::state() const
3269 Q_D(const QQuickItem);
3273 void QQuickItem::setState(const QString &state)
3279 QDeclarativeListProperty<QQuickTransform> QQuickItem::transform()
3281 return QDeclarativeListProperty<QQuickTransform>(this, 0, QQuickItemPrivate::transform_append,
3282 QQuickItemPrivate::transform_count,
3283 QQuickItemPrivate::transform_at,
3284 QQuickItemPrivate::transform_clear);
3287 void QQuickItem::classBegin()
3290 d->componentComplete = false;
3292 d->_stateGroup->classBegin();
3294 d->_anchors->classBegin();
3297 void QQuickItem::componentComplete()
3300 d->componentComplete = true;
3302 d->_stateGroup->componentComplete();
3304 d->_anchors->componentComplete();
3305 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
3308 d->keyHandler->componentComplete();
3310 d->_contents->complete();
3313 QDeclarativeStateGroup *QQuickItemPrivate::_states()
3317 _stateGroup = new QDeclarativeStateGroup;
3318 if (!componentComplete)
3319 _stateGroup->classBegin();
3320 FAST_CONNECT(_stateGroup, SIGNAL(stateChanged(QString)),
3321 q, SIGNAL(stateChanged(QString)))
3327 QQuickItemPrivate::AnchorLines::AnchorLines(QQuickItem *q)
3330 left.anchorLine = QQuickAnchorLine::Left;
3332 right.anchorLine = QQuickAnchorLine::Right;
3334 hCenter.anchorLine = QQuickAnchorLine::HCenter;
3336 top.anchorLine = QQuickAnchorLine::Top;
3338 bottom.anchorLine = QQuickAnchorLine::Bottom;
3340 vCenter.anchorLine = QQuickAnchorLine::VCenter;
3342 baseline.anchorLine = QQuickAnchorLine::Baseline;
3345 QPointF QQuickItemPrivate::computeTransformOrigin() const
3349 case QQuickItem::TopLeft:
3350 return QPointF(0, 0);
3351 case QQuickItem::Top:
3352 return QPointF(width / 2., 0);
3353 case QQuickItem::TopRight:
3354 return QPointF(width, 0);
3355 case QQuickItem::Left:
3356 return QPointF(0, height / 2.);
3357 case QQuickItem::Center:
3358 return QPointF(width / 2., height / 2.);
3359 case QQuickItem::Right:
3360 return QPointF(width, height / 2.);
3361 case QQuickItem::BottomLeft:
3362 return QPointF(0, height);
3363 case QQuickItem::Bottom:
3364 return QPointF(width / 2., height);
3365 case QQuickItem::BottomRight:
3366 return QPointF(width, height);
3370 void QQuickItemPrivate::transformChanged()
3374 void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
3378 Q_ASSERT(e->isAccepted());
3380 if (e->type() == QEvent::KeyPress)
3381 keyHandler->keyPressed(e, false);
3383 keyHandler->keyReleased(e, false);
3385 if (e->isAccepted())
3391 if (e->type() == QEvent::KeyPress)
3392 q->keyPressEvent(e);
3394 q->keyReleaseEvent(e);
3396 if (e->isAccepted())
3402 if (e->type() == QEvent::KeyPress)
3403 keyHandler->keyPressed(e, true);
3405 keyHandler->keyReleased(e, true);
3409 void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
3413 Q_ASSERT(e->isAccepted());
3415 keyHandler->inputMethodEvent(e, false);
3417 if (e->isAccepted())
3423 q->inputMethodEvent(e);
3425 if (e->isAccepted())
3431 keyHandler->inputMethodEvent(e, true);
3435 void QQuickItemPrivate::deliverFocusEvent(QFocusEvent *e)
3439 if (e->type() == QEvent::FocusIn) {
3442 q->focusOutEvent(e);
3446 void QQuickItemPrivate::deliverMouseEvent(QMouseEvent *e)
3450 Q_ASSERT(e->isAccepted());
3452 switch (e->type()) {
3454 Q_ASSERT(!"Unknown event type");
3455 case QEvent::MouseMove:
3456 q->mouseMoveEvent(e);
3458 case QEvent::MouseButtonPress:
3459 q->mousePressEvent(e);
3461 case QEvent::MouseButtonRelease:
3462 q->mouseReleaseEvent(e);
3464 case QEvent::MouseButtonDblClick:
3465 q->mouseDoubleClickEvent(e);
3470 void QQuickItemPrivate::deliverWheelEvent(QWheelEvent *e)
3476 void QQuickItemPrivate::deliverTouchEvent(QTouchEvent *e)
3482 void QQuickItemPrivate::deliverHoverEvent(QHoverEvent *e)
3485 switch (e->type()) {
3487 Q_ASSERT(!"Unknown event type");
3488 case QEvent::HoverEnter:
3489 q->hoverEnterEvent(e);
3491 case QEvent::HoverLeave:
3492 q->hoverLeaveEvent(e);
3494 case QEvent::HoverMove:
3495 q->hoverMoveEvent(e);
3500 void QQuickItemPrivate::deliverDragEvent(QEvent *e)
3503 switch (e->type()) {
3505 Q_ASSERT(!"Unknown event type");
3506 case QEvent::DragEnter:
3507 q->dragEnterEvent(static_cast<QDragEnterEvent *>(e));
3509 case QEvent::DragLeave:
3510 q->dragLeaveEvent(static_cast<QDragLeaveEvent *>(e));
3512 case QEvent::DragMove:
3513 q->dragMoveEvent(static_cast<QDragMoveEvent *>(e));
3516 q->dropEvent(static_cast<QDropEvent *>(e));
3521 void QQuickItem::itemChange(ItemChange change, const ItemChangeData &value)
3528 // XXX todo - do we want/need this anymore?
3529 // Note that it's now used for varying clip rect
3530 QRectF QQuickItem::boundingRect() const
3532 Q_D(const QQuickItem);
3533 return QRectF(0, 0, d->width, d->height);
3536 QQuickItem::TransformOrigin QQuickItem::transformOrigin() const
3538 Q_D(const QQuickItem);
3542 void QQuickItem::setTransformOrigin(TransformOrigin origin)
3545 if (origin == d->origin)
3549 d->dirty(QQuickItemPrivate::TransformOrigin);
3551 emit transformOriginChanged(d->origin);
3554 QPointF QQuickItem::transformOriginPoint() const
3556 Q_D(const QQuickItem);
3557 if (!d->transformOriginPoint.isNull())
3558 return d->transformOriginPoint;
3559 return d->computeTransformOrigin();
3562 void QQuickItem::setTransformOriginPoint(const QPointF &point)
3565 if (d->transformOriginPoint == point)
3568 d->transformOriginPoint = point;
3569 d->dirty(QQuickItemPrivate::TransformOrigin);
3572 qreal QQuickItem::z() const
3574 Q_D(const QQuickItem);
3578 void QQuickItem::setZ(qreal v)
3586 d->dirty(QQuickItemPrivate::ZValue);
3587 if (d->parentItem) {
3588 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
3589 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(this);
3597 \qmlproperty real QtQuick2::Item::rotation
3598 This property holds the rotation of the item in degrees clockwise.
3600 This specifies how many degrees to rotate the item around its transformOrigin.
3601 The default rotation is 0 degrees (i.e. not rotated at all).
3605 \o \image declarative-rotation.png
3610 width: 100; height: 100
3613 x: 25; y: 25; width: 50; height: 50
3620 \sa transform, Rotation
3624 \qmlproperty real QtQuick2::Item::scale
3625 This property holds the scale of the item.
3627 A scale of less than 1 means the item will be displayed smaller than
3628 normal, and a scale of greater than 1 means the item will be
3629 displayed larger than normal. A negative scale means the item will
3632 By default, items are displayed at a scale of 1 (i.e. at their
3635 Scaling is from the item's transformOrigin.
3639 \o \image declarative-scale.png
3644 width: 100; height: 100
3647 width: 25; height: 25
3651 x: 25; y: 25; width: 50; height: 50
3658 \sa transform, Scale
3662 \qmlproperty real QtQuick2::Item::opacity
3664 This property holds the opacity of the item. Opacity is specified as a
3665 number between 0 (fully transparent) and 1 (fully opaque). The default is 1.
3667 When this property is set, the specified opacity is also applied
3668 individually to child items. In almost all cases this is what you want,
3669 but in some cases it may produce undesired results. For example in the
3670 second set of rectangles below, the red rectangle has specified an opacity
3671 of 0.5, which affects the opacity of its blue child rectangle even though
3672 the child has not specified an opacity.
3676 \o \image declarative-item_opacity1.png
3682 width: 100; height: 100
3685 x: 50; y: 50; width: 100; height: 100
3691 \o \image declarative-item_opacity2.png
3698 width: 100; height: 100
3701 x: 50; y: 50; width: 100; height: 100
3708 If an item's opacity is set to 0, the item will no longer receive mouse
3709 events, but will continue to receive key events and will retain the keyboard
3710 \l focus if it has been set. (In contrast, setting the \l visible property
3711 to \c false stops both mouse and keyboard events, and also removes focus
3716 Returns a value indicating whether mouse input should
3717 remain with this item exclusively.
3719 \sa setKeepMouseGrab()
3722 qreal QQuickItem::rotation() const
3724 Q_D(const QQuickItem);
3728 void QQuickItem::setRotation(qreal r)
3731 if (d->rotation == r)
3736 d->dirty(QQuickItemPrivate::BasicTransform);
3738 d->itemChange(ItemRotationHasChanged, r);
3740 emit rotationChanged();
3743 qreal QQuickItem::scale() const
3745 Q_D(const QQuickItem);
3749 void QQuickItem::setScale(qreal s)
3757 d->dirty(QQuickItemPrivate::BasicTransform);
3759 emit scaleChanged();
3762 qreal QQuickItem::opacity() const
3764 Q_D(const QQuickItem);
3768 void QQuickItem::setOpacity(qreal o)
3771 if (d->opacity == o)
3776 d->dirty(QQuickItemPrivate::OpacityValue);
3778 d->itemChange(ItemOpacityHasChanged, o);
3780 emit opacityChanged();
3783 bool QQuickItem::isVisible() const
3785 Q_D(const QQuickItem);
3786 return d->effectiveVisible;
3789 void QQuickItem::setVisible(bool v)
3792 if (v == d->explicitVisible)
3795 d->explicitVisible = v;
3797 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
3800 bool QQuickItem::isEnabled() const
3802 Q_D(const QQuickItem);
3803 return d->effectiveEnable;
3806 void QQuickItem::setEnabled(bool e)
3809 if (e == d->explicitEnable)
3812 d->explicitEnable = e;
3814 d->setEffectiveEnableRecur(d->calcEffectiveEnable());
3817 bool QQuickItemPrivate::calcEffectiveVisible() const
3819 // XXX todo - Should the effective visible of an element with no parent just be the current
3820 // effective visible? This would prevent pointless re-processing in the case of an element
3821 // moving to/from a no-parent situation, but it is different from what graphics view does.
3822 return explicitVisible && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveVisible);
3825 void QQuickItemPrivate::setEffectiveVisibleRecur(bool newEffectiveVisible)
3829 if (newEffectiveVisible && !explicitVisible) {
3830 // This item locally overrides visibility
3834 if (newEffectiveVisible == effectiveVisible) {
3835 // No change necessary
3839 effectiveVisible = newEffectiveVisible;
3841 if (parentItem) QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
3844 QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(canvas);
3845 if (canvasPriv->mouseGrabberItem == q)
3849 for (int ii = 0; ii < childItems.count(); ++ii)
3850 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
3852 for (int ii = 0; ii < changeListeners.count(); ++ii) {
3853 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
3854 if (change.types & QQuickItemPrivate::Visibility)
3855 change.listener->itemVisibilityChanged(q);
3858 emit q->visibleChanged();
3861 bool QQuickItemPrivate::calcEffectiveEnable() const
3863 // XXX todo - Should the effective enable of an element with no parent just be the current
3864 // effective enable? This would prevent pointless re-processing in the case of an element
3865 // moving to/from a no-parent situation, but it is different from what graphics view does.
3866 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
3869 void QQuickItemPrivate::setEffectiveEnableRecur(bool newEffectiveEnable)
3873 // XXX todo - need to fixup focus
3875 if (newEffectiveEnable && !explicitEnable) {
3876 // This item locally overrides enable
3880 if (newEffectiveEnable == effectiveEnable) {
3881 // No change necessary
3885 effectiveEnable = newEffectiveEnable;
3888 QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(canvas);
3889 if (canvasPriv->mouseGrabberItem == q)
3893 for (int ii = 0; ii < childItems.count(); ++ii)
3894 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(newEffectiveEnable);
3896 emit q->enabledChanged();
3899 QString QQuickItemPrivate::dirtyToString() const
3901 #define DIRTY_TO_STRING(value) if (dirtyAttributes & value) { \
3902 if (!rv.isEmpty()) \
3903 rv.append(QLatin1String("|")); \
3904 rv.append(QLatin1String(#value)); \
3907 // QString rv = QLatin1String("0x") + QString::number(dirtyAttributes, 16);
3910 DIRTY_TO_STRING(TransformOrigin);
3911 DIRTY_TO_STRING(Transform);
3912 DIRTY_TO_STRING(BasicTransform);
3913 DIRTY_TO_STRING(Position);
3914 DIRTY_TO_STRING(Size);
3915 DIRTY_TO_STRING(ZValue);
3916 DIRTY_TO_STRING(Content);
3917 DIRTY_TO_STRING(Smooth);
3918 DIRTY_TO_STRING(OpacityValue);
3919 DIRTY_TO_STRING(ChildrenChanged);
3920 DIRTY_TO_STRING(ChildrenStackingChanged);
3921 DIRTY_TO_STRING(ParentChanged);
3922 DIRTY_TO_STRING(Clip);
3923 DIRTY_TO_STRING(Canvas);
3924 DIRTY_TO_STRING(EffectReference);
3925 DIRTY_TO_STRING(Visible);
3926 DIRTY_TO_STRING(HideReference);
3931 void QQuickItemPrivate::dirty(DirtyType type)
3934 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size))
3937 if (!(dirtyAttributes & type) || (canvas && !prevDirtyItem)) {
3938 dirtyAttributes |= type;
3941 QQuickCanvasPrivate::get(canvas)->dirtyItem(q);
3946 void QQuickItemPrivate::addToDirtyList()
3951 if (!prevDirtyItem) {
3952 Q_ASSERT(!nextDirtyItem);
3954 QQuickCanvasPrivate *p = QQuickCanvasPrivate::get(canvas);
3955 nextDirtyItem = p->dirtyItemList;
3956 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
3957 prevDirtyItem = &p->dirtyItemList;
3958 p->dirtyItemList = q;
3961 Q_ASSERT(prevDirtyItem);
3964 void QQuickItemPrivate::removeFromDirtyList()
3966 if (prevDirtyItem) {
3967 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
3968 *prevDirtyItem = nextDirtyItem;
3972 Q_ASSERT(!prevDirtyItem);
3973 Q_ASSERT(!nextDirtyItem);
3976 void QQuickItemPrivate::refFromEffectItem(bool hide)
3979 if (1 == effectRefCount) {
3980 dirty(EffectReference);
3981 if (parentItem) QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
3984 if (++hideRefCount == 1)
3985 dirty(HideReference);
3989 void QQuickItemPrivate::derefFromEffectItem(bool unhide)
3991 Q_ASSERT(effectRefCount);
3993 if (0 == effectRefCount) {
3994 dirty(EffectReference);
3995 if (parentItem) QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
3998 if (--hideRefCount == 0)
3999 dirty(HideReference);
4003 void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data)
4007 case QQuickItem::ItemChildAddedChange:
4008 q->itemChange(change, data);
4009 for (int ii = 0; ii < changeListeners.count(); ++ii) {
4010 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
4011 if (change.types & QQuickItemPrivate::Children) {
4012 change.listener->itemChildAdded(q, data.item);
4016 case QQuickItem::ItemChildRemovedChange:
4017 q->itemChange(change, data);
4018 for (int ii = 0; ii < changeListeners.count(); ++ii) {
4019 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
4020 if (change.types & QQuickItemPrivate::Children) {
4021 change.listener->itemChildRemoved(q, data.item);
4025 case QQuickItem::ItemSceneChange:
4026 q->itemChange(change, data);
4028 case QQuickItem::ItemVisibleHasChanged:
4029 q->itemChange(change, data);
4030 for (int ii = 0; ii < changeListeners.count(); ++ii) {
4031 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
4032 if (change.types & QQuickItemPrivate::Visibility) {
4033 change.listener->itemVisibilityChanged(q);
4037 case QQuickItem::ItemParentHasChanged:
4038 q->itemChange(change, data);
4039 for (int ii = 0; ii < changeListeners.count(); ++ii) {
4040 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
4041 if (change.types & QQuickItemPrivate::Parent) {
4042 change.listener->itemParentChanged(q, data.item);
4046 case QQuickItem::ItemOpacityHasChanged:
4047 q->itemChange(change, data);
4048 for (int ii = 0; ii < changeListeners.count(); ++ii) {
4049 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
4050 if (change.types & QQuickItemPrivate::Opacity) {
4051 change.listener->itemOpacityChanged(q);
4055 case QQuickItem::ItemActiveFocusHasChanged:
4056 q->itemChange(change, data);
4058 case QQuickItem::ItemRotationHasChanged:
4059 q->itemChange(change, data);
4060 for (int ii = 0; ii < changeListeners.count(); ++ii) {
4061 const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii);
4062 if (change.types & QQuickItemPrivate::Rotation) {
4063 change.listener->itemRotationChanged(q);
4071 \property QQuickItem::smooth
4072 \brief whether the item is smoothly transformed.
4074 This property is provided purely for the purpose of optimization. Turning
4075 smooth transforms off is faster, but looks worse; turning smooth
4076 transformations on is slower, but looks better.
4078 By default smooth transformations are off.
4082 Returns true if the item should be drawn with antialiasing and
4083 smooth pixmap filtering, false otherwise.
4085 The default is false.
4089 bool QQuickItem::smooth() const
4091 Q_D(const QQuickItem);
4096 Sets whether the item should be drawn with antialiasing and
4097 smooth pixmap filtering to \a smooth.
4101 void QQuickItem::setSmooth(bool smooth)
4104 if (d->smooth == smooth)
4108 d->dirty(QQuickItemPrivate::Smooth);
4110 emit smoothChanged(smooth);
4113 QQuickItem::Flags QQuickItem::flags() const
4115 Q_D(const QQuickItem);
4116 return (QQuickItem::Flags)d->flags;
4119 void QQuickItem::setFlag(Flag flag, bool enabled)
4123 setFlags((Flags)(d->flags | (quint32)flag));
4125 setFlags((Flags)(d->flags & ~(quint32)flag));
4128 void QQuickItem::setFlags(Flags flags)
4132 if ((flags & ItemIsFocusScope) != (d->flags & ItemIsFocusScope)) {
4133 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->canvas) {
4134 qWarning("QQuickItem: Cannot set FocusScope once item has children and is in a canvas.");
4135 flags &= ~ItemIsFocusScope;
4136 } else if (d->flags & ItemIsFocusScope) {
4137 qWarning("QQuickItem: Cannot unset FocusScope flag.");
4138 flags |= ItemIsFocusScope;
4142 if ((flags & ItemClipsChildrenToShape ) != (d->flags & ItemClipsChildrenToShape))
4143 d->dirty(QQuickItemPrivate::Clip);
4148 qreal QQuickItem::x() const
4150 Q_D(const QQuickItem);
4154 qreal QQuickItem::y() const
4156 Q_D(const QQuickItem);
4160 QPointF QQuickItem::pos() const
4162 Q_D(const QQuickItem);
4163 return QPointF(d->x, d->y);
4166 void QQuickItem::setX(qreal v)
4175 d->dirty(QQuickItemPrivate::Position);
4177 geometryChanged(QRectF(x(), y(), width(), height()),
4178 QRectF(oldx, y(), width(), height()));
4181 void QQuickItem::setY(qreal v)
4190 d->dirty(QQuickItemPrivate::Position);
4192 geometryChanged(QRectF(x(), y(), width(), height()),
4193 QRectF(x(), oldy, width(), height()));
4196 void QQuickItem::setPos(const QPointF &pos)
4199 if (QPointF(d->x, d->y) == pos)
4208 d->dirty(QQuickItemPrivate::Position);
4210 geometryChanged(QRectF(x(), y(), width(), height()),
4211 QRectF(oldx, oldy, width(), height()));
4214 qreal QQuickItem::width() const
4216 Q_D(const QQuickItem);
4220 void QQuickItem::setWidth(qreal w)
4226 d->widthValid = true;
4230 qreal oldWidth = d->width;
4233 d->dirty(QQuickItemPrivate::Size);
4235 geometryChanged(QRectF(x(), y(), width(), height()),
4236 QRectF(x(), y(), oldWidth, height()));
4239 void QQuickItem::resetWidth()
4242 d->widthValid = false;
4243 setImplicitWidth(implicitWidth());
4246 void QQuickItemPrivate::implicitWidthChanged()
4249 emit q->implicitWidthChanged();
4252 qreal QQuickItemPrivate::getImplicitWidth() const
4254 return implicitWidth;
4257 Returns the width of the item that is implied by other properties that determine the content.
4259 qreal QQuickItem::implicitWidth() const
4261 Q_D(const QQuickItem);
4262 return d->getImplicitWidth();
4266 \qmlproperty real QtQuick2::Item::implicitWidth
4267 \qmlproperty real QtQuick2::Item::implicitHeight
4269 Defines the natural width or height of the Item if no \l width or \l height is specified.
4271 The default implicit size for most items is 0x0, however some elements have an inherent
4272 implicit size which cannot be overridden, e.g. Image, Text.
4274 Setting the implicit size is useful for defining components that have a preferred size
4275 based on their content, for example:
4282 property alias icon: image.source
4283 property alias label: text.text
4284 implicitWidth: text.implicitWidth + image.implicitWidth
4285 implicitHeight: Math.max(text.implicitHeight, image.implicitHeight)
4290 anchors.left: image.right; anchors.right: parent.right
4291 anchors.verticalCenter: parent.verticalCenter
4296 \bold Note: using implicitWidth of Text or TextEdit and setting the width explicitly
4297 incurs a performance penalty as the text must be laid out twice.
4301 Sets the implied width of the item to \a w.
4302 This is the width implied by other properties that determine the content.
4304 void QQuickItem::setImplicitWidth(qreal w)
4307 bool changed = w != d->implicitWidth;
4308 d->implicitWidth = w;
4309 if (d->width == w || widthValid()) {
4311 d->implicitWidthChanged();
4315 qreal oldWidth = d->width;
4318 d->dirty(QQuickItemPrivate::Size);
4320 geometryChanged(QRectF(x(), y(), width(), height()),
4321 QRectF(x(), y(), oldWidth, height()));
4324 d->implicitWidthChanged();
4328 Returns whether the width property has been set explicitly.
4330 bool QQuickItem::widthValid() const
4332 Q_D(const QQuickItem);
4333 return d->widthValid;
4336 qreal QQuickItem::height() const
4338 Q_D(const QQuickItem);
4342 void QQuickItem::setHeight(qreal h)
4348 d->heightValid = true;
4352 qreal oldHeight = d->height;
4355 d->dirty(QQuickItemPrivate::Size);
4357 geometryChanged(QRectF(x(), y(), width(), height()),
4358 QRectF(x(), y(), width(), oldHeight));
4361 void QQuickItem::resetHeight()
4364 d->heightValid = false;
4365 setImplicitHeight(implicitHeight());
4368 void QQuickItemPrivate::implicitHeightChanged()
4371 emit q->implicitHeightChanged();
4374 qreal QQuickItemPrivate::getImplicitHeight() const
4376 return implicitHeight;
4380 Returns the height of the item that is implied by other properties that determine the content.
4382 qreal QQuickItem::implicitHeight() const
4384 Q_D(const QQuickItem);
4385 return d->getImplicitHeight();
4390 Sets the implied height of the item to \a h.
4391 This is the height implied by other properties that determine the content.
4393 void QQuickItem::setImplicitHeight(qreal h)
4396 bool changed = h != d->implicitHeight;
4397 d->implicitHeight = h;
4398 if (d->height == h || heightValid()) {
4400 d->implicitHeightChanged();
4404 qreal oldHeight = d->height;
4407 d->dirty(QQuickItemPrivate::Size);
4409 geometryChanged(QRectF(x(), y(), width(), height()),
4410 QRectF(x(), y(), width(), oldHeight));
4413 d->implicitHeightChanged();
4416 void QQuickItem::setImplicitSize(qreal w, qreal h)
4419 bool wChanged = w != d->implicitWidth;
4420 bool hChanged = h != d->implicitHeight;
4422 d->implicitWidth = w;
4423 d->implicitHeight = h;
4427 if (d->width == w || widthValid()) {
4429 d->implicitWidthChanged();
4432 if (d->height == h || heightValid()) {
4434 d->implicitHeightChanged();
4440 qreal oldWidth = d->width;
4441 qreal oldHeight = d->height;
4447 d->dirty(QQuickItemPrivate::Size);
4449 geometryChanged(QRectF(x(), y(), width(), height()),
4450 QRectF(x(), y(), oldWidth, oldHeight));
4452 if (!wDone && wChanged)
4453 d->implicitWidthChanged();
4454 if (!hDone && hChanged)
4455 d->implicitHeightChanged();
4459 Returns whether the height property has been set explicitly.
4461 bool QQuickItem::heightValid() const
4463 Q_D(const QQuickItem);
4464 return d->heightValid;
4467 void QQuickItem::setSize(const QSizeF &size)
4470 d->heightValid = true;
4471 d->widthValid = true;
4473 if (QSizeF(d->width, d->height) == size)
4476 qreal oldHeight = d->height;
4477 qreal oldWidth = d->width;
4478 d->height = size.height();
4479 d->width = size.width();
4481 d->dirty(QQuickItemPrivate::Size);
4483 geometryChanged(QRectF(x(), y(), width(), height()),
4484 QRectF(x(), y(), oldWidth, oldHeight));
4487 bool QQuickItem::hasActiveFocus() const
4489 Q_D(const QQuickItem);
4490 return d->activeFocus;
4493 bool QQuickItem::hasFocus() const
4495 Q_D(const QQuickItem);
4499 void QQuickItem::setFocus(bool focus)
4502 if (d->focus == focus)
4506 // Need to find our nearest focus scope
4507 QQuickItem *scope = parentItem();
4508 while (scope && !scope->isFocusScope())
4509 scope = scope->parentItem();
4511 QQuickCanvasPrivate::get(d->canvas)->setFocusInScope(scope, this);
4513 QQuickCanvasPrivate::get(d->canvas)->clearFocusInScope(scope, this);
4516 emit focusChanged(focus);
4520 bool QQuickItem::isFocusScope() const
4522 return flags() & ItemIsFocusScope;
4525 QQuickItem *QQuickItem::scopedFocusItem() const
4527 Q_D(const QQuickItem);
4528 if (!isFocusScope())
4531 return d->subFocusItem;
4535 Qt::MouseButtons QQuickItem::acceptedMouseButtons() const
4537 Q_D(const QQuickItem);
4538 return d->acceptedMouseButtons;
4541 void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
4544 d->acceptedMouseButtons = buttons;
4547 bool QQuickItem::filtersChildMouseEvents() const
4549 Q_D(const QQuickItem);
4550 return d->filtersChildMouseEvents;
4553 void QQuickItem::setFiltersChildMouseEvents(bool filter)
4556 d->filtersChildMouseEvents = filter;
4559 bool QQuickItem::isUnderMouse() const
4561 Q_D(const QQuickItem);
4565 QPoint cursorPos = QCursor::pos();
4566 if (QRectF(0, 0, width(), height()).contains(mapFromScene(cursorPos))) // ### refactor: d->canvas->mapFromGlobal(cursorPos))))
4571 bool QQuickItem::acceptHoverEvents() const
4573 Q_D(const QQuickItem);
4574 return d->hoverEnabled;
4577 void QQuickItem::setAcceptHoverEvents(bool enabled)
4580 d->hoverEnabled = enabled;
4583 void QQuickItem::grabMouse()
4588 QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas);
4589 if (canvasPriv->mouseGrabberItem == this)
4592 QQuickItem *oldGrabber = canvasPriv->mouseGrabberItem;
4593 canvasPriv->mouseGrabberItem = this;
4595 oldGrabber->mouseUngrabEvent();
4598 void QQuickItem::ungrabMouse()
4603 QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas);
4604 if (canvasPriv->mouseGrabberItem != this) {
4605 qWarning("QQuickItem::ungrabMouse(): Item is not the mouse grabber.");
4609 canvasPriv->mouseGrabberItem = 0;
4613 bool QQuickItem::keepMouseGrab() const
4615 Q_D(const QQuickItem);
4616 return d->keepMouse;
4620 The flag indicating whether the mouse should remain
4621 with this item is set to \a keep.
4623 This is useful for items that wish to grab and keep mouse
4624 interaction following a predefined gesture. For example,
4625 an item that is interested in horizontal mouse movement
4626 may set keepMouseGrab to true once a threshold has been
4627 exceeded. Once keepMouseGrab has been set to true, filtering
4628 items will not react to mouse events.
4630 If the item does not indicate that it wishes to retain mouse grab,
4631 a filtering item may steal the grab. For example, Flickable may attempt
4632 to steal a mouse grab if it detects that the user has begun to
4637 void QQuickItem::setKeepMouseGrab(bool keep)
4640 d->keepMouse = keep;
4644 Grabs the touch points specified by \a ids.
4646 These touch points will be owned by the item until
4647 they are released. Alternatively, the grab can be stolen
4648 by a filtering item like Flickable. Use setKeepTouchGrab()
4649 to prevent the grab from being stolen.
4651 \sa ungrabTouchPoints(), setKeepTouchGrab()
4653 void QQuickItem::grabTouchPoints(const QList<int> &ids)
4658 QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas);
4660 QSet<QQuickItem*> ungrab;
4661 for (int i = 0; i < ids.count(); ++i) {
4662 QQuickItem *oldGrabber = canvasPriv->itemForTouchPointId.value(ids.at(i));
4663 if (oldGrabber == this)
4666 canvasPriv->itemForTouchPointId[ids.at(i)] = this;
4668 ungrab.insert(oldGrabber);
4670 foreach (QQuickItem *oldGrabber, ungrab)
4671 oldGrabber->touchUngrabEvent();
4675 Ungrabs the touch points owned by this item.
4677 \sa grabTouchPoints()
4679 void QQuickItem::ungrabTouchPoints()
4684 QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas);
4686 QMutableHashIterator<int, QQuickItem*> i(canvasPriv->itemForTouchPointId);
4687 while (i.hasNext()) {
4689 if (i.value() == this)
4696 Returns a value indicating whether the touch points grabbed by this item
4697 should remain with this item exclusively.
4699 \sa setKeepTouchGrab(), keepMouseGrab()
4701 bool QQuickItem::keepTouchGrab() const
4703 Q_D(const QQuickItem);
4704 return d->keepTouch;
4708 The flag indicating whether the touch points grabbed
4709 by this item should remain with this item is set to \a keep.
4711 This is useful for items that wish to grab and keep specific touch
4712 points following a predefined gesture. For example,
4713 an item that is interested in horizontal touch point movement
4714 may set setKeepTouchGrab to true once a threshold has been
4715 exceeded. Once setKeepTouchGrab has been set to true, filtering
4716 items will not react to the relevant touch points.
4718 If the item does not indicate that it wishes to retain touch point grab,
4719 a filtering item may steal the grab. For example, Flickable may attempt
4720 to steal a touch point grab if it detects that the user has begun to
4723 \sa keepTouchGrab(), setKeepMouseGrab()
4725 void QQuickItem::setKeepTouchGrab(bool keep)
4728 d->keepTouch = keep;
4732 \qmlmethod object QtQuick2::Item::mapFromItem(Item item, real x, real y)
4734 Maps the point (\a x, \a y), which is in \a item's coordinate system, to
4735 this item's coordinate system, and returns an object with \c x and \c y
4736 properties matching the mapped coordinate.
4738 If \a item is a \c null value, this maps the point from the coordinate
4739 system of the root QML view.
4742 \qmlmethod object QtQuick2::Item::mapToItem(Item item, real x, real y)
4744 Maps the point (\a x, \a y), which is in this item's coordinate system, to
4745 \a item's coordinate system, and returns an object with \c x and \c y
4746 properties matching the mapped coordinate.
4748 If \a item is a \c null value, this maps \a x and \a y to the coordinate
4749 system of the root QML view.
4751 QPointF QQuickItem::mapToItem(const QQuickItem *item, const QPointF &point) const
4753 QPointF p = mapToScene(point);
4755 p = item->mapFromScene(p);
4759 QPointF QQuickItem::mapToScene(const QPointF &point) const
4761 Q_D(const QQuickItem);
4762 return d->itemToCanvasTransform().map(point);
4765 QRectF QQuickItem::mapRectToItem(const QQuickItem *item, const QRectF &rect) const
4767 Q_D(const QQuickItem);
4768 QTransform t = d->itemToCanvasTransform();
4770 t *= QQuickItemPrivate::get(item)->canvasToItemTransform();
4771 return t.mapRect(rect);
4774 QRectF QQuickItem::mapRectToScene(const QRectF &rect) const
4776 Q_D(const QQuickItem);
4777 return d->itemToCanvasTransform().mapRect(rect);
4780 QPointF QQuickItem::mapFromItem(const QQuickItem *item, const QPointF &point) const
4782 QPointF p = item?item->mapToScene(point):point;
4783 return mapFromScene(p);
4786 QPointF QQuickItem::mapFromScene(const QPointF &point) const
4788 Q_D(const QQuickItem);
4789 return d->canvasToItemTransform().map(point);
4792 QRectF QQuickItem::mapRectFromItem(const QQuickItem *item, const QRectF &rect) const
4794 Q_D(const QQuickItem);
4795 QTransform t = item?QQuickItemPrivate::get(item)->itemToCanvasTransform():QTransform();
4796 t *= d->canvasToItemTransform();
4797 return t.mapRect(rect);
4800 QRectF QQuickItem::mapRectFromScene(const QRectF &rect) const
4802 Q_D(const QQuickItem);
4803 return d->canvasToItemTransform().mapRect(rect);
4808 \qmlmethod QtQuick2::Item::forceActiveFocus()
4810 Forces active focus on the item.
4812 This method sets focus on the item and makes sure that all the focus scopes
4813 higher in the object hierarchy are also given the focus.
4817 Forces active focus on the item.
4819 This method sets focus on the item and makes sure that all the focus scopes
4820 higher in the object hierarchy are also given the focus.
4824 \qmlmethod QtQuick2::Item::childAt(real x, real y)
4826 Returns the visible child item at point (\a x, \a y), which is in this
4827 item's coordinate system, or \c null if there is no such item.
4831 Returns the visible child item at point (\a x, \a y), which is in this
4832 item's coordinate system, or 0 if there is no such item.
4836 \qmlproperty list<State> QtQuick2::Item::states
4837 This property holds a list of states defined by the item.
4853 \sa {qmlstate}{States}
4856 \qmlproperty list<Transition> QtQuick2::Item::transitions
4857 This property holds a list of transitions defined by the item.
4873 \sa {QML Animation and Transitions}{Transitions}
4876 \qmlproperty list<Filter> QtQuick2::Item::filter
4877 This property holds a list of graphical filters to be applied to the item.
4879 \l {Filter}{Filters} include things like \l {Blur}{blurring}
4880 the item, or giving it a \l Reflection. Some
4881 filters may not be available on all canvases; if a filter is not
4882 available on a certain canvas, it will simply not be applied for
4883 that canvas (but the QML will still be considered valid).
4901 \qmlproperty bool QtQuick2::Item::clip
4902 This property holds whether clipping is enabled. The default clip value is \c false.
4904 If clipping is enabled, an item will clip its own painting, as well
4905 as the painting of its children, to its bounding rectangle.
4907 Non-rectangular clipping regions are not supported for performance reasons.
4911 \property QQuickItem::clip
4912 This property holds whether clipping is enabled. The default clip value is \c false.
4914 If clipping is enabled, an item will clip its own painting, as well
4915 as the painting of its children, to its bounding rectangle. If you set
4916 clipping during an item's paint operation, remember to re-set it to
4917 prevent clipping the rest of your scene.
4919 Non-rectangular clipping regions are not supported for performance reasons.
4923 \qmlproperty string QtQuick2::Item::state
4925 This property holds the name of the current state of the item.
4927 This property is often used in scripts to change between states. For
4932 if (button.state == 'On')
4933 button.state = 'Off';
4935 button.state = 'On';
4939 If the item is in its base state (i.e. no explicit state has been
4940 set), \c state will be a blank string. Likewise, you can return an
4941 item to its base state by setting its current state to \c ''.
4943 \sa {qmlstates}{States}
4947 \qmlproperty list<Transform> QtQuick2::Item::transform
4948 This property holds the list of transformations to apply.
4950 For more information see \l Transform.
4954 \enum QQuickItem::TransformOrigin
4956 Controls the point about which simple transforms like scale apply.
4958 \value TopLeft The top-left corner of the item.
4959 \value Top The center point of the top of the item.
4960 \value TopRight The top-right corner of the item.
4961 \value Left The left most point of the vertical middle.
4962 \value Center The center of the item.
4963 \value Right The right most point of the vertical middle.
4964 \value BottomLeft The bottom-left corner of the item.
4965 \value Bottom The center point of the bottom of the item.
4966 \value BottomRight The bottom-right corner of the item.
4971 \qmlproperty bool QtQuick2::Item::activeFocus
4973 This property indicates whether the item has active focus.
4975 An item with active focus will receive keyboard input,
4976 or is a FocusScope ancestor of the item that will receive keyboard input.
4978 Usually, activeFocus is gained by setting focus on an item and its enclosing
4979 FocusScopes. In the following example \c input will have activeFocus.
4992 \sa focus, {qmlfocus}{Keyboard Focus}
4996 \qmlproperty bool QtQuick2::Item::focus
4997 This property indicates whether the item has focus within the enclosing focus scope. If true, this item
4998 will gain active focus when the enclosing focus scope gains active focus.
4999 In the following example, \c input will be given active focus when \c scope gains active focus.
5012 For the purposes of this property, the scene as a whole is assumed to act like a focus scope.
5013 On a practical level, that means the following QML will give active focus to \c input on startup.
5024 \sa activeFocus, {qmlfocus}{Keyboard Focus}
5029 \property QQuickItem::anchors
5034 \property QQuickItem::left
5039 \property QQuickItem::right
5044 \property QQuickItem::horizontalCenter
5049 \property QQuickItem::top
5054 \property QQuickItem::bottom
5059 \property QQuickItem::verticalCenter
5064 \property QQuickItem::focus
5069 \property QQuickItem::transform
5074 \property QQuickItem::transformOrigin
5079 \property QQuickItem::activeFocus
5084 \property QQuickItem::baseline
5089 \property QQuickItem::data
5094 \property QQuickItem::resources
5099 \property QQuickItem::state
5104 \property QQuickItem::states
5109 \property QQuickItem::transformOriginPoint
5114 \property QQuickItem::transitions
5118 bool QQuickItem::event(QEvent *ev)
5121 if (ev->type() == QEvent::PolishRequest) {
5123 d->polishScheduled = false;
5127 return QObject::event(ev);
5130 if (ev->type() == QEvent::InputMethodQuery) {
5131 QInputMethodQueryEvent *query = static_cast<QInputMethodQueryEvent *>(ev);
5132 Qt::InputMethodQueries queries = query->queries();
5133 for (uint i = 0; i < 32; ++i) {
5134 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i));
5136 QVariant v = inputMethodQuery(q);
5137 query->setValue(q, v);
5142 } else if (ev->type() == QEvent::InputMethod) {
5143 inputMethodEvent(static_cast<QInputMethodEvent *>(ev));
5146 return QObject::event(ev);
5149 #ifndef QT_NO_DEBUG_STREAM
5150 QDebug operator<<(QDebug debug, QQuickItem *item)
5153 debug << "QQuickItem(0)";
5157 debug << item->metaObject()->className() << "(this =" << ((void*)item)
5158 << ", name=" << item->objectName()
5159 << ", parent =" << ((void*)item->parentItem())
5160 << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height()))
5161 << ", z =" << item->z() << ')';
5166 qint64 QQuickItemPrivate::consistentTime = -1;
5167 void QQuickItemPrivate::setConsistentTime(qint64 t)
5172 class QElapsedTimerConsistentTimeHack
5176 t1 = QQuickItemPrivate::consistentTime;
5180 return QQuickItemPrivate::consistentTime - t1;
5183 qint64 val = QQuickItemPrivate::consistentTime - t1;
5184 t1 = QQuickItemPrivate::consistentTime;
5194 void QQuickItemPrivate::start(QElapsedTimer &t)
5196 if (QQuickItemPrivate::consistentTime == -1)
5199 ((QElapsedTimerConsistentTimeHack*)&t)->start();
5202 qint64 QQuickItemPrivate::elapsed(QElapsedTimer &t)
5204 if (QQuickItemPrivate::consistentTime == -1)
5207 return ((QElapsedTimerConsistentTimeHack*)&t)->elapsed();
5210 qint64 QQuickItemPrivate::restart(QElapsedTimer &t)
5212 if (QQuickItemPrivate::consistentTime == -1)
5215 return ((QElapsedTimerConsistentTimeHack*)&t)->restart();
5219 \fn bool QQuickItem::isTextureProvider() const
5221 Returns true if this item is a texture provider. The default
5222 implementation returns false.
5224 This function can be called from any thread.
5228 \fn QSGTextureProvider *QQuickItem::textureProvider() const
5230 Returns the texture provider for an item. The default implementation
5233 This function may only be called on the rendering thread.
5238 #include <moc_qquickitem.cpp>