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.
284 lines
8.0 KiB
284 lines
8.0 KiB
15 years ago
|
/**
|
||
|
This file is part of Kig, a KDE program for Interactive Geometry...
|
||
|
Copyright (C) 2005 Pino Toscano <toscano.pino@tiscali.it>
|
||
|
|
||
|
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.
|
||
|
|
||
|
This program 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 General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||
|
USA
|
||
|
**/
|
||
|
|
||
|
#include "kiginputdialog.h"
|
||
|
#include "kiginputdialog.moc"
|
||
|
|
||
|
#include "coordinate.h"
|
||
|
#include "coordinate_system.h"
|
||
|
#include "goniometry.h"
|
||
|
|
||
|
#include "../kig/kig_document.h"
|
||
|
|
||
15 years ago
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqpushbutton.h>
|
||
|
#include <tqvalidator.h>
|
||
|
#include <tqwhatsthis.h>
|
||
15 years ago
|
|
||
|
#include <kcombobox.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <klineedit.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <ktextedit.h>
|
||
|
|
||
|
class KigInputDialogPrivate
|
||
|
{
|
||
|
public:
|
||
|
KigInputDialogPrivate();
|
||
|
|
||
15 years ago
|
TQLabel* m_label;
|
||
15 years ago
|
KLineEdit* m_lineEditFirst;
|
||
|
KLineEdit* m_lineEditSecond;
|
||
|
KComboBox* m_comboBox;
|
||
|
KTextEdit* m_textEdit;
|
||
|
|
||
|
Coordinate m_coord1;
|
||
|
Coordinate m_coord2;
|
||
|
KigDocument m_doc;
|
||
15 years ago
|
TQValidator* m_vtor;
|
||
15 years ago
|
Goniometry m_gonio;
|
||
|
bool m_gonioIsNum;
|
||
|
};
|
||
|
|
||
|
KigInputDialogPrivate::KigInputDialogPrivate()
|
||
|
: m_label( 0L ), m_lineEditFirst( 0L ), m_lineEditSecond( 0L ), m_comboBox( 0L ),
|
||
|
m_textEdit( 0L )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KigInputDialog::KigInputDialog( const TQString& caption, const TQString& label,
|
||
13 years ago
|
TQWidget* parent, const KigDocument& doc, Coordinate* c1, Coordinate* c2 )
|
||
|
: KDialogBase( parent, "kigdialog", true, caption, Ok|Cancel, Cancel, true ),
|
||
15 years ago
|
d( new KigInputDialogPrivate() )
|
||
|
{
|
||
|
d->m_coord1 = c1 ? Coordinate( *c1 ) : Coordinate::invalidCoord();
|
||
|
d->m_coord2 = c2 ? Coordinate( *c2 ) : Coordinate::invalidCoord();
|
||
|
d->m_doc = doc;
|
||
|
d->m_vtor = d->m_doc.coordinateSystem().coordinateValidator();
|
||
|
|
||
|
int deltay = 0;
|
||
|
bool ok = false;
|
||
|
|
||
15 years ago
|
TQFrame* frame = makeMainWidget();
|
||
|
TQVBoxLayout* mainlay = new TQVBoxLayout( frame, 0, spacingHint() );
|
||
15 years ago
|
mainlay->activate();
|
||
|
|
||
|
d->m_textEdit = new KTextEdit( frame );
|
||
|
d->m_textEdit->setText( label );
|
||
|
d->m_textEdit->setReadOnly( true );
|
||
14 years ago
|
d->m_textEdit->setFocusPolicy( TQ_NoFocus );
|
||
13 years ago
|
// d->m_textEdit->setAlignment( d->m_textEdit->alignment() | TQt::WordBreak );
|
||
15 years ago
|
d->m_textEdit->setFrameStyle( TQFrame::NoFrame );
|
||
15 years ago
|
mainlay->addWidget( d->m_textEdit );
|
||
|
|
||
|
d->m_lineEditFirst = new KLineEdit( frame );
|
||
|
// d->m_lineEditFirst->setValidator( d->m_vtor );
|
||
|
if ( d->m_coord1.valid() )
|
||
|
{
|
||
|
d->m_lineEditFirst->setText( d->m_doc.coordinateSystem().fromScreen( d->m_coord1, d->m_doc ) );
|
||
|
ok = true;
|
||
|
}
|
||
|
mainlay->addWidget( d->m_lineEditFirst );
|
||
|
|
||
15 years ago
|
connect( d->m_lineEditFirst, TQT_SIGNAL(textChanged(const TQString&)),
|
||
|
this, TQT_SLOT(slotCoordsChanged(const TQString&)) );
|
||
15 years ago
|
|
||
|
if ( d->m_coord2.valid() )
|
||
|
{
|
||
|
d->m_lineEditSecond = new KLineEdit( frame );
|
||
|
// d->m_lineEditSecond->setValidator( d->m_vtor );
|
||
|
d->m_lineEditSecond->setText( d->m_doc.coordinateSystem().fromScreen( d->m_coord2, d->m_doc ) );
|
||
|
mainlay->addWidget( d->m_lineEditSecond );
|
||
|
|
||
15 years ago
|
connect( d->m_lineEditSecond, TQT_SIGNAL(textChanged(const TQString&)),
|
||
|
this, TQT_SLOT(slotCoordsChanged(const TQString&)) );
|
||
15 years ago
|
|
||
|
deltay += d->m_lineEditSecond->height() + spacingHint();
|
||
|
}
|
||
|
|
||
|
resize( 400, 160 + deltay );
|
||
|
|
||
|
d->m_lineEditFirst->setFocus();
|
||
|
|
||
|
enableButtonOK( ok );
|
||
|
}
|
||
|
|
||
13 years ago
|
KigInputDialog::KigInputDialog( TQWidget* parent, const Goniometry& g )
|
||
|
: KDialogBase( parent, "kigdialog", true, i18n( "Set Angle Size" ), Ok|Cancel, Cancel, true ),
|
||
15 years ago
|
d( new KigInputDialogPrivate() )
|
||
|
{
|
||
|
d->m_gonio = g;
|
||
|
d->m_gonioIsNum = true;
|
||
|
|
||
15 years ago
|
TQFrame* frame = makeMainWidget();
|
||
|
TQVBoxLayout* mainlay = new TQVBoxLayout( frame, 0, spacingHint() );
|
||
15 years ago
|
mainlay->activate();
|
||
|
|
||
15 years ago
|
d->m_label = new TQLabel( frame );
|
||
15 years ago
|
d->m_label->setText( i18n( "Insert the new size of this angle:" ) );
|
||
|
mainlay->addWidget( d->m_label );
|
||
|
|
||
15 years ago
|
TQHBoxLayout* horlay = new TQHBoxLayout( 0, 0, spacingHint() );
|
||
15 years ago
|
horlay->activate();
|
||
|
|
||
|
d->m_lineEditFirst = new KLineEdit( frame );
|
||
15 years ago
|
d->m_lineEditFirst->setText( TQString::number( d->m_gonio.value() ) );
|
||
|
TQWhatsThis::add(
|
||
15 years ago
|
d->m_lineEditFirst,
|
||
|
i18n( "Use this edit field to modify the size of this angle." ) );
|
||
|
horlay->addWidget( d->m_lineEditFirst );
|
||
|
|
||
|
d->m_comboBox = new KComboBox( frame );
|
||
|
d->m_comboBox->insertStringList( Goniometry::systemList() );
|
||
|
d->m_comboBox->setCurrentItem( d->m_gonio.system() );
|
||
15 years ago
|
TQWhatsThis::add(
|
||
15 years ago
|
d->m_comboBox,
|
||
|
i18n( "Choose from this list the goniometric unit you want to use to "
|
||
|
"modify the size of this angle.<br>\n"
|
||
|
"If you switch to another unit, the value in the edit field on "
|
||
|
"the left will be converted to the new selected unit." ) );
|
||
|
horlay->addWidget( d->m_comboBox );
|
||
|
|
||
|
mainlay->addLayout( horlay );
|
||
|
|
||
15 years ago
|
connect( d->m_lineEditFirst, TQT_SIGNAL(textChanged(const TQString&)),
|
||
|
this, TQT_SLOT(slotGonioTextChanged(const TQString&)) );
|
||
|
connect( d->m_comboBox, TQT_SIGNAL(activated(int)),
|
||
|
this, TQT_SLOT(slotGonioSystemChanged(int)) );
|
||
15 years ago
|
|
||
|
resize( 350, 100 );
|
||
|
|
||
|
d->m_lineEditFirst->setFocus();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KigInputDialog::keyPressEvent( TQKeyEvent* e )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( ( e->key() == TQt::Key_Return ) && ( e->state() == 0 ) )
|
||
15 years ago
|
{
|
||
|
if ( actionButton( Ok )->isEnabled() )
|
||
|
{
|
||
|
actionButton( Ok )->animateClick();
|
||
|
e->accept();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
else if ( ( e->key() == TQt::Key_Escape ) && ( e->state() == 0 ) )
|
||
15 years ago
|
{
|
||
|
actionButton( Cancel )->animateClick();
|
||
|
e->accept();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
15 years ago
|
void KigInputDialog::slotCoordsChanged( const TQString& )
|
||
15 years ago
|
{
|
||
|
int p = 0;
|
||
15 years ago
|
TQString t = d->m_lineEditFirst->text();
|
||
|
bool ok = d->m_vtor->validate( t, p ) == TQValidator::Acceptable;
|
||
15 years ago
|
if ( ok )
|
||
|
d->m_coord1 = d->m_doc.coordinateSystem().toScreen( t, ok );
|
||
|
if ( d->m_lineEditSecond )
|
||
|
{
|
||
|
p = 0;
|
||
|
t = d->m_lineEditSecond->text();
|
||
15 years ago
|
ok &= d->m_vtor->validate( t, p ) == TQValidator::Acceptable;
|
||
15 years ago
|
if ( ok )
|
||
|
d->m_coord2 = d->m_doc.coordinateSystem().toScreen( t, ok );
|
||
|
}
|
||
|
|
||
|
enableButtonOK( ok );
|
||
|
}
|
||
|
|
||
|
void KigInputDialog::slotGonioSystemChanged( int index )
|
||
|
{
|
||
|
if ( d->m_gonioIsNum )
|
||
|
{
|
||
|
Goniometry::System newsys = Goniometry::intToSystem( index );
|
||
|
d->m_gonio.convertTo( newsys );
|
||
15 years ago
|
d->m_lineEditFirst->setText( TQString::number( d->m_gonio.value() ) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KigInputDialog::slotGonioTextChanged( const TQString& txt )
|
||
15 years ago
|
{
|
||
|
if ( txt.isNull() )
|
||
|
d->m_gonioIsNum = false;
|
||
|
else
|
||
|
{
|
||
|
double v = txt.toDouble( &(d->m_gonioIsNum) );
|
||
|
d->m_gonio.setValue( v );
|
||
|
}
|
||
|
enableButtonOK( d->m_gonioIsNum );
|
||
|
}
|
||
|
|
||
|
|
||
|
Coordinate KigInputDialog::coordinateFirst() const
|
||
|
{
|
||
|
return d->m_coord1;
|
||
|
}
|
||
|
|
||
|
Coordinate KigInputDialog::coordinateSecond() const
|
||
|
{
|
||
|
return d->m_coord2;
|
||
|
}
|
||
|
|
||
|
Goniometry KigInputDialog::goniometry() const
|
||
|
{
|
||
|
return d->m_gonio;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KigInputDialog::getCoordinate( const TQString& caption, const TQString& label,
|
||
13 years ago
|
TQWidget* parent, bool* ok, const KigDocument& doc, Coordinate* cvalue )
|
||
15 years ago
|
{
|
||
13 years ago
|
getTwoCoordinates( caption, label, parent, ok, doc, cvalue, 0 );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KigInputDialog::getTwoCoordinates( const TQString& caption, const TQString& label,
|
||
13 years ago
|
TQWidget* parent, bool* ok, const KigDocument& doc, Coordinate* cvalue,
|
||
15 years ago
|
Coordinate* cvalue2 )
|
||
|
{
|
||
13 years ago
|
KigInputDialog dlg( caption, label, parent, doc, cvalue, cvalue2 );
|
||
15 years ago
|
|
||
|
*ok = ( dlg.exec() == Accepted );
|
||
|
|
||
|
if ( *ok )
|
||
|
{
|
||
|
Coordinate a = dlg.coordinateFirst();
|
||
|
*cvalue = a;
|
||
|
if ( cvalue2 )
|
||
|
{
|
||
|
Coordinate b = dlg.coordinateSecond();
|
||
|
*cvalue2 = b;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
13 years ago
|
Goniometry KigInputDialog::getAngle( TQWidget* parent, bool* ok, const Goniometry& g )
|
||
15 years ago
|
{
|
||
13 years ago
|
KigInputDialog dlg( parent, g );
|
||
15 years ago
|
|
||
|
*ok = ( dlg.exec() == Accepted );
|
||
|
|
||
|
return dlg.goniometry();
|
||
|
}
|