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

Plasma

  • plasma
  • widgets
lineedit.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 "lineedit.h"
21
22#include <QGraphicsSceneResizeEvent>
23#include <QIcon>
24#include <QPainter>
25#include <QGraphicsView>
26
27#include <klineedit.h>
28#include <kmimetype.h>
29
30#include "applet.h"
31#include "framesvg.h"
32#include "private/style_p.h"
33#include "private/focusindicator_p.h"
34#include "private/themedwidgetinterface_p.h"
35#include "theme.h"
36
37namespace Plasma
38{
39
40class LineEditPrivate : public ThemedWidgetInterface<LineEdit>
41{
42public:
43 LineEditPrivate(LineEdit *lineEdit)
44 : ThemedWidgetInterface<LineEdit>(lineEdit)
45 {
46 buttonColorForText = true;
47 }
48
49 ~LineEditPrivate()
50 {
51 }
52
53 LineEdit *q;
54 Plasma::Style::Ptr style;
55 Plasma::FrameSvg *background;
56};
57
58LineEdit::LineEdit(QGraphicsWidget *parent)
59 : QGraphicsProxyWidget(parent),
60 d(new LineEditPrivate(this))
61{
62 d->style = Plasma::Style::sharedStyle();
63 d->background = new Plasma::FrameSvg(this);
64 d->background->setImagePath("widgets/lineedit");
65 d->background->setCacheAllRenderedFrames(true);
66
67#if 0 // causes bug 290111
68 FocusIndicator *indicator = new FocusIndicator(this, d->background);
69 if (d->background->hasElement("hint-focus-over-base")) {
70 indicator->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
71 }
72#endif
73 setNativeWidget(new KLineEdit);
74}
75
76LineEdit::~LineEdit()
77{
78 delete d;
79 Plasma::Style::doneWithSharedStyle();
80}
81
82void LineEdit::setText(const QString &text)
83{
84 static_cast<KLineEdit*>(widget())->setText(text);
85}
86
87QString LineEdit::text() const
88{
89 return static_cast<KLineEdit*>(widget())->text();
90}
91
92void LineEdit::setClearButtonShown(bool show)
93{
94 nativeWidget()->setClearButtonShown(show);
95}
96
97bool LineEdit::isClearButtonShown() const
98{
99 return nativeWidget()->isClearButtonShown();
100}
101
102void LineEdit::setClickMessage(const QString &message)
103{
104 nativeWidget()->setClickMessage(message);
105}
106
107QString LineEdit::clickMessage() const
108{
109 return nativeWidget()->clickMessage();
110}
111
112void LineEdit::setStyleSheet(const QString &stylesheet)
113{
114 widget()->setStyleSheet(stylesheet);
115}
116
117QString LineEdit::styleSheet()
118{
119 return widget()->styleSheet();
120}
121
122void LineEdit::setNativeWidget(KLineEdit *nativeWidget)
123{
124 if (widget()) {
125 widget()->deleteLater();
126 }
127
128 connect(nativeWidget, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
129 connect(nativeWidget, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
130 connect(nativeWidget, SIGNAL(textEdited(QString)), this, SIGNAL(textEdited(QString)));
131 connect(nativeWidget, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
132
133
134 nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
135 d->setWidget(nativeWidget);
136 nativeWidget->setWindowIcon(QIcon());
137
138 nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
139 nativeWidget->setStyle(d->style.data());
140 d->initTheming();
141}
142
143KLineEdit *LineEdit::nativeWidget() const
144{
145 return static_cast<KLineEdit*>(widget());
146}
147
148void LineEdit::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
149{
150 Q_UNUSED(event)
151 update();
152}
153
154void LineEdit::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
155{
156 Q_UNUSED(event)
157 update();
158}
159
160void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
161{
162 Q_UNUSED(option)
163 Q_UNUSED(widget)
164
165 nativeWidget()->render(painter, QPoint(0, 0), QRegion(), QWidget::DrawChildren|QWidget::IgnoreMask);
166}
167
168void LineEdit::changeEvent(QEvent *event)
169{
170 d->changeEvent(event);
171 QGraphicsProxyWidget::changeEvent(event);
172}
173
174void LineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
175{
176 QGraphicsWidget *widget = parentWidget();
177 Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
178
179 while (!applet && widget) {
180 widget = widget->parentWidget();
181 applet = qobject_cast<Plasma::Applet *>(widget);
182 }
183
184 if (applet) {
185 applet->setStatus(Plasma::AcceptingInputStatus);
186 }
187 QGraphicsProxyWidget::mousePressEvent(event);
188}
189
190void LineEdit::focusInEvent(QFocusEvent *event)
191{
192 QGraphicsProxyWidget::focusInEvent(event);
193 if (!nativeWidget()->hasFocus()) {
194 // as of Qt 4.7, apparently we have a bug here in QGraphicsProxyWidget
195 nativeWidget()->setFocus(event->reason());
196 }
197
198 emit focusChanged(true);
199}
200
201void LineEdit::focusOutEvent(QFocusEvent *event)
202{
203 QGraphicsWidget *widget = parentWidget();
204 Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
205
206 while (!applet && widget) {
207 widget = widget->parentWidget();
208 applet = qobject_cast<Plasma::Applet *>(widget);
209 }
210
211 if (applet) {
212 applet->setStatus(Plasma::UnknownStatus);
213 }
214
215 QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
216 if (qApp) {
217 if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
218 if (view->scene() && view->scene() == scene()) {
219 QApplication::sendEvent(view, &closeEvent);
220 }
221 }
222 }
223
224 QGraphicsProxyWidget::focusOutEvent(event);
225
226 emit focusChanged(false);
227}
228
229} // namespace Plasma
230
231#include <lineedit.moc>
232
applet.h
Plasma::Applet
The base Applet class.
Definition: applet.h:78
Plasma::Applet::setStatus
void setStatus(const ItemStatus stat)
sets the status for this applet
Definition: applet.cpp:1198
Plasma::FrameSvg
Provides an SVG with borders.
Definition: framesvg.h:77
Plasma::LineEdit::setNativeWidget
void setNativeWidget(KLineEdit *nativeWidget)
Sets the line edit wrapped by this LineEdit (widget must inherit KLineEdit), ownership is transferred...
Definition: lineedit.cpp:122
Plasma::LineEdit::editingFinished
void editingFinished()
Plasma::LineEdit::returnPressed
void returnPressed()
Plasma::LineEdit::textChanged
void textChanged(const QString &text)
Emitted when the text changes.
Plasma::LineEdit::setText
void setText(const QString &text)
Sets the display text for this LineEdit.
Definition: lineedit.cpp:82
Plasma::LineEdit::parentWidget
QGraphicsWidget * parentWidget
Definition: lineedit.h:43
Plasma::LineEdit::nativeWidget
KLineEdit * nativeWidget
Definition: lineedit.h:48
Plasma::LineEdit::text
QString text
Definition: lineedit.h:44
Plasma::LineEdit::textEdited
void textEdited(const QString &text)
Plasma::LineEdit::focusChanged
void focusChanged(bool focused)
Emitted when the widget receives or loses focus.
QGraphicsProxyWidget
QGraphicsView
QGraphicsWidget
QStyleOptionGraphicsItem
QWidget
framesvg.h
lineedit.h
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
Plasma::AcceptingInputStatus
@ AcceptingInputStatus
The Item is accepting input.
Definition: plasma.h:261
Plasma::UnknownStatus
@ UnknownStatus
The status is unknown.
Definition: plasma.h:257
theme.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

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