1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * 2012 Simon A. Eugster <simon.eu@gmail.com> *
5 * Code borrowed from Dolphin, adapted (2008) to Kdenlive by *
6 * Jean-Baptiste Mardelle, jb@kdenlive.org *
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. *
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. *
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 ***************************************************************************/
24 #ifndef STATUSBARMESSAGELABEL_H
25 #define STATUSBARMESSAGELABEL_H
34 #include <definitions.h>
36 #include "lib/qtimerWithTime.h"
44 Queue-able message item holding all important information
46 struct StatusBarMessageItem {
51 bool confirmed; ///< MLT errors need to be confirmed.
53 /// \return true if the error still needs to be confirmed
54 bool needsConfirmation() const
56 return type == MltError && !confirmed;
59 StatusBarMessageItem(const QString& text = QString(), MessageType type = DefaultMessage, int timeoutMS = 0) :
60 text(text), type(type), timeoutMillis(timeoutMS), confirmed(false) {}
62 bool operator ==(const StatusBarMessageItem &other)
64 return type == other.type && text == other.text;
69 * @brief Represents a message text label as part of the status bar.
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.
76 class StatusBarMessageLabel : public QWidget
81 explicit StatusBarMessageLabel(QWidget* parent);
82 virtual ~StatusBarMessageLabel();
84 // TODO: maybe a better approach is possible with the size hint
85 void setMinimumTextHeight(int min);
86 int minimumTextHeight() const;
89 /** @see QWidget::paintEvent() */
90 void paintEvent(QPaintEvent* event);
92 /** @see QWidget::resizeEvent() */
93 void resizeEvent(QResizeEvent* event);
96 void setMessage(const QString& text, MessageType type, int timeoutMS = 0);
102 * Returns the available width in pixels for the text.
104 int availableTextWidth() const;
107 * Moves the close button to the upper right corner
108 * of the message label.
110 void updateCloseButtonPosition();
113 * Closes the currently shown error message and replaces it
114 * by the next pending message.
116 void confirmErrorMessage();
119 * Shows the next pending error message. If no pending message
120 * was in the queue, false is returned.
122 bool slotMessageTimeout();
132 enum { GeometryTimeout = 100 };
133 enum { BorderGap = 2 };
140 QTimerWithTime m_queueTimer;
141 QSemaphore m_queueSemaphore;
142 QList<StatusBarMessageItem> m_messageQueue;
143 StatusBarMessageItem m_currentMessage;
146 QPushButton* m_closeButton;
149 inline int StatusBarMessageLabel::minimumTextHeight() const
151 return m_minTextHeight;