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