diff options
author | unknown <Roopesh Chander@.(none)> | 2009-11-10 16:48:05 +0530 |
---|---|---|
committer | unknown <Roopesh Chander@.(none)> | 2009-11-10 16:48:05 +0530 |
commit | 6ff9e5a96fba1d1638e01a8d45df74e7a34e978e (patch) | |
tree | 7193d3c48804c73e5ca7dc588dcfcb904421679c /graphicstoolbar.cpp | |
parent | 641fffc31ead062b78385c9285f97a70fd1c9e67 (diff) |
use state transitions for blur/unblur of the toolbar
Diffstat (limited to 'graphicstoolbar.cpp')
-rw-r--r-- | graphicstoolbar.cpp | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/graphicstoolbar.cpp b/graphicstoolbar.cpp index 51860e4..6c6e6ab 100644 --- a/graphicstoolbar.cpp +++ b/graphicstoolbar.cpp @@ -5,6 +5,9 @@ #include <QGraphicsTransform> #include <QPropertyAnimation> #include <QParallelAnimationGroup> +#include <QState> +#include <QEventTransition> +#include <QGraphicsSceneHoverEvent> #include "graphicstoolbar.h" GraphicsToolBar::GraphicsToolBar(QGraphicsScene *scene, QGraphicsItem * parent, Qt::WindowFlags wFlags) @@ -44,6 +47,38 @@ GraphicsToolBar::GraphicsToolBar(QGraphicsScene *scene, QGraphicsItem * parent, QList<QGraphicsTransform *> txs; txs << m_rotation; setTransformations(txs); + + QState *blurredState = new QState; + QState *normalState = new QState; + 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); + + QParallelAnimationGroup *makeBlurAnimation = new QParallelAnimationGroup(this); + QParallelAnimationGroup *makeNormalAnimation = new QParallelAnimationGroup(this); + + QPropertyAnimation *blurAnimation = new QPropertyAnimation(m_blurEffect, "blurRadius", makeBlurAnimation); + blurAnimation->setEndValue(5); + QPropertyAnimation *transparentizeAnimation = new QPropertyAnimation(this, "opacity", makeBlurAnimation); + transparentizeAnimation->setEndValue(0.7); + makeBlurAnimation->addAnimation(blurAnimation); + makeBlurAnimation->addAnimation(transparentizeAnimation); + + QPropertyAnimation *unblurAnimation = new QPropertyAnimation(m_blurEffect, "blurRadius", makeNormalAnimation); + unblurAnimation->setEndValue(0); + QPropertyAnimation *untransparentizeAnimation = new QPropertyAnimation(this, "opacity", makeBlurAnimation); + untransparentizeAnimation->setEndValue(1.0); + makeNormalAnimation->addAnimation(unblurAnimation); + makeNormalAnimation->addAnimation(untransparentizeAnimation); + + makeBlurred->addAnimation(makeBlurAnimation); + makeNormal->addAnimation(makeNormalAnimation); + + m_stateMachine.start(); } void GraphicsToolBar::setGraphicsEffectsEnabled(bool enabled) { @@ -100,18 +135,6 @@ void GraphicsToolBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->restore(); } -void GraphicsToolBar::hoverEnterEvent(QGraphicsSceneHoverEvent* event) { - Q_UNUSED(event); - transitionBlurEnabledTo(false); - update(); -} - -void GraphicsToolBar::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) { - Q_UNUSED(event); - transitionBlurEnabledTo(true); - update(); -} - void GraphicsToolBar::transitionBlurEnabledTo(bool enabled) { if (! graphicsEffectsEnabled()) return; @@ -130,6 +153,8 @@ void GraphicsToolBar::transitionBlurEnabledTo(bool enabled) { void GraphicsToolBar::show() { QGraphicsWidget::show(); + setOpacity(1.0); + m_blurEffect->setProperty("blurRadius", 0); } void GraphicsToolBar::hide() { |