/*************************************************************************** * * * begin : 07 May 2004 * * copyright : (C) 2003 by Samokhvalov Anton :) * * * ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include SizeBox::SizeBox( QWidget* parent, const char* name, WFlags /*fl*/ ): KComboBox( true, parent, name ) { insertItem( "20%" ); insertItem( "30%" ); insertItem( "40%" ); insertItem( "50%" ); insertItem( "60%" ); insertItem( "70%" ); insertItem( "80%" ); insertItem( "90%" ); insertItem( "100%" ); insertItem( "110%" ); insertItem( "120%" ); insertItem( "130%" ); insertItem( "140%" ); insertItem( "150%" ); insertItem( "160%" ); insertItem( "170%" ); insertItem( "180%" ); insertItem( "190%" ); insertItem( "200%" ); insertItem( "210%" ); insertItem( "220%" ); insertItem( "230%" ); insertItem( "240%" ); insertItem( "250%" ); insertItem( "260%" ); insertItem( "270%" ); insertItem( "280%" ); insertItem( "290%" ); insertItem( "300%" ); setInsertionPolicy( NoInsertion ); setCurrentItem( 8 ); setValidator( new QRegExpValidator( QRegExp( "^[0-9]{1,3}%?$" ), this, "validator" ) ); connect( this, SIGNAL(activated(const QString&)), this, SLOT(slotTextChanged(const QString&)) ); } SizeBox::~SizeBox() { } void SizeBox::slotTextChanged( const QString& text ) { if ( text.length() > 1 ) { QString p; if ( text[ text.length() - 1 ] == '%' ) { p = text.left( text.length() - 1 ); } else { p = text; } int percents = 0; bool ok = false; percents = p.toInt( &ok ); if ( !ok ) { return; } if ( ok ) { emit sizeChanged( percents ); } } } void SizeBox::setCurrentText( const QString& txt ) { KComboBox::setCurrentText( txt ); emit activated( txt ); } #include "SizeBox.moc"