kstars
focusdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qtabwidget.h>
00019 #include <qlayout.h>
00020
00021 #include <kdebug.h>
00022 #include <klocale.h>
00023 #include <kmessagebox.h>
00024
00025 #include <qstring.h>
00026 #include <knumvalidator.h>
00027
00028 #include "kstars.h"
00029 #include "kstarsdata.h"
00030 #include "dms.h"
00031 #include "skypoint.h"
00032 #include "dmsbox.h"
00033 #include "focusdialog.h"
00034
00035 FocusDialog::FocusDialog( QWidget *parent )
00036 : KDialogBase( KDialogBase::Plain, i18n( "Set Focus Manually" ), Ok|Cancel, Ok, parent ) {
00037
00038 Point = 0;
00039 UsedAltAz = false;
00040
00041 QFrame *page = plainPage();
00042 setMainWidget(page);
00043 QVBoxLayout *vlay = new QVBoxLayout( page, 0, spacingHint() );
00044 fdlg = new FocusDialogDlg(page);
00045 fdlg->epochName->setValidator( new KDoubleValidator( fdlg->epochName ) );
00046 vlay->addWidget( fdlg );
00047
00048 connect( fdlg->raBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
00049 connect( fdlg->decBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
00050 connect( fdlg->azBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
00051 connect( fdlg->altBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
00052 connect( this, SIGNAL( okClicked() ), this, SLOT( validatePoint() ) );
00053
00054 fdlg->raBox->setDegType(false);
00055 fdlg->raBox->setFocus();
00056 enableButtonOK( false );
00057 }
00058
00059 FocusDialog::~FocusDialog(){
00060 }
00061
00062 void FocusDialog::checkLineEdits() {
00063 bool raOk(false), decOk(false), azOk(false), altOk(false);
00064 fdlg->raBox->createDms( false, &raOk );
00065 fdlg->decBox->createDms( true, &decOk );
00066 fdlg->azBox->createDms( true, &azOk );
00067 fdlg->altBox->createDms( true, &altOk );
00068 if ( ( raOk && decOk ) || ( azOk && altOk ) )
00069 enableButtonOK( true );
00070 else
00071 enableButtonOK( false );
00072 }
00073
00074 void FocusDialog::slotOk() {
00075 emit okClicked();
00076 }
00077
00078 void FocusDialog::validatePoint() {
00079 bool raOk(false), decOk(false), azOk(false), altOk(false);
00080 dms ra( fdlg->raBox->createDms( false, &raOk ) );
00081 dms dec( fdlg->decBox->createDms( true, &decOk ) );
00082 QString message;
00083
00084 KStars *ks = (KStars*) parent();
00085
00086 if ( raOk && decOk ) {
00087
00088 if ( ra.Hours() < 0.0 || ra.Hours() > 24.0 )
00089 message = i18n( "The Right Ascension value must be between 0.0 and 24.0." );
00090 if ( dec.Degrees() < -90.0 || dec.Degrees() > 90.0 )
00091 message += "\n" + i18n( "The Declination value must be between -90.0 and 90.0." );
00092 if ( ! message.isEmpty() ) {
00093 KMessageBox::sorry( 0, message, i18n( "Invalid Coordinate Data" ) );
00094 return;
00095 }
00096
00097 Point = new SkyPoint( ra, dec );
00098 double epoch0 = getEpoch( fdlg->epochName->text() );
00099 long double jd0 = epochToJd ( epoch0 );
00100 Point->apparentCoord(jd0, ks->data()->ut().djd() );
00101
00102 QDialog::accept();
00103 } else {
00104 dms az( fdlg->azBox->createDms( true, &azOk ) );
00105 dms alt( fdlg->altBox->createDms( true, &altOk ) );
00106
00107 if ( azOk && altOk ) {
00108
00109 if ( az.Degrees() < 0.0 || az.Degrees() > 360.0 )
00110 message = i18n( "The Azimuth value must be between 0.0 and 360.0." );
00111 if ( alt.Degrees() < -90.0 || alt.Degrees() > 90.0 )
00112 message += "\n" + i18n( "The Altitude value must be between -90.0 and 90.0." );
00113 if ( ! message.isEmpty() ) {
00114 KMessageBox::sorry( 0, message, i18n( "Invalid Coordinate Data" ) );
00115 return;
00116 }
00117
00118 Point = new SkyPoint();
00119 Point->setAz( az );
00120 Point->setAlt( alt );
00121 UsedAltAz = true;
00122
00123 QDialog::accept();
00124 } else {
00125 QDialog::reject();
00126 }
00127 }
00128 }
00129
00130 double FocusDialog::getEpoch (QString eName) {
00131
00132 bool ok(false);
00133 double epoch = eName.toDouble( &ok );
00134 if ( eName.isEmpty() || ! ok )
00135 return 2000.0;
00136
00137 return epoch;
00138 }
00139
00140 long double FocusDialog::epochToJd (double epoch) {
00141
00142 double yearsTo2000 = 2000.0 - epoch;
00143
00144 if (epoch == 1950.0) {
00145 return 2433282.4235;
00146 } else if ( epoch == 2000.0 ) {
00147 return J2000;
00148 } else {
00149 return ( J2000 - yearsTo2000 * 365.2425 );
00150 }
00151
00152 }
00153
00154
00155 QSize FocusDialog::sizeHint() const
00156 {
00157 return QSize(240,210);
00158 }
00159
00160 void FocusDialog::activateAzAltPage() {
00161 fdlg->fdTab->showPage( fdlg->aaTab );
00162 fdlg->azBox->setFocus();
00163 }
00164 #include "focusdialog.moc"