1 /***************************************************************************
2 kstars.cpp - K Desktop Planetarium
4 begin : Mon Feb 5 01:11:45 PST 2001
5 copyright : (C) 2001 by Jason Harris
6 email : jharris@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 ***************************************************************************/
17 //JH 11.06.2002: replaced infoPanel with infoBoxes
18 //JH 24.08.2001: reorganized infoPanel
19 //JH 25.08.2001: added toolbar, converted menu items to KAction objects
20 //JH 25.08.2001: main window now resizable, window size saved in config file
25 //#include <iostream.h>
31 #include "kstarsdata.h"
32 #include "kstarssplash.h"
35 #include "finddialog.h"
37 #include "infoboxes.h"
38 #include "observinglist.h"
39 #include "imagesequence.h"
43 #include "indidriver.h"
45 KStars::KStars( bool doSplash
, bool clockrun
, const QString
&startdate
) :
46 DCOPObject("KStarsInterface"), KMainWindow(),
47 skymap(0), centralWidget(0), topLayout(0), viewToolBar(0), TimeStep(0),
48 actCoordSys(0), colorActionMenu(0), fovActionMenu(0),
49 AAVSODialog(0), findDialog(0), kns(0),
50 indimenu(0), indidriver(0), indiseq(0),
51 DialogIsObsolete(false), StartClockRunning( clockrun
), StartDateString( startdate
)
53 pd
= new privatedata(this);
55 // we're nowhere near ready to take dcop calls
56 kapp
->dcopClient()->suspend();
59 pd
->kstarsData
= new KStarsData();
60 QObject::connect(pd
->kstarsData
, SIGNAL( initFinished(bool) ),
61 this, SLOT( datainitFinished(bool) ) );
63 pd
->splash
= new KStarsSplash(0, "Splash");
64 QObject::connect(pd
->splash
, SIGNAL( closeWindow() ), kapp
, SLOT( quit() ) );
65 QObject::connect(pd
->kstarsData
, SIGNAL( progressText(QString
) ),
66 pd
->splash
, SLOT( setMessage(QString
) ));
70 pd
->kstarsData
->initialize();
72 //Set Geographic Location
73 pd
->kstarsData
->setLocationFromOptions();
75 //Pause the clock if the user gave the "--paused" arg
76 if ( ! StartClockRunning
) pd
->kstarsData
->clock()->stop();
78 //set up Dark color scheme for application windows
79 DarkPalette
= QPalette(QColor("red4"), QColor("DarkRed"));
80 DarkPalette
.setColor( QPalette::Normal
, QColorGroup::Base
, QColor( "black" ) );
81 DarkPalette
.setColor( QPalette::Normal
, QColorGroup::Text
, QColor( "red2" ) );
82 DarkPalette
.setColor( QPalette::Normal
, QColorGroup::Highlight
, QColor( "red2" ) );
83 DarkPalette
.setColor( QPalette::Normal
, QColorGroup::HighlightedText
, QColor( "black" ) );
86 OriginalPalette
= QApplication::palette();
87 pd
->kstarsData
->colorScheme()->loadFromConfig( kapp
->config() );
88 if ( Options::darkAppColors() ) {
89 QApplication::setPalette( DarkPalette
, true );
92 #if ( __GLIBC__ >= 2 &&__GLIBC_MINOR__ >= 1 )
93 kdDebug() << "glibc >= 2.1 detected. Using GNU extension sincos()" << endl
;
95 kdDebug() << "Did not find glibc >= 2.1. Will use ANSI-compliant sin()/cos() functions." << endl
;
98 obsList
= new ObservingList( this, this );
101 KStars::KStars( KStarsData
* kd
)
102 : DCOPObject("KStarsInterface"), KMainWindow( )
104 // The assumption is that kstarsData is fully initialized
106 pd
= new privatedata(this);
110 kd
->clock()->start();
112 obsList
= new ObservingList( this, this );
119 //store focus values in Options
120 Options::setFocusRA( skymap
->focus()->ra()->Hours() );
121 Options::setFocusDec( skymap
->focus()->dec()->Degrees() );
123 //Store Window geometry in Options object
124 Options::setWindowWidth( width() );
125 Options::setWindowHeight( height() );
127 //We need to explicitly save the colorscheme data to the config file
128 data()->colorScheme()->saveToConfig( kapp
->config() );
130 //synch the config file with the Config object
131 Options::writeConfig();
133 clearCachedFindDialog();
137 delete centralWidget
;
152 KStars::privatedata::~privatedata() {
160 void KStars::clearCachedFindDialog() {
161 if ( findDialog
) { // dialog is cached
163 *Delete findDialog only if it is not opened
165 if ( findDialog
->isHidden() ) {
168 DialogIsObsolete
= false;
171 DialogIsObsolete
= true; // dialog was opened so it could not deleted
175 void KStars::updateTime( const bool automaticDSTchange
) {
176 dms
oldLST( LST()->Degrees() );
177 // Due to frequently use of this function save data and map pointers for speedup.
178 // Save options and geo() to a pointer would not speedup because most of time options
179 // and geo will accessed only one time.
180 KStarsData
*Data
= data();
183 Data
->updateTime( geo(), Map
, automaticDSTchange
);
184 if ( infoBoxes()->timeChanged( Data
->ut(), Data
->lt(), LST() ) )
187 //We do this outside of kstarsdata just to get the coordinates
188 //displayed in the infobox to update every second.
189 // if ( !Options::isTracking() && LST()->Degrees() > oldLST.Degrees() ) {
190 // int nSec = int( 3600.*( LST()->Hours() - oldLST.Hours() ) );
191 // Map->focus()->setRA( Map->focus()->ra()->Hours() + double( nSec )/3600. );
192 // if ( Options::useAltAz() ) Map->focus()->EquatorialToHorizontal( LST(), geo()->lat() );
193 // Map->showFocusCoords();
196 //If time is accelerated beyond slewTimescale, then the clock's timer is stopped,
197 //so that it can be ticked manually after each update, in order to make each time
198 //step exactly equal to the timeScale setting.
199 //Wrap the call to manualTick() in a singleshot timer so that it doesn't get called until
200 //the skymap has been completely updated.
201 if ( Data
->clock()->isManualMode() && Data
->clock()->isActive() ) {
202 QTimer::singleShot( 0, Data
->clock(), SLOT( manualTick() ) );
206 KStarsData
* KStars::data( void ) { return pd
->kstarsData
; }
208 SkyMap
* KStars::map( void ) { return skymap
; }
210 InfoBoxes
* KStars::infoBoxes( void ) { return map()->infoBoxes(); }
212 GeoLocation
* KStars::geo() { return data()->geo(); }
214 void KStars::mapGetsFocus() { map()->QWidget::setFocus(); }
216 dms
* KStars::LST() { return data()->LST
; }
218 ObservingList
* KStars::observingList() { return obsList
; }
220 #include "kstars.moc"