File indexing completed on 2024-04-14 03:55:33
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 KateMessageWidget : public QWidget 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 /** 0035 * The position of the KateMessageWidget 0036 * 0037 * @see KMessageWidget::Position 0038 */ 0039 enum class Position { 0040 Inline, ///< Inline message. 0041 Header, ///< Message positioned at the top of the view. 0042 Footer, ///< Message positioned at the bottom of the view. 0043 }; 0044 0045 /** 0046 * Constructor. By default, the widget is hidden. 0047 */ 0048 explicit KateMessageWidget(QWidget *parent, bool applyFadeEffect = false); 0049 0050 /** 0051 * Post a new incoming message. Show either directly, or queue 0052 */ 0053 void postMessage(KTextEditor::Message *message, QList<std::shared_ptr<QAction>> actions); 0054 0055 // for unit test 0056 KTEXTEDITOR_EXPORT QString text() const; 0057 0058 void setPosition(Position position); 0059 0060 protected Q_SLOTS: 0061 /** 0062 * Show the next message in the queue. 0063 */ 0064 void showNextMessage(); 0065 0066 /** 0067 * Helper that enables word wrap to avoid breaking the layout 0068 */ 0069 void setWordWrap(KTextEditor::Message *message); 0070 0071 /** 0072 * catch when a message is deleted, then show next one, if applicable. 0073 */ 0074 void messageDestroyed(KTextEditor::Message *message); 0075 0076 // ViewPrivate calls startAutoHideTimer() 0077 friend class KTextEditor::ViewPrivate; 0078 /** 0079 * Start autoHide timer if requested 0080 */ 0081 void startAutoHideTimer(); 0082 /** 0083 * User hovers on a link in the message widget. 0084 */ 0085 void linkHovered(const QString &link); 0086 0087 private: 0088 // sorted list of pending messages 0089 QList<KTextEditor::Message *> m_messageQueue; 0090 // pointer to current Message 0091 QPointer<KTextEditor::Message> m_currentMessage; 0092 // shared pointers to QActions as guard 0093 QHash<KTextEditor::Message *, QList<std::shared_ptr<QAction>>> m_messageHash; 0094 // the message widget, showing the actual contents 0095 KMessageWidget *m_messageWidget; 0096 // the show / hide effect controller 0097 KateAnimation *m_animation; 0098 0099 private: // some state variables 0100 // autoHide only once user interaction took place 0101 QTimer *m_autoHideTimer; 0102 // flag: save message's autohide time 0103 int m_autoHideTime; 0104 }; 0105 0106 #endif