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