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 #ifndef QT_ONLY
00027 #include <kurlrequester.h>
00028 #include <klineedit.h>
00029 #else
00030 #include <qpushbutton.h>
00031 #include <qlineedit.h>
00032 #include <qfiledialog.h>
00033 #endif
00034
00035 #include "property.h"
00036
00037
00038 using namespace KoProperty;
00039
00040 URLEdit::URLEdit(Property *property, QWidget *parent, const char *name)
00041 : Widget(property, parent, name)
00042 {
00043 QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00044 #ifndef QT_ONLY
00045 m_edit = new KURLRequester(this);
00046 m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00047 m_edit->setMinimumHeight(5);
00048 l->addWidget(m_edit);
00049
00050 setProperty(property);
00051
00052 connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&)));
00053 #else
00054 m_edit = new QLineEdit(this);
00055 m_select = new QPushButton("...",this);
00056 l->addWidget(m_edit);
00057 l->addWidget(m_select);
00058 connect( m_select, SIGNAL(clicked()),this,SLOT(selectFile()));
00059 connect(m_edit, SLOT(textChanged(const QString&)), this, slotValueChanged(const QString&));
00060 #endif
00061 m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
00062 }
00063
00064 URLEdit::~URLEdit()
00065 {}
00066
00067 QVariant
00068 URLEdit::value() const
00069 {
00070 #ifdef QT_ONLY
00071 return m_edit->text();
00072 #else
00073 return m_edit->url();
00074 #endif
00075 }
00076
00077 void
00078 URLEdit::setValue(const QVariant &value, bool emitChange)
00079 {
00080 m_edit->blockSignals(true);
00081 #ifdef QT_ONLY
00082 m_edit->setText(value.toString());
00083 #else
00084 m_edit->setURL(value.toString());
00085 #endif
00086 m_edit->blockSignals(false);
00087 if (emitChange)
00088 emit valueChanged(this);
00089 }
00090
00091 void
00092 URLEdit::slotValueChanged(const QString&)
00093 {
00094 emit valueChanged(this);
00095 }
00096
00097 void
00098 URLEdit::setProperty(Property *property)
00099 {
00100 #ifndef QT_ONLY
00101 int mode;
00102 if(property) {
00103 switch(property->type()) {
00104 case DirectoryURL: mode = KFile::Directory|KFile::ExistingOnly; break;
00105 case FileURL: case PictureFileURL: default: mode = KFile::File|KFile::ExistingOnly;
00106 }
00107 m_edit->setMode(mode);
00108 }
00109 #endif
00110
00111 Widget::setProperty(property);
00112 }
00113
00114 void
00115 URLEdit::selectFile()
00116 {
00117 #ifdef QT_ONLY
00118 QString path;
00119 if(m_property->type() == DirectoryURL)
00120 path = QFileDialog::getExistingDirectory(path,this);
00121 else if(m_property->type() == FileURL)
00122 path = QFileDialog::getOpenFileName(path, QString::null, this);
00123
00124 m_edit->setText(path);
00125 #endif
00126 }
00127
00128 void
00129 URLEdit::setReadOnlyInternal(bool readOnly)
00130 {
00131 #ifndef QT_ONLY
00132 m_edit->lineEdit()->setReadOnly(readOnly);
00133 m_edit->button()->setEnabled(!readOnly);
00134 #else
00135 m_edit->setReadOnly(readOnly);
00136 m_select->setEnabled(!readOnly);
00137 #endif
00138 }
00139
00140 #include "urledit.moc"
|