File indexing completed on 2022-10-04 15:37:25

0001 /*
0002     SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
0003     SPDX-FileCopyrightText: 2008 Jean-Baptiste Mardelle <jb@kdenlive.org>
0004     SPDX-FileCopyrightText: 2012 Simon A. Eugster <simon.eu@gmail.com>
0005 
0006     Some code borrowed from Dolphin, adapted (2008) to Kdenlive
0007 
0008     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0009 */
0010 
0011 #pragma once
0012 
0013 #include <QColor>
0014 #include <QLabel>
0015 #include <QList>
0016 #include <QSemaphore>
0017 #include <QTimer>
0018 #include <QWidget>
0019 #include <definitions.h>
0020 #include <utility>
0021 
0022 #include "lib/qtimerWithTime.h"
0023 
0024 class QPaintEvent;
0025 class QResizeEvent;
0026 class QProgressBar;
0027 
0028 class FlashLabel : public QWidget
0029 {
0030     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
0031     Q_OBJECT
0032 public:
0033     explicit FlashLabel(QWidget *parent = nullptr);
0034     ~FlashLabel() override;
0035     QColor color() const;
0036     void setColor(const QColor &);
0037 signals:
0038     void colorChanged();
0039 };
0040 
0041 /**
0042   Queue-able message item holding all important information
0043   */
0044 struct StatusBarMessageItem
0045 {
0046 
0047     QString text;
0048     MessageType type;
0049     int timeoutMillis;
0050     bool confirmed{false}; ///< MLT errors need to be confirmed.
0051 
0052     /// @return true if the error still needs to be confirmed
0053     bool needsConfirmation() const { return (type == MltError && !confirmed); }
0054 
0055     StatusBarMessageItem(QString messageText = QString(), MessageType messageType = DefaultMessage, int timeoutMS = 0)
0056         : text(std::move(messageText))
0057         , type(messageType)
0058         , timeoutMillis(timeoutMS)
0059     {
0060     }
0061 
0062     bool operator==(const StatusBarMessageItem &other) const { return type == other.type && text == other.text; }
0063 };
0064 
0065 /**
0066  * @brief Represents a message text label as part of the status bar.
0067  *
0068  * Dependent from the given type automatically a corresponding icon
0069  * is shown in front of the text. For message texts having the type
0070  * DolphinStatusBar::Error a dynamic color blending is done to get the
0071  * attention from the user.
0072  */
0073 class StatusBarMessageLabel : public QWidget
0074 {
0075     Q_OBJECT
0076 
0077 public:
0078     explicit StatusBarMessageLabel(QWidget *parent);
0079     ~StatusBarMessageLabel() override;
0080 
0081 protected:
0082     // void paintEvent(QPaintEvent* event);
0083     void mousePressEvent(QMouseEvent *) override;
0084 
0085     /** @see QWidget::resizeEvent() */
0086     void resizeEvent(QResizeEvent *event) override;
0087 
0088 public slots:
0089     void setProgressMessage(const QString &text, MessageType type = ProcessingJobMessage, int progress = 100);
0090     void setMessage(const QString &text, MessageType type = DefaultMessage, int timeoutMS = 0);
0091     void setSelectionMessage(const QString &text);
0092     /** @brief Display a key binding info in status bar */
0093     void setKeyMap(const QString &text);
0094     /** @brief Display a temporary key binding info in status bar, revert to default one if text is empty */
0095     void setTmpKeyMap(const QString &text);
0096 
0097 private slots:
0098 
0099     /**
0100      * Closes the currently shown error message and replaces it
0101      * by the next pending message.
0102      */
0103     void confirmErrorMessage();
0104 
0105     /**
0106      * Shows the next pending error message. If no pending message
0107      * was in the queue, false is returned.
0108      */
0109     bool slotMessageTimeout();
0110     void slotShowJobLog(const QString &text);
0111 
0112 private:
0113     enum { GeometryTimeout = 100 };
0114     enum { BorderGap = 2 };
0115 
0116     int m_minTextHeight;
0117     FlashLabel *m_container;
0118     QLabel *m_selectionLabel;
0119     QLabel *m_pixmap;
0120     QLabel *m_label;
0121     QLabel *m_keyMap;
0122     QString m_keymapText;
0123     QString m_tooltipText;
0124     QProgressBar *m_progress;
0125     QTimerWithTime m_queueTimer;
0126     QSemaphore m_queueSemaphore;
0127     QList<StatusBarMessageItem> m_messageQueue;
0128     StatusBarMessageItem m_currentMessage;
0129 };