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 | |
12 | namespace KTextEditor |
13 | { |
14 | class MessagePrivate |
15 | { |
16 | public: |
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 | |
30 | Message::Message(const QString &richtext, MessageType type) |
31 | : d(new MessagePrivate()) |
32 | { |
33 | d->messageType = type; |
34 | d->text = richtext; |
35 | } |
36 | |
37 | Message::~Message() |
38 | { |
39 | Q_EMIT closed(message: this); |
40 | |
41 | delete d; |
42 | } |
43 | |
44 | QString Message::text() const |
45 | { |
46 | return d->text; |
47 | } |
48 | |
49 | void Message::setText(const QString &text) |
50 | { |
51 | if (d->text != text) { |
52 | d->text = text; |
53 | Q_EMIT textChanged(text); |
54 | } |
55 | } |
56 | |
57 | void Message::setIcon(const QIcon &newIcon) |
58 | { |
59 | d->icon = newIcon; |
60 | Q_EMIT iconChanged(icon: d->icon); |
61 | } |
62 | |
63 | QIcon Message::icon() const |
64 | { |
65 | return d->icon; |
66 | } |
67 | |
68 | Message::MessageType Message::messageType() const |
69 | { |
70 | return d->messageType; |
71 | } |
72 | |
73 | void 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 | |
85 | QList<QAction *> Message::actions() const |
86 | { |
87 | return d->actions; |
88 | } |
89 | |
90 | void Message::setAutoHide(int delay) |
91 | { |
92 | d->autoHideDelay = delay; |
93 | } |
94 | |
95 | int Message::autoHide() const |
96 | { |
97 | return d->autoHideDelay; |
98 | } |
99 | |
100 | void Message::setAutoHideMode(KTextEditor::Message::AutoHideMode mode) |
101 | { |
102 | d->autoHideMode = mode; |
103 | } |
104 | |
105 | KTextEditor::Message::AutoHideMode Message::autoHideMode() const |
106 | { |
107 | return d->autoHideMode; |
108 | } |
109 | |
110 | void Message::setWordWrap(bool wordWrap) |
111 | { |
112 | d->wordWrap = wordWrap; |
113 | } |
114 | |
115 | bool Message::wordWrap() const |
116 | { |
117 | return d->wordWrap; |
118 | } |
119 | |
120 | void Message::setPriority(int priority) |
121 | { |
122 | d->priority = priority; |
123 | } |
124 | |
125 | int Message::priority() const |
126 | { |
127 | return d->priority; |
128 | } |
129 | |
130 | void Message::setView(KTextEditor::View *view) |
131 | { |
132 | d->view = view; |
133 | } |
134 | |
135 | KTextEditor::View *Message::view() const |
136 | { |
137 | return d->view; |
138 | } |
139 | |
140 | void Message::setDocument(KTextEditor::Document *document) |
141 | { |
142 | d->document = document; |
143 | } |
144 | |
145 | KTextEditor::Document *Message::document() const |
146 | { |
147 | return d->document; |
148 | } |
149 | |
150 | void Message::setPosition(Message::MessagePosition position) |
151 | { |
152 | d->position = position; |
153 | } |
154 | |
155 | Message::MessagePosition Message::position() const |
156 | { |
157 | return d->position; |
158 | } |
159 | |
160 | } // namespace KTextEditor |
161 |