lib

urledit.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 "urledit.h"
00022 
00023 #include <qlayout.h>
00024 #include <qvariant.h>
00025 
00026 #include <kurlrequester.h>
00027 #include <klineedit.h>
00028 
00029 #include "property.h"
00030 
00031 
00032 using namespace KoProperty;
00033 
00034 URLEdit::URLEdit(Property *property, QWidget *parent, const char *name)
00035  : Widget(property, parent, name)
00036 {
00037     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00038     m_edit = new KURLRequester(this);
00039     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00040     m_edit->setMinimumHeight(5);
00041     l->addWidget(m_edit);
00042 
00043     setProperty(property);
00044 
00045     connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&)));
00046     m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
00047 }
00048 
00049 URLEdit::~URLEdit()
00050 {}
00051 
00052 QVariant
00053 URLEdit::value() const
00054 {
00055     return m_edit->url();
00056 }
00057 
00058 void
00059 URLEdit::setValue(const QVariant &value, bool emitChange)
00060 {
00061     m_edit->blockSignals(true);
00062     m_edit->setURL(value.toString());
00063     m_edit->blockSignals(false);
00064     if (emitChange)
00065         emit valueChanged(this);
00066 }
00067 
00068 void
00069 URLEdit::slotValueChanged(const QString&)
00070 {
00071     emit valueChanged(this);
00072 }
00073 
00074 void
00075 URLEdit::setProperty(Property *property)
00076 {
00077     int  mode;
00078     if(property) {
00079         switch(property->type()) {
00080             case DirectoryURL:  mode = KFile::Directory|KFile::ExistingOnly;  break;
00081             case FileURL: case PictureFileURL: default: mode = KFile::File|KFile::ExistingOnly;
00082         }
00083         m_edit->setMode(mode);
00084     }
00085 
00086     Widget::setProperty(property);
00087 }
00088 
00089 void
00090 URLEdit::setReadOnlyInternal(bool readOnly)
00091 {
00092     m_edit->lineEdit()->setReadOnly(readOnly);
00093     m_edit->button()->setEnabled(!readOnly);
00094 }
00095 
00096 #include "urledit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys