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