00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kfilemetainfowidget.h"
00022
00023 #include <keditcl.h>
00024 #include <klocale.h>
00025 #include <knuminput.h>
00026 #include <kcombobox.h>
00027 #include <klineedit.h>
00028 #include <kstringvalidator.h>
00029 #include <kdebug.h>
00030
00031 #include <qlabel.h>
00032 #include <qcheckbox.h>
00033 #include <qspinbox.h>
00034 #include <qdatetimeedit.h>
00035 #include <qpixmap.h>
00036 #include <qimage.h>
00037 #include <qlayout.h>
00038 #include <qvalidator.h>
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
00051 QValidator* val,
00052 QWidget* parent, const char* name)
00053 : QWidget(parent, name),
00054 m_value(item.value()),
00055 m_item(item),
00056 m_validator(val)
00057 {
00058 init(item, ReadWrite);
00059 }
00060
00061 KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
00062 Mode mode,
00063 QValidator* val,
00064 QWidget* parent, const char* name)
00065 : QWidget(parent, name),
00066 m_value(item.value()),
00067 m_item(item),
00068 m_validator(val)
00069 {
00070 init(item, mode);
00071 }
00072
00073 void KFileMetaInfoWidget::init(KFileMetaInfoItem item, Mode mode)
00074 {
00075 kdDebug(7033) << "*** item " << m_item.key()
00076 << " is a " << value().typeName() << endl;
00077
00078 if (m_item.isEditable() && !(mode & ReadOnly))
00079 m_widget = makeWidget();
00080 else
00081 switch (m_value.type())
00082 {
00083 case QVariant::Image :
00084 m_widget = new QLabel(this, "info image");
00085 static_cast<QLabel*>(m_widget)->setPixmap(QPixmap(m_value.toImage()));
00086 break;
00087 case QVariant::Pixmap :
00088 m_widget = new QLabel(this, "info pixmap");
00089 static_cast<QLabel*>(m_widget)->setPixmap(m_value.toPixmap());
00090 break;
00091 default:
00092 m_widget = new QLabel(item.string(true), this, "info label");
00093 }
00094
00095 (new QHBoxLayout(this))->addWidget(m_widget);
00096 }
00097
00098 KFileMetaInfoWidget::~KFileMetaInfoWidget()
00099 {
00100 }
00101
00102 QWidget* KFileMetaInfoWidget::makeWidget()
00103 {
00104 QString valClass;
00105 QWidget* w;
00106
00107 switch (m_value.type())
00108 {
00109 case QVariant::Invalid:
00110
00111 w = new QLabel(i18n("<Error>"), this, "label");
00112 break;
00113
00114 case QVariant::Int:
00115 case QVariant::UInt:
00116 w = makeIntWidget();
00117 break;
00118
00119 case QVariant::Bool:
00120 w = makeBoolWidget();
00121 break;
00122
00123 case QVariant::Double:
00124 w = makeDoubleWidget();
00125 break;
00126
00127
00128 case QVariant::Date:
00129 w = makeDateWidget();
00130 break;
00131
00132 case QVariant::Time:
00133 w = makeTimeWidget();
00134 break;
00135
00136 case QVariant::DateTime:
00137 w = makeDateTimeWidget();
00138 break;
00139
00140 #if 0
00141 case QVariant::Size:
00142 case QVariant::String:
00143 case QVariant::List:
00144 case QVariant::Map:
00145 case QVariant::StringList:
00146 case QVariant::Font:
00147 case QVariant::Pixmap:
00148 case QVariant::Brush:
00149 case QVariant::Rect:
00150 case QVariant::Color:
00151 case QVariant::Palette:
00152 case QVariant::ColorGroup:
00153 case QVariant::IconSet:
00154 case QVariant::Point:
00155 case QVariant::Image:
00156 case QVariant::CString:
00157 case QVariant::PointArray:
00158 case QVariant::Region:
00159 case QVariant::Bitmap:
00160 case QVariant::Cursor:
00161 case QVariant::ByteArray:
00162 case QVariant::BitArray:
00163 case QVariant::SizePolicy:
00164 case QVariant::KeySequence:
00165 #endif
00166 default:
00167 w = makeStringWidget();
00168 }
00169
00170 kdDebug(7033) << "*** item " << m_item.key()
00171 << "is a " << m_item.value().typeName() << endl;
00172 if (m_validator)
00173 kdDebug(7033) << " and validator is a " << m_validator->className() << endl;
00174
00175 kdDebug(7033) << "*** created a " << w->className() << " for it\n";
00176
00177 return w;
00178 }
00179
00180
00181
00182
00183
00184 QWidget* KFileMetaInfoWidget::makeBoolWidget()
00185 {
00186 QCheckBox* cb = new QCheckBox(this, "metainfo bool widget");
00187 cb->setChecked(m_item.value().toBool());
00188 connect(cb, SIGNAL(toggled(bool)), this, SLOT(slotChanged(bool)));
00189 return cb;
00190 }
00191
00192 QWidget* KFileMetaInfoWidget::makeIntWidget()
00193 {
00194 QSpinBox* sb = new QSpinBox(this, "metainfo integer widget");
00195 sb->setValue(m_item.value().toInt());
00196
00197 if (m_validator)
00198 {
00199 if (m_validator->inherits("QIntValidator"))
00200 {
00201 sb->setMinValue(static_cast<QIntValidator*>(m_validator)->bottom());
00202 sb->setMaxValue(static_cast<QIntValidator*>(m_validator)->top());
00203 }
00204 reparentValidator(sb, m_validator);
00205 sb->setValidator(m_validator);
00206 }
00207
00208
00209 if (m_item.type() == QVariant::UInt)
00210 sb->setMinValue(QMAX(sb->minValue(), 0));
00211
00212 connect(sb, SIGNAL(valueChanged(int)), this, SLOT(slotChanged(int)));
00213 return sb;
00214 }
00215
00216 QWidget* KFileMetaInfoWidget::makeDoubleWidget()
00217 {
00218 KDoubleNumInput* dni = new KDoubleNumInput(m_item.value().toDouble(),
00219 this, "metainfo double widget");
00220
00221
00222 if (m_validator)
00223 {
00224 if (m_validator->inherits("QDoubleValidator"))
00225 {
00226 dni->setMinValue(static_cast<QDoubleValidator*>(m_validator)->bottom());
00227 dni->setMaxValue(static_cast<QDoubleValidator*>(m_validator)->top());
00228 }
00229 reparentValidator(dni, m_validator);
00230 }
00231
00232 connect(dni, SIGNAL(valueChanged(double)), this, SLOT(slotChanged(double)));
00233 return dni;
00234 }
00235
00236 QWidget* KFileMetaInfoWidget::makeStringWidget()
00237 {
00238 if (m_validator && m_validator->inherits("KStringListValidator"))
00239 {
00240 KComboBox* b = new KComboBox(true, this, "metainfo combobox");
00241 KStringListValidator* val = static_cast<KStringListValidator*>
00242 (m_validator);
00243 b->insertStringList(val->stringList());
00244 b->setCurrentText(m_item.value().toString());
00245 connect(b, SIGNAL(activated(const QString &)), this, SLOT(slotComboChanged(const QString &)));
00246 b->setValidator(val);
00247 reparentValidator(b, val);
00248 return b;
00249 }
00250
00251 if ( m_item.attributes() & KFileMimeTypeInfo::MultiLine ) {
00252 KEdit *edit = new KEdit( this );
00253 edit->setText( m_item.value().toString() );
00254 connect( edit, SIGNAL( textChanged() ),
00255 this, SLOT( slotMultiLineEditChanged() ));
00256
00257 if ( m_validator )
00258 reparentValidator( edit, m_validator );
00259 return edit;
00260 }
00261
00262 KLineEdit* e = new KLineEdit(m_item.value().toString(), this);
00263 if (m_validator)
00264 {
00265 e->setValidator(m_validator);
00266 reparentValidator(e, m_validator);
00267 }
00268 connect(e, SIGNAL(textChanged(const QString&)),
00269 this, SLOT(slotLineEditChanged(const QString&)));
00270 return e;
00271 }
00272
00273 QWidget* KFileMetaInfoWidget::makeDateWidget()
00274 {
00275 QWidget *e = new QDateEdit(m_item.value().toDate(), this);
00276 connect(e, SIGNAL(valueChanged(const QDate&)),
00277 this, SLOT(slotDateChanged(const QDate&)));
00278 return e;
00279 }
00280
00281 QWidget* KFileMetaInfoWidget::makeTimeWidget()
00282 {
00283 return new QTimeEdit(m_item.value().toTime(), this);
00284 }
00285
00286 QWidget* KFileMetaInfoWidget::makeDateTimeWidget()
00287 {
00288 return new QDateTimeEdit(m_item.value().toDateTime(), this);
00289 }
00290
00291 void KFileMetaInfoWidget::reparentValidator( QWidget *widget,
00292 QValidator *validator )
00293 {
00294 if ( !validator->parent() )
00295 widget->insertChild( validator );
00296 }
00297
00298
00299
00300
00301
00302 void KFileMetaInfoWidget::slotChanged(bool value)
00303 {
00304 Q_ASSERT(m_widget->inherits("QComboBox"));
00305 m_value = QVariant(value);
00306 emit valueChanged(m_value);
00307 m_dirty = true;
00308 }
00309
00310 void KFileMetaInfoWidget::slotChanged(int value)
00311 {
00312 Q_ASSERT(m_widget->inherits("QSpinBox"));
00313 m_value = QVariant(value);
00314 emit valueChanged(m_value);
00315 m_dirty = true;
00316 }
00317
00318 void KFileMetaInfoWidget::slotChanged(double value)
00319 {
00320 Q_ASSERT(m_widget->inherits("KDoubleNumInput"));
00321 m_value = QVariant(value);
00322 emit valueChanged(m_value);
00323 m_dirty = true;
00324 }
00325
00326 void KFileMetaInfoWidget::slotComboChanged(const QString &value)
00327 {
00328 Q_ASSERT(m_widget->inherits("KComboBox"));
00329 m_value = QVariant(value);
00330 emit valueChanged(m_value);
00331 m_dirty = true;
00332 }
00333
00334 void KFileMetaInfoWidget::slotLineEditChanged(const QString& value)
00335 {
00336 Q_ASSERT(m_widget->inherits("KLineEdit"));
00337 m_value = QVariant(value);
00338 emit valueChanged(m_value);
00339 m_dirty = true;
00340 }
00341
00342
00343 void KFileMetaInfoWidget::slotMultiLineEditChanged()
00344 {
00345 Q_ASSERT(m_widget->inherits("QTextEdit"));
00346 m_value = QVariant( static_cast<const QTextEdit*>( sender() )->text() );
00347 emit valueChanged(m_value);
00348 m_dirty = true;
00349 }
00350
00351 void KFileMetaInfoWidget::slotDateChanged(const QDate& value)
00352 {
00353 Q_ASSERT(m_widget->inherits("QDateEdit"));
00354 m_value = QVariant(value);
00355 emit valueChanged(m_value);
00356 m_dirty = true;
00357 }
00358
00359 void KFileMetaInfoWidget::slotTimeChanged(const QTime& value)
00360 {
00361 Q_ASSERT(m_widget->inherits("QTimeEdit"));
00362 m_value = QVariant(value);
00363 emit valueChanged(m_value);
00364 m_dirty = true;
00365 }
00366
00367 void KFileMetaInfoWidget::slotDateTimeChanged(const QDateTime& value)
00368 {
00369 Q_ASSERT(m_widget->inherits("QDateTimeEdit"));
00370 m_value = QVariant(value);
00371 emit valueChanged(m_value);
00372 m_dirty = true;
00373 }
00374
00375 #include "kfilemetainfowidget.moc"