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

Plasma

textedit.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "textedit.h"
00021 
00022 #include <QGraphicsSceneContextMenuEvent>
00023 #include <QMenu>
00024 #include <QPainter>
00025 #include <QScrollBar>
00026 
00027 #include <kmimetype.h>
00028 #include <ktextedit.h>
00029 
00030 #include "applet.h"
00031 #include "private/style_p.h"
00032 #include "private/themedwidgetinterface_p.h"
00033 #include "svg.h"
00034 #include "theme.h"
00035 
00036 namespace Plasma
00037 {
00038 
00039 class TextEditPrivate : public ThemedWidgetInterface<TextEdit>
00040 {
00041 public:
00042     TextEditPrivate(TextEdit *textEdit)
00043         : ThemedWidgetInterface<TextEdit>(textEdit)
00044     {
00045     }
00046 
00047     ~TextEditPrivate()
00048     {
00049     }
00050 
00051     Plasma::Style::Ptr style;
00052 };
00053 
00054 TextEdit::TextEdit(QGraphicsWidget *parent)
00055     : QGraphicsProxyWidget(parent),
00056       d(new TextEditPrivate(this))
00057 {
00058     setNativeWidget(new KTextEdit);
00059     d->style = Plasma::Style::sharedStyle();
00060     d->initTheming();
00061 }
00062 
00063 TextEdit::~TextEdit()
00064 {
00065     delete d;
00066     Plasma::Style::doneWithSharedStyle();
00067 }
00068 
00069 void TextEdit::setText(const QString &text)
00070 {
00071     static_cast<KTextEdit*>(widget())->setText(text);
00072 }
00073 
00074 QString TextEdit::text() const
00075 {
00076     return static_cast<KTextEdit*>(widget())->toHtml();
00077 }
00078 
00079 void TextEdit::setReadOnly(bool readOnly)
00080 {
00081     static_cast<KTextEdit*>(widget())->setReadOnly(readOnly);
00082 }
00083 
00084 bool TextEdit::isReadOnly() const
00085 {
00086     return static_cast<KTextEdit*>(widget())->isReadOnly();
00087 }
00088 
00089 void TextEdit::setStyleSheet(const QString &stylesheet)
00090 {
00091     widget()->setStyleSheet(stylesheet);
00092 }
00093 
00094 QString TextEdit::styleSheet()
00095 {
00096     return widget()->styleSheet();
00097 }
00098 
00099 void TextEdit::setNativeWidget(KTextEdit *nativeWidget)
00100 {
00101     if (widget()) {
00102         widget()->deleteLater();
00103     }
00104 
00105     nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
00106 
00107     connect(nativeWidget, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
00108 
00109     nativeWidget->setWindowIcon(QIcon());
00110     setWidget(nativeWidget);
00111 
00112     nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
00113     nativeWidget->setFrameShape(QFrame::NoFrame);
00114     nativeWidget->setTextBackgroundColor(Qt::transparent);
00115     nativeWidget->viewport()->setAutoFillBackground(false);
00116     nativeWidget->verticalScrollBar()->setStyle(d->style.data());
00117     nativeWidget->horizontalScrollBar()->setStyle(d->style.data());
00118 }
00119 
00120 KTextEdit *TextEdit::nativeWidget() const
00121 {
00122     return static_cast<KTextEdit*>(widget());
00123 }
00124 
00125 void TextEdit::append(const QString &text)
00126 {
00127     return nativeWidget()->append(text);
00128 }
00129 
00130 void TextEdit::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
00131 {
00132     Q_UNUSED(sourceName)
00133 
00134     KTextEdit *te = nativeWidget();
00135     te->clear();
00136 
00137     foreach (const QVariant &v, data) {
00138         if (v.canConvert(QVariant::String)) {
00139             te->append(v.toString() + '\n');
00140         }
00141     }
00142 }
00143 
00144 void TextEdit::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
00145 {
00146     QMenu *popup = nativeWidget()->mousePopupMenu();
00147     popup->exec(event->screenPos());
00148     delete popup;
00149 }
00150 
00151 void TextEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
00152 {
00153     QGraphicsProxyWidget::resizeEvent(event);
00154 }
00155 
00156 void TextEdit::changeEvent(QEvent *event)
00157 {
00158     d->changeEvent(event);
00159     QGraphicsProxyWidget::changeEvent(event);
00160 }
00161 
00162 void TextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
00163 {
00164     QGraphicsWidget *widget = parentWidget();
00165     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00166 
00167     while (!applet && widget) {
00168         widget = widget->parentWidget();
00169         applet = qobject_cast<Plasma::Applet *>(widget);
00170     }
00171 
00172     if (applet) {
00173         applet->setStatus(Plasma::AcceptingInputStatus);
00174     }
00175     QGraphicsProxyWidget::mousePressEvent(event);
00176 }
00177 
00178 void TextEdit::focusOutEvent(QFocusEvent *event)
00179 {
00180     QGraphicsWidget *widget = parentWidget();
00181     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00182 
00183     while (!applet && widget) {
00184         widget = widget->parentWidget();
00185         applet = qobject_cast<Plasma::Applet *>(widget);
00186     }
00187 
00188     if (applet) {
00189         applet->setStatus(Plasma::UnknownStatus);
00190     }
00191     QGraphicsProxyWidget::focusOutEvent(event);
00192 }
00193 
00194 } // namespace Plasma
00195 
00196 #include <textedit.moc>
00197 

Plasma

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal