]> git.sesse.net Git - kdenlive/blob - src/statusbarmessagelabel.h
several small fixes, introduce nice popup messages in statusbar taken from dolphin
[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     Q_OBJECT
48
49 public:
50     explicit StatusBarMessageLabel(QWidget* parent);
51     virtual ~StatusBarMessageLabel();
52
53     MessageType type() const;
54
55     const QString& text() const;
56
57     void setDefaultText(const QString& text);
58     const QString& defaultText() const;
59
60     // TODO: maybe a better approach is possible with the size hint
61     void setMinimumTextHeight(int min);
62     int minimumTextHeight() const;
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 public slots:
79     void setMessage(const QString& text, MessageType type);
80
81 private slots:
82     void timerDone();
83
84     /**
85      * Increases the height of the message label so that
86      * the given text fits into given area.
87      */
88     void assureVisibleText();
89
90     /**
91      * Returns the available width in pixels for the text.
92      */
93     int availableTextWidth() const;
94
95     /**
96      * Moves the close button to the upper right corner
97      * of the message label.
98      */
99     void updateCloseButtonPosition();
100
101     /**
102      * Closes the currently shown error message and replaces it
103      * by the next pending message.
104      */
105     void closeErrorMessage();
106
107 private:
108     /**
109      * Shows the next pending error message. If no pending message
110      * was in the queue, false is returned.
111      */
112     bool showPendingMessage();
113
114     /**
115      * Resets the message label properties. This is useful when the
116      * result of invoking StatusBarMessageLabel::setMessage() should
117      * not rely on previous states.
118      */
119     void reset();
120
121 private:
122     enum State {
123         Default,
124         Illuminate,
125         Illuminated,
126         Desaturate
127     };
128
129     enum { GeometryTimeout = 100 };
130     enum { BorderGap = 2 };
131
132     MessageType m_type;
133     State m_state;
134     int m_illumination;
135     int m_minTextHeight;
136     QTimer* m_timer;
137     QString m_text;
138     QString m_defaultText;
139     QList<QString> m_pendingMessages;
140     QPixmap m_pixmap;
141     QPushButton* m_closeButton;
142 };
143
144 inline MessageType StatusBarMessageLabel::type() const {
145     return m_type;
146 }
147
148 inline const QString& StatusBarMessageLabel::text() const {
149     return m_text;
150 }
151
152 inline void StatusBarMessageLabel::setDefaultText(const QString& text) {
153     m_defaultText = text;
154 }
155
156 inline const QString& StatusBarMessageLabel::defaultText() const {
157     return m_defaultText;
158 }
159
160 inline int StatusBarMessageLabel::minimumTextHeight() const {
161     return m_minTextHeight;
162 }
163
164 #endif