From 6fc7ce61ba1b623421ca3ca8ee2315746be0a37b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 12 Aug 2009 11:31:25 +1000 Subject: Change key handling to use a Keys attached property. Replaces KeyAction, allowing focus to be set on the actual item that wants focus, rather than a separate handler item. --- doc/src/declarative/elements.qdoc | 2 +- examples/declarative/snow/snow.qml | 17 +- src/declarative/fx/fx.pri | 2 - src/declarative/fx/qfxevents.cpp | 7 +- src/declarative/fx/qfxgridview.cpp | 3 +- src/declarative/fx/qfxitem.cpp | 576 ++++++++++++++++++++-- src/declarative/fx/qfxitem.h | 6 +- src/declarative/fx/qfxitem_p.h | 16 +- src/declarative/fx/qfxkeyactions.cpp | 921 ----------------------------------- src/declarative/fx/qfxkeyactions.h | 319 ------------ src/declarative/fx/qfxlineedit.cpp | 2 + src/declarative/fx/qfxlistview.cpp | 3 +- src/declarative/fx/qfxtextedit.cpp | 19 +- 13 files changed, 568 insertions(+), 1325 deletions(-) delete mode 100644 src/declarative/fx/qfxkeyactions.cpp delete mode 100644 src/declarative/fx/qfxkeyactions.h diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 68db351..b5dd2bb 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -42,6 +42,7 @@ The following table lists the Qml elements provided by the Qt Declarative module \list \o \l Bind \o \l ListModel +\o \l VisualItemModel \o \l XmlListModel and XmlRole \o \l SqlQuery, \l SqlConnection, and \l SqlBind \o \l DateTimeFormatter @@ -80,7 +81,6 @@ The following table lists the Qml elements provided by the Qt Declarative module \o \list \o \l MouseRegion -\o \l KeyActions \o \l FocusScope \o \l KeyProxy \endlist diff --git a/examples/declarative/snow/snow.qml b/examples/declarative/snow/snow.qml index aed426f..5dd0006 100644 --- a/examples/declarative/snow/snow.qml +++ b/examples/declarative/snow/snow.qml @@ -48,23 +48,22 @@ Rect { } Script { - function leftPressed() { + function left() { if (selectedItemColumn <= 0) return; selectedItemColumn -= 1; MyLayout.slowDeform = false; MyLayout.targetDeform = Math.max(Math.min(MyLayout.deform - 0.1, -0.1), -0.4); } - function rightPressed() { + function right() { selectedItemColumn += 1; MyLayout.slowDeform = false; MyLayout.targetDeform = Math.min(Math.max(MyLayout.deform + 0.1, 0.1), 0.4); } } - KeyActions { - focus: true - leftArrow: "leftPressed()" - rightArrow: "rightPressed()" - upArrow: "if (selectedItemRow > 0) selectedItemRow = selectedItemRow - 1" - downArrow: "if (selectedItemRow < 3) selectedItemRow = selectedItemRow + 1" - } + + focus: true + Keys.onLeftPressed: "left()" + Keys.onRightPressed: "right()" + Keys.onUpPressed: "if (selectedItemRow > 0) selectedItemRow = selectedItemRow - 1" + Keys.onDownPressed: "if (selectedItemRow < 3) selectedItemRow = selectedItemRow + 1" } diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index a6c5281..d2b97d6 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -15,7 +15,6 @@ HEADERS += \ fx/qfxitem.h \ fx/qfxitem_p.h \ fx/qfxfocusscope.h \ - fx/qfxkeyactions.h \ fx/qfxkeyproxy.h \ fx/qfxlayouts.h \ fx/qfxlayouts_p.h \ @@ -55,7 +54,6 @@ SOURCES += \ fx/qfxpainteditem.cpp \ fx/qfxitem.cpp \ fx/qfxfocusscope.cpp \ - fx/qfxkeyactions.cpp \ fx/qfxkeyproxy.cpp \ fx/qfxlayouts.cpp \ fx/qfxloader.cpp \ diff --git a/src/declarative/fx/qfxevents.cpp b/src/declarative/fx/qfxevents.cpp index f3a3427..b7b332e 100644 --- a/src/declarative/fx/qfxevents.cpp +++ b/src/declarative/fx/qfxevents.cpp @@ -51,14 +51,9 @@ QT_BEGIN_NAMESPACE \qml Item { focus: true - onKeyPress: { if (event.key == Qt.Key_Enter) state = 'ShowDetails'; } + Keys.onPressed: { if (event.key == Qt.Key_Enter) state = 'ShowDetails'; } } \endqml - - The \l KeyActions object could also be used to achieve the above with - a clearer syntax. - - \sa KeyActions */ /*! diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index f471ef2..7e755fb 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -1136,7 +1136,8 @@ void QFxGridView::keyPressEvent(QKeyEvent *event) } } d->moveReason = QFxGridViewPrivate::Other; - QFxFlickable::keyPressEvent(event); + if (!event->isAccepted()) + QFxFlickable::keyPressEvent(event); } /*! diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index b36e994..cae5c72 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -51,6 +51,7 @@ #include #include +#include #include "qmlstate.h" #include "qlistmodelinterface.h" @@ -219,6 +220,517 @@ void QFxContents::setItem(QFxItem *item) } /*! + \qmlclass Keys + \brief The Keys attached property provides key handling to Items. + + All visual primitives support key handling via the \e Keys + attached property. Keys can be handled via the \e onPressed + and \e onReleased signal properties. + + The signal properties have a \l KeyEvent parameter, named + \e event which contains details of the event. If a key is + handled \e event.accepted should be set to true to prevent the + event from propagating up the item heirarchy. + + \code + Item { + focus: true + Keys.onPressed: { + if (event.key == Qt.Key_Left) { + print("move left"); + event.accepted = true; + } + } + } + \endcode + + Some keys may alternatively be handled via specific signal properties, + for example \e onSelectPressed. These handlers automatically set + \e event.accepted to true. + + \code + Item { + focus: true + key.onLeftPressed: print("move left") + } + \endcode + + See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. + + \sa KeyEvent +*/ + +/*! + \qmlproperty bool Keys::enabled + + This flags enables key handling if true (default); otherwise + no key handlers will be called. +*/ + +/*! + \qmlsignal Keys::onPressed(event) + + This handler is called when a key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onReleased(event) + + This handler is called when a key has been released. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit0Pressed(event) + + This handler is called when the digit '0' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit1Pressed(event) + + This handler is called when the digit '1' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit2Pressed(event) + + This handler is called when the digit '2' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit3Pressed(event) + + This handler is called when the digit '3' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit4Pressed(event) + + This handler is called when the digit '4' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit5Pressed(event) + + This handler is called when the digit '5' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit6Pressed(event) + + This handler is called when the digit '6' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit7Pressed(event) + + This handler is called when the digit '7' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit8Pressed(event) + + This handler is called when the digit '8' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDigit9Pressed(event) + + This handler is called when the digit '9' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onLeftPressed(event) + + This handler is called when the Left arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onRightPressed(event) + + This handler is called when the Right arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onUpPressed(event) + + This handler is called when the Up arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDownPressed(event) + + This handler is called when the Down arrow has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onAsteriskPressed(event) + + This handler is called when the Asterisk '*' has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onEscapePressed(event) + + This handler is called when the Escape key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onReturnPressed(event) + + This handler is called when the Return key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onEnterPressed(event) + + This handler is called when the Enter key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onDeletePressed(event) + + This handler is called when the Delete key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onSpacePressed(event) + + This handler is called when the Space key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onBackPressed(event) + + This handler is called when the Back key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onCancelPressed(event) + + This handler is called when the Cancel key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onSelectPressed(event) + + This handler is called when the Select key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onYesPressed(event) + + This handler is called when the Yes key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onNoPressed(event) + + This handler is called when the No key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext1Pressed(event) + + This handler is called when the Context1 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext2Pressed(event) + + This handler is called when the Context2 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext3Pressed(event) + + This handler is called when the Context3 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onContext4Pressed(event) + + This handler is called when the Context4 key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onCallPressed(event) + + This handler is called when the Call key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onHangupPressed(event) + + This handler is called when the Hangup key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onFlipPressed(event) + + This handler is called when the Flip key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onMenuPressed(event) + + This handler is called when the Menu key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onVolumeUpPressed(event) + + This handler is called when the VolumeUp key has been pressed. The \a event + parameter provides information about the event. +*/ + +/*! + \qmlsignal Keys::onVolumeDownPressed(event) + + This handler is called when the VolumeDown key has been pressed. The \a event + parameter provides information about the event. +*/ + +class QFxKeysAttachedPrivate : public QObjectPrivate +{ +public: + QFxKeysAttachedPrivate() : QObjectPrivate(), enabled(true) {} + + bool isConnected(int idx); + + bool enabled; +}; + +class QFxKeysAttached : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QFxKeysAttached); + + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) +public: + QFxKeysAttached(QObject *parent=0); + ~QFxKeysAttached(); + + bool enabled() const { Q_D(const QFxKeysAttached); return d->enabled; } + void setEnabled(bool enabled) { + Q_D(QFxKeysAttached); + if (enabled != d->enabled) { + d->enabled = enabled; + emit enabledChanged(); + } + } + + static QFxKeysAttached *qmlAttachedProperties(QObject *); + +signals: + void enabledChanged(); + void pressed(QFxKeyEvent *event); + void released(QFxKeyEvent *event); + void digit0Pressed(QFxKeyEvent *event); + void digit1Pressed(QFxKeyEvent *event); + void digit2Pressed(QFxKeyEvent *event); + void digit3Pressed(QFxKeyEvent *event); + void digit4Pressed(QFxKeyEvent *event); + void digit5Pressed(QFxKeyEvent *event); + void digit6Pressed(QFxKeyEvent *event); + void digit7Pressed(QFxKeyEvent *event); + void digit8Pressed(QFxKeyEvent *event); + void digit9Pressed(QFxKeyEvent *event); + + void leftPressed(QFxKeyEvent *event); + void rightPressed(QFxKeyEvent *event); + void upPressed(QFxKeyEvent *event); + void downPressed(QFxKeyEvent *event); + + void asteriskPressed(QFxKeyEvent *event); + void escapePressed(QFxKeyEvent *event); + void returnPressed(QFxKeyEvent *event); + void enterPressed(QFxKeyEvent *event); + void deletePressed(QFxKeyEvent *event); + void spacePressed(QFxKeyEvent *event); + void backPressed(QFxKeyEvent *event); + void cancelPressed(QFxKeyEvent *event); + void selectPressed(QFxKeyEvent *event); + void yesPressed(QFxKeyEvent *event); + void noPressed(QFxKeyEvent *event); + void context1Pressed(QFxKeyEvent *event); + void context2Pressed(QFxKeyEvent *event); + void context3Pressed(QFxKeyEvent *event); + void context4Pressed(QFxKeyEvent *event); + void callPressed(QFxKeyEvent *event); + void hangupPressed(QFxKeyEvent *event); + void flipPressed(QFxKeyEvent *event); + void menuPressed(QFxKeyEvent *event); + void volumeUpPressed(QFxKeyEvent *event); + void volumeDownPressed(QFxKeyEvent *event); + +private: + void keyPressed(QKeyEvent *event); + void keyReleased(QKeyEvent *event); + + const char *keyToSignal(int key) { + QByteArray keySignal; + if (key >= Qt::Key_0 && key <= Qt::Key_9) { + keySignal = "digit0Pressed"; + keySignal[5] = '0' + (key - Qt::Key_0); + } else { + int i = 0; + while (sigMap[i].key && sigMap[i].key != key) + ++i; + keySignal = sigMap[i].sig; + } + return keySignal; + } + + struct SigMap { + int key; + const char *sig; + }; + + static const SigMap sigMap[]; + static QHash attachedProperties; + friend class QFxItem; +}; + +const QFxKeysAttached::SigMap QFxKeysAttached::sigMap[] = { + { Qt::Key_Left, "leftPressed" }, + { Qt::Key_Right, "rightPressed" }, + { Qt::Key_Up, "upPressed" }, + { Qt::Key_Down, "downPressed" }, + { Qt::Key_Asterisk, "asteriskPressed" }, + { Qt::Key_Escape, "escapePressed" }, + { Qt::Key_Return, "returnPressed" }, + { Qt::Key_Enter, "enterPressed" }, + { Qt::Key_Delete, "deletePressed" }, + { Qt::Key_Space, "spacePressed" }, + { Qt::Key_Back, "backPressed" }, + { Qt::Key_Cancel, "cancelPressed" }, + { Qt::Key_Select, "selectPressed" }, + { Qt::Key_Yes, "yesPressed" }, + { Qt::Key_No, "noPressed" }, + { Qt::Key_Context1, "context1Pressed" }, + { Qt::Key_Context2, "context2Pressed" }, + { Qt::Key_Context3, "context3Pressed" }, + { Qt::Key_Context4, "context4Pressed" }, + { Qt::Key_Call, "callPressed" }, + { Qt::Key_Hangup, "hangupPressed" }, + { Qt::Key_Flip, "flipPressed" }, + { Qt::Key_Menu, "menuPressed" }, + { Qt::Key_VolumeUp, "volumeUpPressed" }, + { Qt::Key_VolumeDown, "volumeDownPressed" }, + { 0, 0 } +}; + +QHash QFxKeysAttached::attachedProperties; + +bool QFxKeysAttachedPrivate::isConnected(int idx) +{ + if (idx < 32) { + quint32 mask = 1 << idx; + return connectedSignals[0] & mask; + } else if (idx < 64) { + quint32 mask = 1 << (idx-32); + return connectedSignals[1] & mask; + } + return false; +} + +QFxKeysAttached::QFxKeysAttached(QObject *parent) + : QObject(*(new QFxKeysAttachedPrivate), parent) +{ + if (QFxItem *item = qobject_cast(parent)) + item->setKeyHandler(this); +} + +QFxKeysAttached::~QFxKeysAttached() +{ + if (QFxItem *item = qobject_cast(parent())) + item->setKeyHandler(0); +} + +void QFxKeysAttached::keyPressed(QKeyEvent *event) +{ + Q_D(QFxKeysAttached); + if (!d->enabled) { + event->ignore(); + return; + } + + QFxKeyEvent ke(*event); + QByteArray keySignal = keyToSignal(event->key()); + if (!keySignal.isEmpty()) { + keySignal += "(QFxKeyEvent*)"; + int idx = QFxKeysAttached::staticMetaObject.indexOfSignal(keySignal); + if (d->isConnected(idx)) { + // If we specifically handle a key then default to accepted + ke.setAccepted(true); + metaObject()->method(idx).invoke(this, Q_ARG(QFxKeysAttached, &ke)); + } + } + if (!ke.isAccepted()) + emit pressed(&ke); + event->setAccepted(ke.isAccepted()); +} + +void QFxKeysAttached::keyReleased(QKeyEvent *event) +{ + Q_D(QFxKeysAttached); + if (!d->enabled) { + event->ignore(); + return; + } + QFxKeyEvent ke(*event); + emit released(&ke); + event->setAccepted(ke.isAccepted()); +} + +QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj) +{ + QFxKeysAttached *rv = attachedProperties.value(obj); + if (!rv) { + rv = new QFxKeysAttached(obj); + attachedProperties.insert(obj, rv); + } + return rv; +} + + +/*! \qmlclass Item QFxItem \brief The Item is the most basic of all visual items in QML. */ @@ -231,7 +743,7 @@ void QFxContents::setItem(QFxItem *item) All visual items in Qt Declarative inherit from QFxItem. Although QFxItem has no visual appearance, it defines all the properties that are common across visual items - like the x and y position, and the - width and height. + width and height. \l {Keys}{Key handling} is also provided by Item. QFxItem is also useful for grouping items together. @@ -255,6 +767,7 @@ void QFxContents::setItem(QFxItem *item) } } \endqml + \endqmltext \ingroup group_coreitems @@ -318,34 +831,6 @@ void QFxContents::setItem(QFxItem *item) */ /*! - \qmlsignal Item::onKeyPress(event) - - This handler is called when a key is pressed. - - The key event is available via the KeyEvent \a event. - - \qml - Item { - onKeyPress: { if (event.key == Qt.Key_Enter) state='Enter' } - } - \endqml -*/ - -/*! - \qmlsignal Item::onKeyRelease(event) - - This handler is called when a key is released. - - The key event is available in via the KeyEvent \a event. - - \qml - Item { - onKeyRelease: { if (event.key == Qt.Key_Enter) state='Enter' } - } - \endqml -*/ - -/*! \fn void QFxItem::parentChanged() This signal is emitted when the parent of the item changes. @@ -904,22 +1389,22 @@ void QFxItem::geometryChanged(const QRectF &newGeometry, } } -/*! \fn void QFxItem::keyPress(QFxKeyEvent *event) - This signal is emitted by keyPressEvent() for the \a event. - */ - -/*! \fn void QFxItem::keyRelease(QFxKeyEvent *event) - This signal is emitted by keyReleaseEvent() for the \a event. - */ +void QFxItem::setKeyHandler(QFxKeysAttached *handler) +{ + Q_D(QFxItem); + d->keyHandler = handler; +} /*! \reimp */ void QFxItem::keyPressEvent(QKeyEvent *event) { - QFxKeyEvent ke(*event); - emit keyPress(&ke); - event->setAccepted(ke.isAccepted()); + Q_D(QFxItem); + if (d->keyHandler) + d->keyHandler->keyPressed(event); + else + event->ignore(); } /*! @@ -927,9 +1412,11 @@ void QFxItem::keyPressEvent(QKeyEvent *event) */ void QFxItem::keyReleaseEvent(QKeyEvent *event) { - QFxKeyEvent ke(*event); - emit keyRelease(&ke); - event->setAccepted(ke.isAccepted()); + Q_D(QFxItem); + if (d->keyHandler) + d->keyHandler->keyReleased(event); + else + event->ignore(); } /*! @@ -1917,5 +2404,8 @@ QDebug operator<<(QDebug debug, QFxItem *item) QT_END_NAMESPACE -#include "moc_qfxitem.cpp" +QML_DECLARE_TYPE(QFxKeysAttached) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QFxKeysAttached) +#include "moc_qfxitem.cpp" +#include "qfxitem.moc" diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 3ba00cb..6c317f7 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -95,6 +95,7 @@ class QmlTransition; class QFxKeyEvent; class QFxAnchors; class QFxItemPrivate; +class QFxKeysAttached; class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserStatus { Q_OBJECT @@ -195,8 +196,6 @@ Q_SIGNALS: void focusChanged(); void activeFocusChanged(); void parentChanged(); - void keyPress(QFxKeyEvent *event); - void keyRelease(QFxKeyEvent *event); protected: bool isComponentComplete() const; @@ -234,10 +233,13 @@ private: QFxAnchorLine verticalCenter() const; QFxAnchorLine baseline() const; + void setKeyHandler(QFxKeysAttached *); + // ### move to d-pointer void init(QFxItem *parent); 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 08d173d..0e916b2 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -67,6 +67,7 @@ QT_BEGIN_NAMESPACE class QNetworkReply; +class QFxKeysAttached; class QFxItemPrivate : public QGraphicsItemPrivate { @@ -76,10 +77,12 @@ public: QFxItemPrivate() : _anchors(0), _contents(0), _baselineOffset(0), - _componentComplete(true), _keepMouse(false), _anchorLines(0), _stateGroup(0), origin(QFxItem::TopLeft), - widthValid(false), heightValid(false), width(0), height(0), smooth(false) + widthValid(false), heightValid(false), + _componentComplete(true), _keepMouse(false), + smooth(false), keyHandler(0), + width(0), height(0) {} ~QFxItemPrivate() { delete _anchors; } @@ -152,9 +155,6 @@ public: QmlNullableValue _baselineOffset; - bool _componentComplete:1; - bool _keepMouse:1; - struct AnchorLines { AnchorLines(QFxItem *); QFxAnchorLine left; @@ -179,10 +179,14 @@ public: QFxItem::TransformOrigin origin:4; bool widthValid:1; bool heightValid:1; + bool _componentComplete:1; + bool _keepMouse:1; + bool smooth:1; + + QFxKeysAttached *keyHandler; qreal width; qreal height; - bool smooth; QPointF computeTransformOrigin() const; diff --git a/src/declarative/fx/qfxkeyactions.cpp b/src/declarative/fx/qfxkeyactions.cpp deleted file mode 100644 index 186ab45..0000000 --- a/src/declarative/fx/qfxkeyactions.cpp +++ /dev/null @@ -1,921 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxkeyactions.h" -#include -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyActions,QFxKeyActions) - -class QFxKeyActionsPrivate -{ -public: - QFxKeyActionsPrivate(); - - bool enabled; - - uint keys1; - uint keys2; - - QHash actions; - - bool key(Qt::Key) const; - QString action(Qt::Key) const; - void setKey(Qt::Key, bool = true); - - bool testBit(int) const; - void setBit(int, bool); - - int keyToBit(Qt::Key) const; - - QString keyExpr(Qt::Key) const; - void setKeyExpr(Qt::Key, const QString &); -}; - -QFxKeyActionsPrivate::QFxKeyActionsPrivate() -: enabled(true), keys1(0), keys2(0) -{ -} - -int QFxKeyActionsPrivate::keyToBit(Qt::Key k) const -{ - if (k >= Qt::Key_A && k <= Qt::Key_Z ) { - return k - Qt::Key_A; - } else if (k >= Qt::Key_Left && k <= Qt::Key_Down) { - return 26 + k - Qt::Key_Left; - } else if (k >= Qt::Key_0 && k <= Qt::Key_9) { - return 30 + k - Qt::Key_0; - } else if (k >= Qt::Key_Context1 && k <= Qt::Key_Flip) { - return 40 + k - Qt::Key_Context1; - } else if (k >= Qt::Key_Select && k <= Qt::Key_No) { - return 47 + k - Qt::Key_Select; - } else { - const int start = 50; - switch(k) { - case Qt::Key_Escape: - return start + 0; - case Qt::Key_Return: - return start + 1; - case Qt::Key_Enter: - return start + 2; - case Qt::Key_Delete: - return start + 3; - case Qt::Key_Space: - return start + 4; - case Qt::Key_Back: - return start + 5; - case Qt::Key_unknown: - return start + 6; - case Qt::Key_Asterisk: - return start + 7; - default: - return -1; - } - } -} - -bool QFxKeyActionsPrivate::key(Qt::Key k) const -{ - int b = keyToBit(k); - bool rv = testBit(b); - if (!rv && k != Qt::Key_Shift) - rv = testBit(keyToBit(Qt::Key_unknown)); - return rv; -} - -QString QFxKeyActionsPrivate::action(Qt::Key k) const -{ - int b = keyToBit(k); - if (b != -1 && testBit(b)) - return actions.value(k); - else - return actions.value(Qt::Key_unknown); -} - -void QFxKeyActionsPrivate::setKey(Qt::Key k, bool v) -{ - int b = keyToBit(k); - if (b == -1) - return; - - setBit(b, v); -} - -bool QFxKeyActionsPrivate::testBit(int b) const -{ - if (b < 0) - return false; - - if (b < 32) - return keys1 & (1 << b); - else - return keys2 & (1 << (b - 32)); -} - -void QFxKeyActionsPrivate::setBit(int b, bool v) -{ - if (v) { - if (b < 32) - keys1 |= (1 << b); - else - keys2 |= (1 << (b - 32)); - } else { - if (b < 32) - keys1 &= ~(1 << b); - else - keys2 &= ~(1 << (b - 32)); - } -} - - -/*! - \qmlclass KeyActions - \brief The KeyActions item enables simple key handling. - \inherits Item - - KeyActions is typically used in basic key handling scenarios where writing - JavaScript key handling routines would be unnecessarily complicated. The - KeyActions item has a collection of properties that correspond to a - selection of common keys. When a given key is pressed, the item executes - the action script assigned to the matching property. If no action has - been set the KeyActions item does nothing. - - To receive (and susequently respond to) key presses, the KeyActions class - must be in the current focus chain, just like any other item. - - For basic mouse handling, see \l MouseRegion. - - KeyActions is an invisible item: it is never painted. -*/ -QFxKeyActions::QFxKeyActions(QFxItem *parent) -: QFxItem(parent), d(new QFxKeyActionsPrivate) -{ -} - -QFxKeyActions::~QFxKeyActions() -{ - delete d; -} - -QString QFxKeyActionsPrivate::keyExpr(Qt::Key k) const -{ - if (key(k)) - return actions.value(k); - else - return QString(); -} - -void QFxKeyActionsPrivate::setKeyExpr(Qt::Key k, const QString &expr) -{ - if (expr.isEmpty()) { - if (key(k)) { - actions.remove(k); - setKey(k, false); - } - } else { - actions.insert(k, expr); - setKey(k); - } -} - -/*! - \qmlproperty bool KeyActions::enabled - - Enables or disables KeyActions' key handling. When not enabled, the - KeyActions instance does not respond to any key presses. The item is - enabled by default. -*/ -bool QFxKeyActions::enabled() const -{ - return d->enabled; -} - -void QFxKeyActions::setEnabled(bool e) -{ - if (d->enabled == e) - return; - - d->enabled = e; - emit enabledChanged(); -} - -/*! - \qmlproperty string KeyActions::keyA...keyZ - - The action to take for the given letter. - - The following example sets actions for the 'c' and 'x' keys. - \qml - KeyActions { keyC: "print('c is for cookie')"; keyX: "print('I like cookies')" } - \endqml -*/ -QString QFxKeyActions::key_A() const -{ - return d->keyExpr(Qt::Key_A); -} - -void QFxKeyActions::setKey_A(const QString &s) -{ - d->setKeyExpr(Qt::Key_A, s); -} - -QString QFxKeyActions::key_B() const -{ - return d->keyExpr(Qt::Key_B); -} - -void QFxKeyActions::setKey_B(const QString &s) -{ - d->setKeyExpr(Qt::Key_B, s); -} - -QString QFxKeyActions::key_C() const -{ - return d->keyExpr(Qt::Key_C); -} - -void QFxKeyActions::setKey_C(const QString &s) -{ - d->setKeyExpr(Qt::Key_C, s); -} - -QString QFxKeyActions::key_D() const -{ - return d->keyExpr(Qt::Key_D); -} - -void QFxKeyActions::setKey_D(const QString &s) -{ - d->setKeyExpr(Qt::Key_D, s); -} - -QString QFxKeyActions::key_E() const -{ - return d->keyExpr(Qt::Key_E); -} - -void QFxKeyActions::setKey_E(const QString &s) -{ - d->setKeyExpr(Qt::Key_E, s); -} - -QString QFxKeyActions::key_F() const -{ - return d->keyExpr(Qt::Key_F); -} - -void QFxKeyActions::setKey_F(const QString &s) -{ - d->setKeyExpr(Qt::Key_F, s); -} - -QString QFxKeyActions::key_G() const -{ - return d->keyExpr(Qt::Key_G); -} - -void QFxKeyActions::setKey_G(const QString &s) -{ - d->setKeyExpr(Qt::Key_G, s); -} - -QString QFxKeyActions::key_H() const -{ - return d->keyExpr(Qt::Key_H); -} - -void QFxKeyActions::setKey_H(const QString &s) -{ - d->setKeyExpr(Qt::Key_H, s); -} - -QString QFxKeyActions::key_I() const -{ - return d->keyExpr(Qt::Key_I); -} - -void QFxKeyActions::setKey_I(const QString &s) -{ - d->setKeyExpr(Qt::Key_I, s); -} - -QString QFxKeyActions::key_J() const -{ - return d->keyExpr(Qt::Key_J); -} - -void QFxKeyActions::setKey_J(const QString &s) -{ - d->setKeyExpr(Qt::Key_J, s); -} - -QString QFxKeyActions::key_K() const -{ - return d->keyExpr(Qt::Key_K); -} - -void QFxKeyActions::setKey_K(const QString &s) -{ - d->setKeyExpr(Qt::Key_K, s); -} - -QString QFxKeyActions::key_L() const -{ - return d->keyExpr(Qt::Key_L); -} - -void QFxKeyActions::setKey_L(const QString &s) -{ - d->setKeyExpr(Qt::Key_L, s); -} - -QString QFxKeyActions::key_M() const -{ - return d->keyExpr(Qt::Key_M); -} - -void QFxKeyActions::setKey_M(const QString &s) -{ - d->setKeyExpr(Qt::Key_M, s); -} - -QString QFxKeyActions::key_N() const -{ - return d->keyExpr(Qt::Key_N); -} - -void QFxKeyActions::setKey_N(const QString &s) -{ - d->setKeyExpr(Qt::Key_N, s); -} - -QString QFxKeyActions::key_O() const -{ - return d->keyExpr(Qt::Key_O); -} - -void QFxKeyActions::setKey_O(const QString &s) -{ - d->setKeyExpr(Qt::Key_O, s); -} - -QString QFxKeyActions::key_P() const -{ - return d->keyExpr(Qt::Key_P); -} - -void QFxKeyActions::setKey_P(const QString &s) -{ - d->setKeyExpr(Qt::Key_P, s); -} - -QString QFxKeyActions::key_Q() const -{ - return d->keyExpr(Qt::Key_Q); -} - -void QFxKeyActions::setKey_Q(const QString &s) -{ - d->setKeyExpr(Qt::Key_Q, s); -} - -QString QFxKeyActions::key_R() const -{ - return d->keyExpr(Qt::Key_R); -} - -void QFxKeyActions::setKey_R(const QString &s) -{ - d->setKeyExpr(Qt::Key_R, s); -} - -QString QFxKeyActions::key_S() const -{ - return d->keyExpr(Qt::Key_S); -} - -void QFxKeyActions::setKey_S(const QString &s) -{ - d->setKeyExpr(Qt::Key_S, s); -} - -QString QFxKeyActions::key_T() const -{ - return d->keyExpr(Qt::Key_T); -} - -void QFxKeyActions::setKey_T(const QString &s) -{ - d->setKeyExpr(Qt::Key_T, s); -} - -QString QFxKeyActions::key_U() const -{ - return d->keyExpr(Qt::Key_U); -} - -void QFxKeyActions::setKey_U(const QString &s) -{ - d->setKeyExpr(Qt::Key_U, s); -} - -QString QFxKeyActions::key_V() const -{ - return d->keyExpr(Qt::Key_V); -} - -void QFxKeyActions::setKey_V(const QString &s) -{ - d->setKeyExpr(Qt::Key_V, s); -} - -QString QFxKeyActions::key_W() const -{ - return d->keyExpr(Qt::Key_W); -} - -void QFxKeyActions::setKey_W(const QString &s) -{ - d->setKeyExpr(Qt::Key_W, s); -} - -QString QFxKeyActions::key_X() const -{ - return d->keyExpr(Qt::Key_X); -} - -void QFxKeyActions::setKey_X(const QString &s) -{ - d->setKeyExpr(Qt::Key_X, s); -} - -QString QFxKeyActions::key_Y() const -{ - return d->keyExpr(Qt::Key_Y); -} - -void QFxKeyActions::setKey_Y(const QString &s) -{ - d->setKeyExpr(Qt::Key_Y, s); -} - -QString QFxKeyActions::key_Z() const -{ - return d->keyExpr(Qt::Key_Z); -} - -void QFxKeyActions::setKey_Z(const QString &s) -{ - d->setKeyExpr(Qt::Key_Z, s); -} - - -/*! - \qmlproperty string KeyActions::leftArrow - \qmlproperty string KeyActions::rightArrow - \qmlproperty string KeyActions::upArrow - \qmlproperty string KeyActions::downArrow - - The action to take for the given arrow key. - - The following example sets actions for the left and right arrow keys. - \qml - KeyActions { leftArrow: "print('You pressed left')"; rightArrow: "print('You pressed right')" } - \endqml -*/ - -QString QFxKeyActions::key_Left() const -{ - return d->keyExpr(Qt::Key_Left); -} - -void QFxKeyActions::setKey_Left(const QString &s) -{ - d->setKeyExpr(Qt::Key_Left, s); -} - -QString QFxKeyActions::key_Right() const -{ - return d->keyExpr(Qt::Key_Right); -} - -void QFxKeyActions::setKey_Right(const QString &s) -{ - d->setKeyExpr(Qt::Key_Right, s); -} - -QString QFxKeyActions::key_Up() const -{ - return d->keyExpr(Qt::Key_Up); -} - -void QFxKeyActions::setKey_Up(const QString &s) -{ - d->setKeyExpr(Qt::Key_Up, s); -} - -QString QFxKeyActions::key_Down() const -{ - return d->keyExpr(Qt::Key_Down); -} - -void QFxKeyActions::setKey_Down(const QString &s) -{ - d->setKeyExpr(Qt::Key_Down, s); -} - -/*! - \qmlproperty string KeyActions::digit0...digit9 - - The action to take for the given number key. - - The following example sets actions for the '5' and '6' keys. - \qml - KeyActions { digit5: "print('5 is a prime number')"; digit6: "print('6 is a composite number')"; focus: true } - \endqml -*/ - -QString QFxKeyActions::key_0() const -{ - return d->keyExpr(Qt::Key_0); -} - -void QFxKeyActions::setKey_0(const QString &s) -{ - d->setKeyExpr(Qt::Key_0, s); -} - -QString QFxKeyActions::key_1() const -{ - return d->keyExpr(Qt::Key_1); -} - -void QFxKeyActions::setKey_1(const QString &s) -{ - d->setKeyExpr(Qt::Key_1, s); -} - -QString QFxKeyActions::key_2() const -{ - return d->keyExpr(Qt::Key_2); -} - -void QFxKeyActions::setKey_2(const QString &s) -{ - d->setKeyExpr(Qt::Key_2, s); -} - -QString QFxKeyActions::key_3() const -{ - return d->keyExpr(Qt::Key_3); -} - -void QFxKeyActions::setKey_3(const QString &s) -{ - d->setKeyExpr(Qt::Key_3, s); -} - -QString QFxKeyActions::key_4() const -{ - return d->keyExpr(Qt::Key_4); -} - -void QFxKeyActions::setKey_4(const QString &s) -{ - d->setKeyExpr(Qt::Key_4, s); -} - -QString QFxKeyActions::key_5() const -{ - return d->keyExpr(Qt::Key_5); -} - -void QFxKeyActions::setKey_5(const QString &s) -{ - d->setKeyExpr(Qt::Key_5, s); -} - -QString QFxKeyActions::key_6() const -{ - return d->keyExpr(Qt::Key_6); -} - -void QFxKeyActions::setKey_6(const QString &s) -{ - d->setKeyExpr(Qt::Key_6, s); -} - -QString QFxKeyActions::key_7() const -{ - return d->keyExpr(Qt::Key_7); -} - -void QFxKeyActions::setKey_7(const QString &s) -{ - d->setKeyExpr(Qt::Key_7, s); -} - -QString QFxKeyActions::key_8() const -{ - return d->keyExpr(Qt::Key_8); -} - -void QFxKeyActions::setKey_8(const QString &s) -{ - d->setKeyExpr(Qt::Key_8, s); -} - -QString QFxKeyActions::key_9() const -{ - return d->keyExpr(Qt::Key_9); -} - -void QFxKeyActions::setKey_9(const QString &s) -{ - d->setKeyExpr(Qt::Key_9, s); -} - -QString QFxKeyActions::key_Asterisk() const -{ - return d->keyExpr(Qt::Key_Asterisk); -} - -void QFxKeyActions::setKey_Asterisk(const QString &s) -{ - d->setKeyExpr(Qt::Key_Asterisk, s); -} - -QString QFxKeyActions::key_Escape() const -{ - return d->keyExpr(Qt::Key_Escape); -} - -void QFxKeyActions::setKey_Escape(const QString &s) -{ - d->setKeyExpr(Qt::Key_Escape, s); -} - -QString QFxKeyActions::key_Return() const -{ - return d->keyExpr(Qt::Key_Return); -} - -void QFxKeyActions::setKey_Return(const QString &s) -{ - d->setKeyExpr(Qt::Key_Return, s); -} - -QString QFxKeyActions::key_Enter() const -{ - return d->keyExpr(Qt::Key_Enter); -} - -void QFxKeyActions::setKey_Enter(const QString &s) -{ - d->setKeyExpr(Qt::Key_Enter, s); -} - -QString QFxKeyActions::key_Delete() const -{ - return d->keyExpr(Qt::Key_Delete); -} - -void QFxKeyActions::setKey_Delete(const QString &s) -{ - d->setKeyExpr(Qt::Key_Delete, s); -} - -QString QFxKeyActions::key_Space() const -{ - return d->keyExpr(Qt::Key_Space); -} - -void QFxKeyActions::setKey_Space(const QString &s) -{ - d->setKeyExpr(Qt::Key_Space, s); -} - -/*! - \qmlproperty string KeyActions::escape - \qmlproperty string KeyActions::keyReturn - \qmlproperty string KeyActions::enter - \qmlproperty string KeyActions::delete - \qmlproperty string KeyActions::space - - The action to take for the given utility key. - - The following example sets an action for the space key. - \qml - KeyActions { space: "print('Space pressed')" } - \endqml -*/ - -/*! - \qmlproperty string KeyActions::back - \qmlproperty string KeyActions::select - \qmlproperty string KeyActions::yes - \qmlproperty string KeyActions::no - \qmlproperty string KeyActions::context1 - \qmlproperty string KeyActions::context2 - \qmlproperty string KeyActions::context3 - \qmlproperty string KeyActions::context4 - \qmlproperty string KeyActions::call - \qmlproperty string KeyActions::hangup - \qmlproperty string KeyActions::flip - - The action to take for the given device key. - - The following example sets an action for the hangup key. - \qml - KeyActions { hangup: "print('Go away now')" } - \endqml -*/ - -QString QFxKeyActions::key_Back() const -{ - return d->keyExpr(Qt::Key_Back); -} - -void QFxKeyActions::setKey_Back(const QString &s) -{ - d->setKeyExpr(Qt::Key_Back, s); -} - -QString QFxKeyActions::key_Select() const -{ - return d->keyExpr(Qt::Key_Select); -} - -void QFxKeyActions::setKey_Select(const QString &s) -{ - d->setKeyExpr(Qt::Key_Select, s); -} - -QString QFxKeyActions::key_Yes() const -{ - return d->keyExpr(Qt::Key_Yes); -} - -void QFxKeyActions::setKey_Yes(const QString &s) -{ - d->setKeyExpr(Qt::Key_Yes, s); -} - -QString QFxKeyActions::key_No() const -{ - return d->keyExpr(Qt::Key_No); -} - -void QFxKeyActions::setKey_No(const QString &s) -{ - d->setKeyExpr(Qt::Key_No, s); -} - -QString QFxKeyActions::key_Context1() const -{ - return d->keyExpr(Qt::Key_Context1); -} - -void QFxKeyActions::setKey_Context1(const QString &s) -{ - d->setKeyExpr(Qt::Key_Context1, s); -} - -QString QFxKeyActions::key_Context2() const -{ - return d->keyExpr(Qt::Key_Context2); -} - -void QFxKeyActions::setKey_Context2(const QString &s) -{ - d->setKeyExpr(Qt::Key_Context2, s); -} - -QString QFxKeyActions::key_Context3() const -{ - return d->keyExpr(Qt::Key_Context3); -} - -void QFxKeyActions::setKey_Context3(const QString &s) -{ - d->setKeyExpr(Qt::Key_Context3, s); -} - -QString QFxKeyActions::key_Context4() const -{ - return d->keyExpr(Qt::Key_Context4); -} - -void QFxKeyActions::setKey_Context4(const QString &s) -{ - d->setKeyExpr(Qt::Key_Context4, s); -} - -QString QFxKeyActions::key_Call() const -{ - return d->keyExpr(Qt::Key_Call); -} - -void QFxKeyActions::setKey_Call(const QString &s) -{ - d->setKeyExpr(Qt::Key_Call, s); -} - -QString QFxKeyActions::key_Hangup() const -{ - return d->keyExpr(Qt::Key_Hangup); -} - -void QFxKeyActions::setKey_Hangup(const QString &s) -{ - d->setKeyExpr(Qt::Key_Hangup, s); -} - -QString QFxKeyActions::key_Flip() const -{ - return d->keyExpr(Qt::Key_Flip); -} - -void QFxKeyActions::setKey_Flip(const QString &s) -{ - d->setKeyExpr(Qt::Key_Flip, s); -} - -/*! - \qmlproperty string KeyActions::any - - The action to take for any key not otherwise handled. -*/ -QString QFxKeyActions::key_Any() const -{ - return d->keyExpr(Qt::Key_unknown); -} - -void QFxKeyActions::setKey_Any(const QString &s) -{ - d->setKeyExpr(Qt::Key_unknown, s); -} - -void QFxKeyActions::keyPressEvent(QKeyEvent *event) -{ - Qt::Key key = (Qt::Key)event->key(); - if (d->enabled && d->key(key)) { - QmlExpression b(qmlContext(this), d->action(key), this); - b.setTrackChange(false); - b.value(); - event->accept(); - } else { - QFxItem::keyPressEvent(event); - } -} - -void QFxKeyActions::keyReleaseEvent(QKeyEvent *event) -{ - Qt::Key key = (Qt::Key)event->key(); - if (d->enabled && d->key(key)) { - event->accept(); - } else { - QFxItem::keyReleaseEvent(event); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxkeyactions.h b/src/declarative/fx/qfxkeyactions.h deleted file mode 100644 index d679d46..0000000 --- a/src/declarative/fx/qfxkeyactions.h +++ /dev/null @@ -1,319 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXKEYACTIONS_H -#define QFXKEYACTIONS_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QFxKeyActionsPrivate; -class Q_DECLARATIVE_EXPORT QFxKeyActions : public QFxItem -{ - Q_OBJECT - - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QString keyA READ key_A WRITE setKey_A) - Q_PROPERTY(QString keyB READ key_B WRITE setKey_B) - Q_PROPERTY(QString keyC READ key_C WRITE setKey_C) - Q_PROPERTY(QString keyD READ key_D WRITE setKey_D) - Q_PROPERTY(QString keyE READ key_E WRITE setKey_E) - Q_PROPERTY(QString keyF READ key_F WRITE setKey_F) - Q_PROPERTY(QString keyG READ key_G WRITE setKey_G) - Q_PROPERTY(QString keyH READ key_H WRITE setKey_H) - Q_PROPERTY(QString keyI READ key_I WRITE setKey_I) - Q_PROPERTY(QString keyJ READ key_J WRITE setKey_J) - Q_PROPERTY(QString keyK READ key_K WRITE setKey_K) - Q_PROPERTY(QString keyL READ key_L WRITE setKey_L) - Q_PROPERTY(QString keyM READ key_M WRITE setKey_M) - Q_PROPERTY(QString keyN READ key_N WRITE setKey_N) - Q_PROPERTY(QString keyO READ key_O WRITE setKey_O) - Q_PROPERTY(QString keyP READ key_P WRITE setKey_P) - Q_PROPERTY(QString keyQ READ key_Q WRITE setKey_Q) - Q_PROPERTY(QString keyR READ key_R WRITE setKey_R) - Q_PROPERTY(QString keyS READ key_S WRITE setKey_S) - Q_PROPERTY(QString keyT READ key_T WRITE setKey_T) - Q_PROPERTY(QString keyU READ key_U WRITE setKey_U) - Q_PROPERTY(QString keyV READ key_V WRITE setKey_V) - Q_PROPERTY(QString keyW READ key_W WRITE setKey_W) - Q_PROPERTY(QString keyX READ key_X WRITE setKey_X) - Q_PROPERTY(QString keyY READ key_Y WRITE setKey_Y) - Q_PROPERTY(QString keyZ READ key_Z WRITE setKey_Z) - Q_PROPERTY(QString leftArrow READ key_Left WRITE setKey_Left) - Q_PROPERTY(QString rightArrow READ key_Right WRITE setKey_Right) - Q_PROPERTY(QString upArrow READ key_Up WRITE setKey_Up) - Q_PROPERTY(QString downArrow READ key_Down WRITE setKey_Down) - Q_PROPERTY(QString digit0 READ key_0 WRITE setKey_0) - Q_PROPERTY(QString digit1 READ key_1 WRITE setKey_1) - Q_PROPERTY(QString digit2 READ key_2 WRITE setKey_2) - Q_PROPERTY(QString digit3 READ key_3 WRITE setKey_3) - Q_PROPERTY(QString digit4 READ key_4 WRITE setKey_4) - Q_PROPERTY(QString digit5 READ key_5 WRITE setKey_5) - Q_PROPERTY(QString digit6 READ key_6 WRITE setKey_6) - Q_PROPERTY(QString digit7 READ key_7 WRITE setKey_7) - Q_PROPERTY(QString digit8 READ key_8 WRITE setKey_8) - Q_PROPERTY(QString digit9 READ key_9 WRITE setKey_9) - Q_PROPERTY(QString asterisk READ key_Asterisk WRITE setKey_Asterisk) - Q_PROPERTY(QString escape READ key_Escape WRITE setKey_Escape) - Q_PROPERTY(QString keyReturn READ key_Return WRITE setKey_Return) - Q_PROPERTY(QString enter READ key_Enter WRITE setKey_Enter) - Q_PROPERTY(QString delete READ key_Delete WRITE setKey_Delete) - Q_PROPERTY(QString space READ key_Space WRITE setKey_Space) - Q_PROPERTY(QString back READ key_Back WRITE setKey_Back) - Q_PROPERTY(QString select READ key_Select WRITE setKey_Select) - Q_PROPERTY(QString yes READ key_Yes WRITE setKey_Yes) - Q_PROPERTY(QString no READ key_No WRITE setKey_No) - Q_PROPERTY(QString context1 READ key_Context1 WRITE setKey_Context1) - Q_PROPERTY(QString context2 READ key_Context2 WRITE setKey_Context2) - Q_PROPERTY(QString context3 READ key_Context3 WRITE setKey_Context3) - Q_PROPERTY(QString context4 READ key_Context4 WRITE setKey_Context4) - Q_PROPERTY(QString call READ key_Call WRITE setKey_Call) - Q_PROPERTY(QString hangup READ key_Hangup WRITE setKey_Hangup) - Q_PROPERTY(QString flip READ key_Flip WRITE setKey_Flip) - Q_PROPERTY(QString any READ key_Any WRITE setKey_Any) - -public: - QFxKeyActions(QFxItem *parent=0); - virtual ~QFxKeyActions(); - - bool enabled() const; - void setEnabled(bool); - - QString key_A() const; - void setKey_A(const QString &); - - QString key_B() const; - void setKey_B(const QString &); - - QString key_C() const; - void setKey_C(const QString &); - - QString key_D() const; - void setKey_D(const QString &); - - QString key_E() const; - void setKey_E(const QString &); - - QString key_F() const; - void setKey_F(const QString &); - - QString key_G() const; - void setKey_G(const QString &); - - QString key_H() const; - void setKey_H(const QString &); - - QString key_I() const; - void setKey_I(const QString &); - - QString key_J() const; - void setKey_J(const QString &); - - QString key_K() const; - void setKey_K(const QString &); - - QString key_L() const; - void setKey_L(const QString &); - - QString key_M() const; - void setKey_M(const QString &); - - QString key_N() const; - void setKey_N(const QString &); - - QString key_O() const; - void setKey_O(const QString &); - - QString key_P() const; - void setKey_P(const QString &); - - QString key_Q() const; - void setKey_Q(const QString &); - - QString key_R() const; - void setKey_R(const QString &); - - QString key_S() const; - void setKey_S(const QString &); - - QString key_T() const; - void setKey_T(const QString &); - - QString key_U() const; - void setKey_U(const QString &); - - QString key_V() const; - void setKey_V(const QString &); - - QString key_W() const; - void setKey_W(const QString &); - - QString key_X() const; - void setKey_X(const QString &); - - QString key_Y() const; - void setKey_Y(const QString &); - - QString key_Z() const; - void setKey_Z(const QString &); - - QString key_Left() const; - void setKey_Left(const QString &); - - QString key_Right() const; - void setKey_Right(const QString &); - - QString key_Up() const; - void setKey_Up(const QString &); - - QString key_Down() const; - void setKey_Down(const QString &); - - QString key_0() const; - void setKey_0(const QString &); - - QString key_1() const; - void setKey_1(const QString &); - - QString key_2() const; - void setKey_2(const QString &); - - QString key_3() const; - void setKey_3(const QString &); - - QString key_4() const; - void setKey_4(const QString &); - - QString key_5() const; - void setKey_5(const QString &); - - QString key_6() const; - void setKey_6(const QString &); - - QString key_7() const; - void setKey_7(const QString &); - - QString key_8() const; - void setKey_8(const QString &); - - QString key_9() const; - void setKey_9(const QString &); - - QString key_Asterisk() const; - void setKey_Asterisk(const QString &); - - QString key_Escape() const; - void setKey_Escape(const QString &); - - QString key_Return() const; - void setKey_Return(const QString &); - - QString key_Enter() const; - void setKey_Enter(const QString &); - - QString key_Delete() const; - void setKey_Delete(const QString &); - - QString key_Space() const; - void setKey_Space(const QString &); - - QString key_Back() const; - void setKey_Back(const QString &); - - QString key_Select() const; - void setKey_Select(const QString &); - - QString key_Yes() const; - void setKey_Yes(const QString &); - - QString key_No() const; - void setKey_No(const QString &); - - QString key_Context1() const; - void setKey_Context1(const QString &); - - QString key_Context2() const; - void setKey_Context2(const QString &); - - QString key_Context3() const; - void setKey_Context3(const QString &); - - QString key_Context4() const; - void setKey_Context4(const QString &); - - QString key_Call() const; - void setKey_Call(const QString &); - - QString key_Hangup() const; - void setKey_Hangup(const QString &); - - QString key_Flip() const; - void setKey_Flip(const QString &); - - QString key_Any() const; - void setKey_Any(const QString &); - - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); - -Q_SIGNALS: - void enabledChanged(); - -private: - Q_DISABLE_COPY(QFxKeyActions) - QFxKeyActionsPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxKeyActions) - -QT_END_HEADER - -#endif // QFXKEYACTIONS_H diff --git a/src/declarative/fx/qfxlineedit.cpp b/src/declarative/fx/qfxlineedit.cpp index 13267f2..0bb93b6 100644 --- a/src/declarative/fx/qfxlineedit.cpp +++ b/src/declarative/fx/qfxlineedit.cpp @@ -417,6 +417,8 @@ void QFxLineEdit::keyPressEvent(QKeyEvent* ev) { Q_D(QFxLineEdit); d->control->processKeyEvent(ev); + if (!ev->isAccepted()) + QFxPaintedItem::keyPressEvent(ev); } void QFxLineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 860e9e4..9e08b69 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1362,7 +1362,8 @@ void QFxListView::keyPressEvent(QKeyEvent *event) } } d->moveReason = QFxListViewPrivate::Other; - QFxFlickable::keyPressEvent(event); + if (!event->isAccepted()) + QFxFlickable::keyPressEvent(event); } void QFxListView::componentComplete() diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index e4001b2..85e0a5a 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -836,13 +836,6 @@ Handles the given key \a event. void QFxTextEdit::keyPressEvent(QKeyEvent *event) { Q_D(QFxTextEdit); - //### experiment with allowing 'overrides' to key events - QFxKeyEvent ke(*event); - emit keyPress(&ke); - event->setAccepted(ke.isAccepted()); - if (event->isAccepted()) - return; - //### this causes non-standard cursor behavior in some cases. // is it still needed? /*QTextCursor c = textCursor(); @@ -865,6 +858,9 @@ void QFxTextEdit::keyPressEvent(QKeyEvent *event) event->ignore(); else*/ d->control->processEvent(event, QPointF(0, 0)); + + if (!event->isAccepted()) + QFxPaintedItem::keyPressEvent(event); } /*! @@ -874,14 +870,9 @@ Handles the given key \a event. void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) { Q_D(QFxTextEdit); - //### experiment with allowing 'overrides' to key events - QFxKeyEvent ke(*event); - emit keyRelease(&ke); - event->setAccepted(ke.isAccepted()); - if (event->isAccepted()) - return; - d->control->processEvent(event, QPointF(0, 0)); + if (!event->isAccepted()) + QFxPaintedItem::keyReleaseEvent(event); } /*! -- cgit v0.12