00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "tdefilemetainfowidget.h"
00022
00023 #include <keditcl.h>
00024 #include <tdelocale.h>
00025 #include <knuminput.h>
00026 #include <kcombobox.h>
00027 #include <klineedit.h>
00028 #include <kstringvalidator.h>
00029 #include <kdebug.h>
00030
00031 #include <tqlabel.h>
00032 #include <tqcheckbox.h>
00033 #include <tqspinbox.h>
00034 #include <tqdatetimeedit.h>
00035 #include <tqpixmap.h>
00036 #include <tqimage.h>
00037 #include <tqlayout.h>
00038 #include <tqvalidator.h>
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
00051 TQValidator* val,
00052 TQWidget* parent, const char* name)
00053 : TQWidget(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 TQValidator* val,
00064 TQWidget* parent, const char* name)
00065 : TQWidget(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 TQVariant::Image :
00084 m_widget = new TQLabel(this, "info image");
00085 static_cast<TQLabel*>(m_widget)->setPixmap(TQPixmap(m_value.toImage()));
00086 break;
00087 case TQVariant::Pixmap :
00088 m_widget = new TQLabel(this, "info pixmap");
00089 static_cast<TQLabel*>(m_widget)->setPixmap(m_value.toPixmap());
00090 break;
00091 default:
00092 m_widget = new TQLabel(item.string(true), this, "info label");
00093 }
00094
00095 (new TQHBoxLayout(this))->addWidget(m_widget);
00096 }
00097
00098 KFileMetaInfoWidget::~KFileMetaInfoWidget()
00099 {
00100 }
00101
00102 TQWidget* KFileMetaInfoWidget::makeWidget()
00103 {
00104 TQString valClass;
00105 TQWidget* w;
00106
00107 switch (m_value.type())
00108 {
00109 case TQVariant::Invalid:
00110
00111 w = new TQLabel(i18n("<Error>"), this, "label");
00112 break;
00113
00114 case TQVariant::Int:
00115 case TQVariant::UInt:
00116 w = makeIntWidget();
00117 break;
00118
00119 case TQVariant::Bool:
00120 w = makeBoolWidget();
00121 break;
00122
00123 case TQVariant::Double:
00124 w = makeDoubleWidget();
00125 break;
00126
00127
00128 case TQVariant::Date:
00129 w = makeDateWidget();
00130 break;
00131
00132 case TQVariant::Time:
00133 w = makeTimeWidget();
00134 break;
00135
00136 case TQVariant::DateTime:
00137 w = makeDateTimeWidget();
00138 break;
00139
00140 #if 0
00141 case TQVariant::Size:
00142 case TQVariant::String:
00143 case TQVariant::List:
00144 case TQVariant::Map:
00145 case TQVariant::StringList:
00146 case TQVariant::Font:
00147 case TQVariant::Pixmap:
00148 case TQVariant::Brush:
00149 case TQVariant::Rect:
00150 case TQVariant::Color:
00151 case TQVariant::Palette:
00152 case TQVariant::ColorGroup:
00153 case TQVariant::IconSet:
00154 case TQVariant::Point:
00155 case TQVariant::Image:
00156 case TQVariant::CString:
00157 case TQVariant::PointArray:
00158 case TQVariant::Region:
00159 case TQVariant::Bitmap:
00160 case TQVariant::Cursor:
00161 case TQVariant::ByteArray:
00162 case TQVariant::BitArray:
00163 case TQVariant::SizePolicy:
00164 case TQVariant::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 TQWidget* KFileMetaInfoWidget::makeBoolWidget()
00185 {
00186 TQCheckBox* cb = new TQCheckBox(this, "metainfo bool widget");
00187 cb->setChecked(m_item.value().toBool());
00188 connect(cb, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged(bool)));
00189 return cb;
00190 }
00191
00192 TQWidget* KFileMetaInfoWidget::makeIntWidget()
00193 {
00194 TQSpinBox* sb = new TQSpinBox(this, "metainfo integer widget");
00195 sb->setValue(m_item.value().toInt());
00196
00197 if (m_validator)
00198 {
00199 if (m_validator->inherits(TQINTVALIDATOR_OBJECT_NAME_STRING))
00200 {
00201 sb->setMinValue(static_cast<TQIntValidator*>(m_validator)->bottom());
00202 sb->setMaxValue(static_cast<TQIntValidator*>(m_validator)->top());
00203 }
00204 reparentValidator(sb, m_validator);
00205 sb->setValidator(m_validator);
00206 }
00207
00208
00209 if (m_item.type() == TQVariant::UInt)
00210 sb->setMinValue(TQMAX(sb->minValue(), 0));
00211
00212 connect(sb, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged(int)));
00213 return sb;
00214 }
00215
00216 TQWidget* 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<TQDoubleValidator*>(m_validator)->bottom());
00227 dni->setMaxValue(static_cast<TQDoubleValidator*>(m_validator)->top());
00228 }
00229 reparentValidator(dni, m_validator);
00230 }
00231
00232 connect(dni, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(slotChanged(double)));
00233 return dni;
00234 }
00235
00236 TQWidget* 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, TQT_SIGNAL(activated(const TQString &)), this, TQT_SLOT(slotComboChanged(const TQString &)));
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, TQT_SIGNAL( textChanged() ),
00255 this, TQT_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, TQT_SIGNAL(textChanged(const TQString&)),
00269 this, TQT_SLOT(slotLineEditChanged(const TQString&)));
00270 return e;
00271 }
00272
00273 TQWidget* KFileMetaInfoWidget::makeDateWidget()
00274 {
00275 TQWidget *e = new TQDateEdit(m_item.value().toDate(), this);
00276 connect(e, TQT_SIGNAL(valueChanged(const TQDate&)),
00277 this, TQT_SLOT(slotDateChanged(const TQDate&)));
00278 return e;
00279 }
00280
00281 TQWidget* KFileMetaInfoWidget::makeTimeWidget()
00282 {
00283 return new TQTimeEdit(m_item.value().toTime(), this);
00284 }
00285
00286 TQWidget* KFileMetaInfoWidget::makeDateTimeWidget()
00287 {
00288 return new TQDateTimeEdit(m_item.value().toDateTime(), this);
00289 }
00290
00291 void KFileMetaInfoWidget::reparentValidator( TQWidget *widget,
00292 TQValidator *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(TQCOMBOBOX_OBJECT_NAME_STRING));
00305 m_value = TQVariant(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(TQSPINBOX_OBJECT_NAME_STRING));
00313 m_value = TQVariant(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 = TQVariant(value);
00322 emit valueChanged(m_value);
00323 m_dirty = true;
00324 }
00325
00326 void KFileMetaInfoWidget::slotComboChanged(const TQString &value)
00327 {
00328 Q_ASSERT(m_widget->inherits("KComboBox"));
00329 m_value = TQVariant(value);
00330 emit valueChanged(m_value);
00331 m_dirty = true;
00332 }
00333
00334 void KFileMetaInfoWidget::slotLineEditChanged(const TQString& value)
00335 {
00336 Q_ASSERT(m_widget->inherits("KLineEdit"));
00337 m_value = TQVariant(value);
00338 emit valueChanged(m_value);
00339 m_dirty = true;
00340 }
00341
00342
00343 void KFileMetaInfoWidget::slotMultiLineEditChanged()
00344 {
00345 Q_ASSERT(m_widget->inherits(TQTEXTEDIT_OBJECT_NAME_STRING));
00346 m_value = TQVariant( static_cast<const TQTextEdit*>( sender() )->text() );
00347 emit valueChanged(m_value);
00348 m_dirty = true;
00349 }
00350
00351 void KFileMetaInfoWidget::slotDateChanged(const TQDate& value)
00352 {
00353 Q_ASSERT(m_widget->inherits(TQDATEEDIT_OBJECT_NAME_STRING));
00354 m_value = TQVariant(value);
00355 emit valueChanged(m_value);
00356 m_dirty = true;
00357 }
00358
00359 void KFileMetaInfoWidget::slotTimeChanged(const TQTime& value)
00360 {
00361 Q_ASSERT(m_widget->inherits(TQTIMEEDIT_OBJECT_NAME_STRING));
00362 m_value = TQVariant(value);
00363 emit valueChanged(m_value);
00364 m_dirty = true;
00365 }
00366
00367 void KFileMetaInfoWidget::slotDateTimeChanged(const TQDateTime& value)
00368 {
00369 Q_ASSERT(m_widget->inherits(TQDATETIMEEDIT_OBJECT_NAME_STRING));
00370 m_value = TQVariant(value);
00371 emit valueChanged(m_value);
00372 m_dirty = true;
00373 }
00374
00375 #include "tdefilemetainfowidget.moc"