21 #include "tdefilemetainfowidget.h"
24 #include <tdelocale.h>
25 #include <knuminput.h>
26 #include <kcombobox.h>
27 #include <klineedit.h>
28 #include <kstringvalidator.h>
32 #include <tqcheckbox.h>
33 #include <tqspinbox.h>
34 #include <tqdatetimeedit.h>
38 #include <tqvalidator.h>
50 KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
52 TQWidget* parent,
const char* name)
53 : TQWidget(parent, name),
54 m_value(item.value()),
58 init(item, ReadWrite);
61 KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
64 TQWidget* parent,
const char* name)
65 : TQWidget(parent, name),
66 m_value(item.value()),
73 void KFileMetaInfoWidget::init(KFileMetaInfoItem item, Mode mode)
75 kdDebug(7033) <<
"*** item " << m_item.key()
76 <<
" is a " << value().typeName() << endl;
78 if (m_item.isEditable() && !(mode & ReadOnly))
79 m_widget = makeWidget();
81 switch (m_value.type())
83 case TQVariant::Image :
84 m_widget =
new TQLabel(
this,
"info image");
85 static_cast<TQLabel*
>(m_widget)->setPixmap(TQPixmap(m_value.toImage()));
87 case TQVariant::Pixmap :
88 m_widget =
new TQLabel(
this,
"info pixmap");
89 static_cast<TQLabel*
>(m_widget)->setPixmap(m_value.toPixmap());
92 m_widget =
new TQLabel(item.string(
true),
this,
"info label");
95 (
new TQHBoxLayout(
this))->addWidget(m_widget);
98 KFileMetaInfoWidget::~KFileMetaInfoWidget()
102 TQWidget* KFileMetaInfoWidget::makeWidget()
107 switch (m_value.type())
109 case TQVariant::Invalid:
111 w =
new TQLabel(i18n(
"<Error>"),
this,
"label");
115 case TQVariant::UInt:
119 case TQVariant::Bool:
120 w = makeBoolWidget();
123 case TQVariant::Double:
124 w = makeDoubleWidget();
128 case TQVariant::Date:
129 w = makeDateWidget();
132 case TQVariant::Time:
133 w = makeTimeWidget();
136 case TQVariant::DateTime:
137 w = makeDateTimeWidget();
141 case TQVariant::Size:
142 case TQVariant::String:
143 case TQVariant::List:
145 case TQVariant::StringList:
146 case TQVariant::Font:
147 case TQVariant::Pixmap:
148 case TQVariant::Brush:
149 case TQVariant::Rect:
150 case TQVariant::Color:
151 case TQVariant::Palette:
152 case TQVariant::ColorGroup:
153 case TQVariant::IconSet:
154 case TQVariant::Point:
155 case TQVariant::Image:
156 case TQVariant::CString:
157 case TQVariant::PointArray:
158 case TQVariant::Region:
159 case TQVariant::Bitmap:
160 case TQVariant::Cursor:
161 case TQVariant::ByteArray:
162 case TQVariant::BitArray:
163 case TQVariant::SizePolicy:
164 case TQVariant::KeySequence:
167 w = makeStringWidget();
170 kdDebug(7033) <<
"*** item " << m_item.key()
171 <<
"is a " << m_item.value().typeName() << endl;
173 kdDebug(7033) <<
" and validator is a " << m_validator->className() << endl;
175 kdDebug(7033) <<
"*** created a " << w->className() <<
" for it\n";
184 TQWidget* KFileMetaInfoWidget::makeBoolWidget()
186 TQCheckBox* cb =
new TQCheckBox(
this,
"metainfo bool widget");
187 cb->setChecked(m_item.value().toBool());
188 connect(cb, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(slotChanged(
bool)));
192 TQWidget* KFileMetaInfoWidget::makeIntWidget()
194 TQSpinBox* sb =
new TQSpinBox(
this,
"metainfo integer widget");
195 sb->setValue(m_item.value().toInt());
199 if (m_validator->inherits(
"TQIntValidator"))
201 sb->setMinValue(
static_cast<TQIntValidator*
>(m_validator)->bottom());
202 sb->setMaxValue(
static_cast<TQIntValidator*
>(m_validator)->top());
204 reparentValidator(sb, m_validator);
205 sb->setValidator(m_validator);
209 if (m_item.type() == TQVariant::UInt)
210 sb->setMinValue(TQMAX(sb->minValue(), 0));
212 connect(sb, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotChanged(
int)));
216 TQWidget* KFileMetaInfoWidget::makeDoubleWidget()
218 KDoubleNumInput* dni =
new KDoubleNumInput(m_item.value().toDouble(),
219 this,
"metainfo double widget");
224 if (m_validator->inherits(
"QDoubleValidator"))
226 dni->setMinValue(
static_cast<TQDoubleValidator*
>(m_validator)->bottom());
227 dni->setMaxValue(
static_cast<TQDoubleValidator*
>(m_validator)->top());
229 reparentValidator(dni, m_validator);
232 connect(dni, TQ_SIGNAL(valueChanged(
double)),
this, TQ_SLOT(slotChanged(
double)));
236 TQWidget* KFileMetaInfoWidget::makeStringWidget()
238 if (m_validator && m_validator->inherits(
"KStringListValidator"))
240 KComboBox* b =
new KComboBox(
true,
this,
"metainfo combobox");
241 KStringListValidator* val =
static_cast<KStringListValidator*
>
243 b->insertStringList(val->stringList());
244 b->setCurrentText(m_item.value().toString());
245 connect(b, TQ_SIGNAL(activated(
const TQString &)),
this, TQ_SLOT(slotComboChanged(
const TQString &)));
246 b->setValidator(val);
247 reparentValidator(b, val);
251 if ( m_item.attributes() & KFileMimeTypeInfo::MultiLine ) {
252 KEdit *edit =
new KEdit(
this );
253 edit->setText( m_item.value().toString() );
254 connect( edit, TQ_SIGNAL( textChanged() ),
255 this, TQ_SLOT( slotMultiLineEditChanged() ));
258 reparentValidator( edit, m_validator );
262 KLineEdit* e =
new KLineEdit(m_item.value().toString(),
this);
265 e->setValidator(m_validator);
266 reparentValidator(e, m_validator);
268 connect(e, TQ_SIGNAL(textChanged(
const TQString&)),
269 this, TQ_SLOT(slotLineEditChanged(
const TQString&)));
273 TQWidget* KFileMetaInfoWidget::makeDateWidget()
275 TQWidget *e =
new TQDateEdit(m_item.value().toDate(),
this);
276 connect(e, TQ_SIGNAL(valueChanged(
const TQDate&)),
277 this, TQ_SLOT(slotDateChanged(
const TQDate&)));
281 TQWidget* KFileMetaInfoWidget::makeTimeWidget()
283 return new TQTimeEdit(m_item.value().toTime(),
this);
286 TQWidget* KFileMetaInfoWidget::makeDateTimeWidget()
288 return new TQDateTimeEdit(m_item.value().toDateTime(),
this);
291 void KFileMetaInfoWidget::reparentValidator( TQWidget *widget,
292 TQValidator *validator )
294 if ( !validator->parent() )
295 widget->insertChild( validator );
302 void KFileMetaInfoWidget::slotChanged(
bool value)
304 Q_ASSERT(m_widget->inherits(
"TQComboBox"));
305 m_value = TQVariant(value);
306 emit valueChanged(m_value);
310 void KFileMetaInfoWidget::slotChanged(
int value)
312 Q_ASSERT(m_widget->inherits(
"TQSpinBox"));
313 m_value = TQVariant(value);
314 emit valueChanged(m_value);
318 void KFileMetaInfoWidget::slotChanged(
double value)
320 Q_ASSERT(m_widget->inherits(
"KDoubleNumInput"));
321 m_value = TQVariant(value);
322 emit valueChanged(m_value);
326 void KFileMetaInfoWidget::slotComboChanged(
const TQString &value)
328 Q_ASSERT(m_widget->inherits(
"KComboBox"));
329 m_value = TQVariant(value);
330 emit valueChanged(m_value);
334 void KFileMetaInfoWidget::slotLineEditChanged(
const TQString& value)
336 Q_ASSERT(m_widget->inherits(
"KLineEdit"));
337 m_value = TQVariant(value);
338 emit valueChanged(m_value);
343 void KFileMetaInfoWidget::slotMultiLineEditChanged()
345 Q_ASSERT(m_widget->inherits(
"TQTextEdit"));
346 m_value = TQVariant(
static_cast<const TQTextEdit*
>( sender() )->text() );
347 emit valueChanged(m_value);
351 void KFileMetaInfoWidget::slotDateChanged(
const TQDate& value)
353 Q_ASSERT(m_widget->inherits(
"TQDateEdit"));
354 m_value = TQVariant(value);
355 emit valueChanged(m_value);
359 void KFileMetaInfoWidget::slotTimeChanged(
const TQTime& value)
361 Q_ASSERT(m_widget->inherits(
"TQTimeEdit"));
362 m_value = TQVariant(value);
363 emit valueChanged(m_value);
367 void KFileMetaInfoWidget::slotDateTimeChanged(
const TQDateTime& value)
369 Q_ASSERT(m_widget->inherits(
"TQDateTimeEdit"));
370 m_value = TQVariant(value);
371 emit valueChanged(m_value);
375 #include "tdefilemetainfowidget.moc"