• Skip to content
  • Skip to link menu
KDE 4.7 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 #include <QGraphicsView>
00027 
00028 #include <kmimetype.h>
00029 #include <ktextedit.h>
00030 
00031 #include "applet.h"
00032 #include "private/style_p.h"
00033 #include "private/themedwidgetinterface_p.h"
00034 #include "svg.h"
00035 #include "theme.h"
00036 
00037 namespace Plasma
00038 {
00039 
00040 class TextEditPrivate : public ThemedWidgetInterface<TextEdit>
00041 {
00042 public:
00043     TextEditPrivate(TextEdit *textEdit)
00044         : ThemedWidgetInterface<TextEdit>(textEdit)
00045     {
00046     }
00047 
00048     ~TextEditPrivate()
00049     {
00050     }
00051 
00052     Plasma::Style::Ptr style;
00053 };
00054 
00055 TextEdit::TextEdit(QGraphicsWidget *parent)
00056     : QGraphicsProxyWidget(parent),
00057       d(new TextEditPrivate(this))
00058 {
00059     setNativeWidget(new KTextEdit);
00060     d->style = Plasma::Style::sharedStyle();
00061     d->initTheming();
00062 }
00063 
00064 TextEdit::~TextEdit()
00065 {
00066     delete d;
00067     Plasma::Style::doneWithSharedStyle();
00068 }
00069 
00070 void TextEdit::setText(const QString &text)
00071 {
00072     static_cast<KTextEdit*>(widget())->setText(text);
00073 }
00074 
00075 QString TextEdit::text() const
00076 {
00077     return static_cast<KTextEdit*>(widget())->toHtml();
00078 }
00079 
00080 void TextEdit::setReadOnly(bool readOnly)
00081 {
00082     static_cast<KTextEdit*>(widget())->setReadOnly(readOnly);
00083 }
00084 
00085 bool TextEdit::isReadOnly() const
00086 {
00087     return static_cast<KTextEdit*>(widget())->isReadOnly();
00088 }
00089 
00090 void TextEdit::setStyleSheet(const QString &stylesheet)
00091 {
00092     widget()->setStyleSheet(stylesheet);
00093 }
00094 
00095 QString TextEdit::styleSheet()
00096 {
00097     return widget()->styleSheet();
00098 }
00099 
00100 void TextEdit::setNativeWidget(KTextEdit *nativeWidget)
00101 {
00102     if (widget()) {
00103         widget()->deleteLater();
00104     }
00105 
00106     nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
00107 
00108     connect(nativeWidget, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
00109 
00110     nativeWidget->setWindowIcon(QIcon());
00111     setWidget(nativeWidget);
00112 
00113     nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
00114     nativeWidget->setFrameShape(QFrame::NoFrame);
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 
00192     QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
00193     if (qApp) {
00194         if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
00195             if (view->scene() && view->scene() == scene()) {
00196                 QApplication::sendEvent(view, &closeEvent);
00197             }
00198         }
00199     }
00200 
00201     QGraphicsProxyWidget::focusOutEvent(event);
00202 }
00203 
00204 } // namespace Plasma
00205 
00206 #include <textedit.moc>
00207 

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

Skip menu "kdelibs"
  • 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
Generated for kdelibs by doxygen 1.7.5
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