File indexing completed on 2024-04-28 15:30:58

0001 /*
0002     SPDX-FileCopyrightText: 2012 Dominik Haumann <dhaumann@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KATE_MESSAGE_WIDGET_H
0008 #define KATE_MESSAGE_WIDGET_H
0009 
0010 #include <QHash>
0011 #include <QPointer>
0012 #include <QWidget>
0013 
0014 #include <ktexteditor_export.h>
0015 
0016 namespace KTextEditor
0017 {
0018 class Message;
0019 class ViewPrivate;
0020 }
0021 
0022 class KMessageWidget;
0023 class KateAnimation;
0024 
0025 /**
0026  * This class implements a message widget based on KMessageWidget.
0027  * It is used to show messages through the KTextEditior::MessageInterface.
0028  */
0029 class KTEXTEDITOR_EXPORT KateMessageWidget : public QWidget
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     /**
0035      * Constructor. By default, the widget is hidden.
0036      */
0037     explicit KateMessageWidget(QWidget *parent, bool applyFadeEffect = false);
0038 
0039     /**
0040      * Post a new incoming message. Show either directly, or queue
0041      */
0042     void postMessage(KTextEditor::Message *message, QList<QSharedPointer<QAction>> actions);
0043 
0044     // for unit test
0045     QString text() const;
0046 
0047 protected Q_SLOTS:
0048     /**
0049      * Show the next message in the queue.
0050      */
0051     void showNextMessage();
0052 
0053     /**
0054      * Helper that enables word wrap to avoid breaking the layout
0055      */
0056     void setWordWrap(KTextEditor::Message *message);
0057 
0058     /**
0059      * catch when a message is deleted, then show next one, if applicable.
0060      */
0061     void messageDestroyed(KTextEditor::Message *message);
0062 
0063     // ViewPrivate calls startAutoHideTimer()
0064     friend class KTextEditor::ViewPrivate;
0065     /**
0066      * Start autoHide timer if requested
0067      */
0068     void startAutoHideTimer();
0069     /**
0070      * User hovers on a link in the message widget.
0071      */
0072     void linkHovered(const QString &link);
0073 
0074 private:
0075     // sorted list of pending messages
0076     QList<KTextEditor::Message *> m_messageQueue;
0077     // pointer to current Message
0078     QPointer<KTextEditor::Message> m_currentMessage;
0079     // shared pointers to QActions as guard
0080     QHash<KTextEditor::Message *, QList<QSharedPointer<QAction>>> m_messageHash;
0081     // the message widget, showing the actual contents
0082     KMessageWidget *m_messageWidget;
0083     // the show / hide effect controller
0084     KateAnimation *m_animation;
0085 
0086 private: // some state variables
0087     // autoHide only once user interaction took place
0088     QTimer *m_autoHideTimer;
0089     // flag: save message's autohide time
0090     int m_autoHideTime;
0091 };
0092 
0093 #endif