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 
12 namespace KTextEditor
13 {
14 class MessagePrivate
15 {
16 public:
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 
30 Message::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 
49 void Message::setText(const QString &text)
50 {
51  if (d->text != text) {
52  d->text = text;
54  }
55 }
56 
57 void 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 
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(action);
78 
79  // call close if wanted
80  if (closeOnTrigger) {
82  }
83 }
84 
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 
101 {
102  d->autoHideMode = mode;
103 }
104 
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 
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
void textChanged(const QString &text)
This signal is emitted whenever setText() was called.
MessageType
Message types used as visual indicator.
Definition: message.h:106
KTextEditor::Message::AutoHideMode autoHideMode() const
Get the Message's auto hide mode.
void setIcon(const QIcon &icon)
Add an optional icon for this notification which will be shown next to the message text.
void setPriority(int priority)
Set the priority of this message to priority.
void setView(KTextEditor::View *view)
Set the associated view of the message.
AutoHideMode
The AutoHideMode determines when to trigger the autoHide timer.
Definition: message.h:135
QIcon icon() const
Returns the icon of this message.
Q_EMITQ_EMIT
void iconChanged(const QIcon &icon)
This signal is emitted whenever setIcon() was called.
@ AboveView
show message above view.
Definition: message.h:119
int priority() const
Returns the priority of the message.
int autoHide() const
Returns the auto hide time in milliseconds.
QString mode() const override
Return the name of the currently used mode.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
MessageType messageType() const
Returns the message type set in the constructor.
void setDocument(KTextEditor::Document *document)
Set the document pointer to document.
void setAutoHideMode(KTextEditor::Message::AutoHideMode mode)
Sets the auto hide mode to mode.
void deleteLater()
bool wordWrap() const
Check, whether word wrap is enabled or not.
MessagePosition
Message position used to place the message either above or below of the KTextEditor::View.
Definition: message.h:117
KTextEditor::View * view() const
This function returns the view you set by setView().
void setAutoHide(int delay=0)
Set the auto hide time to delay milliseconds.
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:243
QList< QAction * > actions() const
Accessor to all actions, mainly used in the internal implementation to add the actions into the gui.
void setWordWrap(bool wordWrap)
Enabled word wrap according to wordWrap.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition: katetextblock.h:19
Message(const QString &richtext, MessageType type=Message::Information)
Constructor for new messages.
void triggered(bool checked)
KTextEditor::Document * document() const
Returns the document pointer this message was posted in.
void setPosition(MessagePosition position)
Sets the position of the message to position.
~Message() override
Destructor.
void setParent(QObject *parent)
MessagePosition position() const
Returns the message position of this message.
QString text() const
Returns the text set in the constructor.
void addAction(QAction *action, bool closeOnTrigger=true)
Adds an action to the message.
@ AfterUserInteraction
auto-hide is triggered only after the user interacted with the view
Definition: message.h:137
void setText(const QString &richtext)
Sets the notification contents to richtext.
void closed(KTextEditor::Message *message)
This signal is emitted before the message is deleted.
A KParts derived class representing a text document.
Definition: document.h:283
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:50:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.