diff options
| -rw-r--r-- | graphicstoolbar.cpp | 23 | ||||
| -rw-r--r-- | graphicstoolbar.h | 12 |
2 files changed, 28 insertions, 7 deletions
diff --git a/graphicstoolbar.cpp b/graphicstoolbar.cpp index ef29f95..b61ada0 100644 --- a/graphicstoolbar.cpp +++ b/graphicstoolbar.cpp @@ -10,6 +10,16 @@ #include <QGraphicsSceneHoverEvent> #include "graphicstoolbar.h" +bool HoverOutEventTransition::eventTest(QEvent *e) { + if (! QEventTransition::eventTest(e)) + return false; + QGraphicsWidget *toolbar = qobject_cast<QGraphicsWidget*>(eventSource()); + // if focus is now on a widget contained within the toolbar, don't transition + if (toolbar && toolbar->scene() && toolbar->isAncestorOf(toolbar->scene()->focusItem())) + return false; + return true; +} + GraphicsToolBar::GraphicsToolBar(QGraphicsScene *scene, QGraphicsItem * parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent, wFlags) , m_scene(scene) @@ -53,10 +63,10 @@ GraphicsToolBar::GraphicsToolBar(QGraphicsScene *scene, QGraphicsItem * parent, m_stateMachine.addState(blurredState); m_stateMachine.addState(normalState); m_stateMachine.setInitialState(normalState); - QEventTransition *makeBlurred = new QEventTransition(this, QEvent::GraphicsSceneHoverLeave, normalState); - makeBlurred->setTargetState(blurredState); - QEventTransition *makeNormal = new QEventTransition(this, QEvent::GraphicsSceneHoverEnter, blurredState); - makeNormal->setTargetState(normalState); + m_makeBlurred = new HoverOutEventTransition(this, QEvent::GraphicsSceneHoverLeave, normalState); + m_makeBlurred->setTargetState(blurredState); + m_makeNormal = new QEventTransition(this, QEvent::GraphicsSceneHoverEnter, blurredState); + m_makeNormal->setTargetState(normalState); QParallelAnimationGroup *makeBlurAnimation = new QParallelAnimationGroup(this); QParallelAnimationGroup *makeNormalAnimation = new QParallelAnimationGroup(this); @@ -75,9 +85,8 @@ GraphicsToolBar::GraphicsToolBar(QGraphicsScene *scene, QGraphicsItem * parent, makeNormalAnimation->addAnimation(unblurAnimation); makeNormalAnimation->addAnimation(untransparentizeAnimation); - makeBlurred->addAnimation(makeBlurAnimation); - makeNormal->addAnimation(makeNormalAnimation); - + m_makeBlurred->addAnimation(makeBlurAnimation); + m_makeNormal->addAnimation(makeNormalAnimation); m_stateMachine.start(); } diff --git a/graphicstoolbar.h b/graphicstoolbar.h index a8cc4c2..2a56d7a 100644 --- a/graphicstoolbar.h +++ b/graphicstoolbar.h @@ -9,6 +9,16 @@ #include <QGraphicsRotation> #include <QState> #include <QStateMachine> +#include <QEventTransition> + +class HoverOutEventTransition : public QEventTransition { +public: + HoverOutEventTransition(QObject *object, QEvent::Type type, QState *sourceState = 0) + : QEventTransition(object, type, sourceState) { + } +protected: + virtual bool eventTest(QEvent *e); +}; class GraphicsToolBar : public QGraphicsWidget { @@ -40,6 +50,8 @@ private: int m_fillLevel; QGraphicsRotation *m_rotation; QStateMachine m_stateMachine; + HoverOutEventTransition *m_makeBlurred; + QEventTransition *m_makeNormal; }; #endif // GRAPHICSTOOLBAR_H |
