20 #include "sizewidget.h"
22 #include <tqcombobox.h>
23 #include <tqspinbox.h>
26 #include <tdelocale.h>
28 SizeWidget::SizeWidget( TQWidget *parent,
const char *name )
29 : TQWidget( parent, name )
31 m_size =
new TQSpinBox( 0, 9999, 1,
this );
32 m_unit =
new TQComboBox(
this );
34 m_unit->insertItem( i18n(
"KB" ) );
35 m_unit->insertItem( i18n(
"MB" ) );
36 m_unit->insertItem( i18n(
"GB" ) );
37 m_unit->insertItem( i18n(
"Tiles" ) );
38 m_unit->setCurrentItem( 1 );
39 m_size->setSpecialValueText( i18n(
"Unlimited" ) );
41 TQHBoxLayout *l0 =
new TQHBoxLayout(
this, 0, 5 );
42 l0->addWidget( m_size, 1 );
43 l0->addWidget( m_unit, 0 );
46 void SizeWidget::setSizeString(
const TQString& sz )
48 int p = sz.find( TQRegExp(
"\\D" ) );
49 m_size->setValue( sz.left( p ).toInt() );
50 switch( sz[ p ].latin1() )
52 case 'k': p = 0;
break;
54 case 'm': p = 1;
break;
55 case 'g': p = 2;
break;
56 case 't': p = 3;
break;
58 m_unit->setCurrentItem( p );
61 TQString SizeWidget::sizeString()
const
63 TQString result = TQString::number( m_size->value() );
64 switch ( m_unit->currentItem() )
66 case 0: result.append(
"k" );
break;
67 case 1: result.append(
"m" );
break;
68 case 2: result.append(
"g" );
break;
69 case 3: result.append(
"t" );
break;
74 void SizeWidget::setValue(
int value )
76 m_size->setValue( value );
77 m_unit->setCurrentItem( 1 );
80 int SizeWidget::value()
const
82 return m_size->value();