• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • dialogs
focusdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  focusdialog.cpp - description
3  -------------------
4  begin : Sat Mar 23 2002
5  copyright : (C) 2002 by Jason Harris
6  email : kstars@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
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. *
15  * *
16  ***************************************************************************/
17 
18 #include "focusdialog.h"
19 
20 #include <QVBoxLayout>
21 #include <kdebug.h>
22 #include <klocale.h>
23 #include <kmessagebox.h>
24 #include <knumvalidator.h>
25 
26 #include "kstars.h"
27 #include "kstarsdata.h"
28 #include "dms.h"
29 #include "skyobjects/skypoint.h"
30 #include "skymap.h"
31 
32 FocusDialogUI::FocusDialogUI( QWidget *parent ) : QFrame( parent ) {
33  setupUi( this );
34 }
35 
36 FocusDialog::FocusDialog( KStars *_ks )
37  : KDialog( _ks ), ks( _ks )
38 {
39  //initialize point to the current focus position
40  Point = *ks->map()->focus();
41 
42  UsedAltAz = false; //assume RA/Dec by default
43 
44  fd = new FocusDialogUI(this);
45  setMainWidget(fd);
46  setCaption( i18n( "Set Coordinates Manually" ) );
47  setButtons( KDialog::Ok|KDialog::Cancel );
48 
49  fd->epochBox->setValidator( new KDoubleValidator( fd->epochBox ) );
50  fd->raBox->setMinimumWidth( fd->raBox->fontMetrics().boundingRect("00h 00m 00s").width() );
51  fd->azBox->setMinimumWidth( fd->raBox->fontMetrics().boundingRect("00h 00m 00s").width() );
52 
53  fd->raBox->setDegType(false); //RA box should be HMS-style
54  fd->raBox->setFocus(); //set input focus
55  enableButtonOk( false ); //disable until both lineedits are filled
56 
57  connect( fd->raBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
58  connect( fd->decBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
59  connect( fd->azBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
60  connect( fd->altBox, SIGNAL(textChanged( const QString & ) ), this, SLOT( checkLineEdits() ) );
61  connect( this, SIGNAL( okClicked() ), this, SLOT( validatePoint() ) );
62 }
63 
64 FocusDialog::~FocusDialog(){
65 }
66 
67 void FocusDialog::checkLineEdits() {
68  bool raOk(false), decOk(false), azOk(false), altOk(false);
69  fd->raBox->createDms( false, &raOk );
70  fd->decBox->createDms( true, &decOk );
71  fd->azBox->createDms( true, &azOk );
72  fd->altBox->createDms( true, &altOk );
73  if ( ( raOk && decOk ) || ( azOk && altOk ) )
74  enableButtonOk( true );
75  else
76  enableButtonOk( false );
77 }
78 
79 void FocusDialog::validatePoint() {
80  bool raOk(false), decOk(false), azOk(false), altOk(false);
81  dms ra( fd->raBox->createDms( false, &raOk ) ); //false means expressed in hours
82  dms dec( fd->decBox->createDms( true, &decOk ) );
83  QString message;
84 
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" ) );
93  return;
94  }
95 
96  Point.set( ra, dec );
97  double epoch0 = getEpoch( fd->epochBox->text() );
98  long double jd0 = epochToJd ( epoch0 );
99  Point.apparentCoord(jd0, ks->data()->ut().djd() );
100  Point.EquatorialToHorizontal( ks->data()->lst(), ks->data()->geo()->lat() );
101 
102  KDialog::accept();
103  } else {
104  dms az( fd->azBox->createDms( true, &azOk ) );
105  dms alt( fd->altBox->createDms( true, &altOk ) );
106 
107  if ( azOk && altOk ) {
108  //make sure values are in valid range
109  if ( az.Degrees() < 0.0 || az.Degrees() > 360.0 )
110  message = i18n( "The Azimuth value must be between 0.0 and 360.0." );
111  if ( alt.Degrees() < -90.0 || alt.Degrees() > 90.0 )
112  message += '\n' + i18n( "The Altitude value must be between -90.0 and 90.0." );
113  if ( ! message.isEmpty() ) {
114  KMessageBox::sorry( 0, message, i18n( "Invalid Coordinate Data" ) );
115  return;
116  }
117 
118  Point.setAz( az );
119  Point.setAlt( alt );
120  Point.HorizontalToEquatorial( ks->data()->lst(), ks->data()->geo()->lat() );
121 
122  UsedAltAz = true;
123 
124  KDialog::accept();
125  } else {
126  KDialog::reject();
127  }
128  }
129 }
130 
131 double FocusDialog::getEpoch (const QString &eName) {
132  //If eName is empty (or not a number) assume 2000.0
133  bool ok(false);
134  double epoch = eName.toDouble( &ok );
135  if ( eName.isEmpty() || ! ok )
136  return 2000.0;
137 
138  return epoch;
139 }
140 
141 long double FocusDialog::epochToJd (double epoch) {
142 
143  double yearsTo2000 = 2000.0 - epoch;
144 
145  if (epoch == 1950.0) {
146  return 2433282.4235;
147  } else if ( epoch == 2000.0 ) {
148  return J2000;
149  } else {
150  return ( J2000 - yearsTo2000 * 365.2425 );
151  }
152 
153 }
154 
155 
156 QSize FocusDialog::sizeHint() const
157 {
158  return QSize(240,210);
159 }
160 
161 void FocusDialog::activateAzAltPage() const {
162  fd->fdTab->setCurrentWidget( fd->aaTab );
163  fd->azBox->setFocus();
164 }
165 #include "focusdialog.moc"
FocusDialog::sizeHint
QSize sizeHint() const
Definition: focusdialog.cpp:156
KStars::map
SkyMap * map() const
Definition: kstars.h:134
FocusDialog::getEpoch
double getEpoch(const QString &eName)
Convert a string to an epoch number; essentially just converts the string to a double.
Definition: focusdialog.cpp:131
QWidget
FocusDialog::epochToJd
long double epochToJd(double epoch)
Convenience function to convert an epoch number (e.g., 2000.0) to the corresponding Julian Day number...
Definition: focusdialog.cpp:141
KDialog
KStars
This is the main window for KStars.
Definition: kstars.h:94
FocusDialogUI
Definition: focusdialog.h:28
dms.h
FocusDialog::validatePoint
void validatePoint()
Attempt to interpret the text in the KLineEdits as Ra and Dec values.
Definition: focusdialog.cpp:79
SkyMap::focus
SkyPoint * focus()
Retrieve the Focus point; the position on the sky at the center of the skymap.
Definition: skymap.h:120
skymap.h
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
FocusDialog::~FocusDialog
~FocusDialog()
Destructor (empty).
Definition: focusdialog.cpp:64
skypoint.h
focusdialog.h
J2000
#define J2000
Definition: kstarsdatetime.h:21
FocusDialog::checkLineEdits
void checkLineEdits()
If text has been entered in both KLineEdits, enable the Ok button.
Definition: focusdialog.cpp:67
kstarsdata.h
QFrame
FocusDialogUI::FocusDialogUI
FocusDialogUI(QWidget *parent=0)
Definition: focusdialog.cpp:32
FocusDialog::FocusDialog
FocusDialog(KStars *_ks)
Constructor.
Definition: focusdialog.cpp:36
kstars.h
FocusDialog::activateAzAltPage
void activateAzAltPage() const
Show the Az/Alt page instead of the RA/Dec page.
Definition: focusdialog.cpp:161
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal