KTextEditor

messageinterface.cpp
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;
20 QString text;
21 QIcon icon;
22 bool wordWrap = false;
23 int autoHideDelay = -1;
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
38{
39 Q_EMIT closed(this);
40
41 delete d;
42}
43
45{
46 return d->text;
47}
48
49void Message::setText(const QString &text)
50{
51 if (d->text != text) {
52 d->text = text;
54 }
55}
56
57void Message::setIcon(const QIcon &newIcon)
58{
59 d->icon = newIcon;
60 Q_EMIT iconChanged(d->icon);
61}
62
64{
65 return d->icon;
66}
67
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(action);
78
79 // call close if wanted
80 if (closeOnTrigger) {
82 }
83}
84
86{
87 return d->actions;
88}
89
90void Message::setAutoHide(int delay)
91{
92 d->autoHideDelay = delay;
93}
94
96{
97 return d->autoHideDelay;
98}
99
101{
102 d->autoHideMode = mode;
103}
104
106{
107 return d->autoHideMode;
108}
109
110void Message::setWordWrap(bool wordWrap)
111{
112 d->wordWrap = wordWrap;
113}
114
116{
117 return d->wordWrap;
118}
119
120void Message::setPriority(int priority)
121{
122 d->priority = priority;
123}
124
126{
127 return d->priority;
128}
129
131{
132 d->view = view;
133}
134
136{
137 return d->view;
138}
139
141{
142 d->document = document;
143}
144
146{
147 return d->document;
148}
149
151{
152 d->position = position;
153}
154
156{
157 return d->position;
158}
159
160} // namespace KTextEditor
A KParts derived class representing a text document.
Definition document.h:284
void setWordWrap(bool wordWrap)
Enabled word wrap according to wordWrap.
MessagePosition
Message position used to place the message either above or below of the KTextEditor::View.
Definition message.h:117
@ AboveView
show message above view.
Definition message.h:119
KTextEditor::View * view() const
This function returns the view you set by setView().
int autoHide() const
Returns the auto hide time in milliseconds.
~Message() override
Destructor.
void setAutoHide(int delay=0)
Set the auto hide time to delay milliseconds.
void setAutoHideMode(KTextEditor::Message::AutoHideMode mode)
Sets the auto hide mode to mode.
bool wordWrap() const
Check, whether word wrap is enabled or not.
void addAction(QAction *action, bool closeOnTrigger=true)
Adds an action to the message.
QString text() const
Returns the text set in the constructor.
void closed(KTextEditor::Message *message)
This signal is emitted before the message is deleted.
KTextEditor::Message::AutoHideMode autoHideMode() const
Get the Message's auto hide mode.
MessageType messageType() const
Returns the message type set in the constructor.
void textChanged(const QString &text)
This signal is emitted whenever setText() was called.
MessagePosition position() const
Returns the message position of this message.
MessageType
Message types used as visual indicator.
Definition message.h:106
QIcon icon() const
Returns the icon of this message.
void setIcon(const QIcon &icon)
Add an optional icon for this notification which will be shown next to the message text.
int priority() const
Returns the priority of the message.
void setDocument(KTextEditor::Document *document)
Set the document pointer to document.
AutoHideMode
The AutoHideMode determines when to trigger the autoHide timer.
Definition message.h:135
@ AfterUserInteraction
auto-hide is triggered only after the user interacted with the view
Definition message.h:137
Message(const QString &richtext, MessageType type=Message::Information)
Constructor for new messages.
void setPriority(int priority)
Set the priority of this message to priority.
void setView(KTextEditor::View *view)
Set the associated view of the message.
void setPosition(MessagePosition position)
Sets the position of the message to position.
void setText(const QString &richtext)
Sets the notification contents to richtext.
void iconChanged(const QIcon &icon)
This signal is emitted whenever setIcon() was called.
QList< QAction * > actions() const
Accessor to all actions, mainly used in the internal implementation to add the actions into the gui.
KTextEditor::Document * document() const
Returns the document pointer this message was posted in.
A text widget with KXMLGUIClient that represents a Document.
Definition view.h:244
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
void triggered(bool checked)
void append(QList< T > &&value)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
void setParent(QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:57:26 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.