1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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 <tqwidget.h>
#include <tqstyle.h>
#include <tqtimer.h>
#include <tqpainter.h>
#include <tqimage.h>
#include "effectwidget.h"
TQImage* EffectWidget::bgImage = 0;
EffectWidget::EffectWidget(TQWidget* parent, const char* name)
:TQWidget(parent, name)
{
timer = 0;
delayMS = 20;
currentStep = 0;
totalSteps = 0;
playing = false;
loop = false;
beginOpacity = 20.0;
endOpacity = 80.0;
setBackgroundMode(NoBackground);
setBackgroundOrigin(TQWidget::ParentOrigin);
updateCache();
}
void EffectWidget::setImage(TQImage *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 TQTimer(this);
connect(timer,TQT_SIGNAL(timeout()),this,TQT_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(TQMoveEvent *)
{
updateCache();
}
void EffectWidget::resizeEvent(TQResizeEvent *)
{
updateCache();
}
void EffectWidget::updateCache()
{
if (!bgImage)
return;
TQPoint pos(mapToParent(TQPoint(0, 0)));
background = bgImage->copy(pos.x(), pos.y(), width(), height());
bitBlt(this, 0, 0, &background);
}
void EffectWidget::paintEvent(TQPaintEvent *)
{
if (background.isNull())
return;
TQImage upper = image->copy();
TQImage 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"
|