File indexing completed on 2024-04-21 08:48:08

0001 /*
0002     SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KONQ_STATUSBARMESSAGELABEL_H
0008 #define KONQ_STATUSBARMESSAGELABEL_H
0009 
0010 #include <QWidget>
0011 
0012 class QPaintEvent;
0013 class QResizeEvent;
0014 
0015 /**
0016  * @brief Represents a message text label as part of the status bar.
0017  *
0018  * Dependent from the given type automatically a corresponding icon
0019  * is shown in front of the text. For message texts having the type
0020  * KonqStatusBarMessageLabel::Error a dynamic color blending is done to get the
0021  * attention from the user.
0022  */
0023 class KonqStatusBarMessageLabel : public QWidget
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     explicit KonqStatusBarMessageLabel(QWidget *parent);
0029     ~KonqStatusBarMessageLabel() override;
0030 
0031     /**
0032      * Describes the type of the message text. Dependent
0033      * from the type a corresponding icon and color is
0034      * used for the message text.
0035      */
0036     enum Type {
0037         Default,
0038         OperationCompleted,
0039         Information,
0040         Error
0041     };
0042 
0043     void setMessage(const QString &text, Type type);
0044 
0045     Type type() const;
0046 
0047     QString text() const;
0048 
0049     void setDefaultText(const QString &text);
0050     QString defaultText() const;
0051 
0052     // TODO: maybe a better approach is possible with the size hint
0053     void setMinimumTextHeight(int min);
0054     int minimumTextHeight() const;
0055 
0056     /** @see QWidget::sizeHint */
0057     QSize sizeHint() const override;
0058     /** @see QWidget::minimumSizeHint */
0059     QSize minimumSizeHint() const override;
0060 
0061 protected:
0062     /** @see QWidget::paintEvent() */
0063     void paintEvent(QPaintEvent *event) override;
0064 
0065     /** @see QWidget::resizeEvent() */
0066     void resizeEvent(QResizeEvent *event) override;
0067 
0068 private Q_SLOTS:
0069     void timerDone();
0070 
0071     /**
0072      * Increases the height of the message label so that
0073      * the given text fits into given area.
0074      */
0075     void assureVisibleText();
0076 
0077     /**
0078      * Returns the available width in pixels for the text.
0079      */
0080     int availableTextWidth() const;
0081 
0082     /**
0083      * Moves the close button to the upper right corner
0084      * of the message label.
0085      */
0086     void updateCloseButtonPosition();
0087 
0088     /**
0089      * Closes the currently shown error message and replaces it
0090      * by the next pending message.
0091      */
0092     void closeErrorMessage();
0093 
0094 private:
0095     /**
0096      * Shows the next pending error message. If no pending message
0097      * was in the queue, false is returned.
0098      */
0099     bool showPendingMessage();
0100 
0101     /**
0102      * Resets the message label properties. This is useful when the
0103      * result of invoking KonqStatusBarMessageLabel::setMessage() should
0104      * not rely on previous states.
0105      */
0106     void reset();
0107 
0108 private:
0109     enum State {
0110         DefaultState,
0111         Illuminate,
0112         Illuminated,
0113         Desaturate
0114     };
0115 
0116     class Private;
0117     Private *const d;
0118 };
0119 
0120 #endif