moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / kstars.cpp
blobcfcdec347aacd9c117a157eb8ed7537fc7f0ae3d
1 /***************************************************************************
2 kstars.cpp - K Desktop Planetarium
3 -------------------
4 begin : Mon Feb 5 01:11:45 PST 2001
5 copyright : (C) 2001 by Jason Harris
6 email : jharris@30doradus.org
7 ***************************************************************************/
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 //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
23 #include <stdio.h>
24 #include <stdlib.h>
25 //#include <iostream.h>
26 #include <kdebug.h>
27 #include <qpalette.h>
29 #include "Options.h"
30 #include "kstars.h"
31 #include "kstarsdata.h"
32 #include "kstarssplash.h"
33 #include "skymap.h"
34 #include "simclock.h"
35 #include "finddialog.h"
36 #include "ksutils.h"
37 #include "infoboxes.h"
38 #include "observinglist.h"
39 #include "imagesequence.h"
41 // to remove warnings
42 #include "indimenu.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();
58 if ( doSplash ) {
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) ));
67 pd->splash->show();
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" ) );
85 //set color scheme
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;
94 #else
95 kdDebug() << "Did not find glibc >= 2.1. Will use ANSI-compliant sin()/cos() functions." << endl;
96 #endif
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);
107 pd->kstarsData = kd;
108 pd->buildGUI();
110 kd->clock()->start();
112 obsList = new ObservingList( this, this );
114 show();
117 KStars::~KStars()
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();
135 delete skymap;
136 delete pd;
137 delete centralWidget;
138 delete AAVSODialog;
139 delete indimenu;
140 delete indidriver;
141 delete indiseq;
143 skymap = 0;
144 pd = 0;
145 centralWidget = 0;
146 AAVSODialog = 0;
147 indimenu = 0;
148 indidriver = 0;
149 indiseq = 0;
152 KStars::privatedata::~privatedata() {
153 delete splash;
154 delete kstarsData;
156 splash = 0;
157 kstarsData = 0;
160 void KStars::clearCachedFindDialog() {
161 if ( findDialog ) { // dialog is cached
163 *Delete findDialog only if it is not opened
165 if ( findDialog->isHidden() ) {
166 delete findDialog;
167 findDialog = 0;
168 DialogIsObsolete = false;
170 else
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();
181 SkyMap *Map = map();
183 Data->updateTime( geo(), Map, automaticDSTchange );
184 if ( infoBoxes()->timeChanged( Data->ut(), Data->lt(), LST() ) )
185 Map->update();
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();
194 // }
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"