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

Plasma

lineedit.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 "lineedit.h"
00021 
00022 #include <QGraphicsSceneResizeEvent>
00023 #include <QIcon>
00024 #include <QPainter>
00025 #include <QGraphicsView>
00026 
00027 #include <klineedit.h>
00028 #include <kmimetype.h>
00029 
00030 #include "applet.h"
00031 #include "framesvg.h"
00032 #include "private/style_p.h"
00033 #include "private/focusindicator_p.h"
00034 #include "private/themedwidgetinterface_p.h"
00035 #include "theme.h"
00036 
00037 namespace Plasma
00038 {
00039 
00040 class LineEditPrivate : public ThemedWidgetInterface<LineEdit>
00041 {
00042 public:
00043     LineEditPrivate(LineEdit *lineEdit)
00044         : ThemedWidgetInterface<LineEdit>(lineEdit)
00045     {
00046         buttonColorForText = true;
00047     }
00048 
00049     ~LineEditPrivate()
00050     {
00051     }
00052 
00053     LineEdit *q;
00054     Plasma::Style::Ptr style;
00055     Plasma::FrameSvg *background;
00056 };
00057 
00058 LineEdit::LineEdit(QGraphicsWidget *parent)
00059     : QGraphicsProxyWidget(parent),
00060       d(new LineEditPrivate(this))
00061 {
00062     d->style = Plasma::Style::sharedStyle();
00063     d->background = new Plasma::FrameSvg(this);
00064     d->background->setImagePath("widgets/lineedit");
00065     d->background->setCacheAllRenderedFrames(true);
00066 
00067 #if 0 //  causes bug 290111
00068     FocusIndicator *indicator = new FocusIndicator(this, d->background);
00069     if (d->background->hasElement("hint-focus-over-base")) {
00070         indicator->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
00071     }
00072 #endif
00073     setNativeWidget(new KLineEdit);
00074 }
00075 
00076 LineEdit::~LineEdit()
00077 {
00078     delete d;
00079     Plasma::Style::doneWithSharedStyle();
00080 }
00081 
00082 void LineEdit::setText(const QString &text)
00083 {
00084     static_cast<KLineEdit*>(widget())->setText(text);
00085 }
00086 
00087 QString LineEdit::text() const
00088 {
00089     return static_cast<KLineEdit*>(widget())->text();
00090 }
00091 
00092 void LineEdit::setClearButtonShown(bool show)
00093 {
00094     nativeWidget()->setClearButtonShown(show);
00095 }
00096 
00097 bool LineEdit::isClearButtonShown() const
00098 {
00099     return nativeWidget()->isClearButtonShown();
00100 }
00101 
00102 void LineEdit::setClickMessage(const QString &message)
00103 {
00104     nativeWidget()->setClickMessage(message);
00105 }
00106 
00107 QString LineEdit::clickMessage() const
00108 {
00109     return nativeWidget()->clickMessage();
00110 }
00111 
00112 void LineEdit::setStyleSheet(const QString &stylesheet)
00113 {
00114     widget()->setStyleSheet(stylesheet);
00115 }
00116 
00117 QString LineEdit::styleSheet()
00118 {
00119     return widget()->styleSheet();
00120 }
00121 
00122 void LineEdit::setNativeWidget(KLineEdit *nativeWidget)
00123 {
00124     if (widget()) {
00125         widget()->deleteLater();
00126     }
00127 
00128     connect(nativeWidget, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
00129     connect(nativeWidget, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
00130     connect(nativeWidget, SIGNAL(textEdited(QString)), this, SIGNAL(textEdited(QString)));
00131     connect(nativeWidget, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
00132 
00133 
00134     nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
00135     d->setWidget(nativeWidget);
00136     nativeWidget->setWindowIcon(QIcon());
00137 
00138     nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
00139     nativeWidget->setStyle(d->style.data());
00140     d->initTheming();
00141 }
00142 
00143 KLineEdit *LineEdit::nativeWidget() const
00144 {
00145     return static_cast<KLineEdit*>(widget());
00146 }
00147 
00148 void LineEdit::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
00149 {
00150     Q_UNUSED(event)
00151     update();
00152 }
00153 
00154 void LineEdit::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
00155 {
00156     Q_UNUSED(event)
00157     update();
00158 }
00159 
00160 void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00161 {
00162     Q_UNUSED(option)
00163     Q_UNUSED(widget)
00164 
00165     nativeWidget()->render(painter, QPoint(0, 0), QRegion(), QWidget::DrawChildren|QWidget::IgnoreMask);
00166 }
00167 
00168 void LineEdit::changeEvent(QEvent *event)
00169 {
00170     d->changeEvent(event);
00171     QGraphicsProxyWidget::changeEvent(event);
00172 }
00173 
00174 void LineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
00175 {
00176     QGraphicsWidget *widget = parentWidget();
00177     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00178 
00179     while (!applet && widget) {
00180         widget = widget->parentWidget();
00181         applet = qobject_cast<Plasma::Applet *>(widget);
00182     }
00183 
00184     if (applet) {
00185         applet->setStatus(Plasma::AcceptingInputStatus);
00186     }
00187     QGraphicsProxyWidget::mousePressEvent(event);
00188 }
00189 
00190 void LineEdit::focusInEvent(QFocusEvent *event)
00191 {
00192     QGraphicsProxyWidget::focusInEvent(event);
00193     if (!nativeWidget()->hasFocus()) {
00194         // as of Qt 4.7, apparently we have a bug here in QGraphicsProxyWidget
00195         nativeWidget()->setFocus(event->reason());
00196     }
00197 
00198     emit focusChanged(true);
00199 }
00200 
00201 void LineEdit::focusOutEvent(QFocusEvent *event)
00202 {
00203     QGraphicsWidget *widget = parentWidget();
00204     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00205 
00206     while (!applet && widget) {
00207         widget = widget->parentWidget();
00208         applet = qobject_cast<Plasma::Applet *>(widget);
00209     }
00210 
00211     if (applet) {
00212         applet->setStatus(Plasma::UnknownStatus);
00213     }
00214 
00215     QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
00216     if (qApp) {
00217         if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
00218             if (view->scene() && view->scene() == scene()) {
00219                 QApplication::sendEvent(view, &closeEvent);
00220             }
00221         }
00222     }
00223 
00224     QGraphicsProxyWidget::focusOutEvent(event);
00225 
00226     emit focusChanged(false);
00227 }
00228 
00229 } // namespace Plasma
00230 
00231 #include <lineedit.moc>
00232 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:51:36 by doxygen 1.8.0 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.8.3 API Reference

Skip menu "kdelibs-4.8.3 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