1 | /* |
2 | SPDX-FileCopyrightText: 2012 Dominik Haumann <dhaumann@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KATE_MESSAGE_WIDGET_H |
8 | #define KATE_MESSAGE_WIDGET_H |
9 | |
10 | #include <QHash> |
11 | #include <QPointer> |
12 | #include <QWidget> |
13 | |
14 | #include <ktexteditor_export.h> |
15 | |
16 | namespace KTextEditor |
17 | { |
18 | class Message; |
19 | class ViewPrivate; |
20 | } |
21 | |
22 | class KMessageWidget; |
23 | class KateAnimation; |
24 | |
25 | /** |
26 | * This class implements a message widget based on KMessageWidget. |
27 | * It is used to show messages through the KTextEditior::MessageInterface. |
28 | */ |
29 | class KateMessageWidget : public QWidget |
30 | { |
31 | Q_OBJECT |
32 | |
33 | public: |
34 | /** |
35 | * The position of the KateMessageWidget |
36 | * |
37 | * @see KMessageWidget::Position |
38 | */ |
39 | enum class Position { |
40 | Inline, ///< Inline message. |
41 | , ///< Message positioned at the top of the view. |
42 | , ///< Message positioned at the bottom of the view. |
43 | }; |
44 | |
45 | /** |
46 | * Constructor. By default, the widget is hidden. |
47 | */ |
48 | explicit KateMessageWidget(QWidget *parent, bool applyFadeEffect = false); |
49 | |
50 | /** |
51 | * Post a new incoming message. Show either directly, or queue |
52 | */ |
53 | void postMessage(KTextEditor::Message *message, QList<std::shared_ptr<QAction>> actions); |
54 | |
55 | // for unit test |
56 | KTEXTEDITOR_EXPORT QString text() const; |
57 | |
58 | void setPosition(Position position); |
59 | |
60 | protected Q_SLOTS: |
61 | /** |
62 | * Show the next message in the queue. |
63 | */ |
64 | void showNextMessage(); |
65 | |
66 | /** |
67 | * Helper that enables word wrap to avoid breaking the layout |
68 | */ |
69 | void setWordWrap(KTextEditor::Message *message); |
70 | |
71 | /** |
72 | * catch when a message is deleted, then show next one, if applicable. |
73 | */ |
74 | void messageDestroyed(KTextEditor::Message *message); |
75 | |
76 | // ViewPrivate calls startAutoHideTimer() |
77 | friend class KTextEditor::ViewPrivate; |
78 | /** |
79 | * Start autoHide timer if requested |
80 | */ |
81 | void startAutoHideTimer(); |
82 | /** |
83 | * User hovers on a link in the message widget. |
84 | */ |
85 | void linkHovered(const QString &link); |
86 | |
87 | private: |
88 | // sorted list of pending messages |
89 | QList<KTextEditor::Message *> m_messageQueue; |
90 | // pointer to current Message |
91 | QPointer<KTextEditor::Message> m_currentMessage; |
92 | // shared pointers to QActions as guard |
93 | QHash<KTextEditor::Message *, QList<std::shared_ptr<QAction>>> m_messageHash; |
94 | // the message widget, showing the actual contents |
95 | KMessageWidget *m_messageWidget; |
96 | // the show / hide effect controller |
97 | KateAnimation *m_animation; |
98 | |
99 | private: // some state variables |
100 | // autoHide only once user interaction took place |
101 | QTimer *m_autoHideTimer; |
102 | // flag: save message's autohide time |
103 | int m_autoHideTime; |
104 | }; |
105 | |
106 | #endif |
107 | |