]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbarmessagelabel.h
Further optimizations: do a delayed update of the geometry. This leads to a reduced...
[dolphin.git] / src / statusbarmessagelabel.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
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. *
9 * *
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. *
14 * *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #ifndef STATUSBARMESSAGELABEL_H
22 #define STATUSBARMESSAGELABEL_H
23
24 #include <qwidget.h>
25 #include <qpixmap.h>
26 #include <qstring.h>
27 //Added by qt3to4:
28 #include <QPaintEvent>
29 #include <QResizeEvent>
30 #include <dolphinstatusbar.h>
31 class QTimer;
32
33 /**
34 * @brief Represents a message text label as part of the status bar.
35 *
36 * Dependant from the given type automatically a corresponding icon
37 * is shown in front of the text. For message texts having the type
38 * DolphinStatusBar::Error a dynamic color blending is done to get the
39 * attention from the user.
40 */
41 class StatusBarMessageLabel : public QWidget
42 {
43 Q_OBJECT
44
45 public:
46 explicit StatusBarMessageLabel(QWidget* parent);
47 virtual ~StatusBarMessageLabel();
48
49 void setType(DolphinStatusBar::Type type);
50 DolphinStatusBar::Type type() const { return m_type; }
51
52 void setText(const QString& text);
53 const QString& text() const { return m_text; }
54
55 // TODO: maybe a better approach is possible with the size hint
56 void setMinimumTextHeight(int min);
57 int minimumTextHeight() const { return m_minTextHeight; }
58
59 /**
60 * Returns the gap of the width of the current set text to the
61 * width of the message label. A gap <= 0 means that the text
62 * fits into the available width.
63 */
64 int widthGap() const;
65
66 protected:
67 /** @see QWidget::paintEvent() */
68 virtual void paintEvent(QPaintEvent* event);
69
70 /** @see QWidget::resizeEvent() */
71 virtual void resizeEvent(QResizeEvent* event);
72
73 private slots:
74 void timerDone();
75
76 /**
77 * Increases the height of the message label so that
78 * the given text fits into given area.
79 */
80 void assureVisibleText();
81
82 /**
83 * Returns the available width in pixels for the text.
84 */
85 int availableTextWidth() const;
86
87 private:
88 enum State {
89 Default,
90 Illuminate,
91 Illuminated,
92 Desaturate
93 };
94
95 enum { GeometryTimeout = 100 };
96
97 DolphinStatusBar::Type m_type;
98 State m_state;
99 int m_illumination;
100 int m_minTextHeight;
101 QTimer* m_timer;
102 QString m_text;
103 QPixmap m_pixmap;
104
105 QColor mixColors(const QColor& c1,
106 const QColor& c2,
107 int percent) const;
108
109 int pixmapGap() const { return 3; }
110 };
111
112 #endif