1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 "QtQuick1/qdeclarativeitem.h"
44 #include "QtQuick1/private/qdeclarativeevents_p_p.h"
45 #include <QtDeclarative/private/qdeclarativeengine_p.h>
46 #include <private/qgraphicsitem_p.h>
47 #include <QtQuick1/private/qdeclarativeitem_p.h>
49 #include <QtDeclarative/qdeclarativeengine.h>
50 #include <QtQuick1/private/qdeclarativeopenmetaobject_p.h>
51 #include <QtQuick1/private/qdeclarativestate_p.h>
52 #include <QtQuick1/qdeclarativeview.h>
53 #include <QtQuick1/private/qdeclarativestategroup_p.h>
54 #include <QtDeclarative/qdeclarativecomponent.h>
55 #include <QtDeclarative/qdeclarativeinfo.h>
56 // ### Due to the workaround mentioned in accessibleRole()
57 #include <QtQuick1/private/qdeclarativetext_p.h>
62 #include <QGraphicsSceneMouseEvent>
63 #include <QtCore/qnumeric.h>
64 #include <QtDeclarative/qjsengine.h>
66 #include <private/qv8engine_p.h>
67 #include <QtWidgets/qgraphicstransform.h>
68 #include <private/qlistmodelinterface_p.h>
69 #include <QAccessible>
70 #include <QtQuick1/private/qdeclarativeaccessibleattached_p.h>
77 \qmlclass Transform QGraphicsTransform
78 \inqmlmodule QtQuick 1
79 \ingroup qml-transform-elements
81 \brief The Transform elements provide a way of building advanced transformations on Items.
83 The Transform element is a base type which cannot be instantiated directly.
84 The following concrete Transform types are available:
92 The Transform elements let you create and control advanced transformations that can be configured
93 independently using specialized properties.
95 You can assign any number of Transform elements to an \l Item. Each Transform is applied in order,
100 \qmlclass Translate QDeclarative1Translate
101 \inqmlmodule QtQuick 1
102 \ingroup qml-transform-elements
104 \brief The Translate object provides a way to move an Item without changing its x or y properties.
106 The Translate object provides independent control over position in addition to the Item's x and y properties.
108 The following example moves the Y axis of the \l Rectangle elements while still allowing the \l Row element
109 to lay the items out as if they had not been transformed:
115 width: 100; height: 100
117 transform: Translate { y: 20 }
120 width: 100; height: 100
122 transform: Translate { y: -20 }
131 \qmlproperty real QtQuick1::Translate::x
133 The translation along the X axis.
137 \qmlproperty real QtQuick1::Translate::y
139 The translation along the Y axis.
143 \qmlclass Scale QGraphicsScale
144 \inqmlmodule QtQuick 1
145 \ingroup qml-transform-elements
147 \brief The Scale element provides a way to scale an Item.
149 The Scale element gives more control over scaling than using \l Item's \l{Item::scale}{scale} property. Specifically,
150 it allows a different scale for the x and y axes, and allows the scale to be relative to an
153 The following example scales the X axis of the Rectangle, relative to its interior point 25, 25:
156 width: 100; height: 100
158 transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}
162 \sa Rotation, Translate
166 \qmlproperty real QtQuick1::Scale::origin.x
167 \qmlproperty real QtQuick1::Scale::origin.y
169 The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as
170 the rest of the item grows). By default the origin is 0, 0.
174 \qmlproperty real QtQuick1::Scale::xScale
176 The scaling factor for the X axis.
180 \qmlproperty real QtQuick1::Scale::yScale
182 The scaling factor for the Y axis.
186 \qmlclass Rotation QGraphicsRotation
187 \inqmlmodule QtQuick 1
188 \ingroup qml-transform-elements
190 \brief The Rotation object provides a way to rotate an Item.
192 The Rotation object gives more control over rotation than using \l Item's \l{Item::rotation}{rotation} property.
193 Specifically, it allows (z axis) rotation to be relative to an arbitrary point.
195 The following example rotates a Rectangle around its interior point 25, 25:
198 width: 100; height: 100
200 transform: Rotation { origin.x: 25; origin.y: 25; angle: 45}
204 Rotation also provides a way to specify 3D-like rotations for Items. For these types of
205 rotations you must specify the axis to rotate around in addition to the origin point.
207 The following example shows various 3D-like rotations applied to an \l Image.
208 \snippet doc/src/snippets/qtquick1/rotation.qml 0
210 \image axisrotation.png
212 \sa {declarative/ui-components/dialcontrol}{Dial Control example}, {declarative/toys/clocks}{Clocks example}
216 \qmlproperty real QtQuick1::Rotation::origin.x
217 \qmlproperty real QtQuick1::Rotation::origin.y
219 The origin point of the rotation (i.e., the point that stays fixed relative to the parent as
220 the rest of the item rotates). By default the origin is 0, 0.
224 \qmlproperty real QtQuick1::Rotation::axis.x
225 \qmlproperty real QtQuick1::Rotation::axis.y
226 \qmlproperty real QtQuick1::Rotation::axis.z
228 The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis,
229 as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 1 } }).
231 For a typical 3D-like rotation you will usually specify both the origin and the axis.
233 \image 3d-rotation-axis.png
237 \qmlproperty real QtQuick1::Rotation::angle
239 The angle to rotate, in degrees clockwise.
242 QDeclarative1Contents::QDeclarative1Contents(QDeclarativeItem *item) : m_item(item), m_x(0), m_y(0), m_width(0), m_height(0)
245 connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF)));
248 QDeclarative1Contents::~QDeclarative1Contents()
250 QList<QGraphicsItem *> children = m_item->childItems();
251 for (int i = 0; i < children.count(); ++i) {
252 QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
253 if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
255 QDeclarativeItemPrivate::get(child)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
259 QRectF QDeclarative1Contents::rectF() const
261 return QRectF(m_x, m_y, m_width, m_height);
264 void QDeclarative1Contents::calcHeight(QDeclarativeItem *changed)
267 qreal oldheight = m_height;
271 qreal bottom = oldy + oldheight;
272 qreal y = changed->y();
273 if (y + changed->height() > bottom)
274 bottom = y + changed->height();
278 m_height = bottom - top;
282 QList<QGraphicsItem *> children = m_item->childItems();
283 for (int i = 0; i < children.count(); ++i) {
284 QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
285 if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
287 qreal y = child->y();
288 if (y + child->height() > bottom)
289 bottom = y + child->height();
293 if (!children.isEmpty())
295 m_height = qMax(bottom - top, qreal(0.0));
298 if (m_height != oldheight || m_y != oldy)
299 emit rectChanged(rectF());
302 void QDeclarative1Contents::calcWidth(QDeclarativeItem *changed)
305 qreal oldwidth = m_width;
309 qreal right = oldx + oldwidth;
310 qreal x = changed->x();
311 if (x + changed->width() > right)
312 right = x + changed->width();
316 m_width = right - left;
318 qreal left = FLT_MAX;
320 QList<QGraphicsItem *> children = m_item->childItems();
321 for (int i = 0; i < children.count(); ++i) {
322 QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
323 if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
325 qreal x = child->x();
326 if (x + child->width() > right)
327 right = x + child->width();
331 if (!children.isEmpty())
333 m_width = qMax(right - left, qreal(0.0));
336 if (m_width != oldwidth || m_x != oldx)
337 emit rectChanged(rectF());
340 void QDeclarative1Contents::complete()
342 QList<QGraphicsItem *> children = m_item->childItems();
343 for (int i = 0; i < children.count(); ++i) {
344 QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
345 if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
347 QDeclarativeItemPrivate::get(child)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
348 //###what about changes to visibility?
354 void QDeclarative1Contents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry)
357 //### we can only pass changed if the left edge has moved left, or the right edge has moved right
358 if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x())
359 calcWidth(/*changed*/);
360 if (newGeometry.height() != oldGeometry.height() || newGeometry.y() != oldGeometry.y())
361 calcHeight(/*changed*/);
364 void QDeclarative1Contents::itemDestroyed(QDeclarativeItem *item)
367 QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
371 void QDeclarative1Contents::childRemoved(QDeclarativeItem *item)
374 QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
378 void QDeclarative1Contents::childAdded(QDeclarativeItem *item)
381 QDeclarativeItemPrivate::get(item)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed);
386 QDeclarativeItemKeyFilter::QDeclarativeItemKeyFilter(QDeclarativeItem *item)
387 : m_processPost(false), m_next(0)
389 QDeclarativeItemPrivate *p =
390 item?static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(item)):0;
392 m_next = p->keyHandler;
393 p->keyHandler = this;
397 QDeclarativeItemKeyFilter::~QDeclarativeItemKeyFilter()
401 void QDeclarativeItemKeyFilter::keyPressed(QKeyEvent *event, bool post)
403 if (m_next) m_next->keyPressed(event, post);
406 void QDeclarativeItemKeyFilter::keyReleased(QKeyEvent *event, bool post)
408 if (m_next) m_next->keyReleased(event, post);
411 void QDeclarativeItemKeyFilter::inputMethodEvent(QInputMethodEvent *event, bool post)
413 if (m_next) m_next->inputMethodEvent(event, post);
416 QVariant QDeclarativeItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const
418 if (m_next) return m_next->inputMethodQuery(query);
422 void QDeclarativeItemKeyFilter::componentComplete()
424 if (m_next) m_next->componentComplete();
429 \qmlclass KeyNavigation QDeclarative1KeyNavigationAttached
430 \inqmlmodule QtQuick 1
431 \ingroup qml-basic-interaction-elements
433 \brief The KeyNavigation attached property supports key navigation by arrow keys.
435 Key-based user interfaces commonly allow the use of arrow keys to navigate between
436 focusable items. The KeyNavigation attached property enables this behavior by providing a
437 convenient way to specify the item that should gain focus when an arrow or tab key is pressed.
439 The following example provides key navigation for a 2x2 grid of items:
441 \snippet doc/src/snippets/qtquick1/keynavigation.qml 0
443 The top-left item initially receives focus by setting \l {Item::}{focus} to
444 \c true. When an arrow key is pressed, the focus will move to the
445 appropriate item, as defined by the value that has been set for
446 the KeyNavigation \l left, \l right, \l up or \l down properties.
448 Note that if a KeyNavigation attached property receives the key press and release
449 events for a requested arrow or tab key, the event is accepted and does not
450 propagate any further.
452 By default, KeyNavigation receives key events after the item to which it is attached.
453 If the item accepts the key event, the KeyNavigation attached property will not
454 receive an event for that key. Setting the \l priority property to
455 \c KeyNavigation.BeforeItem allows the event to be used for key navigation
456 before the item, rather than after.
458 If item to which the focus is switching is not enabled or visible, an attempt will
459 be made to skip this item and focus on the next. This is possible if there are
460 a chain of items with the same KeyNavigation handler. If multiple items in a row are not enabled
461 or visible, they will also be skipped.
463 KeyNavigation will implicitly set the other direction to return focus to this item. So if you set
464 \l left to another item, \l right will be set on that item's KeyNavigation to set focus back to this
465 item. However, if that item's KeyNavigation has had right explicitly set then no change will occur.
466 This means that the above example could have been written, with the same behaviour, without specifing
467 KeyNavigation.right or KeyNavigation.down for any of the items.
469 \sa {Keys}{Keys attached property}
473 \qmlproperty Item QtQuick1::KeyNavigation::left
474 \qmlproperty Item QtQuick1::KeyNavigation::right
475 \qmlproperty Item QtQuick1::KeyNavigation::up
476 \qmlproperty Item QtQuick1::KeyNavigation::down
477 \qmlproperty Item QtQuick1::KeyNavigation::tab
478 \qmlproperty Item QtQuick1::KeyNavigation::backtab
480 These properties hold the item to assign focus to
481 when the left, right, up or down cursor keys, or the
486 \qmlproperty Item QtQuick1::KeyNavigation::tab
487 \qmlproperty Item QtQuick1::KeyNavigation::backtab
489 These properties hold the item to assign focus to
490 when the Tab key or Shift+Tab key combination (Backtab) are pressed.
493 QDeclarative1KeyNavigationAttached::QDeclarative1KeyNavigationAttached(QObject *parent)
494 : QObject(*(new QDeclarative1KeyNavigationAttachedPrivate), parent),
495 QDeclarativeItemKeyFilter(qobject_cast<QDeclarativeItem*>(parent))
497 m_processPost = true;
500 QDeclarative1KeyNavigationAttached *
501 QDeclarative1KeyNavigationAttached::qmlAttachedProperties(QObject *obj)
503 return new QDeclarative1KeyNavigationAttached(obj);
506 QDeclarativeItem *QDeclarative1KeyNavigationAttached::left() const
508 Q_D(const QDeclarative1KeyNavigationAttached);
512 void QDeclarative1KeyNavigationAttached::setLeft(QDeclarativeItem *i)
514 Q_D(QDeclarative1KeyNavigationAttached);
519 QDeclarative1KeyNavigationAttached* other =
520 qobject_cast<QDeclarative1KeyNavigationAttached*>(qmlAttachedPropertiesObject<QDeclarative1KeyNavigationAttached>(i));
521 if(other && !other->d_func()->rightSet){
522 other->d_func()->right = qobject_cast<QDeclarativeItem*>(parent());
523 emit other->rightChanged();
528 QDeclarativeItem *QDeclarative1KeyNavigationAttached::right() const
530 Q_D(const QDeclarative1KeyNavigationAttached);
534 void QDeclarative1KeyNavigationAttached::setRight(QDeclarativeItem *i)
536 Q_D(QDeclarative1KeyNavigationAttached);
541 QDeclarative1KeyNavigationAttached* other =
542 qobject_cast<QDeclarative1KeyNavigationAttached*>(qmlAttachedPropertiesObject<QDeclarative1KeyNavigationAttached>(i));
543 if(other && !other->d_func()->leftSet){
544 other->d_func()->left = qobject_cast<QDeclarativeItem*>(parent());
545 emit other->leftChanged();
550 QDeclarativeItem *QDeclarative1KeyNavigationAttached::up() const
552 Q_D(const QDeclarative1KeyNavigationAttached);
556 void QDeclarative1KeyNavigationAttached::setUp(QDeclarativeItem *i)
558 Q_D(QDeclarative1KeyNavigationAttached);
563 QDeclarative1KeyNavigationAttached* other =
564 qobject_cast<QDeclarative1KeyNavigationAttached*>(qmlAttachedPropertiesObject<QDeclarative1KeyNavigationAttached>(i));
565 if(other && !other->d_func()->downSet){
566 other->d_func()->down = qobject_cast<QDeclarativeItem*>(parent());
567 emit other->downChanged();
572 QDeclarativeItem *QDeclarative1KeyNavigationAttached::down() const
574 Q_D(const QDeclarative1KeyNavigationAttached);
578 void QDeclarative1KeyNavigationAttached::setDown(QDeclarativeItem *i)
580 Q_D(QDeclarative1KeyNavigationAttached);
585 QDeclarative1KeyNavigationAttached* other =
586 qobject_cast<QDeclarative1KeyNavigationAttached*>(qmlAttachedPropertiesObject<QDeclarative1KeyNavigationAttached>(i));
587 if(other && !other->d_func()->upSet){
588 other->d_func()->up = qobject_cast<QDeclarativeItem*>(parent());
589 emit other->upChanged();
594 QDeclarativeItem *QDeclarative1KeyNavigationAttached::tab() const
596 Q_D(const QDeclarative1KeyNavigationAttached);
600 void QDeclarative1KeyNavigationAttached::setTab(QDeclarativeItem *i)
602 Q_D(QDeclarative1KeyNavigationAttached);
607 QDeclarative1KeyNavigationAttached* other =
608 qobject_cast<QDeclarative1KeyNavigationAttached*>(qmlAttachedPropertiesObject<QDeclarative1KeyNavigationAttached>(i));
609 if(other && !other->d_func()->backtabSet){
610 other->d_func()->backtab = qobject_cast<QDeclarativeItem*>(parent());
611 emit other->backtabChanged();
616 QDeclarativeItem *QDeclarative1KeyNavigationAttached::backtab() const
618 Q_D(const QDeclarative1KeyNavigationAttached);
622 void QDeclarative1KeyNavigationAttached::setBacktab(QDeclarativeItem *i)
624 Q_D(QDeclarative1KeyNavigationAttached);
628 d->backtabSet = true;
629 QDeclarative1KeyNavigationAttached* other =
630 qobject_cast<QDeclarative1KeyNavigationAttached*>(qmlAttachedPropertiesObject<QDeclarative1KeyNavigationAttached>(i));
631 if(other && !other->d_func()->tabSet){
632 other->d_func()->tab = qobject_cast<QDeclarativeItem*>(parent());
633 emit other->tabChanged();
635 emit backtabChanged();
639 \qmlproperty enumeration QtQuick1::KeyNavigation::priority
641 This property determines whether the keys are processed before
642 or after the attached item's own key handling.
645 \o KeyNavigation.BeforeItem - process the key events before normal
646 item key processing. If the event is used for key navigation, it will be accepted and will not
647 be passed on to the item.
648 \o KeyNavigation.AfterItem (default) - process the key events after normal item key
649 handling. If the item accepts the key event it will not be
650 handled by the KeyNavigation attached property handler.
653 QDeclarative1KeyNavigationAttached::Priority QDeclarative1KeyNavigationAttached::priority() const
655 return m_processPost ? AfterItem : BeforeItem;
658 void QDeclarative1KeyNavigationAttached::setPriority(Priority order)
660 bool processPost = order == AfterItem;
661 if (processPost != m_processPost) {
662 m_processPost = processPost;
663 emit priorityChanged();
667 void QDeclarative1KeyNavigationAttached::keyPressed(QKeyEvent *event, bool post)
669 Q_D(QDeclarative1KeyNavigationAttached);
672 if (post != m_processPost) {
673 QDeclarativeItemKeyFilter::keyPressed(event, post);
678 switch(event->key()) {
680 if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
681 mirror = QDeclarativeItemPrivate::get(parentItem)->effectiveLayoutMirror;
682 QDeclarativeItem* leftItem = mirror ? d->right : d->left;
684 setFocusNavigation(leftItem, mirror ? "right" : "left");
689 case Qt::Key_Right: {
690 if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
691 mirror = QDeclarativeItemPrivate::get(parentItem)->effectiveLayoutMirror;
692 QDeclarativeItem* rightItem = mirror ? d->left : d->right;
694 setFocusNavigation(rightItem, mirror ? "left" : "right");
701 setFocusNavigation(d->up, "up");
707 setFocusNavigation(d->down, "down");
713 setFocusNavigation(d->tab, "tab");
717 case Qt::Key_Backtab:
719 setFocusNavigation(d->backtab, "backtab");
727 if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyPressed(event, post);
730 void QDeclarative1KeyNavigationAttached::keyReleased(QKeyEvent *event, bool post)
732 Q_D(QDeclarative1KeyNavigationAttached);
735 if (post != m_processPost) {
736 QDeclarativeItemKeyFilter::keyReleased(event, post);
741 switch(event->key()) {
743 if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
744 mirror = QDeclarativeItemPrivate::get(parentItem)->effectiveLayoutMirror;
745 if (mirror ? d->right : d->left)
749 if (QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent()))
750 mirror = QDeclarativeItemPrivate::get(parentItem)->effectiveLayoutMirror;
751 if (mirror ? d->left : d->right)
769 case Qt::Key_Backtab:
778 if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post);
781 void QDeclarative1KeyNavigationAttached::setFocusNavigation(QDeclarativeItem *currentItem, const char *dir)
783 QDeclarativeItem *initialItem = currentItem;
784 bool isNextItem = false;
787 if (currentItem->isVisible() && currentItem->isEnabled()) {
788 currentItem->setFocus(true);
791 qmlAttachedPropertiesObject<QDeclarative1KeyNavigationAttached>(currentItem, false);
793 QDeclarativeItem *tempItem = qvariant_cast<QDeclarativeItem*>(attached->property(dir));
795 currentItem = tempItem;
801 while (currentItem != initialItem && isNextItem);
805 \qmlclass LayoutMirroring QDeclarative1LayoutMirroringAttached
806 \inqmlmodule QtQuick 1
808 \ingroup qml-utility-elements
809 \brief The LayoutMirroring attached property is used to mirror layout behavior.
811 The LayoutMirroring attached property is used to horizontally mirror \l {anchor-layout}{Item anchors},
812 \l{Using QML Positioner and Repeater Items}{positioner} elements (such as \l Row and \l Grid)
813 and views (such as \l GridView and horizontal \l ListView). Mirroring is a visual change: left
814 anchors become right anchors, and positioner elements like \l Grid and \l Row reverse the
815 horizontal layout of child items.
817 Mirroring is enabled for an item by setting the \l enabled property to true. By default, this
818 only affects the item itself; setting the \l childrenInherit property to true propagates the mirroring
819 behavior to all child elements as well. If the \c LayoutMirroring attached property has not been defined
820 for an item, mirroring is not enabled.
822 The following example shows mirroring in action. The \l Row below is specified as being anchored
823 to the left of its parent. However, since mirroring has been enabled, the anchor is horizontally
824 reversed and it is now anchored to the right. Also, since items in a \l Row are positioned
825 from left to right by default, they are now positioned from right to left instead, as demonstrated
826 by the numbering and opacity of the items:
828 \snippet doc/src/snippets/qtquick1/layoutmirroring.qml 0
830 \image layoutmirroring.png
832 Layout mirroring is useful when it is necessary to support both left-to-right and right-to-left
833 layout versions of an application to target different language areas. The \l childrenInherit
834 property allows layout mirroring to be applied without manually setting layout configurations
835 for every item in an application. Keep in mind, however, that mirroring does not affect any
836 positioning that is defined by the \l Item \l {Item::}{x} coordinate value, so even with
837 mirroring enabled, it will often be necessary to apply some layout fixes to support the
838 desired layout direction. Also, it may be necessary to disable the mirroring of individual
839 child items (by setting \l {enabled}{LayoutMirroring.enabled} to false for such items) if
840 mirroring is not the desired behavior, or if the child item already implements mirroring in
843 See \l {QML Right-to-left User Interfaces} for further details on using \c LayoutMirroring and
844 other related features to implement right-to-left support for an application.
848 \qmlproperty bool QtQuick1::LayoutMirroring::enabled
850 This property holds whether the item's layout is mirrored horizontally. Setting this to true
851 horizontally reverses \l {anchor-layout}{anchor} settings such that left anchors become right,
852 and right anchors become left. For \l{Using QML Positioner and Repeater Items}{positioner} elements
853 (such as \l Row and \l Grid) and view elements (such as \l {GridView}{GridView} and \l {ListView}{ListView})
854 this also mirrors the horizontal layout direction of the item.
856 The default value is false.
860 \qmlproperty bool QtQuick1::LayoutMirroring::childrenInherit
862 This property holds whether the \l {enabled}{LayoutMirroring.enabled} value for this item
863 is inherited by its children.
865 The default value is false.
868 QDeclarative1LayoutMirroringAttached::QDeclarative1LayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(0)
870 if (QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(parent)) {
871 itemPrivate = QDeclarativeItemPrivate::get(item);
872 itemPrivate->attachedLayoutDirection = this;
874 qmlInfo(parent) << tr("LayoutDirection attached property only works with Items");
877 QDeclarative1LayoutMirroringAttached * QDeclarative1LayoutMirroringAttached::qmlAttachedProperties(QObject *object)
879 return new QDeclarative1LayoutMirroringAttached(object);
882 bool QDeclarative1LayoutMirroringAttached::enabled() const
884 return itemPrivate ? itemPrivate->effectiveLayoutMirror : false;
887 void QDeclarative1LayoutMirroringAttached::setEnabled(bool enabled)
892 itemPrivate->isMirrorImplicit = false;
893 if (enabled != itemPrivate->effectiveLayoutMirror) {
894 itemPrivate->setLayoutMirror(enabled);
895 if (itemPrivate->inheritMirrorFromItem)
896 itemPrivate->resolveLayoutMirror();
900 void QDeclarative1LayoutMirroringAttached::resetEnabled()
902 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
903 itemPrivate->isMirrorImplicit = true;
904 itemPrivate->resolveLayoutMirror();
908 bool QDeclarative1LayoutMirroringAttached::childrenInherit() const
910 return itemPrivate ? itemPrivate->inheritMirrorFromItem : false;
913 void QDeclarative1LayoutMirroringAttached::setChildrenInherit(bool childrenInherit) {
914 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
915 itemPrivate->inheritMirrorFromItem = childrenInherit;
916 itemPrivate->resolveLayoutMirror();
917 childrenInheritChanged();
921 void QDeclarativeItemPrivate::resolveLayoutMirror()
923 Q_Q(QDeclarativeItem);
924 if (QDeclarativeItem *parentItem = q->parentItem()) {
925 QDeclarativeItemPrivate *parentPrivate = QDeclarativeItemPrivate::get(parentItem);
926 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
928 setImplicitLayoutMirror(isMirrorImplicit ? false : effectiveLayoutMirror, inheritMirrorFromItem);
932 void QDeclarativeItemPrivate::setImplicitLayoutMirror(bool mirror, bool inherit)
934 inherit = inherit || inheritMirrorFromItem;
935 if (!isMirrorImplicit && inheritMirrorFromItem)
936 mirror = effectiveLayoutMirror;
937 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
940 inheritMirrorFromParent = inherit;
941 inheritedLayoutMirror = inheritMirrorFromParent ? mirror : false;
943 if (isMirrorImplicit)
944 setLayoutMirror(inherit ? inheritedLayoutMirror : false);
945 for (int i = 0; i < children.count(); ++i) {
946 if (QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i))) {
947 QDeclarativeItemPrivate *childPrivate = QDeclarativeItemPrivate::get(child);
948 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
953 void QDeclarativeItemPrivate::setLayoutMirror(bool mirror)
955 if (mirror != effectiveLayoutMirror) {
956 effectiveLayoutMirror = mirror;
958 _anchors->d_func()->fillChanged();
959 _anchors->d_func()->centerInChanged();
960 _anchors->d_func()->updateHorizontalAnchors();
961 emit _anchors->mirroredChanged();
964 if (attachedLayoutDirection) {
965 emit attachedLayoutDirection->enabledChanged();
971 \qmlclass Keys QDeclarative1KeysAttached
972 \inqmlmodule QtQuick 1
973 \ingroup qml-basic-interaction-elements
975 \brief The Keys attached property provides key handling to Items.
977 All visual primitives support key handling via the Keys
978 attached property. Keys can be handled via the onPressed
979 and onReleased signal properties.
981 The signal properties have a \l KeyEvent parameter, named
982 \e event which contains details of the event. If a key is
983 handled \e event.accepted should be set to true to prevent the
984 event from propagating up the item hierarchy.
986 \section1 Example Usage
988 The following example shows how the general onPressed handler can
989 be used to test for a certain key; in this case, the left cursor
992 \snippet doc/src/snippets/qtquick1/keys/keys-pressed.qml key item
994 Some keys may alternatively be handled via specific signal properties,
995 for example \e onSelectPressed. These handlers automatically set
996 \e event.accepted to true.
998 \snippet doc/src/snippets/qtquick1/keys/keys-handler.qml key item
1000 See \l{Qt::Key}{Qt.Key} for the list of keyboard codes.
1002 \section1 Key Handling Priorities
1004 The Keys attached property can be configured to handle key events
1005 before or after the item it is attached to. This makes it possible
1006 to intercept events in order to override an item's default behavior,
1007 or act as a fallback for keys not handled by the item.
1009 If \l priority is Keys.BeforeItem (default) the order of key event processing is:
1012 \o Items specified in \c forwardTo
1013 \o specific key handlers, e.g. onReturnPressed
1014 \o onKeyPress, onKeyRelease handlers
1015 \o Item specific key handling, e.g. TextInput key handling
1019 If priority is Keys.AfterItem the order of key event processing is:
1022 \o Item specific key handling, e.g. TextInput key handling
1023 \o Items specified in \c forwardTo
1024 \o specific key handlers, e.g. onReturnPressed
1025 \o onKeyPress, onKeyRelease handlers
1029 If the event is accepted during any of the above steps, key
1032 \sa KeyEvent, {KeyNavigation}{KeyNavigation attached property}
1036 \qmlproperty bool QtQuick1::Keys::enabled
1038 This flags enables key handling if true (default); otherwise
1039 no key handlers will be called.
1043 \qmlproperty enumeration QtQuick1::Keys::priority
1045 This property determines whether the keys are processed before
1046 or after the attached item's own key handling.
1049 \o Keys.BeforeItem (default) - process the key events before normal
1050 item key processing. If the event is accepted it will not
1051 be passed on to the item.
1052 \o Keys.AfterItem - process the key events after normal item key
1053 handling. If the item accepts the key event it will not be
1054 handled by the Keys attached property handler.
1059 \qmlproperty list<Object> QtQuick1::Keys::forwardTo
1061 This property provides a way to forward key presses, key releases, and keyboard input
1062 coming from input methods to other items. This can be useful when you want
1063 one item to handle some keys (e.g. the up and down arrow keys), and another item to
1064 handle other keys (e.g. the left and right arrow keys). Once an item that has been
1065 forwarded keys accepts the event it is no longer forwarded to items later in the
1068 This example forwards key events to two lists:
1079 Keys.forwardTo: [list1, list2]
1086 \qmlsignal QtQuick1::Keys::onPressed(KeyEvent event)
1088 This handler is called when a key has been pressed. The \a event
1089 parameter provides information about the event.
1093 \qmlsignal QtQuick1::Keys::onReleased(KeyEvent event)
1095 This handler is called when a key has been released. The \a event
1096 parameter provides information about the event.
1100 \qmlsignal QtQuick1::Keys::onDigit0Pressed(KeyEvent event)
1102 This handler is called when the digit '0' has been pressed. The \a event
1103 parameter provides information about the event.
1107 \qmlsignal QtQuick1::Keys::onDigit1Pressed(KeyEvent event)
1109 This handler is called when the digit '1' has been pressed. The \a event
1110 parameter provides information about the event.
1114 \qmlsignal QtQuick1::Keys::onDigit2Pressed(KeyEvent event)
1116 This handler is called when the digit '2' has been pressed. The \a event
1117 parameter provides information about the event.
1121 \qmlsignal QtQuick1::Keys::onDigit3Pressed(KeyEvent event)
1123 This handler is called when the digit '3' has been pressed. The \a event
1124 parameter provides information about the event.
1128 \qmlsignal QtQuick1::Keys::onDigit4Pressed(KeyEvent event)
1130 This handler is called when the digit '4' has been pressed. The \a event
1131 parameter provides information about the event.
1135 \qmlsignal QtQuick1::Keys::onDigit5Pressed(KeyEvent event)
1137 This handler is called when the digit '5' has been pressed. The \a event
1138 parameter provides information about the event.
1142 \qmlsignal QtQuick1::Keys::onDigit6Pressed(KeyEvent event)
1144 This handler is called when the digit '6' has been pressed. The \a event
1145 parameter provides information about the event.
1149 \qmlsignal QtQuick1::Keys::onDigit7Pressed(KeyEvent event)
1151 This handler is called when the digit '7' has been pressed. The \a event
1152 parameter provides information about the event.
1156 \qmlsignal QtQuick1::Keys::onDigit8Pressed(KeyEvent event)
1158 This handler is called when the digit '8' has been pressed. The \a event
1159 parameter provides information about the event.
1163 \qmlsignal QtQuick1::Keys::onDigit9Pressed(KeyEvent event)
1165 This handler is called when the digit '9' has been pressed. The \a event
1166 parameter provides information about the event.
1170 \qmlsignal QtQuick1::Keys::onLeftPressed(KeyEvent event)
1172 This handler is called when the Left arrow has been pressed. The \a event
1173 parameter provides information about the event.
1177 \qmlsignal QtQuick1::Keys::onRightPressed(KeyEvent event)
1179 This handler is called when the Right arrow has been pressed. The \a event
1180 parameter provides information about the event.
1184 \qmlsignal QtQuick1::Keys::onUpPressed(KeyEvent event)
1186 This handler is called when the Up arrow has been pressed. The \a event
1187 parameter provides information about the event.
1191 \qmlsignal QtQuick1::Keys::onDownPressed(KeyEvent event)
1193 This handler is called when the Down arrow has been pressed. The \a event
1194 parameter provides information about the event.
1198 \qmlsignal QtQuick1::Keys::onTabPressed(KeyEvent event)
1200 This handler is called when the Tab key has been pressed. The \a event
1201 parameter provides information about the event.
1205 \qmlsignal QtQuick1::Keys::onBacktabPressed(KeyEvent event)
1207 This handler is called when the Shift+Tab key combination (Backtab) has
1208 been pressed. The \a event parameter provides information about the event.
1212 \qmlsignal QtQuick1::Keys::onAsteriskPressed(KeyEvent event)
1214 This handler is called when the Asterisk '*' has been pressed. The \a event
1215 parameter provides information about the event.
1219 \qmlsignal QtQuick1::Keys::onEscapePressed(KeyEvent event)
1221 This handler is called when the Escape key has been pressed. The \a event
1222 parameter provides information about the event.
1226 \qmlsignal QtQuick1::Keys::onReturnPressed(KeyEvent event)
1228 This handler is called when the Return key has been pressed. The \a event
1229 parameter provides information about the event.
1233 \qmlsignal QtQuick1::Keys::onEnterPressed(KeyEvent event)
1235 This handler is called when the Enter key has been pressed. The \a event
1236 parameter provides information about the event.
1240 \qmlsignal QtQuick1::Keys::onDeletePressed(KeyEvent event)
1242 This handler is called when the Delete key has been pressed. The \a event
1243 parameter provides information about the event.
1247 \qmlsignal QtQuick1::Keys::onSpacePressed(KeyEvent event)
1249 This handler is called when the Space key has been pressed. The \a event
1250 parameter provides information about the event.
1254 \qmlsignal QtQuick1::Keys::onBackPressed(KeyEvent event)
1256 This handler is called when the Back key has been pressed. The \a event
1257 parameter provides information about the event.
1261 \qmlsignal QtQuick1::Keys::onCancelPressed(KeyEvent event)
1263 This handler is called when the Cancel key has been pressed. The \a event
1264 parameter provides information about the event.
1268 \qmlsignal QtQuick1::Keys::onSelectPressed(KeyEvent event)
1270 This handler is called when the Select key has been pressed. The \a event
1271 parameter provides information about the event.
1275 \qmlsignal QtQuick1::Keys::onYesPressed(KeyEvent event)
1277 This handler is called when the Yes key has been pressed. The \a event
1278 parameter provides information about the event.
1282 \qmlsignal QtQuick1::Keys::onNoPressed(KeyEvent event)
1284 This handler is called when the No key has been pressed. The \a event
1285 parameter provides information about the event.
1289 \qmlsignal QtQuick1::Keys::onContext1Pressed(KeyEvent event)
1291 This handler is called when the Context1 key has been pressed. The \a event
1292 parameter provides information about the event.
1296 \qmlsignal QtQuick1::Keys::onContext2Pressed(KeyEvent event)
1298 This handler is called when the Context2 key has been pressed. The \a event
1299 parameter provides information about the event.
1303 \qmlsignal QtQuick1::Keys::onContext3Pressed(KeyEvent event)
1305 This handler is called when the Context3 key has been pressed. The \a event
1306 parameter provides information about the event.
1310 \qmlsignal QtQuick1::Keys::onContext4Pressed(KeyEvent event)
1312 This handler is called when the Context4 key has been pressed. The \a event
1313 parameter provides information about the event.
1317 \qmlsignal QtQuick1::Keys::onCallPressed(KeyEvent event)
1319 This handler is called when the Call key has been pressed. The \a event
1320 parameter provides information about the event.
1324 \qmlsignal QtQuick1::Keys::onHangupPressed(KeyEvent event)
1326 This handler is called when the Hangup key has been pressed. The \a event
1327 parameter provides information about the event.
1331 \qmlsignal QtQuick1::Keys::onFlipPressed(KeyEvent event)
1333 This handler is called when the Flip key has been pressed. The \a event
1334 parameter provides information about the event.
1338 \qmlsignal QtQuick1::Keys::onMenuPressed(KeyEvent event)
1340 This handler is called when the Menu key has been pressed. The \a event
1341 parameter provides information about the event.
1345 \qmlsignal QtQuick1::Keys::onVolumeUpPressed(KeyEvent event)
1347 This handler is called when the VolumeUp key has been pressed. The \a event
1348 parameter provides information about the event.
1352 \qmlsignal QtQuick1::Keys::onVolumeDownPressed(KeyEvent event)
1354 This handler is called when the VolumeDown key has been pressed. The \a event
1355 parameter provides information about the event.
1358 const QDeclarative1KeysAttached::SigMap QDeclarative1KeysAttached::sigMap[] = {
1359 { Qt::Key_Left, "leftPressed" },
1360 { Qt::Key_Right, "rightPressed" },
1361 { Qt::Key_Up, "upPressed" },
1362 { Qt::Key_Down, "downPressed" },
1363 { Qt::Key_Tab, "tabPressed" },
1364 { Qt::Key_Backtab, "backtabPressed" },
1365 { Qt::Key_Asterisk, "asteriskPressed" },
1366 { Qt::Key_NumberSign, "numberSignPressed" },
1367 { Qt::Key_Escape, "escapePressed" },
1368 { Qt::Key_Return, "returnPressed" },
1369 { Qt::Key_Enter, "enterPressed" },
1370 { Qt::Key_Delete, "deletePressed" },
1371 { Qt::Key_Space, "spacePressed" },
1372 { Qt::Key_Back, "backPressed" },
1373 { Qt::Key_Cancel, "cancelPressed" },
1374 { Qt::Key_Select, "selectPressed" },
1375 { Qt::Key_Yes, "yesPressed" },
1376 { Qt::Key_No, "noPressed" },
1377 { Qt::Key_Context1, "context1Pressed" },
1378 { Qt::Key_Context2, "context2Pressed" },
1379 { Qt::Key_Context3, "context3Pressed" },
1380 { Qt::Key_Context4, "context4Pressed" },
1381 { Qt::Key_Call, "callPressed" },
1382 { Qt::Key_Hangup, "hangupPressed" },
1383 { Qt::Key_Flip, "flipPressed" },
1384 { Qt::Key_Menu, "menuPressed" },
1385 { Qt::Key_VolumeUp, "volumeUpPressed" },
1386 { Qt::Key_VolumeDown, "volumeDownPressed" },
1390 bool QDeclarative1KeysAttachedPrivate::isConnected(const char *signalName)
1392 return isSignalConnected(signalIndex(signalName));
1395 QDeclarative1KeysAttached::QDeclarative1KeysAttached(QObject *parent)
1396 : QObject(*(new QDeclarative1KeysAttachedPrivate), parent),
1397 QDeclarativeItemKeyFilter(qobject_cast<QDeclarativeItem*>(parent))
1399 Q_D(QDeclarative1KeysAttached);
1400 m_processPost = false;
1401 d->item = qobject_cast<QDeclarativeItem*>(parent);
1404 QDeclarative1KeysAttached::~QDeclarative1KeysAttached()
1408 QDeclarative1KeysAttached::Priority QDeclarative1KeysAttached::priority() const
1410 return m_processPost ? AfterItem : BeforeItem;
1413 void QDeclarative1KeysAttached::setPriority(Priority order)
1415 bool processPost = order == AfterItem;
1416 if (processPost != m_processPost) {
1417 m_processPost = processPost;
1418 emit priorityChanged();
1422 void QDeclarative1KeysAttached::componentComplete()
1424 Q_D(QDeclarative1KeysAttached);
1426 for (int ii = 0; ii < d->targets.count(); ++ii) {
1427 QGraphicsItem *targetItem = d->finalFocusProxy(d->targets.at(ii));
1428 if (targetItem && (targetItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
1429 d->item->setFlag(QGraphicsItem::ItemAcceptsInputMethod);
1436 void QDeclarative1KeysAttached::keyPressed(QKeyEvent *event, bool post)
1438 Q_D(QDeclarative1KeysAttached);
1439 if (post != m_processPost || !d->enabled || d->inPress) {
1441 QDeclarativeItemKeyFilter::keyPressed(event, post);
1445 // first process forwards
1446 if (d->item && d->item->scene()) {
1448 for (int ii = 0; ii < d->targets.count(); ++ii) {
1449 QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1450 if (i && i->isVisible()) {
1451 d->item->scene()->sendEvent(i, event);
1452 if (event->isAccepted()) {
1461 QDeclarative1KeyEvent ke(*event);
1462 QByteArray keySignal = keyToSignal(event->key());
1463 if (!keySignal.isEmpty()) {
1464 keySignal += "(QDeclarative1KeyEvent*)";
1465 if (d->isConnected(keySignal)) {
1466 // If we specifically handle a key then default to accepted
1467 ke.setAccepted(true);
1468 int idx = QDeclarative1KeysAttached::staticMetaObject.indexOfSignal(keySignal);
1469 metaObject()->method(idx).invoke(this, Qt::DirectConnection, Q_ARG(QDeclarative1KeyEvent*, &ke));
1472 if (!ke.isAccepted())
1474 event->setAccepted(ke.isAccepted());
1476 if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyPressed(event, post);
1479 void QDeclarative1KeysAttached::keyReleased(QKeyEvent *event, bool post)
1481 Q_D(QDeclarative1KeysAttached);
1482 if (post != m_processPost || !d->enabled || d->inRelease) {
1484 QDeclarativeItemKeyFilter::keyReleased(event, post);
1488 if (d->item && d->item->scene()) {
1489 d->inRelease = true;
1490 for (int ii = 0; ii < d->targets.count(); ++ii) {
1491 QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1492 if (i && i->isVisible()) {
1493 d->item->scene()->sendEvent(i, event);
1494 if (event->isAccepted()) {
1495 d->inRelease = false;
1500 d->inRelease = false;
1503 QDeclarative1KeyEvent ke(*event);
1505 event->setAccepted(ke.isAccepted());
1507 if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post);
1510 void QDeclarative1KeysAttached::inputMethodEvent(QInputMethodEvent *event, bool post)
1512 Q_D(QDeclarative1KeysAttached);
1513 if (post == m_processPost && d->item && !d->inIM && d->item->scene()) {
1515 for (int ii = 0; ii < d->targets.count(); ++ii) {
1516 QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1517 if (i && i->isVisible() && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
1518 d->item->scene()->sendEvent(i, event);
1519 if (event->isAccepted()) {
1528 if (!event->isAccepted()) QDeclarativeItemKeyFilter::inputMethodEvent(event, post);
1531 class QDeclarativeItemAccessor : public QGraphicsItem
1534 QVariant doInputMethodQuery(Qt::InputMethodQuery query) const {
1535 return QGraphicsItem::inputMethodQuery(query);
1539 QVariant QDeclarative1KeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const
1541 Q_D(const QDeclarative1KeysAttached);
1543 for (int ii = 0; ii < d->targets.count(); ++ii) {
1544 QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
1545 if (i && i->isVisible() && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check?
1546 QVariant v = static_cast<QDeclarativeItemAccessor *>(i)->doInputMethodQuery(query);
1547 if (v.userType() == QVariant::RectF)
1548 v = d->item->mapRectFromItem(i, v.toRectF()); //### cost?
1553 return QDeclarativeItemKeyFilter::inputMethodQuery(query);
1556 QDeclarative1KeysAttached *QDeclarative1KeysAttached::qmlAttachedProperties(QObject *obj)
1558 return new QDeclarative1KeysAttached(obj);
1562 \class QDeclarativeItem
1564 \brief The QDeclarativeItem class provides the most basic of all visual items in QML.
1566 All visual items in Qt Declarative inherit from QDeclarativeItem. Although QDeclarativeItem
1567 has no visual appearance, it defines all the properties that are
1568 common across visual items - such as the x and y position, the
1569 width and height, \l {anchor-layout}{anchoring} and key handling.
1571 You can subclass QDeclarativeItem to provide your own custom visual item that inherits
1572 these features. Note that, because it does not draw anything, QDeclarativeItem sets the
1573 QGraphicsItem::ItemHasNoContents flag. If you subclass QDeclarativeItem to create a visual
1574 item, you will need to unset this flag.
1579 \qmlclass Item QDeclarativeItem
1580 \inqmlmodule QtQuick 1
1581 \ingroup qml-basic-visual-elements
1583 \brief The Item is the most basic of all visual items in QML.
1585 All visual items in Qt Declarative inherit from Item. Although Item
1586 has no visual appearance, it defines all the properties that are
1587 common across visual items - such as the x and y position, the
1588 width and height, \l {anchor-layout}{anchoring} and key handling.
1590 Item is also useful for grouping items together.
1607 fillMode: Image.Tile
1614 \section1 Key Handling
1616 Key handling is available to all Item-based visual elements via the \l {Keys}{Keys}
1617 attached property. The \e Keys attached property provides basic handlers such
1618 as \l {Keys::onPressed}{onPressed} and \l {Keys::onReleased}{onReleased},
1619 as well as handlers for specific keys, such as
1620 \l {Keys::onCancelPressed}{onCancelPressed}. The example below
1621 assigns \l {qmlfocus}{focus} to the item and handles
1622 the Left key via the general \e onPressed handler and the Select key via the
1623 onSelectPressed handler:
1629 if (event.key == Qt.Key_Left) {
1630 console.log("move left");
1631 event.accepted = true;
1634 Keys.onSelectPressed: console.log("Selected");
1638 See the \l {Keys}{Keys} attached property for detailed documentation.
1640 \section1 Layout Mirroring
1642 Item layouts can be mirrored using the \l {LayoutMirroring}{LayoutMirroring} attached property.
1647 \fn void QDeclarativeItem::childrenRectChanged(const QRectF &)
1652 \fn void QDeclarativeItem::baselineOffsetChanged(qreal)
1657 \fn void QDeclarativeItem::stateChanged(const QString &state)
1662 \fn void QDeclarativeItem::parentChanged(QDeclarativeItem *)
1667 \fn void QDeclarativeItem::smoothChanged(bool)
1672 \fn void QDeclarativeItem::clipChanged(bool)
1676 /*! \fn void QDeclarativeItem::transformOriginChanged(TransformOrigin)
1681 \fn void QDeclarativeItem::focusChanged(bool)
1686 \fn void QDeclarativeItem::activeFocusChanged(bool)
1692 struct RegisterAnchorLineAtStartup {
1693 RegisterAnchorLineAtStartup() {
1694 qRegisterMetaType<QDeclarative1AnchorLine>("QDeclarative1AnchorLine");
1697 static RegisterAnchorLineAtStartup registerAnchorLineAtStartup;
1702 \fn QDeclarativeItem::QDeclarativeItem(QDeclarativeItem *parent)
1704 Constructs a QDeclarativeItem with the given \a parent.
1706 QDeclarativeItem::QDeclarativeItem(QDeclarativeItem* parent)
1707 : QGraphicsObject(*(new QDeclarativeItemPrivate), parent, 0)
1709 Q_D(QDeclarativeItem);
1715 QDeclarativeItem::QDeclarativeItem(QDeclarativeItemPrivate &dd, QDeclarativeItem *parent)
1716 : QGraphicsObject(dd, parent, 0)
1718 Q_D(QDeclarativeItem);
1723 Destroys the QDeclarativeItem.
1725 QDeclarativeItem::~QDeclarativeItem()
1727 Q_D(QDeclarativeItem);
1728 for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
1729 QDeclarative1AnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
1731 anchor->clearItem(this);
1733 if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) {
1734 for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
1735 QDeclarative1AnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
1736 if (anchor && anchor->item && anchor->item->parentItem() != this) //child will be deleted anyway
1737 anchor->updateOnComplete();
1740 for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
1741 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
1742 if (change.types & QDeclarativeItemPrivate::Destroyed)
1743 change.listener->itemDestroyed(this);
1745 d->changeListeners.clear();
1746 delete d->_anchorLines; d->_anchorLines = 0;
1747 delete d->_anchors; d->_anchors = 0;
1748 delete d->_stateGroup; d->_stateGroup = 0;
1749 delete d->_contents; d->_contents = 0;
1753 \qmlproperty enumeration QtQuick1::Item::transformOrigin
1754 This property holds the origin point around which scale and rotation transform.
1756 Nine transform origins are available, as shown in the image below.
1758 \image declarative-transformorigin.png
1760 This example rotates an image around its bottom-right corner.
1763 source: "myimage.png"
1764 transformOrigin: Item.BottomRight
1769 The default transform origin is \c Item.Center.
1771 To set an arbitrary transform origin point use the \l Scale or \l Rotation
1776 \qmlproperty Item QtQuick1::Item::parent
1777 This property holds the parent of the item.
1781 \property QDeclarativeItem::parent
1782 This property holds the parent of the item.
1784 void QDeclarativeItem::setParentItem(QDeclarativeItem *parent)
1786 Q_D(QDeclarativeItem);
1787 QGraphicsObject::setParentItem(parent);
1788 if (d->isAccessible && parentItem()) {
1789 parentItem()->d_func()->setAccessibleFlagAndListener();
1794 Returns the QDeclarativeItem parent of this item.
1796 QDeclarativeItem *QDeclarativeItem::parentItem() const
1798 return qobject_cast<QDeclarativeItem *>(QGraphicsObject::parentItem());
1802 \qmlproperty real QtQuick1::Item::childrenRect.x
1803 \qmlproperty real QtQuick1::Item::childrenRect.y
1804 \qmlproperty real QtQuick1::Item::childrenRect.width
1805 \qmlproperty real QtQuick1::Item::childrenRect.height
1807 The childrenRect properties allow an item access to the geometry of its
1808 children. This property is useful if you have an item that needs to be
1809 sized to fit its children.
1814 \qmlproperty list<Item> QtQuick1::Item::children
1815 \qmlproperty list<Object> QtQuick1::Item::resources
1817 The children property contains the list of visual children of this item.
1818 The resources property contains non-visual resources that you want to
1821 Generally you can rely on Item's default property to handle all this for
1822 you, but it can come in handy in some cases.
1841 Returns true if construction of the QML component is complete; otherwise
1844 It is often desirable to delay some processing until the component is
1847 \sa componentComplete()
1849 bool QDeclarativeItem::isComponentComplete() const
1851 Q_D(const QDeclarativeItem);
1852 return d->componentComplete;
1855 void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
1860 QDeclarativeItem *that = static_cast<QDeclarativeItem *>(prop->object);
1862 // This test is measurably (albeit only slightly) faster than qobject_cast<>()
1863 const QMetaObject *mo = o->metaObject();
1864 while (mo && mo != &QGraphicsObject::staticMetaObject) mo = mo->d.superdata;
1867 QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(o);
1868 QDeclarativeItemPrivate *contentItemPrivate = static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(graphicsObject));
1869 if (contentItemPrivate->componentComplete) {
1870 graphicsObject->setParentItem(that);
1872 contentItemPrivate->setParentItemHelper(that, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
1879 static inline int children_count_helper(QDeclarativeListProperty<QObject> *prop)
1881 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object));
1882 return d->children.count();
1885 static inline QObject *children_at_helper(QDeclarativeListProperty<QObject> *prop, int index)
1887 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object));
1888 if (index >= 0 && index < d->children.count())
1889 return d->children.at(index)->toGraphicsObject();
1894 static inline void children_clear_helper(QDeclarativeListProperty<QObject> *prop)
1896 QDeclarativeItemPrivate *d = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(prop->object)));
1897 int childCount = d->children.count();
1898 if (d->componentComplete) {
1899 for (int index = 0 ;index < childCount; index++)
1900 d->children.at(0)->setParentItem(0);
1902 for (int index = 0 ;index < childCount; index++)
1903 QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
1907 int QDeclarativeItemPrivate::data_count(QDeclarativeListProperty<QObject> *prop)
1909 return resources_count(prop) + children_count_helper(prop);
1912 QObject *QDeclarativeItemPrivate::data_at(QDeclarativeListProperty<QObject> *prop, int i)
1914 int resourcesCount = resources_count(prop);
1915 if (i < resourcesCount)
1916 return resources_at(prop, i);
1917 const int j = i - resourcesCount;
1918 if (j < children_count_helper(prop))
1919 return children_at_helper(prop, j);
1923 void QDeclarativeItemPrivate::data_clear(QDeclarativeListProperty<QObject> *prop)
1925 resources_clear(prop);
1926 children_clear_helper(prop);
1929 QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
1931 const QObjectList children = prop->object->children();
1932 if (index < children.count())
1933 return children.at(index);
1938 void QDeclarativeItemPrivate::resources_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
1940 o->setParent(prop->object);
1943 int QDeclarativeItemPrivate::resources_count(QDeclarativeListProperty<QObject> *prop)
1945 return prop->object->children().count();
1948 void QDeclarativeItemPrivate::resources_clear(QDeclarativeListProperty<QObject> *prop)
1950 const QObjectList children = prop->object->children();
1951 for (int index = 0; index < children.count(); index++)
1952 children.at(index)->setParent(0);
1955 int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform> *list)
1957 QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
1959 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
1960 return d->transformData ? d->transformData->graphicsTransforms.size() : 0;
1966 void QDeclarativeItemPrivate::transform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *item)
1968 QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
1969 if (object && item) // QGraphicsItem applies the list in the wrong order, so we prepend.
1970 QGraphicsItemPrivate::get(object)->prependGraphicsTransform(item);
1973 QGraphicsTransform *QDeclarativeItemPrivate::transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int idx)
1975 QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
1977 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
1978 if (!d->transformData)
1980 return d->transformData->graphicsTransforms.at(idx);
1986 void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphicsTransform> *list)
1988 QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
1990 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object);
1991 if (!d->transformData)
1993 object->setTransformations(QList<QGraphicsTransform *>());
1998 \qmlproperty list<Object> QtQuick1::Item::data
2001 The data property allows you to freely mix visual children and resources
2002 in an item. If you assign a visual item to the data list it becomes
2003 a child and if you assign any other object type, it is added as a resource.
2027 data is a behind-the-scenes property: you should never need to explicitly
2031 QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::data()
2033 return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::data_append,
2034 QDeclarativeItemPrivate::data_count,
2035 QDeclarativeItemPrivate::data_at,
2036 QDeclarativeItemPrivate::data_clear
2041 \property QDeclarativeItem::childrenRect
2042 \brief The geometry of an item's children.
2044 This property holds the (collective) position and size of the item's children.
2046 QRectF QDeclarativeItem::childrenRect()
2048 Q_D(QDeclarativeItem);
2049 if (!d->_contents) {
2050 d->_contents = new QDeclarative1Contents(this);
2051 if (d->componentComplete)
2052 d->_contents->complete();
2054 return d->_contents->rectF();
2057 bool QDeclarativeItem::clip() const
2059 return flags() & ItemClipsChildrenToShape;
2062 void QDeclarativeItem::setClip(bool c)
2066 setFlag(ItemClipsChildrenToShape, c);
2067 emit clipChanged(c);
2071 \qmlproperty real QtQuick1::Item::x
2072 \qmlproperty real QtQuick1::Item::y
2073 \qmlproperty real QtQuick1::Item::width
2074 \qmlproperty real QtQuick1::Item::height
2076 Defines the item's position and size relative to its parent.
2079 Item { x: 100; y: 100; width: 100; height: 100 }
2084 \qmlproperty real QtQuick1::Item::z
2086 Sets the stacking order of sibling items. By default the stacking order is 0.
2088 Items with a higher stacking value are drawn on top of siblings with a
2089 lower stacking order. Items with the same stacking value are drawn
2090 bottom up in the order they appear. Items with a negative stacking
2091 value are drawn under their parent's content.
2093 The following example shows the various effects of stacking order.
2097 \o \image declarative-item_stacking1.png
2098 \o Same \c z - later children above earlier children:
2103 width: 100; height: 100
2107 x: 50; y: 50; width: 100; height: 100
2112 \o \image declarative-item_stacking2.png
2113 \o Higher \c z on top:
2119 width: 100; height: 100
2123 x: 50; y: 50; width: 100; height: 100
2128 \o \image declarative-item_stacking3.png
2129 \o Same \c z - children above parents:
2134 width: 100; height: 100
2137 x: 50; y: 50; width: 100; height: 100
2143 \o \image declarative-item_stacking4.png
2144 \o Lower \c z below:
2149 width: 100; height: 100
2153 x: 50; y: 50; width: 100; height: 100
2162 \qmlproperty bool QtQuick1::Item::visible
2164 This property holds whether the item is visible. By default this is true.
2166 Setting this property directly affects the \c visible value of child
2167 items. When set to \c false, the \c visible values of all child items also
2168 become \c false. When set to \c true, the \c visible values of child items
2169 are returned to \c true, unless they have explicitly been set to \c false.
2171 (Because of this flow-on behavior, using the \c visible property may not
2172 have the intended effect if a property binding should only respond to
2173 explicit property changes. In such cases it may be better to use the
2174 \l opacity property instead.)
2176 Setting this property to \c false automatically causes \l focus to be set
2177 to \c false, and this item will longer receive mouse and keyboard events.
2178 (In contrast, setting the \l opacity to 0 does not affect the \l focus
2179 property and the receiving of key events.)
2181 \note This property's value is only affected by changes to this property or
2182 the parent's \c visible property. It does not change, for example, if this
2183 item moves off-screen, or if the \l opacity changes to 0.
2188 This function is called to handle this item's changes in
2189 geometry from \a oldGeometry to \a newGeometry. If the two
2190 geometries are the same, it doesn't do anything.
2192 void QDeclarativeItem::geometryChanged(const QRectF &newGeometry,
2193 const QRectF &oldGeometry)
2195 Q_D(QDeclarativeItem);
2198 d->_anchors->d_func()->updateMe();
2200 if (transformOrigin() != QDeclarativeItem::TopLeft
2201 && (newGeometry.width() != oldGeometry.width() || newGeometry.height() != oldGeometry.height())) {
2202 if (d->transformData) {
2203 QPointF origin = d->computeTransformOrigin();
2204 if (transformOriginPoint() != origin)
2205 setTransformOriginPoint(origin);
2207 d->transformOriginDirty = true;
2211 for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
2212 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
2213 if (change.types & QDeclarativeItemPrivate::Geometry)
2214 change.listener->itemGeometryChanged(this, newGeometry, oldGeometry);
2217 if (newGeometry.width() != oldGeometry.width())
2218 emit widthChanged();
2219 if (newGeometry.height() != oldGeometry.height())
2220 emit heightChanged();
2223 void QDeclarativeItemPrivate::removeItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types)
2225 ChangeListener change(listener, types);
2226 changeListeners.removeOne(change);
2230 void QDeclarativeItem::keyPressEvent(QKeyEvent *event)
2232 Q_D(QDeclarativeItem);
2233 keyPressPreHandler(event);
2234 if (event->isAccepted())
2237 d->keyHandler->keyPressed(event, true);
2243 void QDeclarativeItem::keyReleaseEvent(QKeyEvent *event)
2245 Q_D(QDeclarativeItem);
2246 keyReleasePreHandler(event);
2247 if (event->isAccepted())
2250 d->keyHandler->keyReleased(event, true);
2256 void QDeclarativeItem::inputMethodEvent(QInputMethodEvent *event)
2258 Q_D(QDeclarativeItem);
2259 inputMethodPreHandler(event);
2260 if (event->isAccepted())
2263 d->keyHandler->inputMethodEvent(event, true);
2269 QVariant QDeclarativeItem::inputMethodQuery(Qt::InputMethodQuery query) const
2271 Q_D(const QDeclarativeItem);
2274 v = d->keyHandler->inputMethodQuery(query);
2277 v = QGraphicsObject::inputMethodQuery(query);
2285 void QDeclarativeItem::keyPressPreHandler(QKeyEvent *event)
2287 Q_D(QDeclarativeItem);
2288 if (d->keyHandler && !d->doneEventPreHandler)
2289 d->keyHandler->keyPressed(event, false);
2292 d->doneEventPreHandler = true;
2298 void QDeclarativeItem::keyReleasePreHandler(QKeyEvent *event)
2300 Q_D(QDeclarativeItem);
2301 if (d->keyHandler && !d->doneEventPreHandler)
2302 d->keyHandler->keyReleased(event, false);
2305 d->doneEventPreHandler = true;
2311 void QDeclarativeItem::inputMethodPreHandler(QInputMethodEvent *event)
2313 Q_D(QDeclarativeItem);
2314 if (d->keyHandler && !d->doneEventPreHandler)
2315 d->keyHandler->inputMethodEvent(event, false);
2318 d->doneEventPreHandler = true;
2324 QDeclarative1AnchorLine QDeclarativeItemPrivate::left() const
2326 return anchorLines()->left;
2332 QDeclarative1AnchorLine QDeclarativeItemPrivate::right() const
2334 return anchorLines()->right;
2340 QDeclarative1AnchorLine QDeclarativeItemPrivate::horizontalCenter() const
2342 return anchorLines()->hCenter;
2348 QDeclarative1AnchorLine QDeclarativeItemPrivate::top() const
2350 return anchorLines()->top;
2356 QDeclarative1AnchorLine QDeclarativeItemPrivate::bottom() const
2358 return anchorLines()->bottom;
2364 QDeclarative1AnchorLine QDeclarativeItemPrivate::verticalCenter() const
2366 return anchorLines()->vCenter;
2373 QDeclarative1AnchorLine QDeclarativeItemPrivate::baseline() const
2375 return anchorLines()->baseline;
2379 \qmlproperty AnchorLine QtQuick1::Item::anchors.top
2380 \qmlproperty AnchorLine QtQuick1::Item::anchors.bottom
2381 \qmlproperty AnchorLine QtQuick1::Item::anchors.left
2382 \qmlproperty AnchorLine QtQuick1::Item::anchors.right
2383 \qmlproperty AnchorLine QtQuick1::Item::anchors.horizontalCenter
2384 \qmlproperty AnchorLine QtQuick1::Item::anchors.verticalCenter
2385 \qmlproperty AnchorLine QtQuick1::Item::anchors.baseline
2387 \qmlproperty Item QtQuick1::Item::anchors.fill
2388 \qmlproperty Item QtQuick1::Item::anchors.centerIn
2390 \qmlproperty real QtQuick1::Item::anchors.margins
2391 \qmlproperty real QtQuick1::Item::anchors.topMargin
2392 \qmlproperty real QtQuick1::Item::anchors.bottomMargin
2393 \qmlproperty real QtQuick1::Item::anchors.leftMargin
2394 \qmlproperty real QtQuick1::Item::anchors.rightMargin
2395 \qmlproperty real QtQuick1::Item::anchors.horizontalCenterOffset
2396 \qmlproperty real QtQuick1::Item::anchors.verticalCenterOffset
2397 \qmlproperty real QtQuick1::Item::anchors.baselineOffset
2399 \qmlproperty bool QtQuick1::Item::anchors.mirrored
2401 Anchors provide a way to position an item by specifying its
2402 relationship with other items.
2404 Margins apply to top, bottom, left, right, and fill anchors.
2405 The \c anchors.margins property can be used to set all of the various margins at once, to the same value.
2406 Note that margins are anchor-specific and are not applied if an item does not
2409 Offsets apply for horizontal center, vertical center, and baseline anchors.
2413 \o \image declarative-anchors_example.png
2414 \o Text anchored to Image, horizontally centered and vertically below, with a margin.
2423 anchors.horizontalCenter: pic.horizontalCenter
2424 anchors.top: pic.bottom
2425 anchors.topMargin: 5
2431 \o \image declarative-anchors_example2.png
2433 Left of Text anchored to right of Image, with a margin. The y
2434 property of both defaults to 0.
2444 anchors.left: pic.right
2445 anchors.leftMargin: 5
2452 \c anchors.fill provides a convenient way for one item to have the
2453 same geometry as another item, and is equivalent to connecting all
2454 four directional anchors.
2456 To clear an anchor value, set it to \c undefined.
2458 \c anchors.mirrored returns true it the layout has been \l {LayoutMirroring}{mirrored}.
2460 \note You can only anchor an item to siblings or a parent.
2462 For more information see \l {anchor-layout}{Anchor Layouts}.
2466 \property QDeclarativeItem::baselineOffset
2467 \brief The position of the item's baseline in local coordinates.
2469 The baseline of a \l Text item is the imaginary line on which the text
2470 sits. Controls containing text usually set their baseline to the
2471 baseline of their text.
2473 For non-text items, a default baseline offset of 0 is used.
2475 qreal QDeclarativeItem::baselineOffset() const
2477 Q_D(const QDeclarativeItem);
2478 if (!d->baselineOffset.isValid()) {
2481 return d->baselineOffset;
2484 void QDeclarativeItem::setBaselineOffset(qreal offset)
2486 Q_D(QDeclarativeItem);
2487 if (offset == d->baselineOffset)
2490 d->baselineOffset = offset;
2492 for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
2493 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
2494 if (change.types & QDeclarativeItemPrivate::Geometry) {
2495 QDeclarative1AnchorsPrivate *anchor = change.listener->anchorPrivate();
2497 anchor->updateVerticalAnchors();
2500 emit baselineOffsetChanged(offset);
2504 \qmlproperty real QtQuick1::Item::rotation
2505 This property holds the rotation of the item in degrees clockwise.
2507 This specifies how many degrees to rotate the item around its transformOrigin.
2508 The default rotation is 0 degrees (i.e. not rotated at all).
2512 \o \image declarative-rotation.png
2517 width: 100; height: 100
2520 x: 25; y: 25; width: 50; height: 50
2527 \sa transform, Rotation
2531 \qmlproperty real QtQuick1::Item::scale
2532 This property holds the scale of the item.
2534 A scale of less than 1 means the item will be displayed smaller than
2535 normal, and a scale of greater than 1 means the item will be
2536 displayed larger than normal. A negative scale means the item will
2539 By default, items are displayed at a scale of 1 (i.e. at their
2542 Scaling is from the item's transformOrigin.
2546 \o \image declarative-scale.png
2551 width: 100; height: 100
2554 width: 25; height: 25
2558 x: 25; y: 25; width: 50; height: 50
2565 \sa transform, Scale
2569 \qmlproperty real QtQuick1::Item::opacity
2571 This property holds the opacity of the item. Opacity is specified as a
2572 number between 0 (fully transparent) and 1 (fully opaque). The default is 1.
2574 When this property is set, the specified opacity is also applied
2575 individually to child items. In almost all cases this is what you want,
2576 but in some cases it may produce undesired results. For example in the
2577 second set of rectangles below, the red rectangle has specified an opacity
2578 of 0.5, which affects the opacity of its blue child rectangle even though
2579 the child has not specified an opacity.
2583 \o \image declarative-item_opacity1.png
2589 width: 100; height: 100
2592 x: 50; y: 50; width: 100; height: 100
2598 \o \image declarative-item_opacity2.png
2605 width: 100; height: 100
2608 x: 50; y: 50; width: 100; height: 100
2615 If an item's opacity is set to 0, the item will no longer receive mouse
2616 events, but will continue to receive key events and will retain the keyboard
2617 \l focus if it has been set. (In contrast, setting the \l visible property
2618 to \c false stops both mouse and keyboard events, and also removes focus
2623 Returns a value indicating whether mouse input should
2624 remain with this item exclusively.
2626 \sa setKeepMouseGrab()
2628 bool QDeclarativeItem::keepMouseGrab() const
2630 Q_D(const QDeclarativeItem);
2631 return d->keepMouse;
2635 The flag indicating whether the mouse should remain
2636 with this item is set to \a keep.
2638 This is useful for items that wish to grab and keep mouse
2639 interaction following a predefined gesture. For example,
2640 an item that is interested in horizontal mouse movement
2641 may set keepMouseGrab to true once a threshold has been
2642 exceeded. Once keepMouseGrab has been set to true, filtering
2643 items will not react to mouse events.
2645 If the item does not indicate that it wishes to retain mouse grab,
2646 a filtering item may steal the grab. For example, Flickable may attempt
2647 to steal a mouse grab if it detects that the user has begun to
2652 void QDeclarativeItem::setKeepMouseGrab(bool keep)
2654 Q_D(QDeclarativeItem);
2655 d->keepMouse = keep;
2659 \qmlmethod object QtQuick1::Item::mapFromItem(Item item, real x, real y)
2661 Maps the point (\a x, \a y), which is in \a item's coordinate system, to
2662 this item's coordinate system, and returns an object with \c x and \c y
2663 properties matching the mapped cooordinate.
2665 If \a item is a \c null value, this maps the point from the coordinate
2666 system of the root QML view.
2668 void QDeclarativeItem::mapFromItem(QDeclarativeV8Function *args) const
2670 if (args->Length() != 0) {
2671 v8::Local<v8::Value> item = (*args)[0];
2672 QV8Engine *engine = args->engine();
2674 QDeclarativeItem *itemObj = 0;
2675 if (!item->IsNull())
2676 itemObj = qobject_cast<QDeclarativeItem*>(engine->toQObject(item));
2678 if (!itemObj && !item->IsNull()) {
2679 qmlInfo(this) << "mapFromItem() given argument \"" << engine->toString(item->ToString())
2680 << "\" which is neither null nor an Item";
2684 v8::Local<v8::Object> rv = v8::Object::New();
2685 args->returnValue(rv);
2687 qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
2688 qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
2690 QPointF p = QGraphicsItem::mapFromItem(itemObj, x, y);
2692 rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
2693 rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
2698 \qmlmethod object QtQuick1::Item::mapToItem(Item item, real x, real y)
2700 Maps the point (\a x, \a y), which is in this item's coordinate system, to
2701 \a item's coordinate system, and returns an object with \c x and \c y
2702 properties matching the mapped cooordinate.
2704 If \a item is a \c null value, this maps \a x and \a y to the coordinate
2705 system of the root QML view.
2707 void QDeclarativeItem::mapToItem(QDeclarativeV8Function *args) const
2709 if (args->Length() != 0) {
2710 v8::Local<v8::Value> item = (*args)[0];
2711 QV8Engine *engine = args->engine();
2713 QDeclarativeItem *itemObj = 0;
2714 if (!item->IsNull())
2715 itemObj = qobject_cast<QDeclarativeItem*>(engine->toQObject(item));
2717 if (!itemObj && !item->IsNull()) {
2718 qmlInfo(this) << "mapToItem() given argument \"" << engine->toString(item->ToString())
2719 << "\" which is neither null nor an Item";
2723 v8::Local<v8::Object> rv = v8::Object::New();
2724 args->returnValue(rv);
2726 qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0;
2727 qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0;
2729 QPointF p = QGraphicsItem::mapToItem(itemObj, x, y);
2731 rv->Set(v8::String::New("x"), v8::Number::New(p.x()));
2732 rv->Set(v8::String::New("y"), v8::Number::New(p.y()));
2737 \qmlmethod QtQuick1::Item::forceActiveFocus()
2739 Forces active focus on the item.
2741 This method sets focus on the item and makes sure that all the focus scopes
2742 higher in the object hierarchy are also given the focus.
2746 Forces active focus on the item.
2748 This method sets focus on the item and makes sure that all the focus scopes
2749 higher in the object hierarchy are also given the focus.
2751 void QDeclarativeItem::forceActiveFocus()
2754 QGraphicsItem *parent = parentItem();
2756 if (parent->flags() & QGraphicsItem::ItemIsFocusScope)
2757 parent->setFocus(Qt::OtherFocusReason);
2758 parent = parent->parentItem();
2764 \qmlmethod QtQuick1::Item::childAt(real x, real y)
2766 Returns the visible child item at point (\a x, \a y), which is in this
2767 item's coordinate system, or \c null if there is no such item.
2771 Returns the visible child item at point (\a x, \a y), which is in this
2772 item's coordinate system, or 0 if there is no such item.
2774 QDeclarativeItem *QDeclarativeItem::childAt(qreal x, qreal y) const
2776 const QList<QGraphicsItem *> children = childItems();
2777 for (int i = children.count()-1; i >= 0; --i) {
2778 if (QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i))) {
2779 if (child->isVisible() && child->x() <= x
2780 && child->x() + child->width() >= x
2782 && child->y() + child->height() >= y)
2789 void QDeclarativeItemPrivate::focusChanged(bool flag)
2791 Q_Q(QDeclarativeItem);
2792 if (!(flags & QGraphicsItem::ItemIsFocusScope) && parent)
2793 emit q->activeFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange()
2794 emit q->focusChanged(flag);
2797 QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::resources()
2799 return QDeclarativeListProperty<QObject>(q_func(), 0, QDeclarativeItemPrivate::resources_append,
2800 QDeclarativeItemPrivate::resources_count,
2801 QDeclarativeItemPrivate::resources_at,
2802 QDeclarativeItemPrivate::resources_clear
2807 \qmlproperty list<State> QtQuick1::Item::states
2808 This property holds a list of states defined by the item.
2824 \sa {qmlstate}{States}
2827 QDeclarativeListProperty<QDeclarative1State> QDeclarativeItemPrivate::states()
2829 return _states()->statesProperty();
2833 \qmlproperty list<Transition> QtQuick1::Item::transitions
2834 This property holds a list of transitions defined by the item.
2850 \sa {QML Animation and Transitions}{Transitions}
2854 QDeclarativeListProperty<QDeclarative1Transition> QDeclarativeItemPrivate::transitions()
2856 return _states()->transitionsProperty();
2860 \qmlproperty list<Filter> QtQuick1::Item::filter
2861 This property holds a list of graphical filters to be applied to the item.
2863 \l {Filter}{Filters} include things like \l {Blur}{blurring}
2864 the item, or giving it a \l Reflection. Some
2865 filters may not be available on all canvases; if a filter is not
2866 available on a certain canvas, it will simply not be applied for
2867 that canvas (but the QML will still be considered valid).
2885 \qmlproperty bool QtQuick1::Item::clip
2886 This property holds whether clipping is enabled. The default clip value is \c false.
2888 If clipping is enabled, an item will clip its own painting, as well
2889 as the painting of its children, to its bounding rectangle.
2891 Non-rectangular clipping regions are not supported for performance reasons.
2895 \property QDeclarativeItem::clip
2896 This property holds whether clipping is enabled. The default clip value is \c false.
2898 If clipping is enabled, an item will clip its own painting, as well
2899 as the painting of its children, to its bounding rectangle. If you set
2900 clipping during an item's paint operation, remember to re-set it to
2901 prevent clipping the rest of your scene.
2903 Non-rectangular clipping regions are not supported for performance reasons.
2907 \qmlproperty string QtQuick1::Item::state
2909 This property holds the name of the current state of the item.
2911 This property is often used in scripts to change between states. For
2916 if (button.state == 'On')
2917 button.state = 'Off';
2919 button.state = 'On';
2923 If the item is in its base state (i.e. no explicit state has been
2924 set), \c state will be a blank string. Likewise, you can return an
2925 item to its base state by setting its current state to \c ''.
2927 \sa {qmlstates}{States}
2930 QString QDeclarativeItemPrivate::state() const
2935 return _stateGroup->state();
2938 void QDeclarativeItemPrivate::setState(const QString &state)
2940 _states()->setState(state);
2944 \qmlproperty list<Transform> QtQuick1::Item::transform
2945 This property holds the list of transformations to apply.
2947 For more information see \l Transform.
2951 QDeclarativeListProperty<QGraphicsTransform> QDeclarativeItem::transform()
2953 return QDeclarativeListProperty<QGraphicsTransform>(this, 0, QDeclarativeItemPrivate::transform_append,
2954 QDeclarativeItemPrivate::transform_count,
2955 QDeclarativeItemPrivate::transform_at,
2956 QDeclarativeItemPrivate::transform_clear);
2962 classBegin() is called when the item is constructed, but its
2963 properties have not yet been set.
2965 \sa componentComplete(), isComponentComplete()
2967 void QDeclarativeItem::classBegin()
2969 Q_D(QDeclarativeItem);
2970 d->componentComplete = false;
2972 d->_stateGroup->classBegin();
2974 d->_anchors->classBegin();
2980 componentComplete() is called when all items in the component
2981 have been constructed. It is often desirable to delay some
2982 processing until the component is complete an all bindings in the
2983 component have been resolved.
2985 void QDeclarativeItem::componentComplete()
2987 Q_D(QDeclarativeItem);
2988 d->componentComplete = true;
2990 d->_stateGroup->componentComplete();
2992 d->_anchors->componentComplete();
2993 d->_anchors->d_func()->updateOnComplete();
2996 d->keyHandler->componentComplete();
2998 d->_contents->complete();
3001 QDeclarative1StateGroup *QDeclarativeItemPrivate::_states()
3003 Q_Q(QDeclarativeItem);
3005 _stateGroup = new QDeclarative1StateGroup;
3006 if (!componentComplete)
3007 _stateGroup->classBegin();
3008 QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)),
3009 q, SIGNAL(stateChanged(QString)));
3015 QDeclarativeItemPrivate::AnchorLines::AnchorLines(QGraphicsObject *q)
3018 left.anchorLine = QDeclarative1AnchorLine::Left;
3020 right.anchorLine = QDeclarative1AnchorLine::Right;
3022 hCenter.anchorLine = QDeclarative1AnchorLine::HCenter;
3024 top.anchorLine = QDeclarative1AnchorLine::Top;
3026 bottom.anchorLine = QDeclarative1AnchorLine::Bottom;
3028 vCenter.anchorLine = QDeclarative1AnchorLine::VCenter;
3030 baseline.anchorLine = QDeclarative1AnchorLine::Baseline;
3033 void QDeclarativeItemPrivate::setAccessibleFlagAndListener()
3035 Q_Q(QDeclarativeItem);
3036 QDeclarativeItem *item = q;
3038 if (item->d_func()->isAccessible)
3039 break; // already set - grandparents should have the flag set as well.
3041 // if (qmlEngine(item) != 0) {
3042 // item->d_func()->addItemChangeListener(QDeclarativeEnginePrivate::getAccessibilityUpdateManager(qmlEngine(item)),
3043 // QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Visibility |
3044 // QDeclarativeItemPrivate::Opacity | QDeclarativeItemPrivate::Destroyed);
3047 item->d_func()->isAccessible = true;
3048 item = item->parentItem();
3052 QPointF QDeclarativeItemPrivate::computeTransformOrigin() const
3054 Q_Q(const QDeclarativeItem);
3056 QRectF br = q->boundingRect();
3060 case QDeclarativeItem::TopLeft:
3061 return QPointF(0, 0);
3062 case QDeclarativeItem::Top:
3063 return QPointF(br.width() / 2., 0);
3064 case QDeclarativeItem::TopRight:
3065 return QPointF(br.width(), 0);
3066 case QDeclarativeItem::Left:
3067 return QPointF(0, br.height() / 2.);
3068 case QDeclarativeItem::Center:
3069 return QPointF(br.width() / 2., br.height() / 2.);
3070 case QDeclarativeItem::Right:
3071 return QPointF(br.width(), br.height() / 2.);
3072 case QDeclarativeItem::BottomLeft:
3073 return QPointF(0, br.height());
3074 case QDeclarativeItem::Bottom:
3075 return QPointF(br.width() / 2., br.height());
3076 case QDeclarativeItem::BottomRight:
3077 return QPointF(br.width(), br.height());
3082 bool QDeclarativeItem::sceneEvent(QEvent *event)
3084 Q_D(QDeclarativeItem);
3085 if (event->type() == QEvent::KeyPress) {
3086 QKeyEvent *k = static_cast<QKeyEvent *>(event);
3087 if ((k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) &&
3088 !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
3089 keyPressEvent(static_cast<QKeyEvent *>(event));
3090 if (!event->isAccepted())
3091 return QGraphicsItem::sceneEvent(event);
3095 return QGraphicsItem::sceneEvent(event);
3098 bool rv = QGraphicsItem::sceneEvent(event);
3100 if (event->type() == QEvent::FocusIn ||
3101 event->type() == QEvent::FocusOut) {
3102 d->focusChanged(hasActiveFocus());
3111 Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is \e not called
3112 during initial widget polishing. Items wishing to optimize start-up construction
3113 should instead consider using componentComplete().
3115 QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
3116 const QVariant &value)
3118 Q_D(QDeclarativeItem);
3120 case ItemParentHasChanged:
3121 d->resolveLayoutMirror();
3122 emit parentChanged(parentItem());
3124 case ItemVisibleHasChanged: {
3125 for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
3126 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
3127 if (change.types & QDeclarativeItemPrivate::Visibility) {
3128 change.listener->itemVisibilityChanged(this);
3133 case ItemOpacityHasChanged: {
3134 for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
3135 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
3136 if (change.types & QDeclarativeItemPrivate::Opacity) {
3137 change.listener->itemOpacityChanged(this);
3142 case ItemChildAddedChange:
3143 if (d->_contents && d->componentComplete)
3144 d->_contents->childAdded(qobject_cast<QDeclarativeItem*>(
3145 value.value<QGraphicsItem*>()));
3147 case ItemChildRemovedChange:
3148 if (d->_contents && d->componentComplete)
3149 d->_contents->childRemoved(qobject_cast<QDeclarativeItem*>(
3150 value.value<QGraphicsItem*>()));
3156 return QGraphicsItem::itemChange(change, value);
3160 QRectF QDeclarativeItem::boundingRect() const
3162 Q_D(const QDeclarativeItem);
3163 return QRectF(0, 0, d->mWidth, d->mHeight);
3167 \enum QDeclarativeItem::TransformOrigin
3169 Controls the point about which simple transforms like scale apply.
3171 \value TopLeft The top-left corner of the item.
3172 \value Top The center point of the top of the item.
3173 \value TopRight The top-right corner of the item.
3174 \value Left The left most point of the vertical middle.
3175 \value Center The center of the item.
3176 \value Right The right most point of the vertical middle.
3177 \value BottomLeft The bottom-left corner of the item.
3178 \value Bottom The center point of the bottom of the item.
3179 \value BottomRight The bottom-right corner of the item.
3183 Returns the current transform origin.
3185 QDeclarativeItem::TransformOrigin QDeclarativeItem::transformOrigin() const
3187 Q_D(const QDeclarativeItem);
3192 Set the transform \a origin.
3194 void QDeclarativeItem::setTransformOrigin(TransformOrigin origin)
3196 Q_D(QDeclarativeItem);
3197 if (origin != d->origin) {
3199 if (d->transformData)
3200 QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin());
3202 d->transformOriginDirty = true;
3203 emit transformOriginChanged(d->origin);
3207 void QDeclarativeItemPrivate::transformChanged()
3209 Q_Q(QDeclarativeItem);
3210 if (transformOriginDirty) {
3211 q->QGraphicsItem::setTransformOriginPoint(computeTransformOrigin());
3212 transformOriginDirty = false;
3217 \property QDeclarativeItem::smooth
3218 \brief whether the item is smoothly transformed.
3220 This property is provided purely for the purpose of optimization. Turning
3221 smooth transforms off is faster, but looks worse; turning smooth
3222 transformations on is slower, but looks better.
3224 By default smooth transformations are off.
3228 Returns true if the item should be drawn with antialiasing and
3229 smooth pixmap filtering, false otherwise.
3231 The default is false.
3235 bool QDeclarativeItem::smooth() const
3237 Q_D(const QDeclarativeItem);
3242 Sets whether the item should be drawn with antialiasing and
3243 smooth pixmap filtering to \a smooth.
3247 void QDeclarativeItem::setSmooth(bool smooth)
3249 Q_D(QDeclarativeItem);
3250 if (d->smooth == smooth)
3253 emit smoothChanged(smooth);
3258 \property QDeclarativeItem::anchors
3263 \property QDeclarativeItem::left
3268 \property QDeclarativeItem::right
3273 \property QDeclarativeItem::horizontalCenter
3278 \property QDeclarativeItem::top
3283 \property QDeclarativeItem::bottom
3288 \property QDeclarativeItem::verticalCenter
3293 \property QDeclarativeItem::focus
3298 \property QDeclarativeItem::transform
3303 \property QDeclarativeItem::transformOrigin
3308 \property QDeclarativeItem::activeFocus
3313 \property QDeclarativeItem::baseline
3318 \property QDeclarativeItem::data
3323 \property QDeclarativeItem::resources
3328 \property QDeclarativeItem::state
3333 \property QDeclarativeItem::states
3338 \property QDeclarativeItem::transformOriginPoint
3343 \property QDeclarativeItem::transitions
3349 Return the width of the item
3351 qreal QDeclarativeItem::width() const
3353 Q_D(const QDeclarativeItem);
3359 Set the width of the item
3361 void QDeclarativeItem::setWidth(qreal w)
3363 Q_D(QDeclarativeItem);
3369 Reset the width of the item
3371 void QDeclarativeItem::resetWidth()
3373 Q_D(QDeclarativeItem);
3379 Return the width of the item
3381 qreal QDeclarativeItemPrivate::width() const
3389 void QDeclarativeItemPrivate::setWidth(qreal w)
3391 Q_Q(QDeclarativeItem);
3399 qreal oldWidth = mWidth;
3401 q->prepareGeometryChange();
3404 q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
3405 QRectF(q->x(), q->y(), oldWidth, height()));
3411 void QDeclarativeItemPrivate::resetWidth()
3413 Q_Q(QDeclarativeItem);
3415 q->setImplicitWidth(q->implicitWidth());
3418 void QDeclarativeItemPrivate::implicitWidthChanged()
3420 Q_Q(QDeclarativeItem);
3421 emit q->implicitWidthChanged();
3424 qreal QDeclarativeItemPrivate::implicitWidth() const
3426 return mImplicitWidth;
3430 Returns the width of the item that is implied by other properties that determine the content.
3432 qreal QDeclarativeItem::implicitWidth() const
3434 Q_D(const QDeclarativeItem);
3435 return d->implicitWidth();
3439 Sets the implied width of the item to \a w.
3440 This is the width implied by other properties that determine the content.
3442 void QDeclarativeItem::setImplicitWidth(qreal w)
3444 Q_D(QDeclarativeItem);
3445 bool changed = w != d->mImplicitWidth;
3446 d->mImplicitWidth = w;
3447 if (d->mWidth == w || widthValid()) {
3449 d->implicitWidthChanged();
3453 qreal oldWidth = d->mWidth;
3455 prepareGeometryChange();
3458 geometryChanged(QRectF(x(), y(), width(), height()),
3459 QRectF(x(), y(), oldWidth, height()));
3462 d->implicitWidthChanged();
3466 Returns whether the width property has been set explicitly.
3468 bool QDeclarativeItem::widthValid() const
3470 Q_D(const QDeclarativeItem);
3471 return d->widthValid;
3476 Return the height of the item
3478 qreal QDeclarativeItem::height() const
3480 Q_D(const QDeclarativeItem);
3486 Set the height of the item
3488 void QDeclarativeItem::setHeight(qreal h)
3490 Q_D(QDeclarativeItem);
3496 Reset the height of the item
3498 void QDeclarativeItem::resetHeight()
3500 Q_D(QDeclarativeItem);
3507 qreal QDeclarativeItemPrivate::height() const
3515 void QDeclarativeItemPrivate::setHeight(qreal h)
3517 Q_Q(QDeclarativeItem);
3525 qreal oldHeight = mHeight;
3527 q->prepareGeometryChange();
3530 q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
3531 QRectF(q->x(), q->y(), width(), oldHeight));
3537 void QDeclarativeItemPrivate::resetHeight()
3539 Q_Q(QDeclarativeItem);
3540 heightValid = false;
3541 q->setImplicitHeight(q->implicitHeight());
3544 void QDeclarativeItemPrivate::implicitHeightChanged()
3546 Q_Q(QDeclarativeItem);
3547 emit q->implicitHeightChanged();
3550 qreal QDeclarativeItemPrivate::implicitHeight() const
3552 return mImplicitHeight;
3556 Returns the height of the item that is implied by other properties that determine the content.
3558 qreal QDeclarativeItem::implicitHeight() const
3560 Q_D(const QDeclarativeItem);
3561 return d->implicitHeight();
3565 \qmlproperty real QtQuick1::Item::implicitWidth
3566 \qmlproperty real QtQuick1::Item::implicitHeight
3569 Defines the natural width or height of the Item if no \l width or \l height is specified.
3571 The default implicit size for most items is 0x0, however some elements have an inherent
3572 implicit size which cannot be overridden, e.g. Image, Text.
3574 Setting the implicit size is useful for defining components that have a preferred size
3575 based on their content, for example:
3582 property alias icon: image.source
3583 property alias label: text.text
3584 implicitWidth: text.implicitWidth + image.implicitWidth
3585 implicitHeight: Math.max(text.implicitHeight, image.implicitHeight)
3590 anchors.left: image.right; anchors.right: parent.right
3591 anchors.verticalCenter: parent.verticalCenter
3596 \bold Note: using implicitWidth of Text or TextEdit and setting the width explicitly
3597 incurs a performance penalty as the text must be laid out twice.
3602 Sets the implied height of the item to \a h.
3603 This is the height implied by other properties that determine the content.
3605 void QDeclarativeItem::setImplicitHeight(qreal h)
3607 Q_D(QDeclarativeItem);
3608 bool changed = h != d->mImplicitHeight;
3609 d->mImplicitHeight = h;
3610 if (d->mHeight == h || heightValid()) {
3612 d->implicitHeightChanged();
3616 qreal oldHeight = d->mHeight;
3618 prepareGeometryChange();
3621 geometryChanged(QRectF(x(), y(), width(), height()),
3622 QRectF(x(), y(), width(), oldHeight));
3625 d->implicitHeightChanged();
3629 Returns whether the height property has been set explicitly.
3631 bool QDeclarativeItem::heightValid() const
3633 Q_D(const QDeclarativeItem);
3634 return d->heightValid;
3638 void QDeclarativeItem::setSize(const QSizeF &size)
3640 Q_D(QDeclarativeItem);
3641 d->heightValid = true;
3642 d->widthValid = true;
3644 if (d->height() == size.height() && d->width() == size.width())
3647 qreal oldHeight = d->height();
3648 qreal oldWidth = d->width();
3650 prepareGeometryChange();
3651 d->setHeight(size.height());
3652 d->setWidth(size.width());
3654 geometryChanged(QRectF(x(), y(), width(), height()),
3655 QRectF(x(), y(), oldWidth, oldHeight));
3659 \qmlproperty bool QtQuick1::Item::activeFocus
3661 This property indicates whether the item has active focus.
3663 An item with active focus will receive keyboard input,
3664 or is a FocusScope ancestor of the item that will receive keyboard input.
3666 Usually, activeFocus is gained by setting focus on an item and its enclosing
3667 FocusScopes. In the following example \c input will have activeFocus.
3680 \sa focus, {qmlfocus}{Keyboard Focus}
3684 bool QDeclarativeItem::hasActiveFocus() const
3686 Q_D(const QDeclarativeItem);
3687 return (focusItem() && focusItem()->isVisible()) && (focusItem() == this ||
3688 (d->flags & QGraphicsItem::ItemIsFocusScope && focusItem() != 0));
3692 \qmlproperty bool QtQuick1::Item::focus
3693 This property indicates whether the item has focus within the enclosing focus scope. If true, this item
3694 will gain active focus when the enclosing focus scope gains active focus.
3695 In the following example, \c input will be given active focus when \c scope gains active focus.
3708 For the purposes of this property, the scene as a whole is assumed to act like a focus scope.
3709 On a practical level, that means the following QML will give active focus to \c input on startup.
3720 \sa activeFocus, {qmlfocus}{Keyboard Focus}
3724 bool QDeclarativeItem::hasFocus() const
3726 Q_D(const QDeclarativeItem);
3727 QGraphicsItem *p = d->parent;
3729 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
3730 return p->focusScopeItem() == this;
3732 p = p->parentItem();
3735 return hasActiveFocus();
3739 void QDeclarativeItem::setFocus(bool focus)
3742 QGraphicsItem::setFocus(Qt::OtherFocusReason);
3744 QGraphicsItem::clearFocus();
3750 void QDeclarativeItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
3757 bool QDeclarativeItem::event(QEvent *ev)
3759 Q_D(QDeclarativeItem);
3760 switch (ev->type()) {
3761 case QEvent::KeyPress:
3762 case QEvent::KeyRelease:
3763 case QEvent::InputMethod:
3764 d->doneEventPreHandler = false;
3770 return QGraphicsObject::event(ev);
3773 #ifndef QT_NO_DEBUG_STREAM
3774 QDebug operator<<(QDebug debug, QDeclarativeItem *item)
3777 debug << "QDeclarativeItem(0)";
3781 debug << item->metaObject()->className() << "(this =" << ((void*)item)
3782 << ", parent =" << ((void*)item->parentItem())
3783 << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height()))
3784 << ", z =" << item->zValue() << ')';
3789 qint64 QDeclarativeItemPrivate::consistentTime = -1;
3790 void QDeclarativeItemPrivate::setConsistentTime(qint64 t)
3795 class QElapsedTimerConsistentTimeHack_1
3799 t1 = QDeclarativeItemPrivate::consistentTime;
3803 return QDeclarativeItemPrivate::consistentTime - t1;
3806 qint64 val = QDeclarativeItemPrivate::consistentTime - t1;
3807 t1 = QDeclarativeItemPrivate::consistentTime;
3817 void QDeclarativeItemPrivate::start(QElapsedTimer &t)
3819 if (QDeclarativeItemPrivate::consistentTime == -1)
3822 ((QElapsedTimerConsistentTimeHack_1*)&t)->start();
3825 qint64 QDeclarativeItemPrivate::elapsed(QElapsedTimer &t)
3827 if (QDeclarativeItemPrivate::consistentTime == -1)
3830 return ((QElapsedTimerConsistentTimeHack_1*)&t)->elapsed();
3833 qint64 QDeclarativeItemPrivate::restart(QElapsedTimer &t)
3835 if (QDeclarativeItemPrivate::consistentTime == -1)
3838 return ((QElapsedTimerConsistentTimeHack_1*)&t)->restart();
3843 #include <moc_qdeclarativeitem.cpp>