kstars.cpp 52.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/***************************************************************************
                          kstars.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : Mon Feb  5 01:11:45 PST 2001
    copyright            : (C) 2001 by Jason Harris
    email                : jharris@30doradus.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
//JH 24.08.2001: reorganized infoPanel
//JH 25.08.2001: added toolbar, converted menu items to KAction objects
//JH 25.08.2001: main window now resizable, window size saved in config file

#include <qfont.h>
22
#include <qpopupmenu.h>
23 24 25 26
#include <qtextstream.h>
#include <qlineedit.h>
#include <qsizepolicy.h>
#include <qtooltip.h>
27
#include <qlayout.h>
Dirk Mueller's avatar
Dirk Mueller committed
28
#include <qtimer.h>
29

30 31 32 33 34
#include <kconfig.h>
#include <kstdaction.h>
#include <kaccel.h>
#include <kiconloader.h>
#include <kmessagebox.h>
35 36
#include <kstatusbar.h>
#include <kpopupmenu.h>
37
#include <klocale.h>
38 39

#include <stdio.h>
40
#include <stdlib.h>
Thomas Leitner's avatar
Thomas Leitner committed
41
#include <iostream.h>
Laurent Montel's avatar
Laurent Montel committed
42
#include <kdebug.h>
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

#include "timedialog.h"
#include "locationdialog.h"
#include "finddialog.h"
#include "viewopsdialog.h"

#include "kstars.h"

KStars::KStars( KStarsData* kstarsData )
	: KMainWindow( NULL, NULL )
{
// need to set the mainwidget here, in main() this will cause a segfault because
// skymap will created in this constructor and needs kapp->mainWidget()
	kapp->setMainWidget( this );
	// here we get the preloaded data (stars, constellations etc.)

	this->kstarsData = kstarsData;

	//resize( 640, 600 );
	initMenuBar();
	initToolBar();
	initStatusBar();
	initOptions();
	initLocation();
Laurent Montel's avatar
Laurent Montel committed
67

68 69 70 71 72
// create the widgets
	QWidget *centralWidget = new QWidget( this );
	setCentralWidget( centralWidget );
	infoPanel = new QFrame( centralWidget );
	skymap = new SkyMap( centralWidget );
73 74 75 76
	skymap->QWidget::setFocus();		// get focus of keyboard and mouse actions (for example zoom in with +)
	skymap->setMinimumSize( 380, 250 );
	skymap->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );

77 78 79 80
// create the layout of the central widget
	QVBoxLayout *topLayout = new QVBoxLayout( centralWidget );
	topLayout->addWidget( infoPanel );
	topLayout->addWidget( skymap );
Laurent Montel's avatar
Laurent Montel committed
81

82 83 84 85
/*	//time settings that we couldn't do in KStarsSplash:
	data()->UTime = data()->now.addSecs( int(geo()->TZ()*-3600) );
	data()->LST   = UTtoLST( data()->UTime, geo()->lng() );
	data()->LSTh.setH( data()->LST.hour(), data()->LST.minute(), data()->LST.second() );
86

87 88 89 90
	data()->CurrentDate = data()->getJD( data()->UTime );
	data()->LastSkyUpdate = data()->CurrentDate;
	updateEpoch( data()->CurrentDate );
*/
Laurent Montel's avatar
Laurent Montel committed
91

92 93 94 95 96 97 98 99 100
	//Create the infoPanel, which displays time/date/location data
	infoPanel->setFrameShape( QFrame::Panel );

	//white-on-black color scheme for infoPanel
	QPalette pal( infoPanel->palette() );
	pal.setColor( QPalette::Normal, QColorGroup::Background, QColor( "Black" ) );
	pal.setColor( QPalette::Normal, QColorGroup::Foreground, QColor( "White" ) );
	pal.setColor( QPalette::Inactive, QColorGroup::Foreground, QColor( "White" ) );
	infoPanel->setPalette( pal );
Laurent Montel's avatar
Laurent Montel committed
101

102 103
	//Create main Layout manager for infoPanel
	iplay = new QHBoxLayout( infoPanel, 2, 2, "iplay" );
Laurent Montel's avatar
Laurent Montel committed
104

105
	//Create Widgets to appear in the info panel
106 107 108
	LTLabel = new QLabel( i18n( "Local Time", "LT:" ), infoPanel );
	UTLabel = new QLabel( i18n( "Universal Time", "UT:" ), infoPanel );
	STLabel = new QLabel( i18n( "Sidereal Time", "ST:" ), infoPanel );
109 110 111 112
	LTLabel->setPalette( pal );
	UTLabel->setPalette( pal );
	STLabel->setPalette( pal );

113 114 115
  //Set font for infoPanel widgets; for now just use default font.
	QFont ipFont = LTLabel->font();
	//Uncomment to set smaller font for infoPanel
116
	//ipFont.setPointSize( ipFont.pointSize() - 2 );
117 118 119 120 121 122 123
  //Uncomment for fixed-width font
	//ipFont.setFixedPitch( true );

	LTLabel->setFont( ipFont );
	UTLabel->setFont( ipFont );
	STLabel->setFont( ipFont );

124 125 126 127
	LT = new QLabel( "00:00:00", infoPanel );
	LT->setFixedSize( LT->sizeHint() ); //otherwise, placement of other labels not static

//not using locale.formatTime() because I couldn't find a way to control whether "pm" is displayed...
128 129
	LT->setText( data()->LTime.time().toString() );
	UT = new QLabel( data()->UTime.time().toString(), infoPanel );
130 131 132 133
	ST = new QLabel( "00:00:00", infoPanel );
	LT->setPalette( pal );
	UT->setPalette( pal );
	ST->setPalette( pal );
134 135 136
	LT->setFont( ipFont );
	UT->setFont( ipFont );
	ST->setFont( ipFont );
137

138 139
	LTDate = new QLabel( data()->locale->formatDate( data()->LTime.date(), true ), infoPanel );
	UTDate = new QLabel( data()->locale->formatDate( data()->UTime.date(), true ), infoPanel );
140 141

//Localize display of decimal point number (slightly different between KDE 2 and 3)
142
	JD = new QLabel( "JD: " + KGlobal::locale()->formatNumber( data()->CurrentEpoch, 2 ), infoPanel );
143

144 145 146
	LTDate->setPalette( pal );
	UTDate->setPalette( pal );
	JD->setPalette( pal );
147 148 149
	LTDate->setFont( ipFont );
	UTDate->setFont( ipFont );
	JD->setFont( ipFont );
150 151

	FocusObject = new QLabel( i18n( "Focused on: " ) + i18n( "nothing" ), infoPanel );
152 153 154 155 156 157
	FocusRA = new QLabel( i18n( "Right Ascension", "RA" ) + ": 00:00:00    ", infoPanel );
	FocusDec = new QLabel( i18n( "Declination", "Dec" ) + ": +00:00:00", infoPanel );
	FocusAz = new QLabel( i18n( "Azimuth", "Az" ) + ": +000:00:00 ", infoPanel );
	FocusAlt = new QLabel( i18n( "Altitude", "Alt" ) + ": +00:00:00", infoPanel );
	FocusRA->setFixedSize( FocusRA->sizeHint() );
	FocusAz->setFixedSize( FocusAz->sizeHint() );
158
	FocusObject->setPalette( pal );
159 160 161 162
	FocusRA->setPalette( pal );
	FocusDec->setPalette( pal );
	FocusAz->setPalette( pal );
	FocusAlt->setPalette( pal );
163
	FocusObject->setFont( ipFont );
164 165 166 167
	FocusRA->setFont( ipFont );
	FocusDec->setFont( ipFont );
	FocusAz->setFont( ipFont );
	FocusAlt->setFont( ipFont );
168

169
	PlaceName = new QLabel( i18n("nowhere"), infoPanel );
170 171
	if ( geo()->province().isEmpty() ) {
		PlaceName->setText( geo()->translatedName() + ", " + geo()->translatedCountry() );
172
	} else {
173
		PlaceName->setText( geo()->translatedName() + ", " + geo()->translatedProvince() + ",  " + geo()->translatedCountry() );
174
	}
175 176
	LongLabel = new QLabel( i18n( "Longitude", "Long: " ), infoPanel );
	LatLabel = new QLabel( i18n( "Latitude", "Lat:  " ), infoPanel );
177

178 179
	Long = new QLabel( KGlobal::locale()->formatNumber( geo()->lng().Degrees(),3) , infoPanel );
	Lat = new QLabel( KGlobal::locale()->formatNumber( geo()->lat().Degrees(),3 ), infoPanel );
180

181 182
	Long->setAlignment( AlignRight );
	Lat->setAlignment( AlignRight );
183

184 185 186 187 188
	PlaceName->setPalette( pal );
	LongLabel->setPalette( pal );
	LatLabel->setPalette( pal );
	Long->setPalette( pal );
	Lat->setPalette( pal );
189 190 191 192 193
	PlaceName->setFont( ipFont );
	LongLabel->setFont( ipFont );
	LatLabel->setFont( ipFont );
	Long->setFont( ipFont );
	Lat->setFont( ipFont );
194 195

	//create layouts to be added to iplay
196
	tlablay = new QVBoxLayout( iplay, 1, "tlablay" );
197
	iplay->addSpacing( 6 );
198 199 200
	timelay = new QVBoxLayout( iplay, 1, "timelay" );
	iplay->addSpacing( 4 );
	datelay = new QVBoxLayout( iplay, 1, "datelay" );
201
	iplay->addSpacing( 16 );
202
	focuslay = new QVBoxLayout( iplay, 1, "focuslay" );
203
	iplay->addStretch();
204
	geolay = new QVBoxLayout( iplay, 1, "geolay" );
Laurent Montel's avatar
Laurent Montel committed
205

206 207 208 209 210 211 212 213
	//Pack widgets into infoPanel
	tlablay->addWidget( LTLabel );
	tlablay->addWidget( UTLabel );
	tlablay->addWidget( STLabel );

	timelay->addWidget( LT );
	timelay->addWidget( UT );
	timelay->addWidget( ST );
Laurent Montel's avatar
Laurent Montel committed
214

215 216 217 218 219
	datelay->addWidget( LTDate );
	datelay->addWidget( UTDate );
	datelay->addWidget( JD );

	focuslay->addWidget( FocusObject );
220 221 222 223 224 225 226 227

	radeclay = new QHBoxLayout( focuslay, 1, "radeclay" );
	radeclay->addWidget( FocusRA );
	radeclay->addWidget( FocusDec );

	altazlay = new QHBoxLayout( focuslay, 1, "altazlay" );
	altazlay->addWidget( FocusAz );
	altazlay->addWidget( FocusAlt );
228 229

	geolay->addWidget( PlaceName );
Laurent Montel's avatar
Laurent Montel committed
230

231 232 233 234 235 236 237
	coolay = new QGridLayout( geolay, 3, 2, 2, "coolay" );
	coolay->addItem( new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding ), 0, 0 );
	coolay->addItem( new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding ), 1, 0 );
	coolay->addWidget( LongLabel, 0, 1 );
	coolay->addWidget( LatLabel, 1, 1 );
	coolay->addWidget( Long, 0, 2 );
	coolay->addWidget( Lat, 1, 2 );
Laurent Montel's avatar
Laurent Montel committed
238

239
	infoPanel->setFixedHeight( infoPanel->sizeHint().height() );	// use sizeHint() to get accurate size
240 241 242 243 244 245 246 247 248 249 250 251 252
	resize( options()->windowWidth, options()->windowHeight );

	//Start the clock; intitialize time to system clock
	data()->SysJD_Mark = data()->getJD( QDateTime::currentDateTime() );
	data()->SkyJD_Mark = data()->SysJD_Mark;
	
	tmr = new QTimer( this );
	tmr->start( TIMER_INTERVAL, FALSE );
	QObject::connect( tmr, SIGNAL( timeout() ), this, SLOT( updateTime() ) );

//Try updateTime() and updateEpoch() here to initialize CurrentDate and CurrentEpoch...
	data()->CurrentEpoch = 0.0; //guarantee that updateTime() calls updateEpoch()

253
	updateTime();
254 255
	initAltAz();

256 257 258 259 260 261 262 263
	SkyPoint newPoint;
	if ( useDefaultOptions ) {
		newPoint.setAz( options()->focusRA );
		newPoint.setAlt( options()->focusDec + 0.0001 );
		newPoint.HorizontalToEquatorial( data()->LSTh, geo()->lat() );
	} else {
		newPoint.set( (double)options()->focusRA, (double)options()->focusDec );
	}
264 265 266

//Set focus of Skymap.
//if user was tracking last time, track on same object now.
267
	if ( options()->isTracking ) {
268

269 270 271 272 273 274 275 276 277 278
    //Set default position in case focus object is below horizon
		SkyPoint DefaultFocus;
		DefaultFocus.setAz( 180.0 );
		DefaultFocus.setAlt( 45.0 );
		DefaultFocus.HorizontalToEquatorial( data()->LSTh, geo()->lat() );
		skymap->setFocus( &DefaultFocus );

		if ( (options()->focusObject== i18n( "star" ) ) ||
		     (options()->focusObject== i18n( "nothing" ) ) ) {
			skymap->setClickedPoint( &newPoint );
279
		} else {
280 281 282
			skymap->setClickedObject( getObjectNamed( options()->focusObject ) );
			if ( skymap->clickedObject() ) {
				skymap->setClickedPoint( skymap->clickedObject()->pos() );
283
			} else {
284
				skymap->setClickedPoint( &newPoint );
285
			}
286 287
		}
	} else {
288
		skymap->setClickedPoint( &newPoint );
Laurent Montel's avatar
Laurent Montel committed
289
	}
290

291 292
	skymap->slotCenter();

293 294 295 296 297
	data()->HourAngle.setH( data()->LSTh.Hours() - skymap->focus()->ra().Hours() );

	skymap->setOldFocus( skymap->focus() );
	skymap->oldfocus()->setAz( skymap->focus()->az() );
	skymap->oldfocus()->setAlt( skymap->focus()->alt() );
298 299 300 301 302 303
}

KStars::~KStars()
{
	//Sync the config file
	kapp->config()->setGroup( "Location" );
304 305 306
	kapp->config()->writeEntry( "City", options()->CityName );
	kapp->config()->writeEntry( "Province", options()->ProvinceName );
	kapp->config()->writeEntry( "Country", options()->CountryName );
307
	kapp->config()->setGroup( "View" );
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
	kapp->config()->writeEntry( "SkyColor", 	options()->colorSky );
	kapp->config()->writeEntry( "MWColor", 		options()->colorMW );
	kapp->config()->writeEntry( "EqColor", 		options()->colorEq );
	kapp->config()->writeEntry( "EclColor", 		options()->colorEcl );
	kapp->config()->writeEntry( "HorzColor", 	options()->colorHorz );
	kapp->config()->writeEntry( "GridColor", 	options()->colorGrid );
	kapp->config()->writeEntry( "MessColor", 	options()->colorMess );
	kapp->config()->writeEntry( "NGCColor", 	options()->colorNGC );
	kapp->config()->writeEntry( "ICColor", 		options()->colorIC );
	kapp->config()->writeEntry( "CLineColor", options()->colorCLine );
	kapp->config()->writeEntry( "CNameColor", options()->colorCName );
	kapp->config()->writeEntry( "SNameColor", options()->colorSName );
	kapp->config()->writeEntry( "HSTColor", 	options()->colorHST );
	kapp->config()->writeEntry( "StarColorMode", options()->starColorMode );
	kapp->config()->writeEntry( "StarColorsIntensity", options()->starColorIntensity );
	kapp->config()->writeEntry( "ShowBSC", 		options()->drawBSC );
	kapp->config()->writeEntry( "ShowMess", 	options()->drawMessier );
	kapp->config()->writeEntry( "ShowMessImages", 	options()->drawMessImages );
	kapp->config()->writeEntry( "ShowNGC", 		options()->drawNGC );
	kapp->config()->writeEntry( "ShowIC", 		options()->drawIC );
	kapp->config()->writeEntry( "ShowCLines", options()->drawConstellLines );
	kapp->config()->writeEntry( "ShowCNames", options()->drawConstellNames );
	kapp->config()->writeEntry( "UseLatinConstellationNames", options()->useLatinConstellNames );
	kapp->config()->writeEntry( "UseLocalConstellationNames", options()->useLocalConstellNames );
	kapp->config()->writeEntry( "UseAbbrevConstellationNames", options()->useAbbrevConstellNames );
	kapp->config()->writeEntry( "ShowMilkyWay", options()->drawMilkyWay );
	kapp->config()->writeEntry( "ShowGrid", options()->drawGrid );
	kapp->config()->writeEntry( "ShowEquator", options()->drawEquator );
	kapp->config()->writeEntry( "ShowEcliptic", options()->drawEcliptic );
	kapp->config()->writeEntry( "ShowHorizon", options()->drawHorizon );
	kapp->config()->writeEntry( "ShowGround", options()->drawGround );
	kapp->config()->writeEntry( "ShowSun", 		options()->drawSun );
	kapp->config()->writeEntry( "ShowMoon", 	options()->drawMoon );
	kapp->config()->writeEntry( "ShowMercury", 	options()->drawMercury );
	kapp->config()->writeEntry( "ShowVenus", 	options()->drawVenus );
	kapp->config()->writeEntry( "ShowMars", 	options()->drawMars );
	kapp->config()->writeEntry( "ShowJupiter", 	options()->drawJupiter );
	kapp->config()->writeEntry( "ShowSaturn", 	options()->drawSaturn );
	kapp->config()->writeEntry( "ShowUranus", 	options()->drawUranus );
	kapp->config()->writeEntry( "ShowNeptune", 	options()->drawNeptune );
	kapp->config()->writeEntry( "ShowPluto", 	options()->drawPluto );
	kapp->config()->writeEntry( "IsTracking", 	options()->isTracking );
	if ( skymap->foundObject() != NULL ) {
		kapp->config()->writeEntry( "FocusObject",  skymap->foundObject()->name() );
352
	} else {
353
		kapp->config()->writeEntry( "FocusObject", i18n( "nothing" ) );
354
	}
355 356 357 358
	kapp->config()->writeEntry( "UseAltAz", 	options()->useAltAz );
	kapp->config()->writeEntry( "FocusRA", skymap->focus()->ra().Hours() );
	kapp->config()->writeEntry( "FocusDec", skymap->focus()->dec().Degrees() );
	kapp->config()->writeEntry( "ZoomLevel", data()->ZoomLevel );
359 360
	kapp->config()->writeEntry( "windowWidth", width() );
	kapp->config()->writeEntry( "windowHeight", height() );
361 362 363 364
	kapp->config()->writeEntry( "magLimitDrawStar", 	 options()->magLimitDrawStar );
	kapp->config()->writeEntry( "magLimitDrawStarInfo",options()->magLimitDrawStarInfo );
	kapp->config()->writeEntry( "drawStarName", 			 options()->drawStarName );
	kapp->config()->writeEntry( "drawStarMagnitude",   options()->drawStarMagnitude );
365 366 367 368 369 370
	kapp->config()->sync();

	// remove data object
	delete kstarsData;
	//kstarsData = 0;

371
	delete Location;
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
	delete LT;
	delete UT;
	delete ST;
	delete JD;
	delete LTDate;
	delete UTDate;
	delete LTLabel;
	delete UTLabel;
	delete STLabel;
	delete PlaceName;
	delete LongLabel;
	delete LatLabel;

	delete skymap;
}

void KStars::initMenuBar() {
389
	KPopupMenu *p;
Laurent Montel's avatar
Laurent Montel committed
390

391
	p = new KPopupMenu;
392 393 394 395
	actQuit = KStdAction::quit(this, SLOT( close() ), actionCollection() );
	actQuit->plug( p );
	menuBar()->insertItem( i18n( "&File" ), p );

396
	p = new KPopupMenu;
397
	actTimeNow = new KAction( i18n( "Set Time to &Now" ), 0, this, SLOT( mSetTimeToNow() ), actionCollection() );
398
	actTimeNow->setAccel( CTRL+Key_N );
399
	actTimeSet = new KAction( i18n( "&Set Time..." ), BarIcon( "clock" ), 0, this, SLOT( mSetTime() ), actionCollection() );
400
	actTimeSet->setAccel( CTRL+Key_S );
401 402 403
	actTimeRun = new KAction( i18n( "Stop &Clock" ), BarIcon( "player_pause" ), 0, this, SLOT( mToggleTimer() ), actionCollection() );
	actTimeNow->plug( p );
	actTimeSet->plug( p );
Laurent Montel's avatar
Laurent Montel committed
404
	actTimeRun->plug( p );
405 406
	menuBar()->insertItem( i18n( "&Time" ), p );

407
	p = new KPopupMenu;
408 409 410 411 412
	p->insertItem( i18n( "&Zenith" ), this, SLOT( mZenith() ));
	actFind = KStdAction::find( this, SLOT( mFind() ), actionCollection() );
	actFind->setText( i18n( "&Find Object..." ) );
	actFind->setToolTip( i18n( "Find Object" ) );
	actFind->plug( p );
413
	actTrack = new KAction( i18n( "&Track Object" ), BarIcon( "decrypted" ), 0, this, SLOT( mTrack() ), actionCollection() );
414
	actTrack->setAccel( CTRL+Key_T );
415 416 417 418 419 420
	actTrack->plug( p );
	p->insertSeparator();

	//use custom icon earth.png for the geoLocator icon.  If it is not installed
  //for some reason, use standard icon gohome.png instead.
	QFile tempFile;
421
	if (KStarsData::openDataFile( tempFile, "earth.png" ) ) {
422 423 424 425 426
		actLocation = new KAction( i18n( "&Geographic..." ), QPixmap( tempFile.name() ), 0, this, SLOT( mGeoLocator() ), actionCollection() );
		actLocation->setToolTip( i18n( "Geographic Location" ) );
		tempFile.close();
	} else {
		actLocation = new KAction( i18n( "&Geographic..." ), BarIcon( "gohome" ), 0, this, SLOT( mGeoLocator() ), actionCollection() );
Laurent Montel's avatar
Laurent Montel committed
427
	}
428
	actLocation->setAccel( CTRL+Key_G );
429 430 431
	actLocation->plug( p );
	menuBar()->insertItem( i18n( "&Location" ), p );

432
	p = new KPopupMenu;
433 434 435 436 437 438 439 440 441 442 443
//	p->insertItem( i18n( "&Reverse Video" ), this, SLOT( mReverseVideo() ));
	actZoomIn = KStdAction::zoomIn(this, SLOT( mZoomIn() ), actionCollection() );
	actZoomOut = KStdAction::zoomOut(this, SLOT( mZoomOut() ), actionCollection() );
	actZoomIn->plug( p );
	actZoomOut->plug( p );

	p->insertSeparator();
	actViewOps = KStdAction::preferences( this, SLOT( mViewOps() ), actionCollection() );
	actViewOps->plug( p );
	menuBar()->insertItem( i18n( "&View" ), p );

444
	p = helpMenu( 0, false );
445 446

	menuBar()->insertItem( i18n( "&Help" ), p );
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469

}

void KStars::initToolBar() {
	toolBar()->setFullSize();
  toolBar()->enableMoving( false );

	actQuit->plug( toolBar() );
	toolBar()->insertSeparator( );
	actZoomIn->plug( toolBar() );
	actZoomOut->plug( toolBar() );
	toolBar()->insertSeparator( );
	actFind->plug( toolBar() );
	actTrack->plug( toolBar() );
	actLocation->plug( toolBar() );
	actViewOps->plug( toolBar() );
	toolBar()->insertSeparator( );
	actTimeSet->plug( toolBar() );
	actTimeRun->plug( toolBar() );
	toolBar()->insertSeparator( );

	TimeStep = new TimeSpinBox( toolBar() );
	QToolTip::add( TimeStep, i18n( "Time Step (seconds)" ) );
470 471
	connect( TimeStep, SIGNAL( valueChanged( int ) ), this, SLOT( changeTimeStep() ) );

472 473 474 475 476
	QWidget *Blank = new QWidget( toolBar() );

	idSpinBox = 0;
	toolBar()->insertWidget( idSpinBox, 6, TimeStep );
	toolBar()->insertWidget( 1, 40, Blank );
477
	toolBar()->setStretchableWidget( Blank );
478
//	actInfo->plug( toolBar() );
479 480
	actHandbook = new KAction( i18n( "&Handbook" ), BarIcon( "contents" ), 0, this, SLOT( appHelpActivated() ), actionCollection() );
	actHandbook->plug( toolBar() );
481 482 483 484 485
}

void KStars::initStatusBar() {
	statusBar()->insertItem( i18n( " Welcome to KStars " ), 0, 1, true );
	statusBar()->setItemAlignment( 0, AlignLeft | AlignVCenter );
486
	QString s = "00:00:00,   +00:00:00";
487

488
	statusBar()->insertItem( s, 1, 1, true );
489 490 491 492 493 494
	statusBar()->setItemAlignment( 1, AlignRight | AlignVCenter );
	statusBar()->setItemFixed( 1, -1 );
}

/** Menu Slot Functions **/
void KStars::mSetTimeToNow() {
495 496
	data()->SysJD_Mark = data()->getJD( QDateTime::currentDateTime() );
	data()->SkyJD_Mark = data()->SysJD_Mark;
Laurent Montel's avatar
Laurent Montel committed
497

498 499 500 501 502 503 504
//	data()->LTime.setTime( QTime::currentTime() );
//	data()->LTime.setDate( QDate::currentDate() );
//	data()->UTime.setTime( data()->LTime.time() );
//	data()->UTime.setDate( data()->LTime.date() );
//	data()->UTime = data()->UTime.addSecs( int( geo()->TZ()*-3600) );

//	data()->then = QDateTime::currentDateTime();
505 506 507 508 509
	updateTime();
}

void KStars::initOptions()
{
510 511 512
	if ( kapp->config()->hasGroup( "Location" ) ) useDefaultOptions = false;
	else useDefaultOptions = true;

513 514
	// Get initial Location from config()
	kapp->config()->setGroup( "Location" );
515
	options()->CityName = kapp->config()->readEntry( "City", "Greenwich" );
516 517

	if ( kapp->config()->readEntry( "State", "" ).length() ) { //old version of config file
518 519
		options()->ProvinceName = kapp->config()->readEntry( "State", "" );
		options()->CountryName = kapp->config()->readEntry( "State", "United Kingdom" );
520
	} else {
521 522
		options()->ProvinceName = kapp->config()->readEntry( "Province", "" );
		options()->CountryName = kapp->config()->readEntry( "Country", "United Kingdom" );
523 524
	}

525
	kapp->config()->setGroup( "View" );
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
	options()->colorSky 		= kapp->config()->readEntry( "SkyColor", "#002" );
//	options()->colorStar 	= kapp->config()->readEntry( "StarColor", "#FFF" );
	options()->colorMW 		= kapp->config()->readEntry( "MWColor", "#123" );
	options()->colorEq 		= kapp->config()->readEntry( "EqColor", "#FFF" );
	options()->colorEcl		= kapp->config()->readEntry( "EclColor", "#663" );
	options()->colorHorz 	= kapp->config()->readEntry( "HorzColor", "#5A3" );
	options()->colorGrid 	= kapp->config()->readEntry( "GridColor", "#456" );
	options()->colorMess 	= kapp->config()->readEntry( "MessColor", "#0F0" );
	options()->colorNGC 		= kapp->config()->readEntry( "NGCColor", "#066" );
	options()->colorIC 		= kapp->config()->readEntry( "ICColor", "#439" );
	options()->colorCLine 	= kapp->config()->readEntry( "CLineColor", "#555" );
	options()->colorCName 	= kapp->config()->readEntry( "CNameColor", "#AA7" );
	options()->colorSName 	= kapp->config()->readEntry( "SNameColor", "#7AA" );
	options()->colorHST 		= kapp->config()->readEntry( "HSTColor", "#A00" );
	options()->drawBSC 		= kapp->config()->readBoolEntry( "ShowBSC", true );
	options()->drawMessier = kapp->config()->readBoolEntry( "ShowMess", true );
	options()->drawMessImages = kapp->config()->readBoolEntry( "ShowMessImages", true );
	options()->drawNGC 		= kapp->config()->readBoolEntry( "ShowNGC", true );
	options()->drawIC 			= kapp->config()->readBoolEntry( "ShowIC", true );
	options()->drawConstellLines = kapp->config()->readBoolEntry( "ShowCLines", true );
	options()->drawConstellNames = kapp->config()->readBoolEntry( "ShowCNames", true );
	options()->useLatinConstellNames = kapp->config()->readBoolEntry( "UseLatinConstellationNames", true );
	options()->useLocalConstellNames = kapp->config()->readBoolEntry( "UseLocalConstellationNames", false );
	options()->useAbbrevConstellNames = kapp->config()->readBoolEntry( "UseAbbrevConstellationNames", false );
	options()->drawMilkyWay = kapp->config()->readBoolEntry( "ShowMilkyWay", true );
	options()->drawGrid = kapp->config()->readBoolEntry( "ShowGrid", true );
	options()->drawEquator = kapp->config()->readBoolEntry( "ShowEquator", true );
	options()->drawEcliptic = kapp->config()->readBoolEntry( "ShowEcliptic", true );
	options()->drawHorizon = kapp->config()->readBoolEntry( "ShowHorizon", true );
	options()->drawGround = kapp->config()->readBoolEntry( "ShowGround", true );
	options()->drawSun = kapp->config()->readBoolEntry( "ShowSun", true );
	options()->drawMoon = kapp->config()->readBoolEntry( "ShowMoon", true );
	options()->drawMercury = kapp->config()->readBoolEntry( "ShowMercury", true );
	options()->drawVenus = kapp->config()->readBoolEntry( "ShowVenus", true );
	options()->drawMars = kapp->config()->readBoolEntry( "ShowMars", true );
	options()->drawJupiter = kapp->config()->readBoolEntry( "ShowJupiter", true );
	options()->drawSaturn = kapp->config()->readBoolEntry( "ShowSaturn", true );
	options()->drawUranus = kapp->config()->readBoolEntry( "ShowUranus", true );
	options()->drawNeptune = kapp->config()->readBoolEntry( "ShowNeptune", true );
	options()->drawPluto = kapp->config()->readBoolEntry( "ShowPluto", true );
	options()->useAltAz = kapp->config()->readBoolEntry( "UseAltAz", true );
	options()->isTracking = kapp->config()->readBoolEntry( "IsTracking", false );
	options()->focusObject = kapp->config()->readEntry( "FocusObject", "nothing" );
	options()->focusDec = kapp->config()->readDoubleNumEntry( "FocusDec", 45.0 );
	options()->focusRA = kapp->config()->readDoubleNumEntry( "FocusRA", 180.0 );
//	options()->magLimitDrawStar = kapp->config()->readDoubleNumEntry( "magLimitDrawStar", 8.0 );		// readed in KStarsOptions()
	options()->magLimitDrawStarInfo = kapp->config()->readDoubleNumEntry( "magLimitDrawStarInfo", 2.0 );
	options()->drawStarName = kapp->config()->readBoolEntry( "drawStarName", false );
	options()->drawStarMagnitude = kapp->config()->readBoolEntry( "drawStarMagnitude", false );
	options()->windowWidth = kapp->config()->readNumEntry( "windowWidth", 600 );
	options()->windowHeight = kapp->config()->readNumEntry( "windowHeight", 600 );
	options()->starColorMode = kapp->config()->readNumEntry( "StarColorMode", 0 );
	options()->starColorIntensity = kapp->config()->readNumEntry ("StarColorsIntensity", 4);
579 580 581 582
}

void KStars::initLocation() {
	//Initialize geographic location
583
	bool bFound = false; bool oldConfig = false;
584
	GeoLocation *GeoData;
585 586 587 588 589 590 591

	kapp->config()->setGroup( "Location" );
	if ( !kapp->config()->readEntry( "State", "" ).stripWhiteSpace().isEmpty() ) {
		oldConfig = true;
    kapp->config()->writeEntry( "State", "" ); //ignore this key from now on...
	}

592
	for (GeoData = data()->geoList.first(); GeoData; GeoData = data()->geoList.next())
593
	{
594 595 596 597 598 599

	//If the config file is old (has a State key) match a city if the city name
  //AND EITHER the province name OR the country name match
  //(old config files set both province and country to "StateName")
  //this can produce the wrong city, if more than one matches these criteria...
		if ( oldConfig ) {
600 601 602
			if ( (GeoData->name().lower() == options()->CityName.lower()) &&
					( (GeoData->province().lower() == options()->ProvinceName.lower()) ||
					(GeoData->country().lower() == options()->CountryName.lower()) ) )
603 604
			{
				bFound = TRUE;
605 606 607 608
				if ( GeoData->province().lower() != options()->ProvinceName.lower() )
					options()->ProvinceName = GeoData->province();
				if ( GeoData->country().lower() != options()->CountryName.lower() )
					options()->CountryName = GeoData->country();
609 610 611 612
				break ;
			}
		} else {
	//Otherwise, require all three fields (City, Province, and Country) to match
613 614 615 616
			if ( options()->ProvinceName.stripWhiteSpace().length() ) {
				if ( (GeoData->name().lower() == options()->CityName.lower()) &&
						(GeoData->province().lower() == options()->ProvinceName.lower()) &&
						(GeoData->country().lower() == options()->CountryName.lower()) )
617 618 619 620 621
				{
					bFound = TRUE;
					break ;
				}
			} else {
622 623
				if ( (GeoData->name().lower() == options()->CityName.lower()) &&
						(GeoData->country().lower() == options()->CountryName.lower()) )
624 625 626 627 628 629
				{
					bFound = TRUE;
					break ;
				}

			}
630 631
		}
	}
Laurent Montel's avatar
Laurent Montel committed
632

633
	if ( !bFound ) { // set city, province and country to default values
634 635 636 637
		options()->CityName = "Greenwich";
		options()->ProvinceName = "";
		options()->CountryName = "United Kingdom";
		for (GeoData = data()->geoList.first(); GeoData; GeoData = data()->geoList.next())
638
		{
639 640 641
			if ( (GeoData->name().lower() == options()->CityName.lower()) &&
					(GeoData->province().lower() == options()->ProvinceName.lower()) &&
					(GeoData->country().lower() == options()->CountryName.lower()) )
642 643 644 645 646 647
			{
				bFound = TRUE;
				break ;
			}
		}
	}
Laurent Montel's avatar
Laurent Montel committed
648

649
	if (bFound) {
650
		Location = new GeoLocation (GeoData);
651
	} else { //couldn't set geographic location, so set the "null" location.
652
		QString message = i18n( "Could not set geographic location!" );
653
		KMessageBox::sorry( 0, message, i18n( "No location set" ) );
654
		Location = new GeoLocation();
655
	}
656 657
// With KDE 3 this needs explicite set (why?)
	((KStars*) kapp)->setLocation( Location );
658 659 660

	if ( geo()->lat().Degrees()==  90.0 ) geo()->lat().setD(  89.9999 );
	if ( geo()->lat().Degrees()== -90.0 ) geo()->lat().setD( -89.9999 );
661 662
}

663
void KStars::initAltAz()
664 665 666 667
{
	// Recompute Alt, Az coords for all objects. This was not possible
	// within loading the KStarsData object. Do it now.
	// Solar System
668 669 670 671 672 673 674 675 676
	data()->Sun->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Mercury->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Venus->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Mars->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Jupiter->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Saturn->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Uranus->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Neptune->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
	data()->Pluto->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
677 678

	// Stars
679 680 681
	for (SkyObject *obj = data()->starList.first(); obj; obj = data()->starList.next()) {
		obj->pos()->updateCoords( data()->CurrentEpoch, data()->Obliquity, data()->dObliq, data()->dEcLong );
		obj->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
682
	}
Laurent Montel's avatar
Laurent Montel committed
683

684
	// Messier
685 686 687
	for (SkyObject *obj = data()->messList.first(); obj; obj = data()->messList.next()) {
		obj->pos()->updateCoords( data()->CurrentEpoch, data()->Obliquity, data()->dObliq, data()->dEcLong );
		obj->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
688
	}
Laurent Montel's avatar
Laurent Montel committed
689

690
	// NGC
691 692 693
	for (SkyObject *obj = data()->ngcList.first(); obj; obj = data()->ngcList.next()) {
		obj->pos()->updateCoords( data()->CurrentEpoch, data()->Obliquity, data()->dObliq, data()->dEcLong );
		obj->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
694
	}
Laurent Montel's avatar
Laurent Montel committed
695

696
	// IC
697 698 699
	for (SkyObject *obj = data()->icList.first(); obj; obj = data()->icList.next()) {
		obj->pos()->updateCoords( data()->CurrentEpoch, data()->Obliquity, data()->dObliq, data()->dEcLong );
		obj->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
700
	}
Laurent Montel's avatar
Laurent Montel committed
701

702
	// Milky Way
703
	for ( unsigned int j=0; j<11; ++j ) {
704 705 706
		for (SkyPoint *obj = data()->MilkyWay[j].first(); obj; obj = data()->MilkyWay[j].next()) {
			obj->updateCoords( data()->CurrentEpoch, data()->Obliquity, data()->dObliq, data()->dEcLong );
			obj->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
707
		}
708
	}
Laurent Montel's avatar
Laurent Montel committed
709

710
	// CLines
711 712 713
	for (SkyPoint *obj = data()->clineList.first(); obj; obj = data()->clineList.next()) {
		obj->updateCoords( data()->CurrentEpoch, data()->Obliquity, data()->dObliq, data()->dEcLong );
		obj->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
714
	}
Laurent Montel's avatar
Laurent Montel committed
715

716
	// CNames
717 718 719
	for (SkyObject *obj = data()->cnameList.first(); obj; obj = data()->cnameList.next()) {
		obj->pos()->updateCoords( data()->CurrentEpoch, data()->Obliquity, data()->dObliq, data()->dEcLong );
		obj->pos()->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
720 721 722
	}

	// Define the Celestial Equator
723 724
	for ( unsigned int i=0; i<NCIRCLE; ++i ) {
		SkyPoint *o = new SkyPoint( i*24./NCIRCLE, 0.0 );
725 726
		o->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
		data()->Equator.append( o );
727
	}
Laurent Montel's avatar
Laurent Montel committed
728

729 730 731 732
  // Define the horizon.
  // Use the celestial Equator as a convenient starting point, but instead of RA and Dec,
  // interpret the coordinates as azimuth and altitude, and then convert to RA, dec.
  // The horizon will be redefined whenever the positions of sky objects are updated.
733
	for (SkyPoint *point = data()->Equator.first(); point; point = data()->Equator.next()) {
734 735 736
		double sinlat, coslat, sindec, cosdec, sinAz, cosAz;
		double HARad;
		dms dec, HA, RA, Az;
737
		Az = point->ra();
738
		Az.SinCos( sinAz, cosAz );
739
		geo()->lat().SinCos( sinlat, coslat );
740 741 742 743 744 745

		dec.setRadians( asin( coslat*cosAz ) );
		dec.SinCos( sindec, cosdec );
   		HARad = acos( -1.0*(sinlat*sindec)/(coslat*cosdec) );
		if ( sinAz > 0.0 ) { HARad = 2.0*PI() - HARad; }
		HA.setRadians( HARad );
746
		RA = data()->LSTh.Degrees() - HA.Degrees();
747 748 749 750 751

		SkyPoint *o = new SkyPoint( RA, dec );
		o->setAlt( 0.0 );
		o->setAz( Az );

752
		data()->Horizon.append( o );
Laurent Montel's avatar
Laurent Montel committed
753

754
		//Define the Ecliptic (use the same ListIteration; interpret coordinates as Ecliptic long/lat)
755
		double ELong, ELat;
756
		ELong = point->ra().Degrees();
757 758
		ELat = 0.0;
		o = new SkyPoint( 0.0, 0.0 );
759 760 761
		o->setEcliptic( ELong, ELat, data()->CurrentDate );
		o->EquatorialToHorizontal( data()->LSTh, geo()->lat() );
		data()->Ecliptic.append( o );
762 763 764 765
	}
}

void KStars::mSetTime() {
766
	TimeDialog timedialog ( data()->LTime, this );
767 768

	if ( timedialog.exec() == QDialog::Accepted ) {
769

770 771
		if (tmr->isActive() ) {
			tmr->stop();
772
			actTimeRun->setIconSet( BarIcon( "1rightarrow" ) );
773 774 775 776
			actTimeRun->setText( i18n( "Start &Clock" ) );
			actTimeRun->setToolTip( i18n( "Start Clock" ) );
		}

777 778
		QTime newTime( timedialog.selectedTime() );
		QDate newDate( timedialog.selectedDate() );
779

780 781 782
		data()->SysJD_Mark = data()->getJD( QDateTime::currentDateTime() );
		data()->SkyJD_Mark = data()->getJD( QDateTime( newDate, newTime ) );
		
783
		//Make sure Moon, planets, and sky objects are updated immediately
784 785 786
		data()->LastMoonUpdate = data()->CurrentDate - 1.0;
		data()->LastPlanetUpdate = data()->CurrentDate - 1.0;
		data()->LastSkyUpdate = data()->CurrentDate - 1.0;
787 788 789 790 791 792 793 794 795 796 797 798

		updateTime();
	}
}

void KStars::mToggleTimer() {
	if ( tmr->isActive() ) {
		tmr->stop();
    actTimeRun->setIconSet( BarIcon( "1rightarrow" ) );
		actTimeRun->setText( i18n( "Start &Clock" ) );
		actTimeRun->setToolTip( i18n( "Start Clock" ) );
	} else {
799 800 801
		data()->SysJD_Mark = data()->getJD( QDateTime::currentDateTime() );
		data()->SkyJD_Mark = data()->getJD( data()->LTime );

802 803 804 805 806 807 808 809
		tmr->start( TIMER_INTERVAL, FALSE );
		actTimeRun->setIconSet( BarIcon( "player_pause" ) );
		actTimeRun->setText( i18n( "Stop &Clock" ) );
		actTimeRun->setToolTip( i18n( "Stop Clock" ) );
	}
}

void KStars::mZenith() {
810 811 812
	skymap->focus()->setAlt( 90.0 );
	skymap->focus()->HorizontalToEquatorial( data()->LSTh, geo()->lat() );
	data()->HourAngle.setH( data()->LSTh.Hours() - skymap->focus()->ra().Hours() );
813 814 815 816 817
	skymap->Update();
}

void KStars::mZoomIn() {
	actZoomOut->setEnabled (true);
818 819
	if ( data()->ZoomLevel < MAXZOOMLEVEL ) {
		++data()->ZoomLevel;
820 821
		skymap->Update();
	}
822
	if ( data()->ZoomLevel == MAXZOOMLEVEL )
823 824 825 826 827
		actZoomIn->setEnabled (false);
}

void KStars::mZoomOut() {
	actZoomIn->setEnabled (true);
828 829
	if ( data()->ZoomLevel > MINZOOMLEVEL ) {
		--data()->ZoomLevel;
830 831
		skymap->Update();
	}
832
	if ( data()->ZoomLevel == MINZOOMLEVEL )
833 834 835 836 837 838
		actZoomOut->setEnabled (false);
}

void KStars::mFind() {
	FindDialog finddialog (this);
	if ( finddialog.exec() == QDialog::Accepted && finddialog.currentItem() ) {
839 840
		skymap->setClickedObject( finddialog.currentItem()->objName()->skyObject() );
		skymap->setClickedPoint( skymap->clickedObject()->pos() );
841
		skymap->slotCenter();
842

843 844 845 846
	}
}

void KStars::mTrack() {
847 848
	if ( options()->isTracking ) {
		options()->isTracking = false;
849
		actTrack->setIconSet( BarIcon( "decrypted" ) );
850 851
		skymap->setClickedObject( NULL );
		skymap->setFoundObject( NULL );//no longer tracking foundObject
852
	} else {
853
		options()->isTracking = true;
854
		actTrack->setIconSet( BarIcon( "encrypted" ) );
Laurent Montel's avatar
Laurent Montel committed
855
	}
856 857 858 859
}

void KStars::mViewOps() {
	// save options for cancel
860
	data()->saveOptions();
Laurent Montel's avatar
Laurent Montel committed
861

862 863 864 865
	ViewOpsDialog viewopsdialog (this);
	// ask for the new options
	if ( viewopsdialog.exec() != QDialog::Accepted ) {
		// cancelled
866
		data()->restoreOptions();
867
		skymap->Update();
868 869 870 871 872 873
	}
}

void KStars::mGeoLocator() {
	LocationDialog locationdialog (this);
	if ( locationdialog.exec() == QDialog::Accepted ) {
874
		if ( !locationdialog.selectedCityName().isEmpty() ) { //user closed the location dialog without adding their new city;
875 876 877 878 879
			locationdialog.addCity();                   //call addCity() for them!
		}

	 	int ii = locationdialog.getCityIndex();
 		if ( ii >= 0 ) {
880 881 882 883 884 885
 			geo()->reset( data()->geoList.at(ii) );
			options()->CityName = geo()->name();
			options()->ProvinceName = geo()->province();
			options()->CountryName = geo()->country();
			if ( geo()->province().isEmpty() )
	 			PlaceName->setText( geo()->translatedName() + ",  " + geo()->translatedCountry() );
886
			else
887
	 			PlaceName->setText( geo()->translatedName() + ", " + geo()->translatedProvince() + ",  " + geo()->translatedCountry() );
888

889 890
 			Long->setText( QString::number( geo()->lng().Degrees(), 'f', 3 ) );
 			Lat->setText( QString::number( geo()->lat().Degrees(), 'f', 3 ) );
Laurent Montel's avatar
Laurent Montel committed
891

892
 			// Adjust Local time for new time zone
893 894 895
	 		data()->LTime.setDate( data()->UTime.date() );
 			data()->LTime.setTime( data()->UTime.time() );
 			data()->LTime = data()->LTime.addSecs( int(geo()->TZ()*3600) );
896

897 898 899
			data()->LST = UTtoLST( data()->UTime, geo()->lng() );
			data()->LSTh.setH( data()->LST.hour(), data()->LST.minute(), data()->LST.second() );
			data()->HourAngle.setH( data()->LSTh.Hours() - skymap->focus()->ra().Hours() );
900 901 902 903

      //need to recompute Alt/Az coordinates of all objects, so
			//adjust LastSkyUpdate to ensure computation.  Then
			//explicitly call updateTime()
904
			data()->LastSkyUpdate -= 1.0; // a full day, should be plenty
905 906
			updateTime();
	 	}
907 908 909 910
 	}
}

void KStars::updateTime( void ) {
911 912
	data()->SysJD = data()->getJD( QDateTime::currentDateTime() );
	data()->SysJD_Elapsed = data()->SysJD - data()->SysJD_Mark;
913

914
	//advance clock by factor*(time elapsed since system time last marked)
915
	float factor = ((TimeSpinBox *)toolBar()->getWidget( idSpinBox ))->text().toFloat();
916 917
	data()->LTime = data()->getDateTime( data()->SkyJD_Mark + factor*data()->SysJD_Elapsed );
	data()->UTime = data()->LTime.addSecs( int( -3600*geo()->TZ() ) );
Laurent Montel's avatar
Laurent Montel committed
918

919 920
	LT->setText( data()->LTime.time().toString() );
	UT->setText( data()->UTime.time().toString() );
Laurent Montel's avatar
Laurent Montel committed
921

922 923
	LTDate->setText( data()->locale->formatDate( data()->LTime.date(), true ) );
	UTDate->setText( data()->locale->formatDate( data()->UTime.date(), true ) );
924

925
	data()->CurrentDate = data()->getJD( data()->UTime );
926
	JD->setText( "JD: " + KGlobal::locale()->formatNumber( data()->CurrentEpoch, 2 ) );
927
	bool isNewEpoch = false;
928 929
	if ( fabs( data()->CurrentDate - data()->CurrentEpoch ) > 365.25 ) { //update epoch-dependent numbers annually
		updateEpoch( data()->CurrentDate );
930 931
		isNewEpoch = true;
	}
Laurent Montel's avatar
Laurent Montel committed
932

933
  data()->LST = UTtoLST( data()->UTime, geo()->lng() );
Laurent Montel's avatar
Laurent Montel committed
934

935 936
	QString dummy;
	QString STString = dummy.sprintf( "%02d:%02d:%02d",
937
			  data()->LST.hour(), data()->LST.minute(), data()->LST.second() );
938 939
	ST->setText( STString );

940
	data()->LSTh.setH( data()->LST.hour(), data()->LST.minute(), data()->LST.second() );
941 942 943

  // Update positions of objects, if necessary
  // Sun and Planet positions change rather slowly, so only update them twice daily
944 945 946 947 948 949 950 951 952 953 954 955 956
  if ( fabs( data()->CurrentDate - data()->LastPlanetUpdate ) > 0.5 ) {
  	data()->LastPlanetUpdate = data()->CurrentDate;

		data()->Sun->findPosition( data()->CurrentDate );
		data()->Earth->findPosition( data()->CurrentDate );
		data()->Mercury->findPosition( data()->CurrentDate, data()->Earth );
		data()->Venus->findPosition( data()->CurrentDate, data()->Earth );
		data()->Mars->findPosition( data()->CurrentDate, data()->Earth );
		data()->Jupiter->findPosition( data()->CurrentDate, data()->Earth );
		data()->Saturn->findPosition( data()->CurrentDate, data()->Earth );
		data()->Uranus->findPosition( data()->CurrentDate, data()->Earth );
		data()->Neptune->findPosition( data()->CurrentDate, data()->Earth );
		data()->Pluto->findPosition( data()->CurrentDate, data()->Earth );
957 958