KTextEditor

messageinterface.cpp
1 /*
2  SPDX-FileCopyrightText: 2012-2013 Dominik Haumann <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "ktexteditor/message.h"
8 
9 namespace KTextEditor
10 {
11 class MessagePrivate
12 {
13 public:
14  QList<QAction *> actions;
15  Message::MessageType messageType;
17  QString text;
18  QIcon icon;
19  bool wordWrap = false;
20  int autoHideDelay = -1;
22  int priority = 0;
23  KTextEditor::View *view = nullptr;
24  KTextEditor::Document *document = nullptr;
25 };
26 
27 Message::Message(const QString &richtext, MessageType type)
28  : d(new MessagePrivate())
29 {
30  d->messageType = type;
31  d->text = richtext;
32 }
33 
35 {
36  Q_EMIT closed(this);
37 
38  delete d;
39 }
40 
42 {
43  return d->text;
44 }
45 
46 void Message::setText(const QString &text)
47 {
48  if (d->text != text) {
49  d->text = text;
51  }
52 }
53 
54 void Message::setIcon(const QIcon &newIcon)
55 {
56  d->icon = newIcon;
57  Q_EMIT iconChanged(d->icon);
58 }
59 
61 {
62  return d->icon;
63 }
64 
66 {
67  return d->messageType;
68 }
69 
70 void Message::addAction(QAction *action, bool closeOnTrigger)
71 {
72  // make sure this is the parent, so all actions are deleted in the destructor
73  action->setParent(this);
74  d->actions.append(action);
75 
76  // call close if wanted
77  if (closeOnTrigger) {
79  }
80 }
81 
83 {
84  return d->actions;
85 }
86 
87 void Message::setAutoHide(int delay)
88 {
89  d->autoHideDelay = delay;
90 }
91 
92 int Message::autoHide() const
93 {
94  return d->autoHideDelay;
95 }
96 
98 {
99  d->autoHideMode = mode;
100 }
101 
103 {
104  return d->autoHideMode;
105 }
106 
107 void Message::setWordWrap(bool wordWrap)
108 {
109  d->wordWrap = wordWrap;
110 }
111 
112 bool Message::wordWrap() const
113 {
114  return d->wordWrap;
115 }
116 
117 void Message::setPriority(int priority)
118 {
119  d->priority = priority;
120 }
121 
122 int Message::priority() const
123 {
124  return d->priority;
125 }
126 
128 {
129  d->view = view;
130 }
131 
133 {
134  return d->view;
135 }
136 
138 {
139  d->document = document;
140 }
141 
143 {
144  return d->document;
145 }
146 
148 {
149  d->position = position;
150 }
151 
153 {
154  return d->position;
155 }
156 
157 } // 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:146
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:22
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:185
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:50:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.