61 #include <QtCore/qnumeric.h> |
61 #include <QtCore/qnumeric.h> |
62 #include <QtScript/qscriptengine.h> |
62 #include <QtScript/qscriptengine.h> |
63 #include <QtGui/qgraphicstransform.h> |
63 #include <QtGui/qgraphicstransform.h> |
64 #include <qlistmodelinterface_p.h> |
64 #include <qlistmodelinterface_p.h> |
65 |
65 |
|
66 #include <float.h> |
|
67 |
66 QT_BEGIN_NAMESPACE |
68 QT_BEGIN_NAMESPACE |
67 |
|
68 #ifndef FLT_MAX |
|
69 #define FLT_MAX 1E+37 |
|
70 #endif |
|
71 |
69 |
72 /*! |
70 /*! |
73 \qmlclass Transform QGraphicsTransform |
71 \qmlclass Transform QGraphicsTransform |
74 \since 4.7 |
72 \since 4.7 |
75 \brief The Transform elements provide a way of building advanced transformations on Items. |
73 \brief The Transform elements provide a way of building advanced transformations on Items. |
84 \endlist |
82 \endlist |
85 |
83 |
86 The Transform elements let you create and control advanced transformations that can be configured |
84 The Transform elements let you create and control advanced transformations that can be configured |
87 independently using specialized properties. |
85 independently using specialized properties. |
88 |
86 |
89 You can assign any number of Transform elements to an Item. Each Transform is applied in order, |
87 You can assign any number of Transform elements to an \l Item. Each Transform is applied in order, |
90 one at a time, to the Item it's assigned to. |
88 one at a time. |
91 */ |
89 */ |
92 |
90 |
93 /*! |
91 /*! |
94 \qmlclass Translate QGraphicsTranslate |
92 \qmlclass Translate QDeclarativeTranslate |
95 \since 4.7 |
93 \since 4.7 |
96 \brief The Translate object provides a way to move an Item without changing its x or y properties. |
94 \brief The Translate object provides a way to move an Item without changing its x or y properties. |
97 |
95 |
98 The Translate object provides independent control over position in addition to the Item's x and y properties. |
96 The Translate object provides independent control over position in addition to the Item's x and y properties. |
99 |
97 |
100 The following example moves the Y axis of the Rectangles while still allowing the Row element |
98 The following example moves the Y axis of the \l Rectangle elements while still allowing the \l Row element |
101 to lay the items out as if they had not been transformed: |
99 to lay the items out as if they had not been transformed: |
102 \qml |
100 \qml |
|
101 import Qt 4.7 |
|
102 |
103 Row { |
103 Row { |
104 Rectangle { |
104 Rectangle { |
105 width: 100; height: 100 |
105 width: 100; height: 100 |
106 color: "blue" |
106 color: "blue" |
107 transform: Translate { y: 20 } |
107 transform: Translate { y: 20 } |
128 */ |
130 */ |
129 |
131 |
130 /*! |
132 /*! |
131 \qmlclass Scale QGraphicsScale |
133 \qmlclass Scale QGraphicsScale |
132 \since 4.7 |
134 \since 4.7 |
133 \brief The Scale object provides a way to scale an Item. |
135 \brief The Scale element provides a way to scale an Item. |
134 |
136 |
135 The Scale object gives more control over scaling than using Item's scale property. Specifically, |
137 The Scale element gives more control over scaling than using \l Item's \l{Item::scale}{scale} property. Specifically, |
136 it allows a different scale for the x and y axes, and allows the scale to be relative to an |
138 it allows a different scale for the x and y axes, and allows the scale to be relative to an |
137 arbitrary point. |
139 arbitrary point. |
138 |
140 |
139 The following example scales the X axis of the Rectangle, relative to its interior point 25, 25: |
141 The following example scales the X axis of the Rectangle, relative to its interior point 25, 25: |
140 \qml |
142 \qml |
169 /*! |
173 /*! |
170 \qmlclass Rotation QGraphicsRotation |
174 \qmlclass Rotation QGraphicsRotation |
171 \since 4.7 |
175 \since 4.7 |
172 \brief The Rotation object provides a way to rotate an Item. |
176 \brief The Rotation object provides a way to rotate an Item. |
173 |
177 |
174 The Rotation object gives more control over rotation than using Item's rotation property. |
178 The Rotation object gives more control over rotation than using \l Item's \l{Item::rotation}{rotation} property. |
175 Specifically, it allows (z axis) rotation to be relative to an arbitrary point. |
179 Specifically, it allows (z axis) rotation to be relative to an arbitrary point. |
176 |
180 |
177 The following example rotates a Rectangle around its interior point 25, 25: |
181 The following example rotates a Rectangle around its interior point 25, 25: |
178 \qml |
182 \qml |
179 Rectangle { |
183 Rectangle { |
188 |
192 |
189 The following example shows various 3D-like rotations applied to an \l Image. |
193 The following example shows various 3D-like rotations applied to an \l Image. |
190 \snippet doc/src/snippets/declarative/rotation.qml 0 |
194 \snippet doc/src/snippets/declarative/rotation.qml 0 |
191 |
195 |
192 \image axisrotation.png |
196 \image axisrotation.png |
|
197 |
|
198 \sa {declarative/ui-components/dialcontrol}{Dial Control example}, {declarative/toys/clocks}{Clocks example} |
193 */ |
199 */ |
194 |
200 |
195 /*! |
201 /*! |
196 \qmlproperty real Rotation::origin.x |
202 \qmlproperty real Rotation::origin.x |
197 \qmlproperty real Rotation::origin.y |
203 \qmlproperty real Rotation::origin.y |
223 \internal |
229 \internal |
224 \class QDeclarativeContents |
230 \class QDeclarativeContents |
225 \brief The QDeclarativeContents class gives access to the height and width of an item's contents. |
231 \brief The QDeclarativeContents class gives access to the height and width of an item's contents. |
226 |
232 |
227 */ |
233 */ |
228 |
234 QDeclarativeContents::QDeclarativeContents(QDeclarativeItem *item) : m_item(item), m_x(0), m_y(0), m_width(0), m_height(0) |
229 QDeclarativeContents::QDeclarativeContents() : m_x(0), m_y(0), m_width(0), m_height(0) |
235 { |
230 { |
236 //### optimize |
|
237 connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); |
231 } |
238 } |
232 |
239 |
233 QDeclarativeContents::~QDeclarativeContents() |
240 QDeclarativeContents::~QDeclarativeContents() |
234 { |
241 { |
235 QList<QGraphicsItem *> children = m_item->childItems(); |
242 QList<QGraphicsItem *> children = m_item->childItems(); |
320 |
327 |
321 if (m_width != oldwidth || m_x != oldx) |
328 if (m_width != oldwidth || m_x != oldx) |
322 emit rectChanged(rectF()); |
329 emit rectChanged(rectF()); |
323 } |
330 } |
324 |
331 |
325 void QDeclarativeContents::setItem(QDeclarativeItem *item) |
332 void QDeclarativeContents::complete() |
326 { |
333 { |
327 m_item = item; |
|
328 //### optimize |
|
329 connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); |
|
330 |
|
331 QList<QGraphicsItem *> children = m_item->childItems(); |
334 QList<QGraphicsItem *> children = m_item->childItems(); |
332 for (int i = 0; i < children.count(); ++i) { |
335 for (int i = 0; i < children.count(); ++i) { |
333 QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i)); |
336 QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i)); |
334 if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? |
337 if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? |
335 continue; |
338 continue; |
336 QDeclarativeItemPrivate::get(child)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); |
339 QDeclarativeItemPrivate::get(child)->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); |
337 //###what about changes to visibility? |
340 //###what about changes to visibility? |
338 } |
341 } |
339 |
342 |
340 //### defer until componentComplete |
343 calcGeometry(); |
341 calcHeight(); |
|
342 calcWidth(); |
|
343 } |
344 } |
344 |
345 |
345 void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry) |
346 void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry) |
346 { |
347 { |
347 if (newGeometry.width() != oldGeometry.width()) |
348 Q_UNUSED(changed) |
348 calcWidth(changed); |
349 //### we can only pass changed if the left edge has moved left, or the right edge has moved right |
349 if (newGeometry.height() != oldGeometry.height()) |
350 if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x()) |
350 calcHeight(changed); |
351 calcWidth(/*changed*/); |
|
352 if (newGeometry.height() != oldGeometry.height() || newGeometry.y() != oldGeometry.y()) |
|
353 calcHeight(/*changed*/); |
351 } |
354 } |
352 |
355 |
353 void QDeclarativeContents::itemDestroyed(QDeclarativeItem *item) |
356 void QDeclarativeContents::itemDestroyed(QDeclarativeItem *item) |
354 { |
357 { |
355 if (item) |
358 if (item) |
356 QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); |
359 QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); |
357 calcWidth(); |
360 calcGeometry(); |
358 calcHeight(); |
|
359 } |
361 } |
360 |
362 |
361 void QDeclarativeContents::childRemoved(QDeclarativeItem *item) |
363 void QDeclarativeContents::childRemoved(QDeclarativeItem *item) |
362 { |
364 { |
363 if (item) |
365 if (item) |
364 QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); |
366 QDeclarativeItemPrivate::get(item)->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry | QDeclarativeItemPrivate::Destroyed); |
365 calcWidth(); |
367 calcGeometry(); |
366 calcHeight(); |
|
367 } |
368 } |
368 |
369 |
369 void QDeclarativeContents::childAdded(QDeclarativeItem *item) |
370 void QDeclarativeContents::childAdded(QDeclarativeItem *item) |
370 { |
371 { |
371 if (item) |
372 if (item) |
415 if (m_next) m_next->componentComplete(); |
416 if (m_next) m_next->componentComplete(); |
416 } |
417 } |
417 |
418 |
418 |
419 |
419 /*! |
420 /*! |
420 \qmlclass KeyNavigation |
421 \qmlclass KeyNavigation QDeclarativeKeyNavigationAttached |
421 \since 4.7 |
422 \since 4.7 |
422 \brief The KeyNavigation attached property supports key navigation by arrow keys. |
423 \brief The KeyNavigation attached property supports key navigation by arrow keys. |
423 |
424 |
424 It is common in key-based UIs to use arrow keys to navigate |
425 It is common in key-based UIs to use arrow keys to navigate |
425 between focussed items. The KeyNavigation property provides a |
426 between focussed items. The KeyNavigation property provides a |
709 |
710 |
710 if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post); |
711 if (!event->isAccepted()) QDeclarativeItemKeyFilter::keyReleased(event, post); |
711 } |
712 } |
712 |
713 |
713 /*! |
714 /*! |
714 \qmlclass Keys |
715 \qmlclass Keys QDeclarativeKeysAttached |
715 \since 4.7 |
716 \since 4.7 |
716 \brief The Keys attached property provides key handling to Items. |
717 \brief The Keys attached property provides key handling to Items. |
717 |
718 |
718 All visual primitives support key handling via the \e Keys |
719 All visual primitives support key handling via the \e Keys |
719 attached property. Keys can be handled via the \e onPressed |
720 attached property. Keys can be handled via the \e onPressed |
720 and \e onReleased signal properties. |
721 and \e onReleased signal properties. |
721 |
722 |
722 The signal properties have a \l KeyEvent parameter, named |
723 The signal properties have a \l KeyEvent parameter, named |
723 \e event which contains details of the event. If a key is |
724 \e event which contains details of the event. If a key is |
724 handled \e event.accepted should be set to true to prevent the |
725 handled \e event.accepted should be set to true to prevent the |
725 event from propagating up the item heirarchy. |
726 event from propagating up the item hierarchy. |
726 |
727 |
727 \code |
728 \code |
728 Item { |
729 Item { |
729 focus: true |
730 focus: true |
730 Keys.onPressed: { |
731 Keys.onPressed: { |
1596 |
1580 |
1597 /*! |
1581 /*! |
1598 Returns true if construction of the QML component is complete; otherwise |
1582 Returns true if construction of the QML component is complete; otherwise |
1599 returns false. |
1583 returns false. |
1600 |
1584 |
1601 It is often desireable to delay some processing until the component is |
1585 It is often desirable to delay some processing until the component is |
1602 completed. |
1586 completed. |
1603 |
1587 |
1604 \sa componentComplete() |
1588 \sa componentComplete() |
1605 */ |
1589 */ |
1606 bool QDeclarativeItem::isComponentComplete() const |
1590 bool QDeclarativeItem::isComponentComplete() const |
1607 { |
1591 { |
1608 Q_D(const QDeclarativeItem); |
1592 Q_D(const QDeclarativeItem); |
1609 return d->_componentComplete; |
1593 return d->componentComplete; |
1610 } |
1594 } |
1611 |
1595 |
1612 void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o) |
1596 void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o) |
1613 { |
1597 { |
1614 if (!o) |
1598 if (!o) |
1744 */ |
1728 */ |
1745 QRectF QDeclarativeItem::childrenRect() |
1729 QRectF QDeclarativeItem::childrenRect() |
1746 { |
1730 { |
1747 Q_D(QDeclarativeItem); |
1731 Q_D(QDeclarativeItem); |
1748 if (!d->_contents) { |
1732 if (!d->_contents) { |
1749 d->_contents = new QDeclarativeContents; |
1733 d->_contents = new QDeclarativeContents(this); |
1750 d->_contents->setItem(this); |
1734 if (d->componentComplete) |
|
1735 d->_contents->complete(); |
1751 } |
1736 } |
1752 return d->_contents->rectF(); |
1737 return d->_contents->rectF(); |
1753 } |
1738 } |
1754 |
1739 |
1755 bool QDeclarativeItem::clip() const |
1740 bool QDeclarativeItem::clip() const |
1964 v = QGraphicsObject::inputMethodQuery(query); |
1949 v = QGraphicsObject::inputMethodQuery(query); |
1965 |
1950 |
1966 return v; |
1951 return v; |
1967 } |
1952 } |
1968 |
1953 |
|
1954 /*! |
|
1955 \internal |
|
1956 */ |
1969 void QDeclarativeItem::keyPressPreHandler(QKeyEvent *event) |
1957 void QDeclarativeItem::keyPressPreHandler(QKeyEvent *event) |
1970 { |
1958 { |
1971 Q_D(QDeclarativeItem); |
1959 Q_D(QDeclarativeItem); |
1972 if (d->keyHandler && !d->doneEventPreHandler) |
1960 if (d->keyHandler && !d->doneEventPreHandler) |
1973 d->keyHandler->keyPressed(event, false); |
1961 d->keyHandler->keyPressed(event, false); |
1974 else |
1962 else |
1975 event->ignore(); |
1963 event->ignore(); |
1976 d->doneEventPreHandler = true; |
1964 d->doneEventPreHandler = true; |
1977 } |
1965 } |
1978 |
1966 |
|
1967 /*! |
|
1968 \internal |
|
1969 */ |
1979 void QDeclarativeItem::keyReleasePreHandler(QKeyEvent *event) |
1970 void QDeclarativeItem::keyReleasePreHandler(QKeyEvent *event) |
1980 { |
1971 { |
1981 Q_D(QDeclarativeItem); |
1972 Q_D(QDeclarativeItem); |
1982 if (d->keyHandler && !d->doneEventPreHandler) |
1973 if (d->keyHandler && !d->doneEventPreHandler) |
1983 d->keyHandler->keyReleased(event, false); |
1974 d->keyHandler->keyReleased(event, false); |
1984 else |
1975 else |
1985 event->ignore(); |
1976 event->ignore(); |
1986 d->doneEventPreHandler = true; |
1977 d->doneEventPreHandler = true; |
1987 } |
1978 } |
1988 |
1979 |
|
1980 /*! |
|
1981 \internal |
|
1982 */ |
1989 void QDeclarativeItem::inputMethodPreHandler(QInputMethodEvent *event) |
1983 void QDeclarativeItem::inputMethodPreHandler(QInputMethodEvent *event) |
1990 { |
1984 { |
1991 Q_D(QDeclarativeItem); |
1985 Q_D(QDeclarativeItem); |
1992 if (d->keyHandler && !d->doneEventPreHandler) |
1986 if (d->keyHandler && !d->doneEventPreHandler) |
1993 d->keyHandler->inputMethodEvent(event, false); |
1987 d->keyHandler->inputMethodEvent(event, false); |
1994 else |
1988 else |
1995 event->ignore(); |
1989 event->ignore(); |
1996 d->doneEventPreHandler = true; |
1990 d->doneEventPreHandler = true; |
1997 } |
1991 } |
1998 |
1992 |
1999 |
|
2000 /*! |
1993 /*! |
2001 \internal |
1994 \internal |
2002 */ |
1995 */ |
2003 QDeclarativeAnchorLine QDeclarativeItemPrivate::left() const |
1996 QDeclarativeAnchorLine QDeclarativeItemPrivate::left() const |
2004 { |
1997 { |
2051 */ |
2044 */ |
2052 QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const |
2045 QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const |
2053 { |
2046 { |
2054 return anchorLines()->baseline; |
2047 return anchorLines()->baseline; |
2055 } |
2048 } |
2056 |
|
2057 /*! |
|
2058 \qmlproperty AnchorLine Item::top |
|
2059 \qmlproperty AnchorLine Item::bottom |
|
2060 \qmlproperty AnchorLine Item::left |
|
2061 \qmlproperty AnchorLine Item::right |
|
2062 \qmlproperty AnchorLine Item::horizontalCenter |
|
2063 \qmlproperty AnchorLine Item::verticalCenter |
|
2064 \qmlproperty AnchorLine Item::baseline |
|
2065 |
|
2066 The anchor lines of the item. |
|
2067 |
|
2068 For more information see \l {anchor-layout}{Anchor Layouts}. |
|
2069 */ |
|
2070 |
2049 |
2071 /*! |
2050 /*! |
2072 \qmlproperty AnchorLine Item::anchors.top |
2051 \qmlproperty AnchorLine Item::anchors.top |
2073 \qmlproperty AnchorLine Item::anchors.bottom |
2052 \qmlproperty AnchorLine Item::anchors.bottom |
2074 \qmlproperty AnchorLine Item::anchors.left |
2053 \qmlproperty AnchorLine Item::anchors.left |
2091 |
2070 |
2092 Anchors provide a way to position an item by specifying its |
2071 Anchors provide a way to position an item by specifying its |
2093 relationship with other items. |
2072 relationship with other items. |
2094 |
2073 |
2095 Margins apply to top, bottom, left, right, and fill anchors. |
2074 Margins apply to top, bottom, left, right, and fill anchors. |
2096 The margins property can be used to set all of the various margins at once, to the same value. |
2075 The \c anchors.margins property can be used to set all of the various margins at once, to the same value. |
2097 |
2076 |
2098 Offsets apply for horizontal center, vertical center, and baseline anchors. |
2077 Offsets apply for horizontal center, vertical center, and baseline anchors. |
2099 |
2078 |
2100 \table |
2079 \table |
2101 \row |
2080 \row |
2126 ... |
2105 ... |
2127 } |
2106 } |
2128 \endqml |
2107 \endqml |
2129 \endtable |
2108 \endtable |
2130 |
2109 |
2131 anchors.fill provides a convenient way for one item to have the |
2110 \c anchors.fill provides a convenient way for one item to have the |
2132 same geometry as another item, and is equivalent to connecting all |
2111 same geometry as another item, and is equivalent to connecting all |
2133 four directional anchors. |
2112 four directional anchors. |
2134 |
2113 |
|
2114 To clear an anchor value, set it to \c undefined. |
|
2115 |
2135 \note You can only anchor an item to siblings or a parent. |
2116 \note You can only anchor an item to siblings or a parent. |
2136 |
2117 |
2137 For more information see \l {anchor-layout}{Anchor Layouts}. |
2118 For more information see \l {anchor-layout}{Anchor Layouts}. |
2138 */ |
2119 */ |
2139 |
2120 |
2140 /*! |
2121 /*! |
2141 \property QDeclarativeItem::baselineOffset |
2122 \property QDeclarativeItem::baselineOffset |
2142 \brief The position of the item's baseline in local coordinates. |
2123 \brief The position of the item's baseline in local coordinates. |
2143 |
2124 |
2144 The baseline of a Text item is the imaginary line on which the text |
2125 The baseline of a \l Text item is the imaginary line on which the text |
2145 sits. Controls containing text usually set their baseline to the |
2126 sits. Controls containing text usually set their baseline to the |
2146 baseline of their text. |
2127 baseline of their text. |
2147 |
2128 |
2148 For non-text items, a default baseline offset of 0 is used. |
2129 For non-text items, a default baseline offset of 0 is used. |
2149 */ |
2130 */ |
2150 qreal QDeclarativeItem::baselineOffset() const |
2131 qreal QDeclarativeItem::baselineOffset() const |
2151 { |
2132 { |
2152 Q_D(const QDeclarativeItem); |
2133 Q_D(const QDeclarativeItem); |
2153 if (!d->_baselineOffset.isValid()) { |
2134 if (!d->baselineOffset.isValid()) { |
2154 return 0.0; |
2135 return 0.0; |
2155 } else |
2136 } else |
2156 return d->_baselineOffset; |
2137 return d->baselineOffset; |
2157 } |
2138 } |
2158 |
2139 |
2159 void QDeclarativeItem::setBaselineOffset(qreal offset) |
2140 void QDeclarativeItem::setBaselineOffset(qreal offset) |
2160 { |
2141 { |
2161 Q_D(QDeclarativeItem); |
2142 Q_D(QDeclarativeItem); |
2162 if (offset == d->_baselineOffset) |
2143 if (offset == d->baselineOffset) |
2163 return; |
2144 return; |
2164 |
2145 |
2165 d->_baselineOffset = offset; |
2146 d->baselineOffset = offset; |
2166 |
2147 |
2167 for(int ii = 0; ii < d->changeListeners.count(); ++ii) { |
2148 for(int ii = 0; ii < d->changeListeners.count(); ++ii) { |
2168 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii); |
2149 const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii); |
2169 if (change.types & QDeclarativeItemPrivate::Geometry) { |
2150 if (change.types & QDeclarativeItemPrivate::Geometry) { |
2170 QDeclarativeAnchorsPrivate *anchor = change.listener->anchorPrivate(); |
2151 QDeclarativeAnchorsPrivate *anchor = change.listener->anchorPrivate(); |
2289 \sa setKeepMouseGrab() |
2274 \sa setKeepMouseGrab() |
2290 */ |
2275 */ |
2291 bool QDeclarativeItem::keepMouseGrab() const |
2276 bool QDeclarativeItem::keepMouseGrab() const |
2292 { |
2277 { |
2293 Q_D(const QDeclarativeItem); |
2278 Q_D(const QDeclarativeItem); |
2294 return d->_keepMouse; |
2279 return d->keepMouse; |
2295 } |
2280 } |
2296 |
2281 |
2297 /*! |
2282 /*! |
2298 The flag indicating whether the mouse should remain |
2283 The flag indicating whether the mouse should remain |
2299 with this item is set to \a keep. |
2284 with this item is set to \a keep. |
2369 sv.setProperty(QLatin1String("y"), p.y()); |
2354 sv.setProperty(QLatin1String("y"), p.y()); |
2370 return sv; |
2355 return sv; |
2371 } |
2356 } |
2372 |
2357 |
2373 /*! |
2358 /*! |
2374 \qmlmethod Item::forceFocus() |
2359 \qmlmethod Item::forceActiveFocus() |
2375 |
2360 |
2376 Force the focus on the item. |
2361 Force active focus on the item. |
2377 This method sets the focus on the item and makes sure that all the focus scopes higher in the object hierarchy are given focus. |
2362 This method sets focus on the item and makes sure that all the focus scopes higher in the object hierarchy are also given focus. |
2378 */ |
2363 */ |
2379 void QDeclarativeItem::forceFocus() |
2364 void QDeclarativeItem::forceActiveFocus() |
2380 { |
2365 { |
2381 setFocus(true); |
2366 setFocus(true); |
2382 QGraphicsItem *parent = parentItem(); |
2367 QGraphicsItem *parent = parentItem(); |
2383 while (parent) { |
2368 while (parent) { |
2384 if (parent->flags() & QGraphicsItem::ItemIsFocusScope) |
2369 if (parent->flags() & QGraphicsItem::ItemIsFocusScope) |
2385 parent->setFocus(Qt::OtherFocusReason); |
2370 parent->setFocus(Qt::OtherFocusReason); |
2386 parent = parent->parentItem(); |
2371 parent = parent->parentItem(); |
2387 } |
2372 } |
2388 } |
2373 } |
2389 |
2374 |
|
2375 |
|
2376 /*! |
|
2377 \qmlmethod Item::childAt(real x, real y) |
|
2378 |
|
2379 Returns the visible child item at point (\a x, \a y), which is in this |
|
2380 item's coordinate system, or \c null if there is no such item. |
|
2381 */ |
|
2382 QDeclarativeItem *QDeclarativeItem::childAt(qreal x, qreal y) const |
|
2383 { |
|
2384 const QList<QGraphicsItem *> children = childItems(); |
|
2385 for (int i = children.count()-1; i >= 0; --i) { |
|
2386 if (QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i))) { |
|
2387 if (child->isVisible() && child->x() <= x |
|
2388 && child->x() + child->width() >= x |
|
2389 && child->y() <= y |
|
2390 && child->y() + child->height() >= y) |
|
2391 return child; |
|
2392 } |
|
2393 } |
|
2394 return 0; |
|
2395 } |
|
2396 |
2390 void QDeclarativeItemPrivate::focusChanged(bool flag) |
2397 void QDeclarativeItemPrivate::focusChanged(bool flag) |
2391 { |
2398 { |
2392 Q_Q(QDeclarativeItem); |
2399 Q_Q(QDeclarativeItem); |
2393 emit q->focusChanged(flag); |
2400 if (!(flags & QGraphicsItem::ItemIsFocusScope) && parent) |
|
2401 emit q->activeFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange() |
|
2402 |
|
2403 bool inScope = false; |
|
2404 QGraphicsItem *p = parent; |
|
2405 while (p) { |
|
2406 if (p->flags() & QGraphicsItem::ItemIsFocusScope) { |
|
2407 inScope = true; |
|
2408 break; |
|
2409 } |
|
2410 p = p->parentItem(); |
|
2411 } |
|
2412 if (!inScope) |
|
2413 emit q->focusChanged(flag); |
2394 } |
2414 } |
2395 |
2415 |
2396 /*! \internal */ |
2416 /*! \internal */ |
2397 QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::resources() |
2417 QDeclarativeListProperty<QObject> QDeclarativeItemPrivate::resources() |
2398 { |
2418 { |
2471 |
2491 |
2472 /*! |
2492 /*! |
2473 \qmlproperty bool Item::clip |
2493 \qmlproperty bool Item::clip |
2474 This property holds whether clipping is enabled. |
2494 This property holds whether clipping is enabled. |
2475 |
2495 |
2476 if clipping is enabled, an item will clip its own painting, as well |
2496 If clipping is enabled, an item will clip its own painting, as well |
2477 as the painting of its children, to its bounding rectangle. |
2497 as the painting of its children, to its bounding rectangle. |
2478 |
2498 |
2479 Non-rectangular clipping regions are not supported for performance reasons. |
2499 Non-rectangular clipping regions are not supported for performance reasons. |
2480 */ |
2500 */ |
2481 |
2501 |
2538 This property holds the list of transformations to apply. |
2553 This property holds the list of transformations to apply. |
2539 |
2554 |
2540 For more information see \l Transform. |
2555 For more information see \l Transform. |
2541 */ |
2556 */ |
2542 |
2557 |
2543 /*! |
|
2544 \property QDeclarativeItem::transform |
|
2545 \internal |
|
2546 */ |
|
2547 |
|
2548 /*! \internal */ |
2558 /*! \internal */ |
2549 QDeclarativeListProperty<QGraphicsTransform> QDeclarativeItem::transform() |
2559 QDeclarativeListProperty<QGraphicsTransform> QDeclarativeItem::transform() |
2550 { |
2560 { |
2551 Q_D(QDeclarativeItem); |
2561 Q_D(QDeclarativeItem); |
2552 return QDeclarativeListProperty<QGraphicsTransform>(this, 0, d->transform_append, d->transform_count, |
2562 return QDeclarativeListProperty<QGraphicsTransform>(this, 0, d->transform_append, d->transform_count, |
2562 \sa componentComplete(), isComponentComplete() |
2572 \sa componentComplete(), isComponentComplete() |
2563 */ |
2573 */ |
2564 void QDeclarativeItem::classBegin() |
2574 void QDeclarativeItem::classBegin() |
2565 { |
2575 { |
2566 Q_D(QDeclarativeItem); |
2576 Q_D(QDeclarativeItem); |
2567 d->_componentComplete = false; |
2577 d->componentComplete = false; |
2568 if (d->_stateGroup) |
2578 if (d->_stateGroup) |
2569 d->_stateGroup->classBegin(); |
2579 d->_stateGroup->classBegin(); |
2570 if (d->_anchors) |
2580 if (d->_anchors) |
2571 d->_anchors->classBegin(); |
2581 d->_anchors->classBegin(); |
2572 } |
2582 } |
2573 |
2583 |
2574 /*! |
2584 /*! |
2575 \internal |
2585 \internal |
2576 |
2586 |
2577 componentComplete() is called when all items in the component |
2587 componentComplete() is called when all items in the component |
2578 have been constructed. It is often desireable to delay some |
2588 have been constructed. It is often desirable to delay some |
2579 processing until the component is complete an all bindings in the |
2589 processing until the component is complete an all bindings in the |
2580 component have been resolved. |
2590 component have been resolved. |
2581 */ |
2591 */ |
2582 void QDeclarativeItem::componentComplete() |
2592 void QDeclarativeItem::componentComplete() |
2583 { |
2593 { |
2584 Q_D(QDeclarativeItem); |
2594 Q_D(QDeclarativeItem); |
2585 d->_componentComplete = true; |
2595 d->componentComplete = true; |
2586 if (d->_stateGroup) |
2596 if (d->_stateGroup) |
2587 d->_stateGroup->componentComplete(); |
2597 d->_stateGroup->componentComplete(); |
2588 if (d->_anchors) { |
2598 if (d->_anchors) { |
2589 d->_anchors->componentComplete(); |
2599 d->_anchors->componentComplete(); |
2590 d->_anchors->d_func()->updateOnComplete(); |
2600 d->_anchors->d_func()->updateOnComplete(); |
2591 } |
2601 } |
2592 if (d->keyHandler) |
2602 if (d->keyHandler) |
2593 d->keyHandler->componentComplete(); |
2603 d->keyHandler->componentComplete(); |
|
2604 if (d->_contents) |
|
2605 d->_contents->complete(); |
2594 } |
2606 } |
2595 |
2607 |
2596 QDeclarativeStateGroup *QDeclarativeItemPrivate::_states() |
2608 QDeclarativeStateGroup *QDeclarativeItemPrivate::_states() |
2597 { |
2609 { |
2598 Q_Q(QDeclarativeItem); |
2610 Q_Q(QDeclarativeItem); |
2599 if (!_stateGroup) { |
2611 if (!_stateGroup) { |
2600 _stateGroup = new QDeclarativeStateGroup; |
2612 _stateGroup = new QDeclarativeStateGroup; |
2601 if (!_componentComplete) |
2613 if (!componentComplete) |
2602 _stateGroup->classBegin(); |
2614 _stateGroup->classBegin(); |
2603 QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)), |
2615 QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)), |
2604 q, SIGNAL(stateChanged(QString))); |
2616 q, SIGNAL(stateChanged(QString))); |
2605 } |
2617 } |
2606 |
2618 |
2673 } else { |
2685 } else { |
2674 bool rv = QGraphicsItem::sceneEvent(event); |
2686 bool rv = QGraphicsItem::sceneEvent(event); |
2675 |
2687 |
2676 if (event->type() == QEvent::FocusIn || |
2688 if (event->type() == QEvent::FocusIn || |
2677 event->type() == QEvent::FocusOut) { |
2689 event->type() == QEvent::FocusOut) { |
2678 d->focusChanged(hasFocus()); |
2690 d->focusChanged(hasActiveFocus()); |
2679 } |
2691 } |
2680 return rv; |
2692 return rv; |
2681 } |
2693 } |
2682 } |
2694 } |
2683 |
2695 |
2684 /*! |
2696 /*! |
2685 \reimp |
2697 \internal |
2686 |
2698 |
2687 Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is \e not called |
2699 Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is \e not called |
2688 during initial widget polishing. Items wishing to optimize start-up construction |
2700 during initial widget polishing. Items wishing to optimize start-up construction |
2689 should instead consider using componentComplete(). |
2701 should instead consider using componentComplete(). |
2690 */ |
2702 */ |
3067 geometryChanged(QRectF(x(), y(), width(), height()), |
3099 geometryChanged(QRectF(x(), y(), width(), height()), |
3068 QRectF(x(), y(), oldWidth, oldHeight)); |
3100 QRectF(x(), y(), oldWidth, oldHeight)); |
3069 } |
3101 } |
3070 |
3102 |
3071 /*! |
3103 /*! |
3072 \qmlproperty bool Item::wantsFocus |
3104 \qmlproperty bool Item::activeFocus |
3073 |
3105 |
3074 This property indicates whether the item has has an active focus request. |
3106 This property indicates whether the item has active focus. |
3075 |
3107 |
3076 \sa {qmlfocus}{Keyboard Focus} |
3108 An item with active focus will receive keyboard input, |
|
3109 or is a FocusScope ancestor of the item that will receive keyboard input. |
|
3110 |
|
3111 Usually, activeFocus is gained by setting focus on an item and its enclosing |
|
3112 FocusScopes. In the following example \c input will have activeFocus. |
|
3113 \qml |
|
3114 Rectangle { |
|
3115 FocusScope { |
|
3116 focus: true |
|
3117 TextInput { |
|
3118 id: input |
|
3119 focus: true |
|
3120 } |
|
3121 } |
|
3122 } |
|
3123 \endqml |
|
3124 |
|
3125 \sa focus, {qmlfocus}{Keyboard Focus} |
3077 */ |
3126 */ |
3078 |
3127 |
3079 /*! \internal */ |
3128 /*! \internal */ |
3080 bool QDeclarativeItem::wantsFocus() const |
3129 bool QDeclarativeItem::hasActiveFocus() const |
3081 { |
3130 { |
3082 return focusItem() != 0; |
3131 Q_D(const QDeclarativeItem); |
|
3132 return focusItem() == this || |
|
3133 (d->flags & QGraphicsItem::ItemIsFocusScope && focusItem() != 0) || |
|
3134 (!parentItem() && focusItem() != 0); |
3083 } |
3135 } |
3084 |
3136 |
3085 /*! |
3137 /*! |
3086 \qmlproperty bool Item::focus |
3138 \qmlproperty bool Item::focus |
3087 This property indicates whether the item has keyboard input focus. Set this |
3139 This property indicates whether the item has focus within the enclosing focus scope. If true, this item |
3088 property to true to request focus. |
3140 will gain active focus when the enclosing focus scope gains active focus. |
3089 |
3141 In the following example, \c input will be given active focus when \c scope gains active focus. |
3090 \sa {qmlfocus}{Keyboard Focus} |
3142 \qml |
|
3143 Rectangle { |
|
3144 FocusScope { |
|
3145 id: scope |
|
3146 TextInput { |
|
3147 id: input |
|
3148 focus: true |
|
3149 } |
|
3150 } |
|
3151 } |
|
3152 \endqml |
|
3153 |
|
3154 For the purposes of this property, the top level item in the scene |
|
3155 is assumed to act like a focus scope, and to always have active focus |
|
3156 when the scene has focus. On a practical level, that means the following |
|
3157 QML will give active focus to \c input on startup. |
|
3158 |
|
3159 \qml |
|
3160 Rectangle { |
|
3161 TextInput { |
|
3162 id: input |
|
3163 focus: true |
|
3164 } |
|
3165 } |
|
3166 \endqml |
|
3167 |
|
3168 \sa activeFocus, {qmlfocus}{Keyboard Focus} |
3091 */ |
3169 */ |
3092 |
3170 |
3093 /*! \internal */ |
3171 /*! \internal */ |
3094 bool QDeclarativeItem::hasFocus() const |
3172 bool QDeclarativeItem::hasFocus() const |
3095 { |
3173 { |
3096 return QGraphicsItem::hasFocus(); |
3174 Q_D(const QDeclarativeItem); |
|
3175 QGraphicsItem *p = d->parent; |
|
3176 while (p) { |
|
3177 if (p->flags() & QGraphicsItem::ItemIsFocusScope) { |
|
3178 return p->focusScopeItem() == this; |
|
3179 } |
|
3180 p = p->parentItem(); |
|
3181 } |
|
3182 |
|
3183 return hasActiveFocus() ? true : (!QGraphicsItem::parentItem() ? true : false); |
3097 } |
3184 } |
3098 |
3185 |
3099 /*! \internal */ |
3186 /*! \internal */ |
3100 void QDeclarativeItem::setFocus(bool focus) |
3187 void QDeclarativeItem::setFocus(bool focus) |
3101 { |
3188 { |
3142 << ", parent =" << ((void*)item->parentItem()) |
3230 << ", parent =" << ((void*)item->parentItem()) |
3143 << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height())) |
3231 << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height())) |
3144 << ", z =" << item->zValue() << ')'; |
3232 << ", z =" << item->zValue() << ')'; |
3145 return debug; |
3233 return debug; |
3146 } |
3234 } |
3147 |
3235 #endif |
3148 int QDeclarativeItemPrivate::consistentTime = -1; |
3236 |
3149 void QDeclarativeItemPrivate::setConsistentTime(int t) |
3237 qint64 QDeclarativeItemPrivate::consistentTime = -1; |
|
3238 void QDeclarativeItemPrivate::setConsistentTime(qint64 t) |
3150 { |
3239 { |
3151 consistentTime = t; |
3240 consistentTime = t; |
3152 } |
3241 } |
3153 |
3242 |
3154 QTime QDeclarativeItemPrivate::currentTime() |
3243 class QElapsedTimerConsistentTimeHack |
3155 { |
3244 { |
3156 if (consistentTime == -1) |
3245 public: |
3157 return QTime::currentTime(); |
3246 void start() { |
|
3247 t1 = QDeclarativeItemPrivate::consistentTime; |
|
3248 t2 = 0; |
|
3249 } |
|
3250 qint64 elapsed() { |
|
3251 return QDeclarativeItemPrivate::consistentTime - t1; |
|
3252 } |
|
3253 qint64 restart() { |
|
3254 qint64 val = QDeclarativeItemPrivate::consistentTime - t1; |
|
3255 t1 = QDeclarativeItemPrivate::consistentTime; |
|
3256 t2 = 0; |
|
3257 return val; |
|
3258 } |
|
3259 |
|
3260 private: |
|
3261 qint64 t1; |
|
3262 qint64 t2; |
|
3263 }; |
|
3264 |
|
3265 void QDeclarativeItemPrivate::start(QElapsedTimer &t) |
|
3266 { |
|
3267 if (QDeclarativeItemPrivate::consistentTime == -1) |
|
3268 t.start(); |
3158 else |
3269 else |
3159 return QTime(0, 0).addMSecs(consistentTime); |
3270 ((QElapsedTimerConsistentTimeHack*)&t)->start(); |
3160 } |
3271 } |
3161 |
3272 |
3162 void QDeclarativeItemPrivate::start(QTime &t) |
3273 qint64 QDeclarativeItemPrivate::elapsed(QElapsedTimer &t) |
3163 { |
3274 { |
3164 t = currentTime(); |
3275 if (QDeclarativeItemPrivate::consistentTime == -1) |
3165 } |
3276 return t.elapsed(); |
3166 |
3277 else |
3167 int QDeclarativeItemPrivate::elapsed(QTime &t) |
3278 return ((QElapsedTimerConsistentTimeHack*)&t)->elapsed(); |
3168 { |
3279 } |
3169 int n = t.msecsTo(currentTime()); |
3280 |
3170 if (n < 0) // passed midnight |
3281 qint64 QDeclarativeItemPrivate::restart(QElapsedTimer &t) |
3171 n += 86400 * 1000; |
3282 { |
3172 return n; |
3283 if (QDeclarativeItemPrivate::consistentTime == -1) |
3173 } |
3284 return t.restart(); |
3174 |
3285 else |
3175 int QDeclarativeItemPrivate::restart(QTime &t) |
3286 return ((QElapsedTimerConsistentTimeHack*)&t)->restart(); |
3176 { |
|
3177 QTime time = currentTime(); |
|
3178 int n = t.msecsTo(time); |
|
3179 if (n < 0) // passed midnight |
|
3180 n += 86400*1000; |
|
3181 t = time; |
|
3182 return n; |
|
3183 } |
3287 } |
3184 |
3288 |
3185 QT_END_NAMESPACE |
3289 QT_END_NAMESPACE |
3186 |
3290 |
3187 #include <moc_qdeclarativeitem.cpp> |
3291 #include <moc_qdeclarativeitem.cpp> |