]>
cloud.milkyroute.net Git - dolphin.git/blob - src/statusbarmessagelabel.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "statusbarmessagelabel.h"
24 #include <qfontmetrics.h>
27 #include <QResizeEvent>
28 #include <QPaintEvent>
29 #include <kiconloader.h>
30 #include <kglobalsettings.h>
32 StatusBarMessageLabel::StatusBarMessageLabel(QWidget
* parent
) :
34 m_type(DolphinStatusBar::Default
),
40 setMinimumHeight(KIcon::SizeSmall
);
42 m_timer
= new QTimer(this);
43 connect(m_timer
, SIGNAL(timeout()),
44 this, SLOT(timerDone()));
47 StatusBarMessageLabel::~StatusBarMessageLabel()
51 void StatusBarMessageLabel::setType(DolphinStatusBar::Type type
)
60 const char* iconName
= 0;
63 case DolphinStatusBar::OperationCompleted
:
67 case DolphinStatusBar::Information
:
71 case DolphinStatusBar::Error
:
77 case DolphinStatusBar::Default
:
81 m_pixmap
= (iconName
== 0) ? QPixmap() : SmallIcon(iconName
);
87 void StatusBarMessageLabel::setText(const QString
& text
)
90 if (m_type
== DolphinStatusBar::Error
) {
101 void StatusBarMessageLabel::setMinimumTextHeight(int min
)
103 if (min
!= m_minTextHeight
) {
104 m_minTextHeight
= min
;
105 setMinimumHeight(min
);
109 void StatusBarMessageLabel::paintEvent(QPaintEvent
* /* event */)
111 QPixmap
buffer(size());
112 QPainter
painter(&buffer
);
115 QColor
backgroundColor(colorGroup().background());
116 QColor
foregroundColor(KGlobalSettings::textColor());
117 if (m_illumination
> 0) {
118 backgroundColor
= mixColors(backgroundColor
, QColor(255, 255, 64), m_illumination
);
119 foregroundColor
= mixColors(foregroundColor
, QColor(0, 0, 0), m_illumination
);
121 painter
.setBrush(backgroundColor
);
122 painter
.setPen(backgroundColor
);
123 painter
.drawRect(QRect(0, 0, width(), height()));
127 int y
= (height() - m_pixmap
.height()) / 2;
129 if (!m_pixmap
.isNull()) {
130 painter
.drawPixmap(x
, y
, m_pixmap
);
131 x
+= m_pixmap
.width() + pixmapGap();
135 painter
.setPen(foregroundColor
);
136 painter
.drawText(QRect(x
, 0, width() - x
, height()), Qt::AlignVCenter
| Qt::WordBreak
, m_text
);
139 bitBlt(this, 0, 0, &buffer
);
142 void StatusBarMessageLabel::resizeEvent(QResizeEvent
* event
)
144 QWidget::resizeEvent(event
);
145 QTimer::singleShot(0, this, SLOT(assureVisibleText()));
148 void StatusBarMessageLabel::timerDone()
152 // increase the illumination
153 if (m_illumination
< 100) {
154 m_illumination
+= 20;
158 m_state
= Illuminated
;
159 m_timer
->start(1000);
165 // start desaturation
166 m_state
= Desaturate
;
173 if (m_illumination
> 0) {
189 void StatusBarMessageLabel::assureVisibleText()
191 if (m_text
.isEmpty()) {
196 int availableWidth
= width() - m_pixmap
.width() - pixmapGap() * 2;
198 QFontMetrics
fontMetrics(font());
199 QRect
bounds(fontMetrics
.boundingRect(0, 0, availableWidth
, height(),
200 Qt::AlignVCenter
| Qt::TextWordWrap
,
202 int requiredHeight
= bounds
.height();
203 if (requiredHeight
< m_minTextHeight
) {
204 requiredHeight
= m_minTextHeight
;
206 setMinimumHeight(requiredHeight
);
210 QColor
StatusBarMessageLabel::mixColors(const QColor
& c1
,
214 const int recip
= 100 - percent
;
215 const int red
= (c1
.red() * recip
+ c2
.red() * percent
) / 100;
216 const int green
= (c1
.green() * recip
+ c2
.green() * percent
) / 100;
217 const int blue
= (c1
.blue() * recip
+ c2
.blue() * percent
) / 100;
218 return QColor(red
, green
, blue
);