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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/***************************************************************************
* Copyright (C) 2006 by Peter Penz *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "statusbarmessagelabel.h"
#include <tqpainter.h>
#include <tqtimer.h>
#include <tqfontmetrics.h>
#include <kiconloader.h>
#include <kglobalsettings.h>
StatusBarMessageLabel::StatusBarMessageLabel(TQWidget* parent) :
TQWidget(parent),
m_type(DolphinStatusBar::Default),
m_state(Default),
m_illumination(0),
m_minTextHeight(-1),
m_timer(0)
{
setMinimumHeight(KIcon::SizeSmall);
m_timer = new TQTimer(this);
connect(m_timer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(timerDone()));
}
StatusBarMessageLabel::~StatusBarMessageLabel()
{
}
void StatusBarMessageLabel::setType(DolphinStatusBar::Type type)
{
if (type != m_type) {
m_type = type;
m_timer->stop();
m_illumination = 0;
m_state = Default;
const char* iconName = 0;
TQPixmap pixmap;
switch (type) {
case DolphinStatusBar::OperationCompleted:
iconName = "ok";
break;
case DolphinStatusBar::Information:
iconName = "info";
break;
case DolphinStatusBar::Error:
iconName = "error";
m_timer->start(100);
m_state = Illuminate;
break;
case DolphinStatusBar::Default:
default: break;
}
m_pixmap = (iconName == 0) ? TQPixmap() : SmallIcon(iconName);
assureVisibleText();
update();
}
}
void StatusBarMessageLabel::setText(const TQString& text)
{
if (text != m_text) {
if (m_type == DolphinStatusBar::Error) {
m_timer->start(100);
m_illumination = 0;
m_state = Illuminate;
}
m_text = text;
assureVisibleText();
update();
}
}
void StatusBarMessageLabel::setMinimumTextHeight(int min)
{
if (min != m_minTextHeight) {
m_minTextHeight = min;
setMinimumHeight(min);
}
}
void StatusBarMessageLabel::paintEvent(TQPaintEvent* /* event */)
{
TQPixmap buffer(size());
TQPainter painter(&buffer);
// draw background
TQColor backgroundColor(colorGroup().background());
TQColor foregroundColor(TDEGlobalSettings::textColor());
if (m_illumination > 0) {
backgroundColor = mixColors(backgroundColor, TQColor(255, 255, 64), m_illumination);
foregroundColor = mixColors(foregroundColor, TQColor(0, 0, 0), m_illumination);
}
painter.setBrush(backgroundColor);
painter.setPen(backgroundColor);
painter.drawRect(TQRect(0, 0, width(), height()));
// draw pixmap
int x = pixmapGap();
int y = (height() - m_pixmap.height()) / 2;
if (!m_pixmap.isNull()) {
painter.drawPixmap(x, y, m_pixmap);
x += m_pixmap.width() + pixmapGap();
}
// draw text
painter.setPen(foregroundColor);
painter.drawText(TQRect(x, 0, width() - x, height()), TQt::AlignVCenter | TQt::WordBreak, m_text);
painter.end();
bitBlt(this, 0, 0, &buffer);
}
void StatusBarMessageLabel::resizeEvent(TQResizeEvent* event)
{
TQWidget::resizeEvent(event);
TQTimer::singleShot(0, this, TQT_SLOT(assureVisibleText()));
}
void StatusBarMessageLabel::timerDone()
{
switch (m_state) {
case Illuminate: {
// increase the illumination
if (m_illumination < 100) {
m_illumination += 20;
update();
}
else {
m_state = Illuminated;
m_timer->start(1000);
}
break;
}
case Illuminated: {
// start desaturation
m_state = Desaturate;
m_timer->start(100);
break;
}
case Desaturate: {
// desaturate
if (m_illumination > 0) {
m_illumination -= 5;
update();
}
else {
m_state = Default;
m_timer->stop();
}
break;
}
default:
break;
}
}
void StatusBarMessageLabel::assureVisibleText()
{
if (m_text.isEmpty()) {
return;
}
int availableWidth = width() - m_pixmap.width() - pixmapGap() * 2;
TQFontMetrics fontMetrics(font());
TQRect bounds(fontMetrics.boundingRect(0, 0, availableWidth, height(),
TQt::AlignVCenter | TQt::WordBreak,
m_text));
int requiredHeight = bounds.height();
if (requiredHeight < m_minTextHeight) {
requiredHeight = m_minTextHeight;
}
setMinimumHeight(requiredHeight);
updateGeometry();
}
TQColor StatusBarMessageLabel::mixColors(const TQColor& c1,
const TQColor& c2,
int percent) const
{
const int recip = 100 - percent;
const int red = (c1.red() * recip + c2.red() * percent) / 100;
const int green = (c1.green() * recip + c2.green() * percent) / 100;
const int blue = (c1.blue() * recip + c2.blue() * percent) / 100;
return TQColor(red, green, blue);
}
#include "statusbarmessagelabel.moc"
|