]> cloud.milkyroute.net Git - dolphin.git/blob - src/statusbarmessagelabel.h
forwardport r757231
[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 <QtCore/QList>
27 #include <QtGui/QPixmap>
28
29 #include <QtGui/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 const QString& text() const;
57
58 void setDefaultText(const QString& text);
59 const QString& defaultText() const;
60
61 // TODO: maybe a better approach is possible with the size hint
62 void setMinimumTextHeight(int min);
63 int minimumTextHeight() const;
64
65 /**
66 * Returns the gap of the width of the current set text to the
67 * width of the message label. A gap <= 0 means that the text
68 * fits into the available width.
69 */
70 int widthGap() const;
71
72 protected:
73 /** @see QWidget::paintEvent() */
74 virtual void paintEvent(QPaintEvent* event);
75
76 /** @see QWidget::resizeEvent() */
77 virtual void resizeEvent(QResizeEvent* event);
78
79 private slots:
80 void timerDone();
81
82 /**
83 * Increases the height of the message label so that
84 * the given text fits into given area.
85 */
86 void assureVisibleText();
87
88 /**
89 * Returns the available width in pixels for the text.
90 */
91 int availableTextWidth() const;
92
93 /**
94 * Moves the close button to the upper right corner
95 * of the message label.
96 */
97 void updateCloseButtonPosition();
98
99 /**
100 * Closes the currently shown error message and replaces it
101 * by the next pending message.
102 */
103 void closeErrorMessage();
104
105 private:
106 /**
107 * Shows the next pending error message. If no pending message
108 * was in the queue, false is returned.
109 */
110 bool showPendingMessage();
111
112 /**
113 * Resets the message label properties. This is useful when the
114 * result of invoking StatusBarMessageLabel::setMessage() should
115 * not rely on previous states.
116 */
117 void reset();
118
119 private:
120 enum State
121 {
122 Default,
123 Illuminate,
124 Illuminated,
125 Desaturate
126 };
127
128 enum { GeometryTimeout = 100 };
129 enum { BorderGap = 2 };
130
131 DolphinStatusBar::Type m_type;
132 State m_state;
133 int m_illumination;
134 int m_minTextHeight;
135 QTimer* m_timer;
136 QString m_text;
137 QString m_defaultText;
138 QList<QString> m_pendingMessages;
139 QPixmap m_pixmap;
140 QPushButton* m_closeButton;
141 };
142
143 inline DolphinStatusBar::Type StatusBarMessageLabel::type() const
144 {
145 return m_type;
146 }
147
148 inline const QString& StatusBarMessageLabel::text() const
149 {
150 return m_text;
151 }
152
153 inline void StatusBarMessageLabel::setDefaultText(const QString& text)
154 {
155 m_defaultText = text;
156 }
157
158 inline const QString& StatusBarMessageLabel::defaultText() const
159 {
160 return m_defaultText;
161 }
162
163 inline int StatusBarMessageLabel::minimumTextHeight() const
164 {
165 return m_minTextHeight;
166 }
167
168 #endif