]> git.sesse.net Git - kdenlive/blob - src/statusbarmessagelabel.h
Make Mlt error message more visible (they don't close automatically)
[kdenlive] / src / statusbarmessagelabel.h
1 /***************************************************************************
2  *   Copyright (C) 2006 by Peter Penz                                      *
3  *   peter.penz@gmx.at                                                     *
4  *   Code borrowed from Dolphin, adapted (2008) to Kdenlive by             *
5  *   Jean-Baptiste Mardelle, jb@kdenlive.org                               *
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
21  ***************************************************************************/
22
23 #ifndef STATUSBARMESSAGELABEL_H
24 #define STATUSBARMESSAGELABEL_H
25
26
27 #include <QtCore/QList>
28 #include <QtGui/QPixmap>
29
30 #include <QtGui/QWidget>
31 #include <definitions.h>
32
33 class QPaintEvent;
34 class QResizeEvent;
35 class QPushButton;
36 class QTimer;
37
38 /**
39  * @brief Represents a message text label as part of the status bar.
40  *
41  * Dependent from the given type automatically a corresponding icon
42  * is shown in front of the text. For message texts having the type
43  * DolphinStatusBar::Error a dynamic color blending is done to get the
44  * attention from the user.
45  */
46 class StatusBarMessageLabel : public QWidget
47 {
48     Q_OBJECT
49
50 public:
51     explicit StatusBarMessageLabel(QWidget* parent);
52     virtual ~StatusBarMessageLabel();
53
54     MessageType type() const;
55
56     const QString& text() const;
57
58     // TODO: maybe a better approach is possible with the size hint
59     void setMinimumTextHeight(int min);
60     int minimumTextHeight() const;
61
62 protected:
63     /** @see QWidget::paintEvent() */
64     virtual void paintEvent(QPaintEvent* event);
65
66     /** @see QWidget::resizeEvent() */
67     virtual void resizeEvent(QResizeEvent* event);
68
69 public slots:
70     void setMessage(const QString& text, MessageType type);
71
72 private slots:
73     void timerDone();
74
75     /**
76      * Increases the height of the message label so that
77      * the given text fits into given area.
78      */
79     void assureVisibleText();
80
81     /**
82      * Returns the available width in pixels for the text.
83      */
84     int availableTextWidth() const;
85
86     /**
87      * Moves the close button to the upper right corner
88      * of the message label.
89      */
90     void updateCloseButtonPosition();
91
92     /**
93      * Closes the currently shown error message and replaces it
94      * by the next pending message.
95      */
96     void closeErrorMessage();
97
98 private:
99     /**
100      * Shows the next pending error message. If no pending message
101      * was in the queue, false is returned.
102      */
103     bool showPendingMessage();
104
105     /**
106      * Resets the message label properties. This is useful when the
107      * result of invoking StatusBarMessageLabel::setMessage() should
108      * not rely on previous states.
109      */
110     void reset();
111
112 private:
113     enum State {
114         Default,
115         Illuminate,
116         Illuminated,
117         Desaturate
118     };
119
120     enum { GeometryTimeout = 100 };
121     enum { BorderGap = 2 };
122
123     MessageType m_type;
124     State m_state;
125     int m_illumination;
126     int m_minTextHeight;
127     QTimer* m_timer;
128     QString m_text;
129     QList<QString> m_pendingMessages;
130     QPixmap m_pixmap;
131     QPushButton* m_closeButton;
132 };
133
134 inline MessageType StatusBarMessageLabel::type() const
135 {
136     return m_type;
137 }
138
139 inline const QString& StatusBarMessageLabel::text() const
140 {
141     return m_text;
142 }
143
144 inline int StatusBarMessageLabel::minimumTextHeight() const
145 {
146     return m_minTextHeight;
147 }
148
149 #endif