lib

stringedit.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "stringedit.h"
00022 
00023 #include <qlayout.h>
00024 #include <qlineedit.h>
00025 #include <qvariant.h>
00026 
00027 using namespace KoProperty;
00028 
00029 StringEdit::StringEdit(Property *property, QWidget *parent, const char *name)
00030  : Widget(property, parent, name)
00031 {
00032     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00033     m_edit = new QLineEdit(this);
00034     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00035     m_edit->setMargin(1);
00036     m_edit->setMinimumHeight(5);
00037     l->addWidget(m_edit);
00038     setFocusWidget(m_edit);
00039 
00040     connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&)));
00041 }
00042 
00043 StringEdit::~StringEdit()
00044 {}
00045 
00046 QVariant
00047 StringEdit::value() const
00048 {
00049     return m_edit->text();
00050 }
00051 
00052 void
00053 StringEdit::setValue(const QVariant &value, bool emitChange)
00054 {
00055     m_edit->blockSignals(true);
00056     m_edit->setText(value.toString());
00057     m_edit->blockSignals(false);
00058     if (emitChange)
00059         emit valueChanged(this);
00060 }
00061 
00062 void
00063 StringEdit::slotValueChanged(const QString &)
00064 {
00065     emit valueChanged(this);
00066 }
00067 
00068 void
00069 StringEdit::setReadOnlyInternal(bool readOnly)
00070 {
00071     m_edit->setReadOnly(readOnly);
00072 }
00073 
00074 #include "stringedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys