• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • plasma
  • widgets
textedit.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2008 Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "textedit.h"
21
22#include <QGraphicsSceneContextMenuEvent>
23#include <QMenu>
24#include <QPainter>
25#include <QScrollBar>
26#include <QGraphicsView>
27
28#include <kmimetype.h>
29#include <ktextedit.h>
30
31#include "applet.h"
32#include "private/style_p.h"
33#include "private/themedwidgetinterface_p.h"
34#include "svg.h"
35#include "theme.h"
36
37namespace Plasma
38{
39
40class TextEditPrivate : public ThemedWidgetInterface<TextEdit>
41{
42public:
43 TextEditPrivate(TextEdit *textEdit)
44 : ThemedWidgetInterface<TextEdit>(textEdit)
45 {
46 }
47
48 ~TextEditPrivate()
49 {
50 }
51
52 Plasma::Style::Ptr style;
53};
54
55TextEdit::TextEdit(QGraphicsWidget *parent)
56 : QGraphicsProxyWidget(parent),
57 d(new TextEditPrivate(this))
58{
59 setNativeWidget(new KTextEdit);
60 d->style = Plasma::Style::sharedStyle();
61 d->initTheming();
62}
63
64TextEdit::~TextEdit()
65{
66 delete d;
67 Plasma::Style::doneWithSharedStyle();
68}
69
70void TextEdit::setText(const QString &text)
71{
72 static_cast<KTextEdit*>(widget())->setText(text);
73}
74
75QString TextEdit::text() const
76{
77 return static_cast<KTextEdit*>(widget())->toHtml();
78}
79
80void TextEdit::setReadOnly(bool readOnly)
81{
82 static_cast<KTextEdit*>(widget())->setReadOnly(readOnly);
83}
84
85bool TextEdit::isReadOnly() const
86{
87 return static_cast<KTextEdit*>(widget())->isReadOnly();
88}
89
90void TextEdit::setStyleSheet(const QString &stylesheet)
91{
92 widget()->setStyleSheet(stylesheet);
93}
94
95QString TextEdit::styleSheet()
96{
97 return widget()->styleSheet();
98}
99
100void TextEdit::setNativeWidget(KTextEdit *nativeWidget)
101{
102 if (widget()) {
103 widget()->deleteLater();
104 }
105
106 nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
107
108 connect(nativeWidget, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
109
110 nativeWidget->setWindowIcon(QIcon());
111 d->setWidget(nativeWidget);
112
113 nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
114 nativeWidget->setFrameShape(QFrame::NoFrame);
115 nativeWidget->viewport()->setAutoFillBackground(false);
116 nativeWidget->verticalScrollBar()->setStyle(d->style.data());
117 nativeWidget->horizontalScrollBar()->setStyle(d->style.data());
118}
119
120KTextEdit *TextEdit::nativeWidget() const
121{
122 return static_cast<KTextEdit*>(widget());
123}
124
125void TextEdit::append(const QString &text)
126{
127 return nativeWidget()->append(text);
128}
129
130void TextEdit::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
131{
132 Q_UNUSED(sourceName)
133
134 KTextEdit *te = nativeWidget();
135 te->clear();
136
137 foreach (const QVariant &v, data) {
138 if (v.canConvert(QVariant::String)) {
139 te->append(v.toString() + '\n');
140 }
141 }
142}
143
144void TextEdit::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
145{
146 QMenu *popup = nativeWidget()->mousePopupMenu();
147 popup->exec(event->screenPos());
148 delete popup;
149}
150
151void TextEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
152{
153 QGraphicsProxyWidget::resizeEvent(event);
154}
155
156void TextEdit::changeEvent(QEvent *event)
157{
158 d->changeEvent(event);
159 QGraphicsProxyWidget::changeEvent(event);
160}
161
162void TextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
163{
164 QGraphicsWidget *widget = parentWidget();
165 Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
166
167 while (!applet && widget) {
168 widget = widget->parentWidget();
169 applet = qobject_cast<Plasma::Applet *>(widget);
170 }
171
172 if (applet) {
173 applet->setStatus(Plasma::AcceptingInputStatus);
174 }
175 QGraphicsProxyWidget::mousePressEvent(event);
176}
177
178void TextEdit::focusOutEvent(QFocusEvent *event)
179{
180 QGraphicsWidget *widget = parentWidget();
181 Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
182
183 while (!applet && widget) {
184 widget = widget->parentWidget();
185 applet = qobject_cast<Plasma::Applet *>(widget);
186 }
187
188 if (applet) {
189 applet->setStatus(Plasma::UnknownStatus);
190 }
191
192 QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
193 if (qApp) {
194 if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
195 if (view->scene() && view->scene() == scene()) {
196 QApplication::sendEvent(view, &closeEvent);
197 }
198 }
199 }
200
201 QGraphicsProxyWidget::focusOutEvent(event);
202}
203
204} // namespace Plasma
205
206#include <textedit.moc>
207
applet.h
Plasma::Applet
The base Applet class.
Definition: applet.h:78
Plasma::Applet::setStatus
void setStatus(const ItemStatus stat)
sets the status for this applet
Definition: applet.cpp:1198
Plasma::DataEngine::Data
QHash< QString, QVariant > Data
Definition: dataengine.h:68
Plasma::TextEdit::nativeWidget
KTextEdit * nativeWidget
Definition: textedit.h:47
Plasma::TextEdit::setReadOnly
void setReadOnly(bool readOnly)
Sets the text area to be read only or interactive.
Definition: textedit.cpp:80
Plasma::TextEdit::setText
void setText(const QString &text)
Sets the display text for this TextEdit.
Definition: textedit.cpp:70
Plasma::TextEdit::setNativeWidget
void setNativeWidget(KTextEdit *nativeWidget)
Sets the text edit wrapped by this TextEdit (widget must inherit KTextEdit), ownership is transferred...
Definition: textedit.cpp:100
Plasma::TextEdit::textChanged
void textChanged()
Plasma::TextEdit::text
QString text
Definition: textedit.h:45
Plasma::TextEdit::isReadOnly
bool isReadOnly() const
Definition: textedit.cpp:85
Plasma::TextEdit::readOnly
bool readOnly
Definition: textedit.h:48
Plasma::TextEdit::parentWidget
QGraphicsWidget * parentWidget
Definition: textedit.h:44
QGraphicsProxyWidget
QGraphicsView
QGraphicsWidget
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
Plasma::AcceptingInputStatus
@ AcceptingInputStatus
The Item is accepting input.
Definition: plasma.h:261
Plasma::UnknownStatus
@ UnknownStatus
The status is unknown.
Definition: plasma.h:257
svg.h
textedit.h
theme.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal