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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • 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 
37 namespace Plasma
38 {
39 
40 class LineEditPrivate : public ThemedWidgetInterface<LineEdit>
41 {
42 public:
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 
58 LineEdit::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 
76 LineEdit::~LineEdit()
77 {
78  delete d;
79  Plasma::Style::doneWithSharedStyle();
80 }
81 
82 void LineEdit::setText(const QString &text)
83 {
84  static_cast<KLineEdit*>(widget())->setText(text);
85 }
86 
87 QString LineEdit::text() const
88 {
89  return static_cast<KLineEdit*>(widget())->text();
90 }
91 
92 void LineEdit::setClearButtonShown(bool show)
93 {
94  nativeWidget()->setClearButtonShown(show);
95 }
96 
97 bool LineEdit::isClearButtonShown() const
98 {
99  return nativeWidget()->isClearButtonShown();
100 }
101 
102 void LineEdit::setClickMessage(const QString &message)
103 {
104  nativeWidget()->setClickMessage(message);
105 }
106 
107 QString LineEdit::clickMessage() const
108 {
109  return nativeWidget()->clickMessage();
110 }
111 
112 void LineEdit::setStyleSheet(const QString &stylesheet)
113 {
114  widget()->setStyleSheet(stylesheet);
115 }
116 
117 QString LineEdit::styleSheet()
118 {
119  return widget()->styleSheet();
120 }
121 
122 void 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 
143 KLineEdit *LineEdit::nativeWidget() const
144 {
145  return static_cast<KLineEdit*>(widget());
146 }
147 
148 void LineEdit::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
149 {
150  Q_UNUSED(event)
151  update();
152 }
153 
154 void LineEdit::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
155 {
156  Q_UNUSED(event)
157  update();
158 }
159 
160 void 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 
168 void LineEdit::changeEvent(QEvent *event)
169 {
170  d->changeEvent(event);
171  QGraphicsProxyWidget::changeEvent(event);
172 }
173 
174 void 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 
190 void 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 
201 void 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 
Plasma::LineEdit::nativeWidget
KLineEdit * nativeWidget() const
Plasma::UnknownStatus
The status is unknown.
Definition: plasma.h:257
Plasma::LineEdit::parentWidget
QGraphicsWidget parentWidget
Definition: lineedit.h:43
Plasma::LineEdit::textEdited
void textEdited(const QString &text)
Plasma::LineEdit::clickMessage
QString clickMessage() const
QWidget
lineedit.h
Plasma::LineEdit::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: lineedit.cpp:154
Plasma::LineEdit::editingFinished
void editingFinished()
theme.h
Plasma::LineEdit::isClearButtonShown
bool isClearButtonShown() const
Definition: lineedit.cpp:97
Plasma::LineEdit::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: lineedit.cpp:174
Plasma::FrameSvg
Provides an SVG with borders.
Definition: framesvg.h:76
Plasma::LineEdit::focusOutEvent
void focusOutEvent(QFocusEvent *event)
Definition: lineedit.cpp:201
Plasma::LineEdit::returnPressed
void returnPressed()
Plasma::Applet
The base Applet class.
Definition: applet.h:77
Plasma::LineEdit::setClickMessage
void setClickMessage(const QString &message)
Sets a greyed out message that will go away after the user clicked the line edit. ...
Definition: lineedit.cpp:102
Plasma::Applet::setStatus
void setStatus(const ItemStatus stat)
sets the status for this applet
Definition: applet.cpp:1198
Plasma::LineEdit::styleSheet
QString styleSheet()
Plasma::LineEdit::changeEvent
void changeEvent(QEvent *event)
Definition: lineedit.cpp:168
Plasma::LineEdit::setClearButtonShown
void setClearButtonShown(bool show)
Shows a button to clear the text.
Definition: lineedit.cpp:92
Plasma::LineEdit::focusInEvent
void focusInEvent(QFocusEvent *event)
Definition: lineedit.cpp:190
applet.h
Plasma::LineEdit::textChanged
void textChanged(const QString &text)
Emitted when the text changes.
Plasma::LineEdit::text
QString text() const
Plasma::LineEdit::setText
void setText(const QString &text)
Sets the display text for this LineEdit.
Definition: lineedit.cpp:82
QGraphicsProxyWidget
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::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: lineedit.cpp:160
Plasma::LineEdit::~LineEdit
~LineEdit()
Definition: lineedit.cpp:76
Plasma::LineEdit::focusChanged
void focusChanged(bool focused)
Emitted when the widget receives or loses focus.
framesvg.h
QGraphicsView
Plasma::LineEdit::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Definition: lineedit.cpp:148
QStyleOptionGraphicsItem
Plasma::LineEdit::LineEdit
LineEdit(QGraphicsWidget *parent=0)
Definition: lineedit.cpp:58
Plasma::AcceptingInputStatus
The Item is accepting input.
Definition: plasma.h:261
Plasma::LineEdit::setStyleSheet
void setStyleSheet(const QString &stylesheet)
Sets the stylesheet used to control the visual display of this LineEdit.
Definition: lineedit.cpp:112
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:33 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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