summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativeitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativeitem.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp220
1 files changed, 142 insertions, 78 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 190b22c..2c295cd 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -63,11 +63,9 @@
#include <QtGui/qgraphicstransform.h>
#include <qlistmodelinterface_p.h>
-QT_BEGIN_NAMESPACE
+#include <float.h>
-#ifndef FLT_MAX
-#define FLT_MAX 1E+37
-#endif
+QT_BEGIN_NAMESPACE
/*!
\qmlclass Transform QGraphicsTransform
@@ -91,7 +89,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlclass Translate QGraphicsTranslate
+ \qmlclass Translate QDeclarativeTranslate
\since 4.7
\brief The Translate object provides a way to move an Item without changing its x or y properties.
@@ -420,12 +418,12 @@ void QDeclarativeItemKeyFilter::componentComplete()
/*!
- \qmlclass KeyNavigation
+ \qmlclass KeyNavigation QDeclarativeKeyNavigationAttached
\since 4.7
\brief The KeyNavigation attached property supports key navigation by arrow keys.
It is common in key-based UIs to use arrow keys to navigate
- between focussed items. The KeyNavigation property provides a
+ between focused items. The KeyNavigation property provides a
convenient way of specifying which item will gain focus
when an arrow key is pressed. The following example provides
key navigation for a 2x2 grid of items.
@@ -513,8 +511,10 @@ QDeclarativeItem *QDeclarativeKeyNavigationAttached::left() const
void QDeclarativeKeyNavigationAttached::setLeft(QDeclarativeItem *i)
{
Q_D(QDeclarativeKeyNavigationAttached);
+ if (d->left == i)
+ return;
d->left = i;
- emit changed();
+ emit leftChanged();
}
QDeclarativeItem *QDeclarativeKeyNavigationAttached::right() const
@@ -526,8 +526,10 @@ QDeclarativeItem *QDeclarativeKeyNavigationAttached::right() const
void QDeclarativeKeyNavigationAttached::setRight(QDeclarativeItem *i)
{
Q_D(QDeclarativeKeyNavigationAttached);
+ if (d->right == i)
+ return;
d->right = i;
- emit changed();
+ emit rightChanged();
}
QDeclarativeItem *QDeclarativeKeyNavigationAttached::up() const
@@ -539,8 +541,10 @@ QDeclarativeItem *QDeclarativeKeyNavigationAttached::up() const
void QDeclarativeKeyNavigationAttached::setUp(QDeclarativeItem *i)
{
Q_D(QDeclarativeKeyNavigationAttached);
+ if (d->up == i)
+ return;
d->up = i;
- emit changed();
+ emit upChanged();
}
QDeclarativeItem *QDeclarativeKeyNavigationAttached::down() const
@@ -552,8 +556,10 @@ QDeclarativeItem *QDeclarativeKeyNavigationAttached::down() const
void QDeclarativeKeyNavigationAttached::setDown(QDeclarativeItem *i)
{
Q_D(QDeclarativeKeyNavigationAttached);
+ if (d->down == i)
+ return;
d->down = i;
- emit changed();
+ emit downChanged();
}
QDeclarativeItem *QDeclarativeKeyNavigationAttached::tab() const
@@ -565,8 +571,10 @@ QDeclarativeItem *QDeclarativeKeyNavigationAttached::tab() const
void QDeclarativeKeyNavigationAttached::setTab(QDeclarativeItem *i)
{
Q_D(QDeclarativeKeyNavigationAttached);
+ if (d->tab == i)
+ return;
d->tab = i;
- emit changed();
+ emit tabChanged();
}
QDeclarativeItem *QDeclarativeKeyNavigationAttached::backtab() const
@@ -578,8 +586,10 @@ QDeclarativeItem *QDeclarativeKeyNavigationAttached::backtab() const
void QDeclarativeKeyNavigationAttached::setBacktab(QDeclarativeItem *i)
{
Q_D(QDeclarativeKeyNavigationAttached);
+ if (d->backtab == i)
+ return;
d->backtab = i;
- emit changed();
+ emit backtabChanged();
}
/*!
@@ -714,7 +724,7 @@ void QDeclarativeKeyNavigationAttached::keyReleased(QKeyEvent *event, bool post)
}
/*!
- \qmlclass Keys
+ \qmlclass Keys QDeclarativeKeysAttached
\since 4.7
\brief The Keys attached property provides key handling to Items.
@@ -1388,26 +1398,6 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec
*/
/*!
- \property QDeclarativeItem::baseline
- \internal
-*/
-
-/*!
- \property QDeclarativeItem::focus
- \internal
-*/
-
-/*!
- \property QDeclarativeItem::wantsFocus
- \internal
-*/
-
-/*!
- \property QDeclarativeItem::transformOrigin
- \internal
-*/
-
-/*!
\fn void QDeclarativeItem::childrenRectChanged(const QRectF &)
\internal
*/
@@ -1452,7 +1442,7 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec
*/
/*!
- \fn void QDeclarativeItem::wantsFocusChanged(bool)
+ \fn void QDeclarativeItem::activeFocusChanged(bool)
\internal
*/
@@ -1534,6 +1524,9 @@ QDeclarativeItem::~QDeclarativeItem()
\endqml
The default transform origin is \c Item.Center.
+
+ To set an arbitrary transform origin point use the \l Scale or \l Rotation
+ transform elements.
*/
/*!
@@ -1970,6 +1963,9 @@ QVariant QDeclarativeItem::inputMethodQuery(Qt::InputMethodQuery query) const
return v;
}
+/*!
+ \internal
+ */
void QDeclarativeItem::keyPressPreHandler(QKeyEvent *event)
{
Q_D(QDeclarativeItem);
@@ -1980,6 +1976,9 @@ void QDeclarativeItem::keyPressPreHandler(QKeyEvent *event)
d->doneEventPreHandler = true;
}
+/*!
+ \internal
+ */
void QDeclarativeItem::keyReleasePreHandler(QKeyEvent *event)
{
Q_D(QDeclarativeItem);
@@ -1990,6 +1989,9 @@ void QDeclarativeItem::keyReleasePreHandler(QKeyEvent *event)
d->doneEventPreHandler = true;
}
+/*!
+ \internal
+ */
void QDeclarativeItem::inputMethodPreHandler(QInputMethodEvent *event)
{
Q_D(QDeclarativeItem);
@@ -2000,7 +2002,6 @@ void QDeclarativeItem::inputMethodPreHandler(QInputMethodEvent *event)
d->doneEventPreHandler = true;
}
-
/*!
\internal
*/
@@ -2059,20 +2060,6 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const
}
/*!
- \qmlproperty AnchorLine Item::top
- \qmlproperty AnchorLine Item::bottom
- \qmlproperty AnchorLine Item::left
- \qmlproperty AnchorLine Item::right
- \qmlproperty AnchorLine Item::horizontalCenter
- \qmlproperty AnchorLine Item::verticalCenter
- \qmlproperty AnchorLine Item::baseline
-
- The anchor lines of the item.
-
- For more information see \l {anchor-layout}{Anchor Layouts}.
-*/
-
-/*!
\qmlproperty AnchorLine Item::anchors.top
\qmlproperty AnchorLine Item::anchors.bottom
\qmlproperty AnchorLine Item::anchors.left
@@ -2204,6 +2191,8 @@ void QDeclarativeItem::setBaselineOffset(qreal offset)
}
\endqml
\endtable
+
+ \sa transform, Rotation
*/
/*!
@@ -2240,6 +2229,8 @@ void QDeclarativeItem::setBaselineOffset(qreal offset)
}
\endqml
\endtable
+
+ \sa transform, Scale
*/
/*!
@@ -2377,12 +2368,12 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qrea
}
/*!
- \qmlmethod Item::forceFocus()
+ \qmlmethod Item::forceActiveFocus()
- Force the focus on the item.
- This method sets the focus on the item and makes sure that all the focus scopes higher in the object hierarchy are given focus.
+ Force active focus on the item.
+ This method sets focus on the item and makes sure that all the focus scopes higher in the object hierarchy are also given focus.
*/
-void QDeclarativeItem::forceFocus()
+void QDeclarativeItem::forceActiveFocus()
{
setFocus(true);
QGraphicsItem *parent = parentItem();
@@ -2419,8 +2410,19 @@ void QDeclarativeItemPrivate::focusChanged(bool flag)
{
Q_Q(QDeclarativeItem);
if (!(flags & QGraphicsItem::ItemIsFocusScope) && parent)
- emit q->wantsFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange()
- emit q->focusChanged(flag);
+ emit q->activeFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange()
+
+ bool inScope = false;
+ QGraphicsItem *p = parent;
+ while (p) {
+ if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
+ inScope = true;
+ break;
+ }
+ p = p->parentItem();
+ }
+ if (!inScope)
+ emit q->focusChanged(flag);
}
/*! \internal */
@@ -2492,7 +2494,7 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItemPrivate::transi
Item {
filter: [
Blur { ... },
- Relection { ... }
+ Reflection { ... }
...
]
}
@@ -2503,7 +2505,7 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItemPrivate::transi
\qmlproperty bool Item::clip
This property holds whether clipping is enabled.
- if clipping is enabled, an item will clip its own painting, as well
+ If clipping is enabled, an item will clip its own painting, as well
as the painting of its children, to its bounding rectangle.
Non-rectangular clipping regions are not supported for performance reasons.
@@ -2543,11 +2545,6 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItemPrivate::transi
\sa {qmlstates}{States}
*/
-/*!
- \property QDeclarativeItem::state
- \internal
-*/
-
/*! \internal */
QString QDeclarativeItemPrivate::state() const
{
@@ -2570,11 +2567,6 @@ void QDeclarativeItemPrivate::setState(const QString &state)
For more information see \l Transform.
*/
-/*!
- \property QDeclarativeItem::transform
- \internal
-*/
-
/*! \internal */
QDeclarativeListProperty<QGraphicsTransform> QDeclarativeItem::transform()
{
@@ -2707,14 +2699,14 @@ bool QDeclarativeItem::sceneEvent(QEvent *event)
if (event->type() == QEvent::FocusIn ||
event->type() == QEvent::FocusOut) {
- d->focusChanged(hasFocus());
+ d->focusChanged(hasActiveFocus());
}
return rv;
}
}
/*!
- \reimp
+ \internal
Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is \e not called
during initial widget polishing. Items wishing to optimize start-up construction
@@ -2863,6 +2855,26 @@ void QDeclarativeItem::setSmooth(bool smooth)
}
/*!
+ \property QDeclarativeItem::focus
+ \internal
+*/
+
+/*!
+ \property QDeclarativeItem::transform
+ \internal
+*/
+
+/*!
+ \property QDeclarativeItem::transformOrigin
+ \internal
+*/
+
+/*!
+ \property QDeclarativeItem::activeFocus
+ \internal
+*/
+
+/*!
\internal
Return the width of the item
*/
@@ -3101,15 +3113,32 @@ void QDeclarativeItem::setSize(const QSizeF &size)
}
/*!
- \qmlproperty bool Item::wantsFocus
+ \qmlproperty bool Item::activeFocus
+
+ This property indicates whether the item has active focus.
- This property indicates whether the item has has an active focus request.
+ An item with active focus will receive keyboard input,
+ or is a FocusScope ancestor of the item that will receive keyboard input.
- \sa {qmlfocus}{Keyboard Focus}
+ Usually, activeFocus is gained by setting focus on an item and its enclosing
+ FocusScopes. In the following example \c input will have activeFocus.
+ \qml
+ Rectangle {
+ FocusScope {
+ focus: true
+ TextInput {
+ id: input
+ focus: true
+ }
+ }
+ }
+ \endqml
+
+ \sa focus, {qmlfocus}{Keyboard Focus}
*/
/*! \internal */
-bool QDeclarativeItem::wantsFocus() const
+bool QDeclarativeItem::hasActiveFocus() const
{
Q_D(const QDeclarativeItem);
return focusItem() == this ||
@@ -3119,16 +3148,51 @@ bool QDeclarativeItem::wantsFocus() const
/*!
\qmlproperty bool Item::focus
- This property indicates whether the item has keyboard input focus. Set this
- property to true to request focus.
+ This property indicates whether the item has focus within the enclosing focus scope. If true, this item
+ will gain active focus when the enclosing focus scope gains active focus.
+ In the following example, \c input will be given active focus when \c scope gains active focus.
+ \qml
+ Rectangle {
+ FocusScope {
+ id: scope
+ TextInput {
+ id: input
+ focus: true
+ }
+ }
+ }
+ \endqml
+
+ For the purposes of this property, the top level item in the scene
+ is assumed to act like a focus scope, and to always have active focus
+ when the scene has focus. On a practical level, that means the following
+ QML will give active focus to \c input on startup.
+
+ \qml
+ Rectangle {
+ TextInput {
+ id: input
+ focus: true
+ }
+ }
+ \endqml
- \sa {qmlfocus}{Keyboard Focus}
+ \sa activeFocus, {qmlfocus}{Keyboard Focus}
*/
/*! \internal */
bool QDeclarativeItem::hasFocus() const
{
- return QGraphicsItem::hasFocus();
+ Q_D(const QDeclarativeItem);
+ QGraphicsItem *p = d->parent;
+ while (p) {
+ if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
+ return p->focusScopeItem() == this;
+ }
+ p = p->parentItem();
+ }
+
+ return hasActiveFocus() ? true : (!QGraphicsItem::parentItem() ? true : false);
}
/*! \internal */