1 /***************************************************************************
2 focusdialog.cpp - description
4 begin : Sat Mar 23 2002
5 copyright : (C) 2002 by Jason Harris
6 email : kstars@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include <qtabwidget.h>
23 #include <kmessagebox.h>
26 #include <knumvalidator.h>
29 #include "kstarsdata.h"
33 #include "focusdialog.h"
35 FocusDialog::FocusDialog( QWidget
*parent
)
36 : KDialogBase( KDialogBase::Plain
, i18n( "Set Focus Manually" ), Ok
|Cancel
, Ok
, parent
) {
38 Point
= 0; //initialize pointer to null
39 UsedAltAz
= false; //assume RA/Dec by default
41 QFrame
*page
= plainPage();
43 QVBoxLayout
*vlay
= new QVBoxLayout( page
, 0, spacingHint() );
44 fdlg
= new FocusDialogDlg(page
);
45 fdlg
->epochName
->setValidator( new KDoubleValidator( fdlg
->epochName
) );
46 vlay
->addWidget( fdlg
);
48 connect( fdlg
->raBox
, SIGNAL(textChanged( const QString
& ) ), this, SLOT( checkLineEdits() ) );
49 connect( fdlg
->decBox
, SIGNAL(textChanged( const QString
& ) ), this, SLOT( checkLineEdits() ) );
50 connect( fdlg
->azBox
, SIGNAL(textChanged( const QString
& ) ), this, SLOT( checkLineEdits() ) );
51 connect( fdlg
->altBox
, SIGNAL(textChanged( const QString
& ) ), this, SLOT( checkLineEdits() ) );
52 connect( this, SIGNAL( okClicked() ), this, SLOT( validatePoint() ) );
54 fdlg
->raBox
->setFocus(); //set input focus
55 enableButtonOK( false ); //disable until both lineedits are filled
58 FocusDialog::~FocusDialog(){
61 void FocusDialog::checkLineEdits() {
62 bool raOk(false), decOk(false), azOk(false), altOk(false);
63 fdlg
->raBox
->createDms( false, &raOk
);
64 fdlg
->decBox
->createDms( true, &decOk
);
65 fdlg
->azBox
->createDms( true, &azOk
);
66 fdlg
->altBox
->createDms( true, &altOk
);
67 if ( ( raOk
&& decOk
) || ( azOk
&& altOk
) )
68 enableButtonOK( true );
70 enableButtonOK( false );
73 void FocusDialog::slotOk() {
77 void FocusDialog::validatePoint() {
78 bool raOk(false), decOk(false), azOk(false), altOk(false);
79 dms
ra( fdlg
->raBox
->createDms( false, &raOk
) ); //false means expressed in hours
80 dms
dec( fdlg
->decBox
->createDms( true, &decOk
) );
83 KStars
*ks
= (KStars
*) parent();
85 if ( raOk
&& decOk
) {
86 //make sure values are in valid range
87 if ( ra
.Hours() < 0.0 || ra
.Hours() > 24.0 )
88 message
= i18n( "The Right Ascension value must be between 0.0 and 24.0." );
89 if ( dec
.Degrees() < -90.0 || dec
.Degrees() > 90.0 )
90 message
+= "\n" + i18n( "The Declination value must be between -90.0 and 90.0." );
91 if ( ! message
.isEmpty() ) {
92 KMessageBox::sorry( 0, message
, i18n( "Invalid Coordinate Data" ) );
96 Point
= new SkyPoint( ra
, dec
);
97 double epoch0
= getEpoch( fdlg
->epochName
->text() );
98 long double jd0
= epochToJd ( epoch0
);
99 Point
->apparentCoord(jd0
, ks
->data()->ut().djd() );
103 dms
az( fdlg
->azBox
->createDms( true, &azOk
) );
104 dms
alt( fdlg
->altBox
->createDms( true, &altOk
) );
106 if ( azOk
&& altOk
) {
107 //make sure values are in valid range
108 if ( az
.Degrees() < 0.0 || az
.Degrees() > 360.0 )
109 message
= i18n( "The Azimuth value must be between 0.0 and 360.0." );
110 if ( alt
.Degrees() < -90.0 || alt
.Degrees() > 90.0 )
111 message
+= "\n" + i18n( "The Altitude value must be between -90.0 and 90.0." );
112 if ( ! message
.isEmpty() ) {
113 KMessageBox::sorry( 0, message
, i18n( "Invalid Coordinate Data" ) );
117 Point
= new SkyPoint();
119 Point
->setAlt( alt
);
129 double FocusDialog::getEpoch (QString eName
) {
130 //If eName is empty (or not a number) assume 2000.0
132 double epoch
= eName
.toDouble( &ok
);
133 if ( eName
.isEmpty() || ! ok
)
139 long double FocusDialog::epochToJd (double epoch
) {
141 double yearsTo2000
= 2000.0 - epoch
;
143 if (epoch
== 1950.0) {
145 } else if ( epoch
== 2000.0 ) {
148 return ( J2000
- yearsTo2000
* 365.2425 );
154 QSize
FocusDialog::sizeHint() const
156 return QSize(240,210);
159 void FocusDialog::activateAzAltPage() {
160 fdlg
->fdTab
->showPage( fdlg
->aaTab
);
161 fdlg
->azBox
->setFocus();
163 #include "focusdialog.moc"