22 #include "kiginputdialog.moc"
28 #include "../kig/kig_document.h"
33 #include <qvalidator.h>
35 #include <kcombobox.h>
36 #include <klineedit.h>
38 #include <kpushbutton.h>
40 class KigInputDialogPrivate
43 KigInputDialogPrivate();
46 KLineEdit* m_lineEditFirst;
47 KLineEdit* m_lineEditSecond;
48 KComboBox* m_comboBox;
58 KigInputDialogPrivate::KigInputDialogPrivate()
59 : m_label( 0L ), m_lineEditFirst( 0L ), m_lineEditSecond( 0L ), m_comboBox( 0L ),
64 KigInputDialog::~KigInputDialog()
69 KigInputDialog::KigInputDialog(
const QString& caption,
const QString& label,
72 d( new KigInputDialogPrivate() )
74 setCaption( caption );
75 setButtons( Ok | Cancel );
77 d->m_coord1 = c1 ?
Coordinate( *c1 ) : Coordinate::invalidCoord();
78 d->m_coord2 = c2 ? Coordinate( *c2 ) : Coordinate::invalidCoord();
85 setMainWidget( frame );
86 QVBoxLayout* mainlay =
new QVBoxLayout( frame );
87 mainlay->setMargin( 0 );
88 mainlay->setSpacing( spacingHint() );
91 d->m_label =
new QLabel( frame );
92 d->m_label->setTextFormat( Qt::RichText );
93 d->m_label->setText( label );
94 mainlay->addWidget( d->m_label );
96 d->m_lineEditFirst =
new KLineEdit( frame );
98 if ( d->m_coord1.valid() )
100 d->m_lineEditFirst->setText( d->m_doc->coordinateSystem().fromScreen( d->m_coord1, *d->m_doc ) );
103 mainlay->addWidget( d->m_lineEditFirst );
105 connect( d->m_lineEditFirst, SIGNAL(textChanged(
const QString&)),
106 this, SLOT(slotCoordsChanged(
const QString&)) );
108 if ( d->m_coord2.valid() )
110 d->m_lineEditSecond =
new KLineEdit( frame );
112 d->m_lineEditSecond->setText( d->m_doc->coordinateSystem().fromScreen( d->m_coord2, *d->m_doc ) );
113 mainlay->addWidget( d->m_lineEditSecond );
115 connect( d->m_lineEditSecond, SIGNAL(textChanged(
const QString&)),
116 this, SLOT(slotCoordsChanged(
const QString&)) );
119 resize( minimumSizeHint() );
121 d->m_lineEditFirst->setFocus();
123 enableButtonOk( ok );
128 d( new KigInputDialogPrivate() )
130 setCaption( i18n(
"Set Angle Size" ) );
131 setButtons( Ok | Cancel );
134 d->m_gonioIsNum =
true;
137 setMainWidget( frame );
138 QVBoxLayout* mainlay =
new QVBoxLayout( frame );
139 mainlay->setMargin( 0 );
140 mainlay->setSpacing( spacingHint() );
143 d->m_label =
new QLabel( frame );
144 d->m_label->setText( i18n(
"Insert the new size of this angle:" ) );
145 mainlay->addWidget( d->m_label );
147 QHBoxLayout* horlay =
new QHBoxLayout( (
QWidget*)0 );
148 horlay->setMargin( 0 );
149 horlay->setSpacing( spacingHint() );
152 d->m_lineEditFirst =
new KLineEdit( frame );
153 d->m_lineEditFirst->setText( QString::number( d->m_gonio.value() ) );
154 d->m_lineEditFirst->setWhatsThis(
155 i18n(
"Use this edit field to modify the size of this angle." ) );
156 horlay->addWidget( d->m_lineEditFirst );
158 d->m_comboBox =
new KComboBox( frame );
160 d->m_comboBox->setCurrentIndex( d->m_gonio.system() );
161 d->m_comboBox->setWhatsThis(
162 i18n(
"Choose from this list the goniometric unit you want to use to "
163 "modify the size of this angle.<br />\n"
164 "If you switch to another unit, the value in the edit field on "
165 "the left will be converted to the new selected unit." ) );
166 horlay->addWidget( d->m_comboBox );
168 mainlay->addLayout( horlay );
170 connect( d->m_lineEditFirst, SIGNAL(textChanged(
const QString&)),
171 this, SLOT(slotGonioTextChanged(
const QString&)) );
172 connect( d->m_comboBox, SIGNAL(activated(
int)),
173 this, SLOT(slotGonioSystemChanged(
int)) );
177 d->m_lineEditFirst->setFocus();
180 void KigInputDialog::keyPressEvent( QKeyEvent* e )
183 if ( ( e->key() == Qt::Key_Return ) && ( e->modifiers() == 0 ) )
185 if ( actionButton( Ok )->isEnabled() )
187 actionButton( Ok )->animateClick();
192 else if ( ( e->key() == Qt::Key_Escape ) && ( e->modifiers() == 0 ) )
194 actionButton( Cancel )->animateClick();
199 KDialog::keyPressEvent( e );
202 void KigInputDialog::slotCoordsChanged(
const QString& )
205 QString t = d->m_lineEditFirst->text();
206 bool ok = d->m_vtor->validate( t, p ) == QValidator::Acceptable;
208 d->m_coord1 = d->m_doc->coordinateSystem().toScreen( t, ok );
209 if ( d->m_lineEditSecond )
212 t = d->m_lineEditSecond->text();
213 ok &= d->m_vtor->validate( t, p ) == QValidator::Acceptable;
215 d->m_coord2 = d->m_doc->coordinateSystem().toScreen( t, ok );
218 enableButtonOk( ok );
221 void KigInputDialog::slotGonioSystemChanged(
int index )
223 if ( d->m_gonioIsNum )
226 d->m_gonio.convertTo( newsys );
227 d->m_lineEditFirst->setText( QString::number( d->m_gonio.value() ) );
231 void KigInputDialog::slotGonioTextChanged(
const QString& txt )
234 d->m_gonioIsNum =
false;
237 double v = txt.toDouble( &(d->m_gonioIsNum) );
238 d->m_gonio.setValue( v );
240 enableButtonOk( d->m_gonioIsNum );
244 Coordinate KigInputDialog::coordinateFirst()
const
249 Coordinate KigInputDialog::coordinateSecond()
const
267 Coordinate* cvalue2 )
269 KigInputDialog dlg( caption, label, parent, doc, cvalue, cvalue2 );
271 *ok = ( dlg.exec() == Accepted );
275 Coordinate a = dlg.coordinateFirst();
279 Coordinate b = dlg.coordinateSecond();
290 *ok = ( dlg.exec() == Accepted );
292 return dlg.goniometry();
virtual QValidator * coordinateValidator() const =0
Manage an angle and convert it from/to other goniometric systems.
static Goniometry::System intToSystem(const int index)
The Coordinate class is the basic class representing a 2D location by its x and y components...
static QStringList systemList()
Get a list of the supported goniometric systems.
KigDocument is the class holding the real data in a Kig document.
const CoordinateSystem & coordinateSystem() const