lib
urledit.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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"
|