summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2009-08-25 01:24:31 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2009-08-25 01:24:31 (GMT)
commit128828d0fc00dd75f155bed1eaaea287a9de15f1 (patch)
treec1f23802dfcc476118d023d83aa100ce4575ec49 /src
parent1970d1fb78a300247cd3f14445da481558eef1af (diff)
parentf69d8805291ee46856b21d9091693cdc139765b8 (diff)
downloadQt-128828d0fc00dd75f155bed1eaaea287a9de15f1.zip
Qt-128828d0fc00dd75f155bed1eaaea287a9de15f1.tar.gz
Qt-128828d0fc00dd75f155bed1eaaea287a9de15f1.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/qfxitem.cpp265
-rw-r--r--src/declarative/fx/qfxitem.h5
-rw-r--r--src/declarative/fx/qfxitem_p.h4
-rw-r--r--src/declarative/qml/qmlbindingoptimizations.cpp12
-rw-r--r--src/declarative/qml/qmlbindingoptimizations_p.h5
5 files changed, 252 insertions, 39 deletions
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index ed2386b..7938dc9 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -299,6 +299,229 @@ void QFxContents::setItem(QFxItem *item)
calcWidth();
}
+/*
+ Key filters can be installed on a QFxItem, but not removed. Currently they
+ are only used by attached objects (which are only destroyed on Item
+ destruction), so this isn't a problem. If in future this becomes any form
+ of public API, they will have to support removal too.
+*/
+class QFxItemKeyFilter
+{
+public:
+ QFxItemKeyFilter(QFxItem * = 0);
+ virtual ~QFxItemKeyFilter();
+
+ virtual void keyPressed(QKeyEvent *event);
+ virtual void keyReleased(QKeyEvent *event);
+
+private:
+ QFxItemKeyFilter *m_next;
+};
+
+QFxItemKeyFilter::QFxItemKeyFilter(QFxItem *item)
+: m_next(0)
+{
+ QFxItemPrivate *p =
+ item?static_cast<QFxItemPrivate *>(QGraphicsItemPrivate::get(item)):0;
+ if (p) {
+ m_next = p->keyHandler;
+ p->keyHandler = this;
+ }
+}
+
+QFxItemKeyFilter::~QFxItemKeyFilter()
+{
+}
+
+void QFxItemKeyFilter::keyPressed(QKeyEvent *event)
+{
+ if (m_next) m_next->keyPressed(event);
+}
+
+void QFxItemKeyFilter::keyReleased(QKeyEvent *event)
+{
+ if (m_next) m_next->keyReleased(event);
+}
+
+class QFxKeyNavigationAttachedPrivate : public QObjectPrivate
+{
+public:
+ QFxKeyNavigationAttachedPrivate()
+ : QObjectPrivate(), left(0), right(0), up(0), down(0) {}
+
+ QFxItem *left;
+ QFxItem *right;
+ QFxItem *up;
+ QFxItem *down;
+};
+
+class QFxKeyNavigationAttached : public QObject, public QFxItemKeyFilter
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QFxKeyNavigationAttached);
+
+ Q_PROPERTY(QFxItem *left READ left WRITE setLeft NOTIFY changed);
+ Q_PROPERTY(QFxItem *right READ right WRITE setRight NOTIFY changed);
+ Q_PROPERTY(QFxItem *up READ up WRITE setUp NOTIFY changed);
+ Q_PROPERTY(QFxItem *down READ down WRITE setDown NOTIFY changed);
+public:
+ QFxKeyNavigationAttached(QObject * = 0);
+
+ QFxItem *left() const;
+ void setLeft(QFxItem *);
+ QFxItem *right() const;
+ void setRight(QFxItem *);
+ QFxItem *up() const;
+ void setUp(QFxItem *);
+ QFxItem *down() const;
+ void setDown(QFxItem *);
+
+ static QFxKeyNavigationAttached *qmlAttachedProperties(QObject *);
+
+signals:
+ void changed();
+
+private:
+ virtual void keyPressed(QKeyEvent *event);
+ virtual void keyReleased(QKeyEvent *event);
+};
+
+QFxKeyNavigationAttached::QFxKeyNavigationAttached(QObject *parent)
+: QObject(*(new QFxKeyNavigationAttachedPrivate), parent),
+ QFxItemKeyFilter(qobject_cast<QFxItem*>(parent))
+{
+}
+
+QFxKeyNavigationAttached *
+QFxKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
+{
+ return new QFxKeyNavigationAttached(obj);
+}
+
+QFxItem *QFxKeyNavigationAttached::left() const
+{
+ Q_D(const QFxKeyNavigationAttached);
+ return d->left;
+}
+
+void QFxKeyNavigationAttached::setLeft(QFxItem *i)
+{
+ Q_D(QFxKeyNavigationAttached);
+ d->left = i;
+ emit changed();
+}
+
+QFxItem *QFxKeyNavigationAttached::right() const
+{
+ Q_D(const QFxKeyNavigationAttached);
+ return d->right;
+}
+
+void QFxKeyNavigationAttached::setRight(QFxItem *i)
+{
+ Q_D(QFxKeyNavigationAttached);
+ d->right = i;
+ emit changed();
+}
+
+QFxItem *QFxKeyNavigationAttached::up() const
+{
+ Q_D(const QFxKeyNavigationAttached);
+ return d->up;
+}
+
+void QFxKeyNavigationAttached::setUp(QFxItem *i)
+{
+ Q_D(QFxKeyNavigationAttached);
+ d->up = i;
+ emit changed();
+}
+
+QFxItem *QFxKeyNavigationAttached::down() const
+{
+ Q_D(const QFxKeyNavigationAttached);
+ return d->down;
+}
+
+void QFxKeyNavigationAttached::setDown(QFxItem *i)
+{
+ Q_D(QFxKeyNavigationAttached);
+ d->down = i;
+ emit changed();
+}
+
+void QFxKeyNavigationAttached::keyPressed(QKeyEvent *event)
+{
+ Q_D(QFxKeyNavigationAttached);
+
+ event->ignore();
+
+ switch(event->key()) {
+ case Qt::Key_Left:
+ if (d->left) {
+ d->left->setFocus(true);
+ event->accept();
+ }
+ break;
+ case Qt::Key_Right:
+ if (d->right) {
+ d->right->setFocus(true);
+ event->accept();
+ }
+ break;
+ case Qt::Key_Up:
+ if (d->up) {
+ d->up->setFocus(true);
+ event->accept();
+ }
+ break;
+ case Qt::Key_Down:
+ if (d->down) {
+ d->down->setFocus(true);
+ event->accept();
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (!event->isAccepted()) QFxItemKeyFilter::keyPressed(event);
+}
+
+void QFxKeyNavigationAttached::keyReleased(QKeyEvent *event)
+{
+ Q_D(QFxKeyNavigationAttached);
+
+ event->ignore();
+
+ switch(event->key()) {
+ case Qt::Key_Left:
+ if (d->left) {
+ event->accept();
+ }
+ break;
+ case Qt::Key_Right:
+ if (d->right) {
+ event->accept();
+ }
+ break;
+ case Qt::Key_Up:
+ if (d->up) {
+ event->accept();
+ }
+ break;
+ case Qt::Key_Down:
+ if (d->down) {
+ event->accept();
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (!event->isAccepted()) QFxItemKeyFilter::keyReleased(event);
+}
+
/*!
\qmlclass Keys
\brief The Keys attached property provides key handling to Items.
@@ -616,7 +839,7 @@ public:
bool enabled;
};
-class QFxKeysAttached : public QObject
+class QFxKeysAttached : public QObject, public QFxItemKeyFilter
{
Q_OBJECT
Q_DECLARE_PRIVATE(QFxKeysAttached);
@@ -681,8 +904,8 @@ signals:
void volumeDownPressed(QFxKeyEvent *event);
private:
- void keyPressed(QKeyEvent *event);
- void keyReleased(QKeyEvent *event);
+ virtual void keyPressed(QKeyEvent *event);
+ virtual void keyReleased(QKeyEvent *event);
const char *keyToSignal(int key) {
QByteArray keySignal;
@@ -704,7 +927,6 @@ private:
};
static const SigMap sigMap[];
- friend class QFxItem;
};
const QFxKeysAttached::SigMap QFxKeysAttached::sigMap[] = {
@@ -743,16 +965,13 @@ bool QFxKeysAttachedPrivate::isConnected(const char *signalName)
}
QFxKeysAttached::QFxKeysAttached(QObject *parent)
- : QObject(*(new QFxKeysAttachedPrivate), parent)
+: QObject(*(new QFxKeysAttachedPrivate), parent),
+ QFxItemKeyFilter(qobject_cast<QFxItem*>(parent))
{
- if (QFxItem *item = qobject_cast<QFxItem*>(parent))
- item->setKeyHandler(this);
}
QFxKeysAttached::~QFxKeysAttached()
{
- if (QFxItem *item = qobject_cast<QFxItem*>(parent()))
- item->setKeyHandler(0);
}
void QFxKeysAttached::keyPressed(QKeyEvent *event)
@@ -777,6 +996,8 @@ void QFxKeysAttached::keyPressed(QKeyEvent *event)
if (!ke.isAccepted())
emit pressed(&ke);
event->setAccepted(ke.isAccepted());
+
+ if (!event->isAccepted()) QFxItemKeyFilter::keyPressed(event);
}
void QFxKeysAttached::keyReleased(QKeyEvent *event)
@@ -789,21 +1010,15 @@ void QFxKeysAttached::keyReleased(QKeyEvent *event)
QFxKeyEvent ke(*event);
emit released(&ke);
event->setAccepted(ke.isAccepted());
+
+ if (!event->isAccepted()) QFxItemKeyFilter::keyReleased(event);
}
QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj)
{
- QFxKeysAttached *rv = 0;
- QFxItem *item = qobject_cast<QFxItem*>(obj);
- if (item) {
- rv = item->keyHandler();
- if (!rv)
- rv = new QFxKeysAttached(obj);
- }
- return rv;
+ return new QFxKeysAttached(obj);
}
-
/*!
\qmlclass Item QFxItem
\brief The Item is the most basic of all visual items in QML.
@@ -1422,18 +1637,6 @@ void QFxItem::geometryChanged(const QRectF &newGeometry,
}
}
-QFxKeysAttached *QFxItem::keyHandler()
-{
- Q_D(QFxItem);
- return d->keyHandler;
-}
-
-void QFxItem::setKeyHandler(QFxKeysAttached *handler)
-{
- Q_D(QFxItem);
- d->keyHandler = handler;
-}
-
/*!
\reimp
*/
@@ -2443,6 +2646,8 @@ QT_END_NAMESPACE
QML_DECLARE_TYPE(QFxKeysAttached)
QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QFxKeysAttached)
+QML_DECLARE_TYPE(QFxKeyNavigationAttached)
+QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QFxKeyNavigationAttached)
#include "moc_qfxitem.cpp"
#include "qfxitem.moc"
diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h
index 222677c..cb2d97a 100644
--- a/src/declarative/fx/qfxitem.h
+++ b/src/declarative/fx/qfxitem.h
@@ -63,7 +63,6 @@ class QmlTransition;
class QFxKeyEvent;
class QFxAnchors;
class QFxItemPrivate;
-class QFxKeysAttached;
class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserStatus
{
Q_OBJECT
@@ -197,12 +196,8 @@ private:
QFxAnchorLine verticalCenter() const;
QFxAnchorLine baseline() const;
- QFxKeysAttached *keyHandler();
- void setKeyHandler(QFxKeysAttached *);
-
friend class QmlStatePrivate;
friend class QFxAnchors;
- friend class QFxKeysAttached;
Q_DISABLE_COPY(QFxItem)
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxItem)
};
diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h
index 1d4bef3..d30e324 100644
--- a/src/declarative/fx/qfxitem_p.h
+++ b/src/declarative/fx/qfxitem_p.h
@@ -67,7 +67,7 @@
QT_BEGIN_NAMESPACE
class QNetworkReply;
-class QFxKeysAttached;
+class QFxItemKeyFilter;
//### merge into private?
class QFxContents : public QObject
@@ -209,7 +209,7 @@ public:
bool _keepMouse:1;
bool smooth:1;
- QFxKeysAttached *keyHandler;
+ QFxItemKeyFilter *keyHandler;
qreal width;
qreal height;
diff --git a/src/declarative/qml/qmlbindingoptimizations.cpp b/src/declarative/qml/qmlbindingoptimizations.cpp
index e1f4a90..e4ca358 100644
--- a/src/declarative/qml/qmlbindingoptimizations.cpp
+++ b/src/declarative/qml/qmlbindingoptimizations.cpp
@@ -64,6 +64,11 @@ QmlBinding_Id::QmlBinding_Id(QObject *object, int propertyIdx,
QmlAbstractExpression::setContext(context);
}
+QmlBinding_Id::~QmlBinding_Id()
+{
+ removeFromContext();
+}
+
void QmlBinding_Id::setEnabled(bool e)
{
if (e) {
@@ -103,7 +108,7 @@ void QmlBinding_Id::update()
}
}
-void QmlBinding_Id::reset()
+void QmlBinding_Id::removeFromContext()
{
if (m_prev) {
*m_prev = m_next;
@@ -111,6 +116,11 @@ void QmlBinding_Id::reset()
m_next = 0;
m_prev = 0;
}
+}
+
+void QmlBinding_Id::reset()
+{
+ removeFromContext();
QObject *o = 0;
void *a[] = { &o, 0 };
diff --git a/src/declarative/qml/qmlbindingoptimizations_p.h b/src/declarative/qml/qmlbindingoptimizations_p.h
index 2d2ffec..ab264c7 100644
--- a/src/declarative/qml/qmlbindingoptimizations_p.h
+++ b/src/declarative/qml/qmlbindingoptimizations_p.h
@@ -65,7 +65,8 @@ class QmlBinding_Id : public QmlAbstractExpression,
{
public:
QmlBinding_Id(QObject *object, int propertyIdx,
- QmlContext *context, int id);
+ QmlContext *context, int id);
+ virtual ~QmlBinding_Id();
// Inherited from QmlAbstractBinding
virtual void setEnabled(bool);
@@ -75,6 +76,8 @@ public:
void reset();
private:
+ void removeFromContext();
+
QmlBinding_Id **m_prev;
QmlBinding_Id *m_next;