From kde-commits Tue Oct 28 09:25:57 2008 From: =?utf-8?q?Aaron=20J=2E=20Seigo?= Date: Tue, 28 Oct 2008 09:25:57 +0000 To: kde-commits Subject: KDE/kdebase/workspace/libs/plasma/widgets Message-Id: <1225185957.602711.24074.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=122518596608080 SVN commit 876852 by aseigo: something i've wanted for a bit: autohide on fade. perfect kind of "i don't have to think to add this" kind of feature to fill in my boredom during meetings full of powerpoint presentations ;) M +45 -10 flash.cpp M +4 -0 flash.h --- trunk/KDE/kdebase/workspace/libs/plasma/widgets/flash.cpp #876851:876852 @@ -46,12 +46,14 @@ Invisible }; - FlashPrivate() - : defaultDuration(3000), + FlashPrivate(Flash *flash) + : q(flash), + defaultDuration(3000), type(FlashPrivate::Text), color(Qt::black), animId(0), - state(FlashPrivate::Invisible) + state(FlashPrivate::Invisible), + autohide(false) { //TODO: put this on a diet by using timerEvent instead? fadeOutTimer.setInterval(defaultDuration); @@ -59,11 +61,14 @@ fadeInTimer.setInterval(0); fadeInTimer.setSingleShot(true); } + ~FlashPrivate() { } void renderPixmap(const QSize &size); - void setupFlash(Flash *flash, int duration); + void setupFlash(int duration); + void elementAnimationFinished(int); + Flash *q; int defaultDuration; FlashType type; QTimer fadeInTimer; @@ -80,11 +85,12 @@ Qt::Alignment alignment; State state; + bool autohide; }; Flash::Flash(QGraphicsItem *parent) : QGraphicsWidget(parent), - d(new FlashPrivate) + d(new FlashPrivate(this)) { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); setCacheMode(NoCache); @@ -126,7 +132,7 @@ d->type = FlashPrivate::Text; d->text = text; d->textOption = option; - d->setupFlash(this, duration); + d->setupFlash(duration); } void Flash::flash(const QPixmap &pixmap, int duration, Qt::Alignment align) @@ -138,9 +144,27 @@ d->type = FlashPrivate::Pixmap; d->pixmap = pixmap; d->alignment = align; - d->setupFlash(this, duration); + d->setupFlash(duration); } +void Flash::setAutohide(bool autohide) +{ + d->autohide = autohide; + + if (autohide) { + connect(Plasma::Animator::self(), SIGNAL(elementAnimationFinished(int)), + this, SLOT(elementAnimationFinished(int))); + } else { + disconnect(Plasma::Animator::self(), SIGNAL(elementAnimationFinished(int)), + this, SLOT(elementAnimationFinished(int))); + } +} + +bool Flash::autohide() const +{ + return d->autohide; +} + void Flash::kill() { d->fadeInTimer.stop(); @@ -152,6 +176,10 @@ void Flash::fadeIn() { //kDebug(); + if (d->autohide) { + show(); + } + d->state = FlashPrivate::Visible; d->animId = Plasma::Animator::self()->animateElement(this, Plasma::Animator::AppearAnimation); Plasma::Animator::self()->setInitialPixmap(d->animId, d->renderedPixmap); @@ -225,16 +253,16 @@ } } -void FlashPrivate::setupFlash(Flash *flash, int duration) +void FlashPrivate::setupFlash(int duration) { fadeOutTimer.stop(); fadeOutTimer.setInterval(duration > 0 ? duration : defaultDuration); - renderPixmap(flash->size().toSize()); + renderPixmap(q->size().toSize()); if (state != FlashPrivate::Visible) { fadeInTimer.start(); } else { - flash->update(); + q->update(); } if (fadeOutTimer.interval() > 0) { @@ -242,4 +270,11 @@ } } +void FlashPrivate::elementAnimationFinished(int id) +{ + if (autohide && state == FlashPrivate::Invisible && id == animId) { + q->hide(); + } +} + #include "flash.moc" --- trunk/KDE/kdebase/workspace/libs/plasma/widgets/flash.h #876851:876852 @@ -54,6 +54,9 @@ void flash(const QPixmap &pixmap, int duration = 0, Qt::Alignment align = Qt::AlignCenter); + void setAutohide(bool autohide); + bool autohide() const; + public Q_SLOTS: void kill(); @@ -62,6 +65,7 @@ void fadeOut(); private: + Q_PRIVATE_SLOT(d, void elementAnimationFinished(int)) FlashPrivate *const d; };