• Skip to content
  • Skip to link menu
KDE 4.8 API Reference
  • KDE API Reference
  • kdelibs
  • 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     FocusIndicator *indicator = new FocusIndicator(this, d->background);
00068     if (d->background->hasElement("hint-focus-over-base")) {
00069         indicator->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
00070     }
00071     setNativeWidget(new KLineEdit);
00072 }
00073 
00074 LineEdit::~LineEdit()
00075 {
00076     delete d;
00077     Plasma::Style::doneWithSharedStyle();
00078 }
00079 
00080 void LineEdit::setText(const QString &text)
00081 {
00082     static_cast<KLineEdit*>(widget())->setText(text);
00083 }
00084 
00085 QString LineEdit::text() const
00086 {
00087     return static_cast<KLineEdit*>(widget())->text();
00088 }
00089 
00090 void LineEdit::setClearButtonShown(bool show)
00091 {
00092     nativeWidget()->setClearButtonShown(show);
00093 }
00094 
00095 bool LineEdit::isClearButtonShown() const
00096 {
00097     return nativeWidget()->isClearButtonShown();
00098 }
00099 
00100 void LineEdit::setClickMessage(const QString &message)
00101 {
00102     nativeWidget()->setClickMessage(message);
00103 }
00104 
00105 QString LineEdit::clickMessage() const
00106 {
00107     return nativeWidget()->clickMessage();
00108 }
00109 
00110 void LineEdit::setStyleSheet(const QString &stylesheet)
00111 {
00112     widget()->setStyleSheet(stylesheet);
00113 }
00114 
00115 QString LineEdit::styleSheet()
00116 {
00117     return widget()->styleSheet();
00118 }
00119 
00120 void LineEdit::setNativeWidget(KLineEdit *nativeWidget)
00121 {
00122     if (widget()) {
00123         widget()->deleteLater();
00124     }
00125 
00126     connect(nativeWidget, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
00127     connect(nativeWidget, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
00128     connect(nativeWidget, SIGNAL(textEdited(const QString&)), this, SIGNAL(textEdited(const QString&)));
00129     connect(nativeWidget, SIGNAL(textChanged(const QString&)), this, SIGNAL(textChanged(const QString&)));
00130 
00131 
00132     nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
00133     d->setWidget(nativeWidget);
00134     nativeWidget->setWindowIcon(QIcon());
00135 
00136     nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
00137     nativeWidget->setStyle(d->style.data());
00138     d->initTheming();
00139 }
00140 
00141 KLineEdit *LineEdit::nativeWidget() const
00142 {
00143     return static_cast<KLineEdit*>(widget());
00144 }
00145 
00146 void LineEdit::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
00147 {
00148     Q_UNUSED(event)
00149     update();
00150 }
00151 
00152 void LineEdit::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
00153 {
00154     Q_UNUSED(event)
00155     update();
00156 }
00157 
00158 void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00159 {
00160     Q_UNUSED(option)
00161     Q_UNUSED(widget)
00162 
00163     nativeWidget()->render(painter, QPoint(0, 0), QRegion(), QWidget::DrawChildren|QWidget::IgnoreMask);
00164 }
00165 
00166 void LineEdit::changeEvent(QEvent *event)
00167 {
00168     d->changeEvent(event);
00169     QGraphicsProxyWidget::changeEvent(event);
00170 }
00171 
00172 void LineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
00173 {
00174     QGraphicsWidget *widget = parentWidget();
00175     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00176 
00177     while (!applet && widget) {
00178         widget = widget->parentWidget();
00179         applet = qobject_cast<Plasma::Applet *>(widget);
00180     }
00181 
00182     if (applet) {
00183         applet->setStatus(Plasma::AcceptingInputStatus);
00184     }
00185     QGraphicsProxyWidget::mousePressEvent(event);
00186 }
00187 
00188 void LineEdit::focusInEvent(QFocusEvent *event)
00189 {
00190     QGraphicsProxyWidget::focusInEvent(event);
00191     if (!nativeWidget()->hasFocus()) {
00192         // as of Qt 4.7, apparently we have a bug here in QGraphicsProxyWidget
00193         nativeWidget()->setFocus(event->reason());
00194     }
00195 
00196     emit focusChanged(true);
00197 }
00198 
00199 void LineEdit::focusOutEvent(QFocusEvent *event)
00200 {
00201     QGraphicsWidget *widget = parentWidget();
00202     Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
00203 
00204     while (!applet && widget) {
00205         widget = widget->parentWidget();
00206         applet = qobject_cast<Plasma::Applet *>(widget);
00207     }
00208 
00209     if (applet) {
00210         applet->setStatus(Plasma::UnknownStatus);
00211     }
00212 
00213     QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
00214     if (qApp) {
00215         if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
00216             if (view->scene() && view->scene() == scene()) {
00217                 QApplication::sendEvent(view, &closeEvent);
00218             }
00219         }
00220     }
00221 
00222     QGraphicsProxyWidget::focusOutEvent(event);
00223 
00224     emit focusChanged(false);
00225 }
00226 
00227 } // namespace Plasma
00228 
00229 #include <lineedit.moc>
00230 

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.6.1
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