1/*
2 SPDX-FileCopyrightText: 2012-2013 Dominik Haumann <dhaumann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "ktexteditor/message.h"
8
9#include <QAction>
10#include <QIcon>
11
12namespace KTextEditor
13{
14class MessagePrivate
15{
16public:
17 QList<QAction *> actions;
18 Message::MessageType messageType;
19 Message::MessagePosition position = Message::AboveView;
20 QString text;
21 QIcon icon;
22 bool wordWrap = false;
23 int autoHideDelay = -1;
24 KTextEditor::Message::AutoHideMode autoHideMode = KTextEditor::Message::AfterUserInteraction;
25 int priority = 0;
26 KTextEditor::View *view = nullptr;
27 KTextEditor::Document *document = nullptr;
28};
29
30Message::Message(const QString &richtext, MessageType type)
31 : d(new MessagePrivate())
32{
33 d->messageType = type;
34 d->text = richtext;
35}
36
37Message::~Message()
38{
39 Q_EMIT closed(message: this);
40
41 delete d;
42}
43
44QString Message::text() const
45{
46 return d->text;
47}
48
49void Message::setText(const QString &text)
50{
51 if (d->text != text) {
52 d->text = text;
53 Q_EMIT textChanged(text);
54 }
55}
56
57void Message::setIcon(const QIcon &newIcon)
58{
59 d->icon = newIcon;
60 Q_EMIT iconChanged(icon: d->icon);
61}
62
63QIcon Message::icon() const
64{
65 return d->icon;
66}
67
68Message::MessageType Message::messageType() const
69{
70 return d->messageType;
71}
72
73void Message::addAction(QAction *action, bool closeOnTrigger)
74{
75 // make sure this is the parent, so all actions are deleted in the destructor
76 action->setParent(this);
77 d->actions.append(t: action);
78
79 // call close if wanted
80 if (closeOnTrigger) {
81 connect(sender: action, signal: &QAction::triggered, context: this, slot: &QObject::deleteLater);
82 }
83}
84
85QList<QAction *> Message::actions() const
86{
87 return d->actions;
88}
89
90void Message::setAutoHide(int delay)
91{
92 d->autoHideDelay = delay;
93}
94
95int Message::autoHide() const
96{
97 return d->autoHideDelay;
98}
99
100void Message::setAutoHideMode(KTextEditor::Message::AutoHideMode mode)
101{
102 d->autoHideMode = mode;
103}
104
105KTextEditor::Message::AutoHideMode Message::autoHideMode() const
106{
107 return d->autoHideMode;
108}
109
110void Message::setWordWrap(bool wordWrap)
111{
112 d->wordWrap = wordWrap;
113}
114
115bool Message::wordWrap() const
116{
117 return d->wordWrap;
118}
119
120void Message::setPriority(int priority)
121{
122 d->priority = priority;
123}
124
125int Message::priority() const
126{
127 return d->priority;
128}
129
130void Message::setView(KTextEditor::View *view)
131{
132 d->view = view;
133}
134
135KTextEditor::View *Message::view() const
136{
137 return d->view;
138}
139
140void Message::setDocument(KTextEditor::Document *document)
141{
142 d->document = document;
143}
144
145KTextEditor::Document *Message::document() const
146{
147 return d->document;
148}
149
150void Message::setPosition(Message::MessagePosition position)
151{
152 d->position = position;
153}
154
155Message::MessagePosition Message::position() const
156{
157 return d->position;
158}
159
160} // namespace KTextEditor
161

source code of ktexteditor/src/utils/messageinterface.cpp