diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-05-12 12:51:15 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-05-12 12:51:15 (GMT) |
commit | 90d801f05f64c645f0899e3d81b23ecf53bf4835 (patch) | |
tree | 14362a48f6c74709972ab1a92d7be81d910f788d /src/gui | |
parent | 1898c46452beae9e28cf9be7851099b4b4d2779e (diff) | |
parent | c6add575d50ee30b19580fc2c1ebda5316a2f51b (diff) | |
download | Qt-90d801f05f64c645f0899e3d81b23ecf53bf4835.zip Qt-90d801f05f64c645f0899e3d81b23ecf53bf4835.tar.gz Qt-90d801f05f64c645f0899e3d81b23ecf53bf4835.tar.bz2 |
Merge branch 'kinetic-statemachine' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-statemachine
Conflicts:
src/gui/graphicsview/qgraphicsitem.cpp
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/animation/animation.pri | 7 | ||||
-rw-r--r-- | src/gui/animation/qguivariantanimation.cpp (renamed from src/gui/animation/qitemanimation_p.h) | 57 | ||||
-rw-r--r-- | src/gui/animation/qitemanimation.cpp | 361 | ||||
-rw-r--r-- | src/gui/animation/qitemanimation.h | 111 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 2 | ||||
-rw-r--r-- | src/gui/statemachine/qbasickeyeventtransition.cpp | 29 | ||||
-rw-r--r-- | src/gui/statemachine/qbasickeyeventtransition_p.h | 9 | ||||
-rw-r--r-- | src/gui/statemachine/qbasicmouseeventtransition.cpp | 24 | ||||
-rw-r--r-- | src/gui/statemachine/qbasicmouseeventtransition_p.h | 5 | ||||
-rw-r--r-- | src/gui/statemachine/qkeyeventtransition.cpp | 44 | ||||
-rw-r--r-- | src/gui/statemachine/qkeyeventtransition.h | 8 | ||||
-rw-r--r-- | src/gui/statemachine/qmouseeventtransition.cpp | 57 | ||||
-rw-r--r-- | src/gui/statemachine/qmouseeventtransition.h | 8 | ||||
-rw-r--r-- | src/gui/statemachine/statemachine.pri | 3 |
14 files changed, 154 insertions, 571 deletions
diff --git a/src/gui/animation/animation.pri b/src/gui/animation/animation.pri index 3092117..27763ca 100644 --- a/src/gui/animation/animation.pri +++ b/src/gui/animation/animation.pri @@ -1,8 +1,3 @@ # Qt gui animation module -HEADERS += \ - animation/qitemanimation.h \ - animation/qitemanimation_p.h - -SOURCES += \ - animation/qitemanimation.cpp +SOURCES += animation/qguivariantanimation.cpp diff --git a/src/gui/animation/qitemanimation_p.h b/src/gui/animation/qguivariantanimation.cpp index 027c199..ed18caa 100644 --- a/src/gui/animation/qitemanimation_p.h +++ b/src/gui/animation/qguivariantanimation.cpp @@ -39,45 +39,42 @@ ** ****************************************************************************/ -#ifndef QITEMANIMATION_P_H -#define QITEMANIMATION_P_H +#ifndef QT_NO_ANIMATION -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of QIODevice. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qitemanimation.h" - -#if defined(QT_EXPERIMENTAL_SOLUTION) -#include "qvariantanimation_p.h" +#ifdef QT_EXPERIMENTAL_SOLUTION +# include "qvariantanimation.h" +# include "qvariantanimation_p.h" #else -#include "private/qvariantanimation_p.h" +#include <QtCore/qvariantanimation.h> +#include <private/qvariantanimation_p.h> #endif +#include <QtGui/qcolor.h> + QT_BEGIN_NAMESPACE -class QItemAnimationPrivate : public QVariantAnimationPrivate +template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress) { - Q_DECLARE_PUBLIC(QItemAnimation) -public: - QItemAnimationPrivate() : propertyName(QItemAnimation::None), - target(0) - { - } + return QColor(_q_interpolate(f.red(), t.red(), progress), + _q_interpolate(f.green(), t.green(), progress), + _q_interpolate(f.blue(), t.blue(), progress), + _q_interpolate(f.alpha(), t.alpha(), progress)); +} - void initDefaultStartValue(); +static int qRegisterGuiGetInterpolator() +{ + qRegisterAnimationInterpolator<QColor>(_q_interpolateVariant<QColor>); + return 1; +} +Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator) - QItemAnimation::PropertyName propertyName; - QGraphicsItem *target; -}; +static int qUnregisterGuiGetInterpolator() +{ + qRegisterAnimationInterpolator<QColor>(0); + return 1; +} +Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) QT_END_NAMESPACE -#endif //QITEMANIMATION_P_H +#endif //QT_NO_ANIMATION diff --git a/src/gui/animation/qitemanimation.cpp b/src/gui/animation/qitemanimation.cpp deleted file mode 100644 index 484b386..0000000 --- a/src/gui/animation/qitemanimation.cpp +++ /dev/null @@ -1,361 +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 QtGui 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$ -** -****************************************************************************/ - -/*! - \class QItemAnimation - \brief The QItemAnimation class animates properties for QGraphicsItem - \since 4.5 - \ingroup animation - \preliminary - - This class is part of {The Animation Framework}. You can use QItemAnimation - by itself as a simple animation class, or as part of more complex - animations through QAnimationGroup. - - The most common way to use QItemAnimation is to construct an instance - of it by passing a pointer to a QGraphicsItem and the property you - would like to animate to QItemAnimation's constructor. - - The start value of the animation is optional. If you do not set any start - value, the animation will operate on the target's current property value - at the point when the animation was started. You can call setStartValue() - to set the start value, and setEndValue() to set the target value for - the animated property. - - You can choose to assign a target item by either calling setTargetItem() - or by passing a QGraphicsItem pointer to QVariantAnimation's constructor. - - \sa QVariantAnimation, QAnimationGroup, {The Animation Framework} -*/ - - -#ifndef QT_NO_ANIMATION - -#include "qitemanimation.h" -#include "qitemanimation_p.h" - -#include <QtCore/QMutex> -#ifdef QT_EXPERIMENTAL_SOLUTION -#include "qanimationgroup.h" -#else -#include <QtCore/QAnimationGroup> -#endif -#include <QtGui/QGraphicsItem> - - -QT_BEGIN_NAMESPACE - -typedef QPair<QGraphicsItem *, QItemAnimation::PropertyName> QItemAnimationPair; -typedef QHash<QItemAnimationPair, QItemAnimation*> QItemAnimationHash; -Q_GLOBAL_STATIC(QItemAnimationHash, _q_runningAnimations) -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, guardHashLock, (QMutex::Recursive) ) - -void QItemAnimationPrivate::initDefaultStartValue() -{ - if (target && !defaultStartValue.isValid() && (atBeginning() || atEnd())) { - switch (propertyName) - { - case QItemAnimation::Position: - setDefaultStartValue(target->pos()); - break; - case QItemAnimation::Opacity: - setDefaultStartValue(target->opacity()); - break; - case QItemAnimation::RotationX: - setDefaultStartValue(target->xRotation()); - break; - case QItemAnimation::RotationY: - setDefaultStartValue(target->yRotation()); - break; - case QItemAnimation::RotationZ: - setDefaultStartValue(target->zRotation()); - break; - case QItemAnimation::ScaleFactorX: - setDefaultStartValue(target->xScale()); - break; - case QItemAnimation::ScaleFactorY: - setDefaultStartValue(target->yScale()); - break; - default: - break; - } - } -} - - -/*! - Construct a QItemAnimation object. \a parent is passed to QObject's - constructor. -*/ - -QItemAnimation::QItemAnimation(QObject *parent) : QVariantAnimation(*new QItemAnimationPrivate, parent) -{ -} - -/*! - Construct a QItemAnimation object. \a parent is passed to QObject's - constructor. The animation changes the property \a propertyName on \a - target. The default duration is 250ms. - - \sa targetItem, propertyName -*/ - -QItemAnimation::QItemAnimation(QGraphicsItem *target, PropertyName p, QObject *parent) : QVariantAnimation(*new QItemAnimationPrivate, parent) -{ - Q_D(QItemAnimation); - d->target = target; - d->propertyName = p; -} - -/*! - Destroys the QPropertyAnimation instance. - */ -QItemAnimation::~QItemAnimation() -{ - stop(); -} - -/*! - \property QItemAnimation::targetItem - \brief the target Graphics Item for this animation. - - This property defines the target item for this animation. - - \sa targetItem - */ - -QGraphicsItem *QItemAnimation::targetItem() const -{ - Q_D(const QItemAnimation); - return d->target; -} - -void QItemAnimation::setTargetItem(QGraphicsItem *item) -{ - Q_D(QItemAnimation); - d->target = item; -} - -/*! - \property QItemAnimation::propertyName - \brief the target property for this animation - - This property defines the target property for this animation. The - property is required for the animation to operate. - */ -QItemAnimation::PropertyName QItemAnimation::propertyName() const -{ - Q_D(const QItemAnimation); - return d->propertyName; -} - -void QItemAnimation::setPropertyName(PropertyName p) -{ - Q_D(QItemAnimation); - d->propertyName = p; -} - -/*! - This static function returns the list of running animations on \a item. - If item is 0, then it returns all QItemAnimations running on all QGraphicsItem. - */ -QList<QItemAnimation*> QItemAnimation::runningAnimations(QGraphicsItem *item) -{ - QMutexLocker locker(guardHashLock()); - QList<QItemAnimation*> animList = _q_runningAnimations()->values(); - if (item == 0) - return animList; - - QList<QItemAnimation*> ret; - - for (QList<QItemAnimation*>::const_iterator it = animList.constBegin(); it != animList.constEnd(); ++it) { - if ((*it)->targetItem() == item) - ret += *it; - } - - return ret; -} - -/*! - This static function returns the running animations on \a item and on \a property. - \a prop. - */ -QItemAnimation* QItemAnimation::runningAnimation(QGraphicsItem *item, PropertyName prop) -{ - QMutexLocker locker(guardHashLock()); - return _q_runningAnimations()->value(qMakePair(item, prop), 0 /*default value*/); -} - -/*! - \reimp - */ -bool QItemAnimation::event(QEvent *event) -{ - return QVariantAnimation::event(event); -} - -/*! - \reimp - */ -void QItemAnimation::updateCurrentValue(const QVariant &value) -{ - Q_D(QItemAnimation); - if (!d->target || d->state == Stopped) - return; - - switch (d->propertyName) - { - case Position: - d->target->setPos(qVariantValue<QPointF>(value)); - break; - case Opacity: - d->target->setOpacity(qVariantValue<qreal>(value)); - break; - case RotationX: - d->target->setXRotation(qVariantValue<qreal>(value)); - break; - case RotationY: - d->target->setYRotation(qVariantValue<qreal>(value)); - break; - case RotationZ: - d->target->setZRotation(qVariantValue<qreal>(value)); - break; - case ScaleFactorX: - d->target->setXScale(qVariantValue<qreal>(value)); - break; - case ScaleFactorY: - d->target->setYScale(qVariantValue<qreal>(value)); - break; - default: - qWarning("The property you're trying to animate is not managed by the item"); - break; - } -} - - -/*! - \reimp -*/ -void QItemAnimation::updateState(QAbstractAnimation::State oldState, - QAbstractAnimation::State newState) -{ - Q_D(QItemAnimation); - QVariantAnimation::updateState(oldState, newState); - QMutexLocker locker(guardHashLock()); - QItemAnimationHash *hash = _q_runningAnimations(); - QItemAnimationPair key(d->target, d->propertyName); - - //let's try to convert start and target values according to the type of the proerty - //we're animating - if (newState != Stopped) { - int type = QVariant::Invalid; - switch (d->propertyName) - { - case Position: - type = QVariant::PointF; - break; - case Opacity: - case RotationX: - case RotationY: - case RotationZ: - case ScaleFactorX: - case ScaleFactorY: - type = qMetaTypeId<qreal>(); - break; - case None: - default: - break; - - } - if (type != QVariant::Invalid) { - d->convertValues(type); - } - } - - if (newState == Running) { - if (hash->contains(key)) { - QItemAnimation *oldAnim = hash->value(key); - if (oldAnim != this) { - //we try to stop the top level group - QAbstractAnimation *current = oldAnim; - while(current->group() && current->state() != Stopped) current = current->group(); - current->stop(); - } - } - hash->insert(key, this); - // Initialize start value - d->initDefaultStartValue(); - - } else if (hash->value(key) == this) { - hash->remove(key); - } -} - -///TODO: should be placed somewhere else (in its own file) -template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress) -{ - return QColor(_q_interpolate(f.red(), t.red(), progress), - _q_interpolate(f.green(), t.green(), progress), - _q_interpolate(f.blue(), t.blue(), progress), - _q_interpolate(f.alpha(), t.alpha(), progress)); -} - - - -static int qRegisterGuiGetInterpolator() -{ - qRegisterAnimationInterpolator<QColor>(_q_interpolateVariant<QColor>); - return 1; -} -Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator) - -static int qUnregisterGuiGetInterpolator() -{ - qRegisterAnimationInterpolator<QColor>(0); - return 1; -} -Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) - -QT_END_NAMESPACE - -#include "moc_qitemanimation.cpp" - -#endif //QT_NO_ANIMATION diff --git a/src/gui/animation/qitemanimation.h b/src/gui/animation/qitemanimation.h deleted file mode 100644 index d630fe7..0000000 --- a/src/gui/animation/qitemanimation.h +++ /dev/null @@ -1,111 +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 QtGui 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 QITEMANIMATION_H -#define QITEMANIMATION_H - -#if defined(QT_EXPERIMENTAL_SOLUTION) -# include "qvariantanimation.h" -#else -# include <QtCore/qvariantanimation.h> -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_ANIMATION - -class QGraphicsItem; - -class QItemAnimationPrivate; -class Q_GUI_EXPORT QItemAnimation : public QVariantAnimation -{ -public: - enum PropertyName - { - None, //default - Position, - Opacity, - RotationX, - RotationY, - RotationZ, - ScaleFactorX, - ScaleFactorY - }; - - Q_OBJECT - Q_PROPERTY(PropertyName propertyName READ propertyName WRITE setPropertyName) - Q_PROPERTY(QGraphicsItem* targetItem READ targetItem WRITE setTargetItem) /*NOTIFY targetItemChanged*/ - -public: - QItemAnimation(QObject *parent = 0); - QItemAnimation(QGraphicsItem *target, PropertyName p = None, QObject *parent = 0); - ~QItemAnimation(); - - QGraphicsItem *targetItem() const; - void setTargetItem(QGraphicsItem *item); - - PropertyName propertyName() const; - void setPropertyName(PropertyName); - - static QList<QItemAnimation*> runningAnimations(QGraphicsItem *item = 0); - static QItemAnimation* runningAnimation(QGraphicsItem *item, PropertyName prop); - -protected: - bool event(QEvent *event); - void updateCurrentValue(const QVariant &value); - void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); - -private: - Q_DISABLE_COPY(QItemAnimation) - Q_DECLARE_PRIVATE(QItemAnimation) -}; - -#endif //QT_NO_ANIMATION - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif //QITEMANIMATION_H diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 201dfb8..5ff2acf 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2790,7 +2790,7 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine) if (oldTransform == newTransform) return; - // Notify the item that the matrix is changing. + // Notify the item that the transformation matrix is changing. QVariant newTransformVariant(itemChange(ItemMatrixChange, qVariantFromValue<QMatrix>(newTransform.toAffine()))); newTransform = QTransform(qVariantValue<QMatrix>(newTransformVariant)); diff --git a/src/gui/statemachine/qbasickeyeventtransition.cpp b/src/gui/statemachine/qbasickeyeventtransition.cpp index 2ce428c..7821feb 100644 --- a/src/gui/statemachine/qbasickeyeventtransition.cpp +++ b/src/gui/statemachine/qbasickeyeventtransition.cpp @@ -39,14 +39,14 @@ public: QEvent::Type eventType; int key; - Qt::KeyboardModifiers modifiers; + Qt::KeyboardModifiers modifiersMask; }; QBasicKeyEventTransitionPrivate::QBasicKeyEventTransitionPrivate() { eventType = QEvent::None; key = 0; - modifiers = Qt::NoModifier; + modifiersMask = Qt::NoModifier; } QBasicKeyEventTransitionPrivate *QBasicKeyEventTransitionPrivate::get(QBasicKeyEventTransition *q) @@ -77,17 +77,17 @@ QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key, /*! Constructs a new event transition for events of the given \a type for the - given \a key, with the given \a modifiers and \a sourceState. + given \a key, with the given \a modifiersMask and \a sourceState. */ QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key, - Qt::KeyboardModifiers modifiers, + Qt::KeyboardModifiers modifiersMask, QState *sourceState) : QAbstractTransition(*new QBasicKeyEventTransitionPrivate, sourceState) { Q_D(QBasicKeyEventTransition); d->eventType = type; d->key = key; - d->modifiers = modifiers; + d->modifiersMask = modifiersMask; } /*! @@ -134,21 +134,23 @@ void QBasicKeyEventTransition::setKey(int key) } /*! - Returns the keyboard modifiers that this key event transition checks for. + Returns the keyboard modifiers mask that this key event transition checks + for. */ -Qt::KeyboardModifiers QBasicKeyEventTransition::modifiers() const +Qt::KeyboardModifiers QBasicKeyEventTransition::modifiersMask() const { Q_D(const QBasicKeyEventTransition); - return d->modifiers; + return d->modifiersMask; } /*! - Sets the keyboard modifiers that this key event transition will check for. + Sets the keyboard modifiers mask that this key event transition will check + for. */ -void QBasicKeyEventTransition::setModifiers(Qt::KeyboardModifiers modifiers) +void QBasicKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) { Q_D(QBasicKeyEventTransition); - d->modifiers = modifiers; + d->modifiersMask = modifiersMask; } /*! @@ -159,7 +161,8 @@ bool QBasicKeyEventTransition::eventTest(QEvent *event) const Q_D(const QBasicKeyEventTransition); if (event->type() == d->eventType) { QKeyEvent *ke = static_cast<QKeyEvent*>(event); - return (ke->key() == d->key) && (ke->modifiers() == d->modifiers); + return (ke->key() == d->key) + && ((ke->modifiers() & d->modifiersMask) == d->modifiersMask); } return false; } @@ -167,7 +170,7 @@ bool QBasicKeyEventTransition::eventTest(QEvent *event) const /*! \reimp */ -void QBasicKeyEventTransition::onTransition() +void QBasicKeyEventTransition::onTransition(QEvent *) { } diff --git a/src/gui/statemachine/qbasickeyeventtransition_p.h b/src/gui/statemachine/qbasickeyeventtransition_p.h index ff52f4d..0d08da0 100644 --- a/src/gui/statemachine/qbasickeyeventtransition_p.h +++ b/src/gui/statemachine/qbasickeyeventtransition_p.h @@ -41,7 +41,8 @@ public: QBasicKeyEventTransition(QState *sourceState = 0); QBasicKeyEventTransition(QEvent::Type type, int key, QState *sourceState = 0); QBasicKeyEventTransition(QEvent::Type type, int key, - Qt::KeyboardModifiers modifiers, QState *sourceState = 0); + Qt::KeyboardModifiers modifiersMask, + QState *sourceState = 0); ~QBasicKeyEventTransition(); QEvent::Type eventType() const; @@ -50,12 +51,12 @@ public: int key() const; void setKey(int key); - Qt::KeyboardModifiers modifiers() const; - void setModifiers(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifiersMask() const; + void setModifiersMask(Qt::KeyboardModifiers modifiers); protected: bool eventTest(QEvent *event) const; - void onTransition(); + void onTransition(QEvent *); private: Q_DISABLE_COPY(QBasicKeyEventTransition) diff --git a/src/gui/statemachine/qbasicmouseeventtransition.cpp b/src/gui/statemachine/qbasicmouseeventtransition.cpp index b7583f8..0cb727e 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition.cpp +++ b/src/gui/statemachine/qbasicmouseeventtransition.cpp @@ -39,6 +39,7 @@ public: QEvent::Type eventType; Qt::MouseButton button; + Qt::KeyboardModifiers modifiersMask; QPainterPath path; }; @@ -118,6 +119,26 @@ void QBasicMouseEventTransition::setButton(Qt::MouseButton button) } /*! + Returns the keyboard modifiers mask that this mouse event transition checks + for. +*/ +Qt::KeyboardModifiers QBasicMouseEventTransition::modifiersMask() const +{ + Q_D(const QBasicMouseEventTransition); + return d->modifiersMask; +} + +/*! + Sets the keyboard modifiers mask that this mouse event transition will check + for. +*/ +void QBasicMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +{ + Q_D(QBasicMouseEventTransition); + d->modifiersMask = modifiersMask; +} + +/*! Returns the path for this mouse event transition. */ QPainterPath QBasicMouseEventTransition::path() const @@ -144,6 +165,7 @@ bool QBasicMouseEventTransition::eventTest(QEvent *event) const if (event->type() == d->eventType) { QMouseEvent *me = static_cast<QMouseEvent*>(event); return (me->button() == d->button) + && ((me->modifiers() & d->modifiersMask) == d->modifiersMask) && (d->path.isEmpty() || d->path.contains(me->pos())); } return false; @@ -152,7 +174,7 @@ bool QBasicMouseEventTransition::eventTest(QEvent *event) const /*! \reimp */ -void QBasicMouseEventTransition::onTransition() +void QBasicMouseEventTransition::onTransition(QEvent *) { } diff --git a/src/gui/statemachine/qbasicmouseeventtransition_p.h b/src/gui/statemachine/qbasicmouseeventtransition_p.h index ee04fc7..20c7f8f 100644 --- a/src/gui/statemachine/qbasicmouseeventtransition_p.h +++ b/src/gui/statemachine/qbasicmouseeventtransition_p.h @@ -51,12 +51,15 @@ public: Qt::MouseButton button() const; void setButton(Qt::MouseButton button); + Qt::KeyboardModifiers modifiersMask() const; + void setModifiersMask(Qt::KeyboardModifiers modifiers); + QPainterPath path() const; void setPath(const QPainterPath &path); protected: bool eventTest(QEvent *event) const; - void onTransition(); + void onTransition(QEvent *); private: Q_DISABLE_COPY(QBasicMouseEventTransition) diff --git a/src/gui/statemachine/qkeyeventtransition.cpp b/src/gui/statemachine/qkeyeventtransition.cpp index a4e882d..e6ab11b 100644 --- a/src/gui/statemachine/qkeyeventtransition.cpp +++ b/src/gui/statemachine/qkeyeventtransition.cpp @@ -11,6 +11,7 @@ #include "qkeyeventtransition.h" #include "qbasickeyeventtransition_p.h" +#include <QtCore/qwrappedevent.h> #if defined(QT_EXPERIMENTAL_SOLUTION) # include "qeventtransition_p.h" @@ -25,6 +26,7 @@ QT_BEGIN_NAMESPACE \brief The QKeyEventTransition class provides a transition for key events. + \since 4.6 \ingroup statemachine QKeyEventTransition is part of \l{The State Machine Framework}. @@ -38,6 +40,12 @@ QT_BEGIN_NAMESPACE \brief the key that this key event transition is associated with */ +/*! + \property QKeyEventTransition::modifiersMask + + \brief the keyboard modifiers mask that this key event transition checks for +*/ + class QKeyEventTransitionPrivate : public QEventTransitionPrivate { Q_DECLARE_PUBLIC(QKeyEventTransition) @@ -110,32 +118,23 @@ void QKeyEventTransition::setKey(int key) } /*! - Returns the keyboard modifiers that this key event transition checks for. + Returns the keyboard modifiers mask that this key event transition checks + for. */ -Qt::KeyboardModifiers QKeyEventTransition::modifiers() const +Qt::KeyboardModifiers QKeyEventTransition::modifiersMask() const { Q_D(const QKeyEventTransition); - return d->transition->modifiers(); + return d->transition->modifiersMask(); } /*! - Sets the keyboard \a modifiers that this key event transition will check - for. + Sets the keyboard \a modifiers mask that this key event transition will + check for. */ -void QKeyEventTransition::setModifiers(Qt::KeyboardModifiers modifiers) +void QKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) { Q_D(QKeyEventTransition); - d->transition->setModifiers(modifiers); -} - -/*! - \reimp -*/ -bool QKeyEventTransition::testEventCondition(QEvent *event) const -{ - Q_D(const QKeyEventTransition); - d->transition->setEventType(event->type()); - return QAbstractTransitionPrivate::get(d->transition)->callEventTest(event); + d->transition->setModifiersMask(modifiersMask); } /*! @@ -143,15 +142,20 @@ bool QKeyEventTransition::testEventCondition(QEvent *event) const */ bool QKeyEventTransition::eventTest(QEvent *event) const { - return QEventTransition::eventTest(event); + Q_D(const QKeyEventTransition); + if (!QEventTransition::eventTest(event)) + return false; + QWrappedEvent *we = static_cast<QWrappedEvent*>(event); + d->transition->setEventType(we->event()->type()); + return QAbstractTransitionPrivate::get(d->transition)->callEventTest(we->event()); } /*! \reimp */ -void QKeyEventTransition::onTransition() +void QKeyEventTransition::onTransition(QEvent *event) { - QEventTransition::onTransition(); + QEventTransition::onTransition(event); } QT_END_NAMESPACE diff --git a/src/gui/statemachine/qkeyeventtransition.h b/src/gui/statemachine/qkeyeventtransition.h index 5bae8d7..3f797f1 100644 --- a/src/gui/statemachine/qkeyeventtransition.h +++ b/src/gui/statemachine/qkeyeventtransition.h @@ -28,6 +28,7 @@ class Q_GUI_EXPORT QKeyEventTransition : public QEventTransition { Q_OBJECT Q_PROPERTY(int key READ key WRITE setKey) + Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask) public: QKeyEventTransition(QState *sourceState = 0); QKeyEventTransition(QObject *object, QEvent::Type type, int key, @@ -40,13 +41,12 @@ public: int key() const; void setKey(int key); - Qt::KeyboardModifiers modifiers() const; - void setModifiers(Qt::KeyboardModifiers modifiers); + Qt::KeyboardModifiers modifiersMask() const; + void setModifiersMask(Qt::KeyboardModifiers modifiers); protected: - void onTransition(); + void onTransition(QEvent *event); bool eventTest(QEvent *event) const; - bool testEventCondition(QEvent *event) const; private: Q_DISABLE_COPY(QKeyEventTransition) diff --git a/src/gui/statemachine/qmouseeventtransition.cpp b/src/gui/statemachine/qmouseeventtransition.cpp index 1621c78..3191a2f 100644 --- a/src/gui/statemachine/qmouseeventtransition.cpp +++ b/src/gui/statemachine/qmouseeventtransition.cpp @@ -11,6 +11,7 @@ #include "qmouseeventtransition.h" #include "qbasicmouseeventtransition_p.h" +#include <QtCore/qwrappedevent.h> #include <QtGui/qpainterpath.h> #if defined(QT_EXPERIMENTAL_SOLUTION) @@ -26,6 +27,7 @@ QT_BEGIN_NAMESPACE \brief The QMouseEventTransition class provides a transition for mouse events. + \since 4.6 \ingroup statemachine QMouseEventTransition is part of \l{The State Machine Framework}. @@ -33,6 +35,18 @@ QT_BEGIN_NAMESPACE \sa QState::addTransition() */ +/*! + \property QMouseEventTransition::button + + \brief the button that this mouse event transition is associated with +*/ + +/*! + \property QMouseEventTransition::modifiersMask + + \brief the keyboard modifiers mask that this mouse event transition checks for +*/ + class QMouseEventTransitionPrivate : public QEventTransitionPrivate { Q_DECLARE_PUBLIC(QMouseEventTransition) @@ -103,7 +117,7 @@ Qt::MouseButton QMouseEventTransition::button() const } /*! - Sets the button that this mouse event transition will check for. + Sets the \a button that this mouse event transition will check for. */ void QMouseEventTransition::setButton(Qt::MouseButton button) { @@ -112,6 +126,26 @@ void QMouseEventTransition::setButton(Qt::MouseButton button) } /*! + Returns the keyboard modifiers mask that this mouse event transition checks + for. +*/ +Qt::KeyboardModifiers QMouseEventTransition::modifiersMask() const +{ + Q_D(const QMouseEventTransition); + return d->transition->modifiersMask(); +} + +/*! + Sets the keyboard \a modifiers mask that this mouse event transition will + check for. +*/ +void QMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask) +{ + Q_D(QMouseEventTransition); + d->transition->setModifiersMask(modifiersMask); +} + +/*! Returns the path for this mouse event transition. */ QPainterPath QMouseEventTransition::path() const @@ -136,27 +170,22 @@ void QMouseEventTransition::setPath(const QPainterPath &path) /*! \reimp */ -bool QMouseEventTransition::testEventCondition(QEvent *event) const -{ - Q_D(const QMouseEventTransition); - d->transition->setEventType(event->type()); - return QAbstractTransitionPrivate::get(d->transition)->callEventTest(event); -} - -/*! - \reimp -*/ bool QMouseEventTransition::eventTest(QEvent *event) const { - return QEventTransition::eventTest(event); + Q_D(const QMouseEventTransition); + if (!QEventTransition::eventTest(event)) + return false; + QWrappedEvent *we = static_cast<QWrappedEvent*>(event); + d->transition->setEventType(we->event()->type()); + return QAbstractTransitionPrivate::get(d->transition)->callEventTest(we->event()); } /*! \reimp */ -void QMouseEventTransition::onTransition() +void QMouseEventTransition::onTransition(QEvent *event) { - QEventTransition::onTransition(); + QEventTransition::onTransition(event); } QT_END_NAMESPACE diff --git a/src/gui/statemachine/qmouseeventtransition.h b/src/gui/statemachine/qmouseeventtransition.h index 162b1b5..eee971e 100644 --- a/src/gui/statemachine/qmouseeventtransition.h +++ b/src/gui/statemachine/qmouseeventtransition.h @@ -29,6 +29,8 @@ class QPainterPath; class Q_GUI_EXPORT QMouseEventTransition : public QEventTransition { Q_OBJECT + Q_PROPERTY(Qt::MouseButton button READ button WRITE setButton) + Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask) public: QMouseEventTransition(QState *sourceState = 0); QMouseEventTransition(QObject *object, QEvent::Type type, @@ -42,13 +44,15 @@ public: Qt::MouseButton button() const; void setButton(Qt::MouseButton button); + Qt::KeyboardModifiers modifiersMask() const; + void setModifiersMask(Qt::KeyboardModifiers modifiers); + QPainterPath path() const; void setPath(const QPainterPath &path); protected: - void onTransition(); + void onTransition(QEvent *event); bool eventTest(QEvent *event) const; - bool testEventCondition(QEvent *event) const; private: Q_DISABLE_COPY(QMouseEventTransition) diff --git a/src/gui/statemachine/statemachine.pri b/src/gui/statemachine/statemachine.pri index 24de458..2eb1e05 100644 --- a/src/gui/statemachine/statemachine.pri +++ b/src/gui/statemachine/statemachine.pri @@ -1,6 +1,3 @@ -INCLUDEPATH += $$PWD -DEPENDPATH += $$PWD - SOURCES += $$PWD/qguistatemachine.cpp !contains(DEFINES, QT_NO_STATEMACHINE_EVENTFILTER) { HEADERS += \ |