From bc6d40852bfc42c492ec6aa7d2f53d1570746f6e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 16 Aug 2010 21:16:53 +0000 Subject: [PATCH] animate hide of the focus indicator when a button is pressed svn path=/trunk/KDE/kdelibs/; revision=1164481 --- private/focusindicator.cpp | 12 ++++++++++++ private/focusindicator_p.h | 1 + widgets/pushbutton.cpp | 14 +++++++++++++- widgets/pushbutton.h | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/private/focusindicator.cpp b/private/focusindicator.cpp index 20debebdb..aa67647cd 100644 --- a/private/focusindicator.cpp +++ b/private/focusindicator.cpp @@ -155,6 +155,18 @@ void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *event) m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap()); } +void FocusIndicator::animateVisibility(const bool visible) +{ + m_fade->setProperty("startOpacity", opacity()); + + if (visible) { + m_fade->setProperty("targetOpacity", 1.0); + } else { + m_fade->setProperty("targetOpacity", 0); + } + m_fade->start(); +} + void FocusIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) diff --git a/private/focusindicator_p.h b/private/focusindicator_p.h index 3b771470e..c223788c6 100644 --- a/private/focusindicator_p.h +++ b/private/focusindicator_p.h @@ -39,6 +39,7 @@ public: void setCustomGeometry(const QRectF &geometry); void setCustomPrefix(const QString &prefix); + void animateVisibility(const bool visible); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); protected: diff --git a/widgets/pushbutton.cpp b/widgets/pushbutton.cpp index c0b2a15f9..89a996948 100644 --- a/widgets/pushbutton.cpp +++ b/widgets/pushbutton.cpp @@ -107,6 +107,15 @@ public: static_cast(q->widget())->setIcon(KIcon(pm)); } + void pressedChanged() + { + if (q->nativeWidget()->isDown() || q->nativeWidget()->isChecked()) { + focusIndicator->animateVisibility(false); + } else { + focusIndicator->animateVisibility(true); + } + } + void syncActiveRect(); void syncBorders(); @@ -119,6 +128,7 @@ public: Animation *hoverAnimation; + FocusIndicator *focusIndicator; QString imagePath; QString absImagePath; Svg *svg; @@ -174,7 +184,9 @@ PushButton::PushButton(QGraphicsWidget *parent) KPushButton *native = new KPushButton; connect(native, SIGNAL(pressed()), this, SIGNAL(pressed())); + connect(native, SIGNAL(pressed()), this, SLOT(pressedChanged())); connect(native, SIGNAL(released()), this, SIGNAL(released())); + connect(native, SIGNAL(released()), this, SLOT(pressedChanged())); connect(native, SIGNAL(clicked()), this, SIGNAL(clicked())); connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool))); setWidget(native); @@ -183,7 +195,7 @@ PushButton::PushButton(QGraphicsWidget *parent) setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - FocusIndicator *focusIndicator = new FocusIndicator(this, "widgets/button"); + d->focusIndicator = new FocusIndicator(this, "widgets/button"); d->syncBorders(); setAcceptHoverEvents(true); diff --git a/widgets/pushbutton.h b/widgets/pushbutton.h index 8d78f780a..318aa4e41 100644 --- a/widgets/pushbutton.h +++ b/widgets/pushbutton.h @@ -222,6 +222,7 @@ protected: private: Q_PRIVATE_SLOT(d, void syncBorders()) Q_PRIVATE_SLOT(d, void setPixmap()) + Q_PRIVATE_SLOT(d, void pressedChanged()) friend class PushButtonPrivate; PushButtonPrivate *const d;