Plasma
lineedit.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "lineedit.h"
00021
00022 #include <QPainter>
00023
00024 #include <klineedit.h>
00025 #include <kmimetype.h>
00026
00027 #include <plasma/private/style_p.h>
00028
00029 #include "theme.h"
00030 #include "svg.h"
00031
00032 namespace Plasma
00033 {
00034
00035 class LineEditPrivate
00036 {
00037 public:
00038 LineEditPrivate(LineEdit *lineEdit)
00039 :q(lineEdit)
00040 {
00041 }
00042
00043 ~LineEditPrivate()
00044 {
00045 }
00046
00047 void setPalette()
00048 {
00049 KLineEdit *native = q->nativeWidget();
00050 QColor color = Theme::defaultTheme()->color(Theme::TextColor);
00051 QPalette p = native->palette();
00052
00053 p.setColor(QPalette::Normal, QPalette::Text, color);
00054 p.setColor(QPalette::Inactive, QPalette::Text, color);
00055 native->setPalette(p);
00056 native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
00057 }
00058
00059 LineEdit *q;
00060 Plasma::Style::Ptr style;
00061 };
00062
00063 LineEdit::LineEdit(QGraphicsWidget *parent)
00064 : QGraphicsProxyWidget(parent),
00065 d(new LineEditPrivate(this))
00066 {
00067 KLineEdit *native = new KLineEdit;
00068 connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
00069 connect(native, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
00070 connect(native, SIGNAL(textEdited(const QString&)), this, SIGNAL(textEdited(const QString&)));
00071 setWidget(native);
00072 native->setAttribute(Qt::WA_NoSystemBackground);
00073 d->style = Plasma::Style::sharedStyle();
00074 native->setStyle(d->style.data());
00075
00076 d->setPalette();
00077 connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
00078 }
00079
00080 LineEdit::~LineEdit()
00081 {
00082 delete d;
00083 Plasma::Style::doneWithSharedStyle();
00084 }
00085
00086 void LineEdit::setText(const QString &text)
00087 {
00088 static_cast<KLineEdit*>(widget())->setText(text);
00089 }
00090
00091 QString LineEdit::text() const
00092 {
00093 return static_cast<KLineEdit*>(widget())->text();
00094 }
00095
00096 void LineEdit::setStyleSheet(const QString &stylesheet)
00097 {
00098 widget()->setStyleSheet(stylesheet);
00099 }
00100
00101 QString LineEdit::styleSheet()
00102 {
00103 return widget()->styleSheet();
00104 }
00105
00106 KLineEdit *LineEdit::nativeWidget() const
00107 {
00108 return static_cast<KLineEdit*>(widget());
00109 }
00110
00111 }
00112
00113 #include <lineedit.moc>
00114