From fc1c74083780acb76e2d0b7deea320bf131be5a7 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 24 Apr 2009 19:29:16 +0000 Subject: [PATCH] get the highlight/unhilight and shown/unshown sorted out.. now it all works on for the spacer in the panel containment :) svn path=/trunk/KDE/kdelibs/; revision=958825 --- private/paneltoolbox.cpp | 76 ++++++++++++++-------------------------- private/paneltoolbox_p.h | 1 + 2 files changed, 28 insertions(+), 49 deletions(-) diff --git a/private/paneltoolbox.cpp b/private/paneltoolbox.cpp index 19d64ea74..17617c229 100644 --- a/private/paneltoolbox.cpp +++ b/private/paneltoolbox.cpp @@ -43,7 +43,7 @@ public: : icon("plasma"), animId(0), animFrame(0), - toggled(false) + highlighting(false) { } @@ -51,10 +51,10 @@ public: KIcon icon; int animId; qreal animFrame; - bool toggled; QColor fgColor; QColor bgColor; Plasma::Svg *background; + bool highlighting; }; PanelToolBox::PanelToolBox(Containment *parent) @@ -72,7 +72,7 @@ PanelToolBox::PanelToolBox(Containment *parent) connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(assignColors())); - d->background = new Plasma::Svg(); + d->background = new Plasma::Svg(this); d->background->setImagePath("widgets/toolbox"); d->background->setContainsMultipleImages(true); } @@ -210,74 +210,54 @@ QPainterPath PanelToolBox::shape() const void PanelToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - if (showing()) { - QGraphicsItem::hoverEnterEvent(event); - return; - } - - showToolBox(); + highlight(true); QGraphicsItem::hoverEnterEvent(event); } -void PanelToolBox::showToolBox() -{ - if (showing()) { - return; - } - - int maxwidth = 0; - foreach (QGraphicsItem *tool, QGraphicsItem::children()) { - if (!tool->isEnabled()) { - continue; - } - maxwidth = qMax(static_cast(tool->boundingRect().width()), maxwidth); - } - - // put tools 5px from icon edge - Plasma::Animator *animdriver = Plasma::Animator::self(); - - if (d->animId) { - animdriver->stopCustomAnimation(d->animId); - } - - setShowing(true); - // TODO: 10 and 200 shouldn't be hardcoded here. There needs to be a way to - // match whatever the time is that moveItem() takes. Same in hoverLeaveEvent(). - d->animId = animdriver->customAnimation( - 10, 240, Plasma::Animator::EaseInCurve, this, "animate"); -} - void PanelToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { //kDebug() << event->pos() << event->scenePos() - if (!d->toggled) { - hideToolBox(); + if (!showing()) { + highlight(false); } QGraphicsItem::hoverLeaveEvent(event); } +void PanelToolBox::showToolBox() +{ + setShowing(true); + highlight(true); +} + void PanelToolBox::hideToolBox() { - if (!showing()) { + setShowing(false); + highlight(false); +} + +void PanelToolBox::highlight(bool highlighting) +{ + if (d->highlighting == highlighting) { return; } - d->toggled = false; Plasma::Animator *animdriver = Plasma::Animator::self(); if (d->animId) { animdriver->stopCustomAnimation(d->animId); } - setShowing(false); - d->animId = animdriver->customAnimation( - 10, 240, Plasma::Animator::EaseOutCurve, this, "animate"); + d->highlighting = highlighting; + d->animId = animdriver->customAnimation(10, 240, + highlighting ? Plasma::Animator::EaseInCurve + : Plasma::Animator::EaseOutCurve, + this, "animate"); } void PanelToolBox::animate(qreal progress) { - if (showing()) { + if (d->highlighting) { d->animFrame = size() * progress; } else { d->animFrame = size() * (1.0 - progress); @@ -294,10 +274,8 @@ void PanelToolBox::animate(qreal progress) void PanelToolBox::toggle() { - d->toggled = !d->toggled; - if (showing() && !d->toggled) { - hideToolBox(); - } + setShowing(!showing()); + highlight(showing()); } } // plasma namespace diff --git a/private/paneltoolbox_p.h b/private/paneltoolbox_p.h index b24ab5a70..86bf70232 100644 --- a/private/paneltoolbox_p.h +++ b/private/paneltoolbox_p.h @@ -62,6 +62,7 @@ protected slots: void assignColors(); private: + void highlight(bool highlighting); PanelToolBoxPrivate *d; };