You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
376 lines
12 KiB
376 lines
12 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2001,2002 Rolf Magnus <ramagnus@kde.org>
|
||
|
|
||
|
library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
|
||
|
$Id$
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include "tdefilemetainfowidget.h"
|
||
15 years ago
|
|
||
|
#include <keditcl.h>
|
||
|
#include <klocale.h>
|
||
|
#include <knuminput.h>
|
||
|
#include <kcombobox.h>
|
||
|
#include <klineedit.h>
|
||
|
#include <kstringvalidator.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqspinbox.h>
|
||
|
#include <tqdatetimeedit.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqimage.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqvalidator.h>
|
||
15 years ago
|
|
||
|
/*
|
||
|
Widgets used for different types:
|
||
|
|
||
|
bool : QCheckBox
|
||
|
int : QSpinBox
|
||
15 years ago
|
TQString : KComboBox if the validator is a KStringListValidator, else lineedit
|
||
|
TQDateTime : QDateTimeEdit
|
||
15 years ago
|
|
||
|
*/
|
||
|
|
||
|
KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
|
||
15 years ago
|
TQValidator* val,
|
||
|
TQWidget* parent, const char* name)
|
||
|
: TQWidget(parent, name),
|
||
15 years ago
|
m_value(item.value()),
|
||
|
m_item(item),
|
||
|
m_validator(val)
|
||
|
{
|
||
|
init(item, ReadWrite);
|
||
|
}
|
||
|
|
||
|
KFileMetaInfoWidget::KFileMetaInfoWidget(KFileMetaInfoItem item,
|
||
|
Mode mode,
|
||
15 years ago
|
TQValidator* val,
|
||
|
TQWidget* parent, const char* name)
|
||
|
: TQWidget(parent, name),
|
||
15 years ago
|
m_value(item.value()),
|
||
|
m_item(item),
|
||
|
m_validator(val)
|
||
|
{
|
||
|
init(item, mode);
|
||
|
}
|
||
|
|
||
|
void KFileMetaInfoWidget::init(KFileMetaInfoItem item, Mode mode)
|
||
|
{
|
||
|
kdDebug(7033) << "*** item " << m_item.key()
|
||
|
<< " is a " << value().typeName() << endl;
|
||
|
|
||
|
if (m_item.isEditable() && !(mode & ReadOnly))
|
||
|
m_widget = makeWidget();
|
||
|
else
|
||
|
switch (m_value.type())
|
||
|
{
|
||
15 years ago
|
case TQVariant::Image :
|
||
|
m_widget = new TQLabel(this, "info image");
|
||
|
static_cast<TQLabel*>(m_widget)->setPixmap(TQPixmap(m_value.toImage()));
|
||
15 years ago
|
break;
|
||
15 years ago
|
case TQVariant::Pixmap :
|
||
|
m_widget = new TQLabel(this, "info pixmap");
|
||
|
static_cast<TQLabel*>(m_widget)->setPixmap(m_value.toPixmap());
|
||
15 years ago
|
break;
|
||
|
default:
|
||
15 years ago
|
m_widget = new TQLabel(item.string(true), this, "info label");
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
(new TQHBoxLayout(this))->addWidget(m_widget);
|
||
15 years ago
|
}
|
||
|
|
||
|
KFileMetaInfoWidget::~KFileMetaInfoWidget()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeWidget()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString valClass;
|
||
|
TQWidget* w;
|
||
15 years ago
|
|
||
|
switch (m_value.type())
|
||
|
{
|
||
15 years ago
|
case TQVariant::Invalid: // no type
|
||
15 years ago
|
// just make a label
|
||
15 years ago
|
w = new TQLabel(i18n("<Error>"), this, "label");
|
||
15 years ago
|
break;
|
||
|
|
||
15 years ago
|
case TQVariant::Int: // an int
|
||
|
case TQVariant::UInt: // an unsigned int
|
||
15 years ago
|
w = makeIntWidget();
|
||
|
break;
|
||
|
|
||
15 years ago
|
case TQVariant::Bool: // a bool
|
||
15 years ago
|
w = makeBoolWidget();
|
||
|
break;
|
||
|
|
||
15 years ago
|
case TQVariant::Double: // a double
|
||
15 years ago
|
w = makeDoubleWidget();
|
||
|
break;
|
||
|
|
||
|
|
||
15 years ago
|
case TQVariant::Date: // a QDate
|
||
15 years ago
|
w = makeDateWidget();
|
||
|
break;
|
||
|
|
||
15 years ago
|
case TQVariant::Time: // a QTime
|
||
15 years ago
|
w = makeTimeWidget();
|
||
|
break;
|
||
|
|
||
15 years ago
|
case TQVariant::DateTime: // a QDateTime
|
||
15 years ago
|
w = makeDateTimeWidget();
|
||
|
break;
|
||
|
|
||
|
#if 0
|
||
15 years ago
|
case TQVariant::Size: // a QSize
|
||
|
case TQVariant::String: // a QString
|
||
|
case TQVariant::List: // a QValueList
|
||
|
case TQVariant::Map: // a QMap
|
||
|
case TQVariant::StringList: // a QStringList
|
||
|
case TQVariant::Font: // a QFont
|
||
|
case TQVariant::Pixmap: // a QPixmap
|
||
|
case TQVariant::Brush: // a QBrush
|
||
|
case TQVariant::Rect: // a QRect
|
||
|
case TQVariant::Color: // a QColor
|
||
|
case TQVariant::Palette: // a QPalette
|
||
|
case TQVariant::ColorGroup: // a QColorGroup
|
||
|
case TQVariant::IconSet: // a QIconSet
|
||
|
case TQVariant::Point: // a QPoint
|
||
|
case TQVariant::Image: // a QImage
|
||
|
case TQVariant::CString: // a QCString
|
||
|
case TQVariant::PointArray: // a QPointArray
|
||
|
case TQVariant::Region: // a QRegion
|
||
|
case TQVariant::Bitmap: // a QBitmap
|
||
|
case TQVariant::Cursor: // a QCursor
|
||
|
case TQVariant::ByteArray: // a QByteArray
|
||
|
case TQVariant::BitArray: // a QBitArray
|
||
|
case TQVariant::SizePolicy: // a QSizePolicy
|
||
|
case TQVariant::KeySequence: // a QKeySequence
|
||
15 years ago
|
#endif
|
||
|
default:
|
||
|
w = makeStringWidget();
|
||
|
}
|
||
|
|
||
|
kdDebug(7033) << "*** item " << m_item.key()
|
||
|
<< "is a " << m_item.value().typeName() << endl;
|
||
|
if (m_validator)
|
||
|
kdDebug(7033) << " and validator is a " << m_validator->className() << endl;
|
||
|
|
||
|
kdDebug(7033) << "*** created a " << w->className() << " for it\n";
|
||
|
|
||
|
return w;
|
||
|
}
|
||
|
|
||
|
// ****************************************************************
|
||
|
// now the different methods to make the widgets for specific types
|
||
|
// ****************************************************************
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeBoolWidget()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQCheckBox* cb = new TQCheckBox(this, "metainfo bool widget");
|
||
15 years ago
|
cb->setChecked(m_item.value().toBool());
|
||
15 years ago
|
connect(cb, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotChanged(bool)));
|
||
15 years ago
|
return cb;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeIntWidget()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQSpinBox* sb = new TQSpinBox(this, "metainfo integer widget");
|
||
15 years ago
|
sb->setValue(m_item.value().toInt());
|
||
|
|
||
|
if (m_validator)
|
||
|
{
|
||
14 years ago
|
if (m_validator->inherits(TQINTVALIDATOR_OBJECT_NAME_STRING))
|
||
15 years ago
|
{
|
||
15 years ago
|
sb->setMinValue(static_cast<TQIntValidator*>(m_validator)->bottom());
|
||
|
sb->setMaxValue(static_cast<TQIntValidator*>(m_validator)->top());
|
||
15 years ago
|
}
|
||
|
reparentValidator(sb, m_validator);
|
||
|
sb->setValidator(m_validator);
|
||
|
}
|
||
|
|
||
|
// make sure that an uint cannot be set to a value < 0
|
||
15 years ago
|
if (m_item.type() == TQVariant::UInt)
|
||
15 years ago
|
sb->setMinValue(QMAX(sb->minValue(), 0));
|
||
|
|
||
15 years ago
|
connect(sb, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotChanged(int)));
|
||
15 years ago
|
return sb;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeDoubleWidget()
|
||
15 years ago
|
{
|
||
|
KDoubleNumInput* dni = new KDoubleNumInput(m_item.value().toDouble(),
|
||
|
this, "metainfo double widget");
|
||
|
|
||
|
|
||
|
if (m_validator)
|
||
|
{
|
||
14 years ago
|
if (m_validator->inherits("QDoubleValidator"))
|
||
15 years ago
|
{
|
||
15 years ago
|
dni->setMinValue(static_cast<TQDoubleValidator*>(m_validator)->bottom());
|
||
|
dni->setMaxValue(static_cast<TQDoubleValidator*>(m_validator)->top());
|
||
15 years ago
|
}
|
||
|
reparentValidator(dni, m_validator);
|
||
|
}
|
||
|
|
||
15 years ago
|
connect(dni, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(slotChanged(double)));
|
||
15 years ago
|
return dni;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeStringWidget()
|
||
15 years ago
|
{
|
||
|
if (m_validator && m_validator->inherits("KStringListValidator"))
|
||
|
{
|
||
|
KComboBox* b = new KComboBox(true, this, "metainfo combobox");
|
||
|
KStringListValidator* val = static_cast<KStringListValidator*>
|
||
|
(m_validator);
|
||
|
b->insertStringList(val->stringList());
|
||
|
b->setCurrentText(m_item.value().toString());
|
||
15 years ago
|
connect(b, TQT_SIGNAL(activated(const TQString &)), this, TQT_SLOT(slotComboChanged(const TQString &)));
|
||
15 years ago
|
b->setValidator(val);
|
||
|
reparentValidator(b, val);
|
||
|
return b;
|
||
|
}
|
||
|
|
||
|
if ( m_item.attributes() & KFileMimeTypeInfo::MultiLine ) {
|
||
|
KEdit *edit = new KEdit( this );
|
||
|
edit->setText( m_item.value().toString() );
|
||
15 years ago
|
connect( edit, TQT_SIGNAL( textChanged() ),
|
||
|
this, TQT_SLOT( slotMultiLineEditChanged() ));
|
||
|
// can't use a validator with a TQTextEdit, but we may need to delete it
|
||
15 years ago
|
if ( m_validator )
|
||
|
reparentValidator( edit, m_validator );
|
||
|
return edit;
|
||
|
}
|
||
|
|
||
|
KLineEdit* e = new KLineEdit(m_item.value().toString(), this);
|
||
|
if (m_validator)
|
||
|
{
|
||
|
e->setValidator(m_validator);
|
||
|
reparentValidator(e, m_validator);
|
||
|
}
|
||
15 years ago
|
connect(e, TQT_SIGNAL(textChanged(const TQString&)),
|
||
|
this, TQT_SLOT(slotLineEditChanged(const TQString&)));
|
||
15 years ago
|
return e;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeDateWidget()
|
||
15 years ago
|
{
|
||
14 years ago
|
TQWidget *e = new TQDateEdit(m_item.value().toDate(), this);
|
||
15 years ago
|
connect(e, TQT_SIGNAL(valueChanged(const TQDate&)),
|
||
|
this, TQT_SLOT(slotDateChanged(const TQDate&)));
|
||
15 years ago
|
return e;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeTimeWidget()
|
||
15 years ago
|
{
|
||
14 years ago
|
return new TQTimeEdit(m_item.value().toTime(), this);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KFileMetaInfoWidget::makeDateTimeWidget()
|
||
15 years ago
|
{
|
||
14 years ago
|
return new TQDateTimeEdit(m_item.value().toDateTime(), this);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KFileMetaInfoWidget::reparentValidator( TQWidget *widget,
|
||
|
TQValidator *validator )
|
||
15 years ago
|
{
|
||
|
if ( !validator->parent() )
|
||
|
widget->insertChild( validator );
|
||
|
}
|
||
|
|
||
|
// ****************************************************************
|
||
|
// now the slots that let us get notified if the value changed in the child
|
||
|
// ****************************************************************
|
||
|
|
||
|
void KFileMetaInfoWidget::slotChanged(bool value)
|
||
|
{
|
||
14 years ago
|
Q_ASSERT(m_widget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
|
void KFileMetaInfoWidget::slotChanged(int value)
|
||
|
{
|
||
14 years ago
|
Q_ASSERT(m_widget->inherits(TQSPINBOX_OBJECT_NAME_STRING));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
|
void KFileMetaInfoWidget::slotChanged(double value)
|
||
|
{
|
||
|
Q_ASSERT(m_widget->inherits("KDoubleNumInput"));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileMetaInfoWidget::slotComboChanged(const TQString &value)
|
||
15 years ago
|
{
|
||
|
Q_ASSERT(m_widget->inherits("KComboBox"));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileMetaInfoWidget::slotLineEditChanged(const TQString& value)
|
||
15 years ago
|
{
|
||
|
Q_ASSERT(m_widget->inherits("KLineEdit"));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
|
// that may be a little expensive for long texts, but what can we do?
|
||
|
void KFileMetaInfoWidget::slotMultiLineEditChanged()
|
||
|
{
|
||
14 years ago
|
Q_ASSERT(m_widget->inherits(TQTEXTEDIT_OBJECT_NAME_STRING));
|
||
15 years ago
|
m_value = TQVariant( static_cast<const TQTextEdit*>( sender() )->text() );
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileMetaInfoWidget::slotDateChanged(const TQDate& value)
|
||
15 years ago
|
{
|
||
14 years ago
|
Q_ASSERT(m_widget->inherits(TQDATEEDIT_OBJECT_NAME_STRING));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileMetaInfoWidget::slotTimeChanged(const TQTime& value)
|
||
15 years ago
|
{
|
||
14 years ago
|
Q_ASSERT(m_widget->inherits(TQTIMEEDIT_OBJECT_NAME_STRING));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFileMetaInfoWidget::slotDateTimeChanged(const TQDateTime& value)
|
||
15 years ago
|
{
|
||
14 years ago
|
Q_ASSERT(m_widget->inherits(TQDATETIMEEDIT_OBJECT_NAME_STRING));
|
||
15 years ago
|
m_value = TQVariant(value);
|
||
15 years ago
|
emit valueChanged(m_value);
|
||
|
m_dirty = true;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdefilemetainfowidget.moc"
|