summaryrefslogtreecommitdiffstats
path: root/src/effectwidget.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-22 19:13:25 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-22 19:13:25 +0000
commit7d8a8bdafccd66e70f313ee233cff920eac9d830 (patch)
treec0877b2799255f52ea6bfdfb60e5eb2f60926b6b /src/effectwidget.cpp
downloadksplash-engine-moodin-7d8a8bdafccd66e70f313ee233cff920eac9d830.tar.gz
ksplash-engine-moodin-7d8a8bdafccd66e70f313ee233cff920eac9d830.zip
Added KDE3 moodin engine
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ksplash-engine-moodin@1094437 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/effectwidget.cpp')
-rw-r--r--src/effectwidget.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/effectwidget.cpp b/src/effectwidget.cpp
new file mode 100644
index 0000000..1a2804a
--- /dev/null
+++ b/src/effectwidget.cpp
@@ -0,0 +1,165 @@
+/***************************************************************************
+ * Copyright Sean Meiners 2004 <Sean.Meiners@LinspireInc.com> *
+ * Copyright (C) by *
+ * - 2005: Christian Leh <moodwrod@web.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License (version 2) as *
+ * published by the Free Software Foundation. (The original KSplash/ML *
+ * codebase (upto version 0.95.3) is BSD-licensed.) *
+ * *
+ ***************************************************************************/
+
+#include <qwidget.h>
+#include <qstyle.h>
+#include <qtimer.h>
+#include <qpainter.h>
+#include <qimage.h>
+
+#include "effectwidget.h"
+
+QImage* EffectWidget::bgImage = 0;
+
+EffectWidget::EffectWidget(QWidget* parent, const char* name)
+ :QWidget(parent, name)
+{
+ timer = 0;
+ delayMS = 20;
+ currentStep = 0;
+ totalSteps = 0;
+ playing = false;
+ loop = false;
+ beginOpacity = 20.0;
+ endOpacity = 80.0;
+ setBackgroundMode(NoBackground);
+ setBackgroundOrigin(QWidget::ParentOrigin);
+ updateCache();
+}
+
+
+void EffectWidget::setImage(QImage *i)
+{
+ image = i;
+}
+
+
+void EffectWidget::setDelay(int delayInMS)
+{
+ delayMS = delayInMS;
+
+ if (timer)
+ timer->changeInterval(delayMS);
+}
+
+
+void EffectWidget::setLoop(bool loop)
+{
+ this->loop = loop;
+}
+
+
+void EffectWidget::setSteps(int steps)
+{
+ totalSteps = steps;
+}
+
+
+void EffectWidget::start()
+{
+ if ((playing) || (!image) || (totalSteps < 1) || (image->isNull()))
+ return;
+
+ if (!timer)
+ {
+ timer = new QTimer(this);
+ connect(timer,SIGNAL(timeout()),this,SLOT(timerTick()));
+ }
+
+ playing = true;
+ update();
+ timer->start(delayMS);
+}
+
+
+void EffectWidget::stop()
+{
+ if ((!playing) || (!timer))
+ return;
+
+ timer->stop();
+ playing = false;
+}
+
+
+void EffectWidget::setStart(float begin, float end, bool reverse)
+{
+ beginOpacity = begin;
+ endOpacity = end - beginOpacity;
+
+ if (reverse)
+ {
+ float h = beginOpacity;
+ beginOpacity = endOpacity;
+ endOpacity = h;
+ }
+}
+
+
+void EffectWidget::rewind()
+{
+ stop();
+ currentStep = 0;
+}
+
+
+void EffectWidget::timerTick()
+{
+ if (loop)
+ {
+ currentStep ++;
+ currentStep %= totalSteps;
+ }
+ else if (currentStep + 1 < totalSteps)
+ currentStep ++;
+ else
+ timer->stop();
+
+ update();
+}
+
+
+void EffectWidget::moveEvent(QMoveEvent *)
+{
+ updateCache();
+}
+
+
+void EffectWidget::resizeEvent(QResizeEvent *)
+{
+ updateCache();
+}
+
+
+void EffectWidget::updateCache()
+{
+ if (!bgImage)
+ return;
+
+ QPoint pos(mapToParent(QPoint(0, 0)));
+ background = bgImage->copy(pos.x(), pos.y(), width(), height());
+ bitBlt(this, 0, 0, &background);
+}
+
+void EffectWidget::paintEvent(QPaintEvent *)
+{
+ if (background.isNull())
+ return;
+
+ QImage upper = image->copy();
+ QImage lower = background.copy();
+ KImageEffect::blendOnLower(upper, lower, KImageEffect::Centered, (currentStep + 1 == totalSteps) ? 1.0 : endOpacity / float(totalSteps) * float(currentStep) + beginOpacity);
+
+ bitBlt(this, 0, 0, &lower);
+}
+
+#include "effectwidget.moc"