]> git.sesse.net Git - kdenlive/blob - src/statusbarmessagelabel.h
Reindent the codebase using 'linux' bracket placement.
[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     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 public slots:
80     void setMessage(const QString& text, MessageType type);
81
82 private slots:
83     void timerDone();
84
85     /**
86      * Increases the height of the message label so that
87      * the given text fits into given area.
88      */
89     void assureVisibleText();
90
91     /**
92      * Returns the available width in pixels for the text.
93      */
94     int availableTextWidth() const;
95
96     /**
97      * Moves the close button to the upper right corner
98      * of the message label.
99      */
100     void updateCloseButtonPosition();
101
102     /**
103      * Closes the currently shown error message and replaces it
104      * by the next pending message.
105      */
106     void closeErrorMessage();
107
108 private:
109     /**
110      * Shows the next pending error message. If no pending message
111      * was in the queue, false is returned.
112      */
113     bool showPendingMessage();
114
115     /**
116      * Resets the message label properties. This is useful when the
117      * result of invoking StatusBarMessageLabel::setMessage() should
118      * not rely on previous states.
119      */
120     void reset();
121
122 private:
123     enum State {
124         Default,
125         Illuminate,
126         Illuminated,
127         Desaturate
128     };
129
130     enum { GeometryTimeout = 100 };
131     enum { BorderGap = 2 };
132
133     MessageType m_type;
134     State m_state;
135     int m_illumination;
136     int m_minTextHeight;
137     QTimer* m_timer;
138     QString m_text;
139     QString m_defaultText;
140     QList<QString> m_pendingMessages;
141     QPixmap m_pixmap;
142     QPushButton* m_closeButton;
143 };
144
145 inline MessageType StatusBarMessageLabel::type() const
146 {
147     return m_type;
148 }
149
150 inline const QString& StatusBarMessageLabel::text() const
151 {
152     return m_text;
153 }
154
155 inline void StatusBarMessageLabel::setDefaultText(const QString& text)
156 {
157     m_defaultText = text;
158 }
159
160 inline const QString& StatusBarMessageLabel::defaultText() const
161 {
162     return m_defaultText;
163 }
164
165 inline int StatusBarMessageLabel::minimumTextHeight() const
166 {
167     return m_minTextHeight;
168 }
169
170 #endif