]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbarmessagelabel.h
adapt Dolphin to kdelibs coding style (http://techbase.kde.org/Policies/Kdelibs_Codin...
[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 <dolphinstatusbar.h>
25
26 #include <QList>
27 #include <QPixmap>
28 #include <QString>
29 #include <QWidget>
30
31 class QPaintEvent;
32 class QResizeEvent;
33 class QPushButton;
34 class QTimer;
35
36 /**
37 * @brief Represents a message text label as part of the status bar.
38 *
39 * Dependent from the given type automatically a corresponding icon
40 * is shown in front of the text. For message texts having the type
41 * DolphinStatusBar::Error a dynamic color blending is done to get the
42 * attention from the user.
43 */
44 class StatusBarMessageLabel : public QWidget
45 {
46 Q_OBJECT
47
48 public:
49 explicit StatusBarMessageLabel(QWidget* parent);
50 virtual ~StatusBarMessageLabel();
51
52 void setMessage(const QString& text, DolphinStatusBar::Type type);
53
54 DolphinStatusBar::Type type() const
55 {
56 return m_type;
57 }
58 const QString& text() const
59 {
60 return m_text;
61 }
62
63 void setDefaultText(const QString& text)
64 {
65 m_defaultText = text;
66 }
67 const QString& defaultText() const
68 {
69 return m_defaultText;
70 }
71
72 // TODO: maybe a better approach is possible with the size hint
73 void setMinimumTextHeight(int min);
74 int minimumTextHeight() const
75 {
76 return m_minTextHeight;
77 }
78
79 /**
80 * Returns the gap of the width of the current set text to the
81 * width of the message label. A gap <= 0 means that the text
82 * fits into the available width.
83 */
84 int widthGap() const;
85
86 protected:
87 /** @see QWidget::paintEvent() */
88 virtual void paintEvent(QPaintEvent* event);
89
90 /** @see QWidget::resizeEvent() */
91 virtual void resizeEvent(QResizeEvent* event);
92
93 private slots:
94 void timerDone();
95
96 /**
97 * Increases the height of the message label so that
98 * the given text fits into given area.
99 */
100 void assureVisibleText();
101
102 /**
103 * Returns the available width in pixels for the text.
104 */
105 int availableTextWidth() const;
106
107 /**
108 * Moves the close button to the upper right corner
109 * of the message label.
110 */
111 void updateCloseButtonPosition();
112
113 /**
114 * Closes the currently shown error message and replaces it
115 * by the next pending message.
116 */
117 void closeErrorMessage();
118
119 private:
120 /**
121 * Shows the next pending error message. If no pending message
122 * was in the queue, false is returned.
123 */
124 bool showPendingMessage();
125
126 /**
127 * Resets the message label properties. This is useful when the
128 * result of invoking StatusBarMessageLabel::setMessage() should
129 * not rely on previous states.
130 */
131 void reset();
132
133 private:
134 enum State
135 {
136 Default,
137 Illuminate,
138 Illuminated,
139 Desaturate
140 };
141
142 enum
143 {
144 GeometryTimeout = 100
145 };
146
147 DolphinStatusBar::Type m_type;
148 State m_state;
149 int m_illumination;
150 int m_minTextHeight;
151 QTimer* m_timer;
152 QString m_text;
153 QString m_defaultText;
154 QList<QString> m_pendingMessages;
155 QPixmap m_pixmap;
156 QPushButton* m_closeButton;
157
158 QColor mixColors(const QColor& c1,
159 const QColor& c2,
160 int percent) const;
161
162 int borderGap() const
163 {
164 return 2;
165 }
166 };
167
168 #endif