animate hide of the focus indicator when a button is pressed

svn path=/trunk/KDE/kdelibs/; revision=1164481
This commit is contained in:
Marco Martin 2010-08-16 21:16:53 +00:00
parent 4fdf87b54f
commit bc6d40852b
4 changed files with 27 additions and 1 deletions

View File

@ -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)

View File

@ -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:

View File

@ -107,6 +107,15 @@ public:
static_cast<KPushButton*>(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);

View File

@ -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;