21#include "KoUnitWidgets.h"
22#include "KoUnitWidgets.moc"
26#include <tqpushbutton.h>
34KoUnitDoubleValidator::KoUnitDoubleValidator(
KoUnitDoubleBase *base, TQObject *parent,
const char *name )
40KoUnitDoubleValidator::validate( TQString &s,
int &pos )
const
43 kdDebug(30004) <<
"KoUnitDoubleValidator::validate : " << s <<
" at " << pos << endl;
44 TQValidator::State result = Acceptable;
46 TQRegExp regexp (
"([ a-zA-Z]+)$");
47 const int res = regexp.search( s );
52 kdDebug(30004) <<
"Intermediate (no unit)" << endl;
57 const TQString number ( s.left( res ).stripWhiteSpace() );
58 const TQString unitName ( regexp.cap( 1 ).stripWhiteSpace().lower() );
60 kdDebug(30004) <<
"Split:" << number <<
":" << unitName <<
":" << endl;
63 const double value = m_base->
toDouble( number, &ok );
73 kdDebug(30004) <<
"Intermediate (unknown unit)" << endl;
79 kdWarning(30004) <<
"Not a number: " << number << endl;
93 const TQString num ( TQString(
"%1%2").arg( TDEGlobal::locale()->formatNumber( value, m_precision ),
KoUnit::unitName( m_unit ) ) );
94 kdDebug(30004) <<
"getVisibleText: " << TQString::number( value,
'f', 12 ) <<
" => " << num << endl;
100 TQString str2( str );
103 const TQString sep( TDEGlobal::locale()->thousandsSeparator() );
104 if ( !sep.isEmpty() )
107 const double dbl = TDEGlobal::locale()->readNumber( str2, ok );
109 kdDebug(30004) <<
"toDouble:" << str <<
": => :" << str2 <<
": => " << TQString::number( dbl,
'f', 12 ) << endl;
111 kdWarning(30004) <<
"toDouble error:" << str <<
": => :" << str2 <<
":" << endl;
120KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( TQWidget *parent,
const char *name )
122 , m_lowerInPoints( -9999 )
123 , m_upperInPoints( 9999 )
124 , m_stepInPoints( 1 )
128 TQSpinBox::setValidator( m_validator );
129 setAcceptLocalizedNumbers(
true );
130 setUnit( KoUnit::U_PT );
132 connect(
this, TQ_SIGNAL(valueChanged(
double )), TQ_SLOT(privateValueChanged()));
136KoUnitDoubleSpinBox::KoUnitDoubleSpinBox( TQWidget *parent,
137 double lower,
double upper,
141 unsigned int precision,
145 m_lowerInPoints( lower ), m_upperInPoints( upper ), m_stepInPoints( step )
147 m_unit = KoUnit::U_PT;
149 TQSpinBox::setValidator( m_validator );
150 setAcceptLocalizedNumbers(
true );
152 changeValue( value );
155 connect(
this, TQ_SIGNAL(valueChanged(
double )), TQ_SLOT(privateValueChanged()));
159KoUnitDoubleSpinBox::changeValue(
double val )
167void KoUnitDoubleSpinBox::privateValueChanged() {
190 m_lowerInPoints = min;
196 m_upperInPoints = max;
208 m_stepInPoints = step;
222KoUnitDoubleLineEdit::KoUnitDoubleLineEdit( TQWidget *parent,
const char *name )
224 m_lowerInPoints( 0.0 ), m_upperInPoints( 9999.99 )
226 setAlignment( TQt::AlignRight );
229 setUnit( KoUnit::U_PT );
233KoUnitDoubleLineEdit::KoUnitDoubleLineEdit( TQWidget *parent,
double lower,
double upper,
double value,
KoUnit::Unit unit,
234 unsigned int precision,
const char *name )
236 m_lowerInPoints( lower ), m_upperInPoints( upper )
238 setAlignment( TQt::AlignRight );
246KoUnitDoubleLineEdit::changeValue(
double value )
248 m_value =
value < m_lower ? m_lower : (
value > m_upper ? m_upper :
value );
263KoUnitDoubleLineEdit::eventFilter( TQObject* o, TQEvent* ev )
266 if( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Leave || ev->type() == TQEvent::Hide )
270 changeValue(
value );
275 return TQLineEdit::eventFilter( o, ev );
287KoUnitDoubleComboBox::KoUnitDoubleComboBox( TQWidget *parent,
const char *name )
288 :
KComboBox( true, parent, name ),
KoUnitDoubleBase(
KoUnit::U_PT, 2 ), m_value( 0.0 ), m_lower( 0.0 ), m_upper( 9999.99 ), m_lowerInPoints( 0.0 ), m_upperInPoints( 9999.99 )
290 lineEdit()->setAlignment( TQt::AlignRight );
292 lineEdit()->setValidator( m_validator );
293 setUnit( KoUnit::U_PT );
295 connect(
this, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( slotActivated(
int ) ) );
298KoUnitDoubleComboBox::KoUnitDoubleComboBox( TQWidget *parent,
double lower,
double upper,
double value,
KoUnit::Unit unit,
299 unsigned int precision,
const char *name )
301 m_lowerInPoints( lower ), m_upperInPoints( upper )
303 lineEdit()->setAlignment( TQt::AlignRight );
305 lineEdit()->setValidator( m_validator );
308 connect(
this, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( slotActivated(
int ) ) );
312KoUnitDoubleComboBox::changeValue(
double value )
314 TQString oldLabel = lineEdit()->text();
315 updateValue(
value );
316 if( lineEdit()->text() != oldLabel )
317 emit valueChanged( m_value );
321KoUnitDoubleComboBox::updateValue(
double value )
323 m_value =
value < m_lower ? m_lower : (
value > m_upper ? m_upper :
value );
328KoUnitDoubleComboBox::insertItem(
double value,
int index )
334KoUnitDoubleComboBox::slotActivated(
int index )
336 double oldvalue = m_value;
339 m_value =
value < m_lower ? m_lower : (
value > m_upper ? m_upper :
value );
340 if( m_value != oldvalue )
341 emit valueChanged( m_value );
355KoUnitDoubleComboBox::eventFilter( TQObject* o, TQEvent* ev )
358 if( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Leave || ev->type() == TQEvent::Hide )
362 changeValue(
value );
367 return TQComboBox::eventFilter( o, ev );
379KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( TQWidget *parent,
const char *name )
380 : TQWidget( parent ), m_step( 1.0 )
382 TQGridLayout *layout =
new TQGridLayout(
this, 2, 3 );
384 TQPushButton *up =
new TQPushButton(
"+",
this );
386 up->setMaximumHeight( 15 );
387 up->setMaximumWidth( 15 );
388 layout->addWidget( up, 0, 0 );
389 connect( up, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotUpClicked() ) );
391 TQPushButton *down =
new TQPushButton(
"-",
this );
392 down->setMaximumHeight( 15 );
393 down->setMaximumWidth( 15 );
394 layout->addWidget( down, 1, 0 );
395 connect( down, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotDownClicked() ) );
398 connect( m_combo, TQ_SIGNAL( valueChanged(
double ) ),
this, TQ_SIGNAL( valueChanged(
double ) ) );
399 layout->addMultiCellWidget( m_combo, 0, 1, 2, 2 );
402KoUnitDoubleSpinComboBox::KoUnitDoubleSpinComboBox( TQWidget *parent,
double lower,
double upper,
double step,
double value,
403 KoUnit::Unit unit,
unsigned int precision,
const char *name )
404 : TQWidget( parent ), m_step( step )
406 TQGridLayout *layout =
new TQGridLayout(
this, 2, 3 );
408 TQPushButton *
up =
new TQPushButton(
"+",
this );
410 up->setMaximumHeight( 15 );
411 up->setMaximumWidth( 15 );
412 layout->addWidget( up, 0, 0 );
413 connect( up, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotUpClicked() ) );
415 TQPushButton *down =
new TQPushButton(
"-",
this );
416 down->setMaximumHeight( 15 );
417 down->setMaximumWidth( 15 );
418 layout->addWidget( down, 1, 0 );
419 connect( down, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotDownClicked() ) );
422 connect( m_combo, TQ_SIGNAL( valueChanged(
double ) ),
this, TQ_SIGNAL( valueChanged(
double ) ) );
423 layout->addMultiCellWidget( m_combo, 0, 1, 2, 2 );
427KoUnitDoubleSpinComboBox::slotUpClicked()
429 m_combo->changeValue( m_combo->
value() + m_step );
433KoUnitDoubleSpinComboBox::slotDownClicked()
435 m_combo->changeValue( m_combo->
value() - m_step );
439KoUnitDoubleSpinComboBox::insertItem(
double value,
int index )
441 m_combo->insertItem(
value, index );
445KoUnitDoubleSpinComboBox::updateValue(
double value )
447 m_combo->updateValue(
value );
453 return m_combo->
value();
void setPrecision(int precision)
void setValidator(const TQValidator *)
virtual void setValue(double value)
void setMaxValue(double value)
void setMinValue(double value)
void setLineStep(double step)
virtual void setText(const TQString &)
Base for the unit widgets.
TQString getVisibleText(double value) const
Transform the double in a nice text, using locale symbols.
double toDouble(const TQString &str, bool *ok) const
Transfrom a string into a double, while taking care of locale specific symbols.
Combo box for double precision numbers with unit display.
double m_upperInPoints
highest value in points
double m_lowerInPoints
lowest value in points
void valueChangedPt(double)
emitted like valueChanged in the parent, but this one emits the point value
void setMinValue(double min)
Set minimum value in points.
void setLineStep(double step)
Set step size in the current unit.
void setMaxValue(double max)
Set maximum value in points.
void setMinMaxStep(double min, double max, double step)
Set minimum, maximum value and the step size (all in points) (by Tymoteusz Majewski,...
void setLineStepPt(double step)
Set step size in points.
Validator for the unit widget classes.
KOffice stores everything in pt (using "double") internally.
static double toUserValue(double ptValue, Unit unit)
This method is the one to use to display a value in a dialog.
static double fromUserValue(double value, Unit unit)
This method is the one to use to read a value from a dialog.
static double ptToUnit(const double ptValue, const Unit unit)
Convert the value ptValue to a given unit unit Unlike KoUnit::ptToUnit the return value remains unrou...
Unit
Length units supported by KOffice.
static Unit unit(const TQString &_unitName, bool *ok=0)
Convert a unit name into a Unit enum.
static TQString unitName(Unit _unit)
Get the name of a unit.
TDEAction * up(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const char * name(StdAction id)
@ Invalid
invalid property type