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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • 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 
37 namespace Plasma
38 {
39 
40 class TextEditPrivate : public ThemedWidgetInterface<TextEdit>
41 {
42 public:
43  TextEditPrivate(TextEdit *textEdit)
44  : ThemedWidgetInterface<TextEdit>(textEdit)
45  {
46  }
47 
48  ~TextEditPrivate()
49  {
50  }
51 
52  Plasma::Style::Ptr style;
53 };
54 
55 TextEdit::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 
64 TextEdit::~TextEdit()
65 {
66  delete d;
67  Plasma::Style::doneWithSharedStyle();
68 }
69 
70 void TextEdit::setText(const QString &text)
71 {
72  static_cast<KTextEdit*>(widget())->setText(text);
73 }
74 
75 QString TextEdit::text() const
76 {
77  return static_cast<KTextEdit*>(widget())->toHtml();
78 }
79 
80 void TextEdit::setReadOnly(bool readOnly)
81 {
82  static_cast<KTextEdit*>(widget())->setReadOnly(readOnly);
83 }
84 
85 bool TextEdit::isReadOnly() const
86 {
87  return static_cast<KTextEdit*>(widget())->isReadOnly();
88 }
89 
90 void TextEdit::setStyleSheet(const QString &stylesheet)
91 {
92  widget()->setStyleSheet(stylesheet);
93 }
94 
95 QString TextEdit::styleSheet()
96 {
97  return widget()->styleSheet();
98 }
99 
100 void 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 
120 KTextEdit *TextEdit::nativeWidget() const
121 {
122  return static_cast<KTextEdit*>(widget());
123 }
124 
125 void TextEdit::append(const QString &text)
126 {
127  return nativeWidget()->append(text);
128 }
129 
130 void 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 
144 void TextEdit::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
145 {
146  QMenu *popup = nativeWidget()->mousePopupMenu();
147  popup->exec(event->screenPos());
148  delete popup;
149 }
150 
151 void TextEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
152 {
153  QGraphicsProxyWidget::resizeEvent(event);
154 }
155 
156 void TextEdit::changeEvent(QEvent *event)
157 {
158  d->changeEvent(event);
159  QGraphicsProxyWidget::changeEvent(event);
160 }
161 
162 void 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 
178 void 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 
Plasma::UnknownStatus
The status is unknown.
Definition: plasma.h:257
Plasma::TextEdit::setText
void setText(const QString &text)
Sets the display text for this TextEdit.
Definition: textedit.cpp:70
Plasma::TextEdit::append
void append(const QString &text)
Allows appending text to the text browser.
Definition: textedit.cpp:125
textedit.h
Plasma::TextEdit::setReadOnly
void setReadOnly(bool readOnly)
Sets the text area to be read only or interactive.
Definition: textedit.cpp:80
Plasma::TextEdit::contextMenuEvent
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
Definition: textedit.cpp:144
theme.h
Plasma::TextEdit::dataUpdated
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
Definition: textedit.cpp:130
Plasma::TextEdit::parentWidget
QGraphicsWidget parentWidget
Definition: textedit.h:44
Plasma::DataEngine::Data
QHash< QString, QVariant > Data
Definition: dataengine.h:68
Plasma::TextEdit::isReadOnly
bool isReadOnly() const
Definition: textedit.cpp:85
Plasma::TextEdit::nativeWidget
KTextEdit * nativeWidget() const
Plasma::Applet
The base Applet class.
Definition: applet.h:77
Plasma::Applet::setStatus
void setStatus(const ItemStatus stat)
sets the status for this applet
Definition: applet.cpp:1198
applet.h
Plasma::TextEdit::resizeEvent
void resizeEvent(QGraphicsSceneResizeEvent *event)
Definition: textedit.cpp:151
Plasma::TextEdit::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: textedit.cpp:162
QGraphicsProxyWidget
Plasma::TextEdit::~TextEdit
~TextEdit()
Definition: textedit.cpp:64
Plasma::TextEdit::TextEdit
TextEdit(QGraphicsWidget *parent=0)
Definition: textedit.cpp:55
Plasma::TextEdit::textChanged
void textChanged()
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::text
QString text() const
Plasma::TextEdit::styleSheet
QString styleSheet()
Plasma::TextEdit::changeEvent
void changeEvent(QEvent *event)
Definition: textedit.cpp:156
QGraphicsView
Plasma::TextEdit::setStyleSheet
void setStyleSheet(const QString &stylesheet)
Sets the stylesheet used to control the visual display of this TextEdit.
Definition: textedit.cpp:90
Plasma::TextEdit::focusOutEvent
void focusOutEvent(QFocusEvent *event)
Definition: textedit.cpp:178
svg.h
Plasma::AcceptingInputStatus
The Item is accepting input.
Definition: plasma.h:261
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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