Commit 207a3627 authored by Thomas Kabelmann's avatar Thomas Kabelmann
Browse files

Closing a window will now not close all other windows too.

svn path=/trunk/kdeedu/kstars/; revision=183493
parent 68d6307f
......@@ -100,7 +100,8 @@ void AddCatDialog::validateFile() {
// data files without needing an AddCatDialog (on startup, for example).
// The bool argument below flags whether the detailed warning messagebox
// should appear when parse errors are found.
KStars *ksw = (KStars*)kapp->mainWidget();
// KStars *ksw = (KStars*)kapp->mainWidget();
KStars *ksw = (KStars*) parent()->parent(); // ViewOpsDialog->KStars
bool result = ksw->data()->readCustomData( filename(), objList, true );
if ( result ) {
......
......@@ -24,8 +24,8 @@
#include "kssun.h"
#include "ksmoon.h"
KSMoon::KSMoon()
: KSPlanetBase( I18N_NOOP( "Moon" ) ) {
KSMoon::KSMoon(KStars *ks)
: KSPlanetBase( ks, I18N_NOOP( "Moon" ) ) {
BData.setAutoDelete(true);
LRData.setAutoDelete(true);
}
......
......@@ -31,12 +31,13 @@
*@version 0.9
*/
class KStars;
class KSMoon : public KSPlanetBase {
public:
/**
*Default constructor. Set name="Moon".
*/
KSMoon();
KSMoon(KStars *ks);
/**Destructor (empty). */
~KSMoon();
......
......@@ -138,8 +138,8 @@ KSPlanet::OrbitDataColl *KSPlanet::OrbitDataManager::loadData(QString n) {
//========================================================================
//
KSPlanet::KSPlanet( QString s, QString imfile )
: KSPlanetBase(s, imfile), data_loaded(false) {
KSPlanet::KSPlanet( KStars *ks, QString s, QString imfile )
: KSPlanetBase(ks, s, imfile), data_loaded(false) {
}
bool KSPlanet::loadData() {
......
......@@ -40,6 +40,8 @@
*@version 0.9
*/
class KStars;
class KSPlanet : public KSPlanetBase {
public:
......@@ -49,7 +51,7 @@ public:
*@param s Name of planet
*@param im the planet's image
*/
KSPlanet( QString s="unnamed", QString image_file="" );
KSPlanet( KStars *ks, QString s="unnamed", QString image_file="" );
/**
*Destructor (empty)
......
......@@ -21,8 +21,8 @@
#include "ksplanetbase.h"
KSPlanetBase::KSPlanetBase( QString s, QString image_file )
: SkyObject( 2, 0.0, 0.0, 0.0, s, "" ), Image(0) {
KSPlanetBase::KSPlanetBase( KStars *ks, QString s, QString image_file )
: SkyObject( 2, 0.0, 0.0, 0.0, s, "" ), Image(0), kstars(ks) {
if (! image_file.isEmpty()) {
QFile imFile;
......@@ -47,9 +47,9 @@ void KSPlanetBase::EclipticToEquatorial( dms Obliquity ) {
void KSPlanetBase::updateCoords( KSNumbers *num, bool includePlanets ){
if ( includePlanets ) {
KStars *ks = (KStars *)kapp->mainWidget();
ks->data()->earth()->findPosition( num );
findPosition( num, ks->data()->earth() );
// KStars *ks = (KStars *)kapp->mainWidget();
kstars->data()->earth()->findPosition( num );
findPosition( num, kstars->data()->earth() );
}
}
......
......@@ -63,6 +63,7 @@ class EclipticPosition {
*@version 0.9
*/
class KStars;
class KSPlanetBase : public SkyObject {
public:
......@@ -72,7 +73,7 @@ public:
*@param s Name of planet
*@param im the planet's image
*/
KSPlanetBase( QString s = i18n("unnamed"), QString image_file="" );
KSPlanetBase( KStars *ks, QString s = i18n("unnamed"), QString image_file="" );
/**
*Destructor (empty)
......@@ -196,6 +197,7 @@ protected:
private:
QImage Image0, Image;
double PositionAngle;
KStars *kstars;
};
/**Helper function for xFormImage */
......
......@@ -23,6 +23,7 @@
#include "ksutils.h"
#include "kspluto.h"
#include "kstars.h"
int KSPluto::DATAARRAYSIZE = 106;
bool KSPluto::data_loaded = false;
......@@ -30,29 +31,33 @@ double *KSPluto::freq = 0;
KSPluto::XYZData *KSPluto::xdata = 0;
KSPluto::XYZData *KSPluto::ydata = 0;
KSPluto::XYZData *KSPluto::zdata = 0;
int KSPluto::objects = 0;
KSPluto::KSPluto(QString fn) : KSPlanetBase( I18N_NOOP( "Pluto" ), fn ) {
KSPluto::KSPluto(KStars *ks, QString fn) : KSPlanetBase( ks, I18N_NOOP( "Pluto" ), fn ) {
objects++;
}
KSPluto::~KSPluto() {
if (freq) {
delete [] freq;
freq = 0;
}
if (xdata) {
delete [] xdata;
xdata = 0;
}
if (ydata) {
delete [] ydata;
ydata = 0;
}
if (zdata) {
delete [] zdata;
zdata = 0;
objects--;
// delete arrays if all other objects are closed
if (!objects) {
if (freq) {
delete [] freq;
freq = 0;
}
if (xdata) {
delete [] xdata;
xdata = 0;
}
if (ydata) {
delete [] ydata;
ydata = 0;
}
if (zdata) {
delete [] zdata;
zdata = 0;
}
}
}
bool KSPluto::loadData() {
......
......@@ -30,13 +30,14 @@
*@version 0.9
*/
class KStars;
class KSPluto : public KSPlanetBase {
public:
/**
*Default constructor. Calls KSPlanetBase constructor with name="Pluto" and
*a null image.
*/
KSPluto(QString fn="");
KSPluto(KStars *ks, QString fn="");
/**Destructor */
virtual ~KSPluto();
......@@ -78,6 +79,7 @@ private:
};
XYZpos calcRectCoords(double jc);
static int objects; // count number of open objects
};
#endif
......@@ -23,7 +23,7 @@
#include "kssun.h"
#include "ksutils.h"
KSSun::KSSun( QString fn ) : KSPlanet( I18N_NOOP( "Sun" ), fn ) {
KSSun::KSSun( KStars *ks, QString fn ) : KSPlanet( ks, I18N_NOOP( "Sun" ), fn ) {
/*
JD0 = 2447892.5; //Jan 1, 1990
eclong0 = 279.403303; //mean ecliptic longitude at JD0
......
......@@ -29,13 +29,14 @@
*@version 0.9
*/
class KStars;
class KSSun : public KSPlanet {
public:
/**
*Default constructor. Defines constants needed by findPosition().
*Sets Ecliptic coordinates appropriate for J2000.
*/
KSSun(QString fn = "");
KSSun(KStars *ks, QString fn = "");
/**
*Destructor (empty)
......
......@@ -33,7 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
//#include <iostream.h>
#include <kdebug.h>
#include <dcopclient.h>
......@@ -177,7 +177,7 @@ SkyObject* KStars::getObjectNamed( QString name ) {
if ( (name== "star") || (name== "nothing") || name.isEmpty() ) return NULL;
if ( name== data()->Moon->name() ) return data()->Moon;
SkyObject *so = data()->PC.findByName(name);
SkyObject *so = data()->PC->findByName(name);
if (so != 0)
return so;
......
......@@ -47,6 +47,8 @@ KStarsData::KStarsData( KStars *ks ) : Moon(0), kstars( ks ), initTimer(0), init
locale = new KLocale( "kstars" );
oldOptions = 0;
PC = new PlanetCatalog(ks);
geoList.setAutoDelete( TRUE );
starList.setAutoDelete( TRUE );
deepSkyList.setAutoDelete( TRUE );
......@@ -94,6 +96,8 @@ KStarsData::~KStarsData() {
if (Moon) delete Moon;
if (locale) delete locale;
delete PC;
/*
QString s = QString( "geoList count: %1" ).arg( geoList.count() );
qDebug( s.local8Bit() );
......@@ -600,6 +604,8 @@ bool KStarsData::readCustomData( QString filename, QList<SkyObject> &objList, bo
}
return false;
}
// all test passed
return false;
}
......@@ -977,14 +983,14 @@ void KStarsData::slotInitialize() {
case 8: //Initialize the Planets//
emit progressText( i18n("Creating Planets" ) );
if (PC.initialize())
PC.addObject( ObjNames );
if (PC->initialize())
PC->addObject( ObjNames );
break;
case 9: //Initialize the Moon//
emit progressText( i18n("Creating Moon" ) );
Moon = new KSMoon();
Moon = new KSMoon(kstars);
ObjNames.append( Moon );
Moon->loadData();
break;
......@@ -1068,7 +1074,7 @@ void KStarsData::updateTime( SimClock *clock, GeoLocation *geo, SkyMap *skymap,
if ( fabs( CurrentDate - LastPlanetUpdate ) > 0.01 ) {
LastPlanetUpdate = CurrentDate;
PC.findPosition(&num);
PC->findPosition(&num);
//Recompute the Ecliptic
if ( options->drawEcliptic ) {
......@@ -1086,7 +1092,7 @@ void KStarsData::updateTime( SimClock *clock, GeoLocation *geo, SkyMap *skymap,
LastMoonUpdate = CurrentDate;
if ( options->drawMoon ) {
Moon->findPosition( &num, geo->lat(), LSTh );
Moon->findPhase( PC.planetSun() );
Moon->findPhase( PC->planetSun() );
}
}
......@@ -1097,7 +1103,7 @@ void KStarsData::updateTime( SimClock *clock, GeoLocation *geo, SkyMap *skymap,
//Recompute Alt, Az coords for all objects
//Planets
PC.EquatorialToHorizontal( LSTh, geo->lat() );
PC->EquatorialToHorizontal( LSTh, geo->lat() );
if ( options->drawMoon ) Moon->EquatorialToHorizontal( LSTh, geo->lat() );
//Stars
......@@ -1192,7 +1198,7 @@ void KStarsData::updateTime( SimClock *clock, GeoLocation *geo, SkyMap *skymap,
skymap->destination()->HorizontalToEquatorial( LSTh, geo->lat() );
skymap->setFocus( skymap->destination() );
} else if (skymap->foundObject()==Moon || PC.isPlanet(skymap->foundObject()) ) {
} else if (skymap->foundObject()==Moon || PC->isPlanet(skymap->foundObject()) ) {
//Tracking on the Moon or Planet requires focus updates in both coord systems
skymap->setDestination( skymap->foundObject() );
skymap->setFocus( skymap->destination() );
......
......@@ -277,7 +277,7 @@ public:
KLocale *getLocale() { return locale; };
KSPlanet *earth() { return PC.earth(); }
KSPlanet *earth() { return PC->earth(); }
/**The Sky is updated more frequently than the moon, which is updated more frequently
*than the planets. The date of the last update for each category is recorded so we
......@@ -390,7 +390,7 @@ private:
QMap<QString, QList<SkyObject> > CustomCatalogs;
QMap<QString, TimeZoneRule> Rulebook;
PlanetCatalog PC;
PlanetCatalog *PC;
QString cnameFile;
KStandardDirs *stdDirs;
......
......@@ -377,7 +377,7 @@ void KStars::datainitFinished(bool worked) {
void KStars::privatedata::buildGUI() {
// need to set the mainwidget here, in main() this will cause a segfault because
// skymap will be created in this constructor and needs kapp->mainWidget()
kapp->setMainWidget( ks );
// kapp->setMainWidget( ks );
// here we get the preloaded data (stars, constellations etc.)
//Instantiate the SimClock object
......
......@@ -76,6 +76,7 @@ int main(int argc, char *argv[])
#endif
KStars *kstars = new KStars( true );
QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
return a.exec();
}
......@@ -206,14 +206,16 @@ void modCalcDayLength::showCurrentDate (void)
void modCalcDayLength::initGeo(void)
{
KStars *ks = (KStars*)kapp->mainWidget();
// KStars *ks = (KStars*)kapp->mainWidget();
KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
geoPlace = new GeoLocation( ks->geo() );
}
void modCalcDayLength::showLongLat(void)
{
KStars *ks = (KStars*)kapp->mainWidget();
// KStars *ks = (KStars*)kapp->mainWidget();
KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
longBox->show( ks->geo()->lng() );
latBox->show( ks->geo()->lat() );
}
......@@ -288,7 +290,7 @@ void modCalcDayLength::slotComputePosTime()
long double jd0 = computeJdFromCalendar();
KSNumbers * num = new KSNumbers(jd0);
KSSun *Sun = new KSSun();
KSSun *Sun = new KSSun((KStars*) parent()->parent()->parent());
Sun->findPosition(num);
QTime setQtime = Sun->setTime(jd0 , geoPlace);
......
......@@ -191,7 +191,8 @@ modCalcGeodCoord::~modCalcGeodCoord(){
void modCalcGeodCoord::showLongLat(void)
{
KStars *ks = (KStars*)kapp->mainWidget();
// KStars *ks = (KStars*)kapp->mainWidget();
KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
lonGeoBox->show( ks->geo()->lng() );
latGeoBox->show( ks->geo()->lat() );
altGeoName->setText( QString("0.0") );
......
......@@ -24,6 +24,7 @@
#include "kstars.h"
#include <qwidget.h>
#include <qwidgetlist.h>
#include <qlabel.h>
#include <qvbox.h>
#include <qgroupbox.h>
......@@ -213,7 +214,9 @@ void modCalcSidTime::showCurrentTimeAndLong (void)
#endif
showUT( dt.time() );
KStars *ks = (KStars*)kapp->mainWidget();
// KStars *ks = (KStars*)kapp->mainWidget();
KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
longBox->show( ks->geo()->lng() );
}
......
......@@ -19,9 +19,9 @@
#include "planetcatalog.h"
#include "kssun.h"
#include "kspluto.h"
#include "kstars.h"
PlanetCatalog::PlanetCatalog() : Earth(0), Sun(0) {
PlanetCatalog::PlanetCatalog(KStars *ks) : Earth(0), Sun(0), kstars(ks) {
planets.setAutoDelete(true);
}
......@@ -38,43 +38,43 @@ PlanetCatalog::~PlanetCatalog() {
bool PlanetCatalog::initialize() {
KSPlanetBase *ksp;
Earth = new KSPlanet( I18N_NOOP( "Earth" ) );
Earth = new KSPlanet( kstars, I18N_NOOP( "Earth" ) );
if (!Earth->loadData())
return false;
Sun = new KSSun("sun.png");
Sun = new KSSun( kstars, "sun.png");
if (Sun->loadData())
planets.append(Sun);
ksp = new KSPluto("pluto.png");
ksp = new KSPluto( kstars, "pluto.png");
if (ksp->loadData())
planets.append(ksp);
ksp = new KSPlanet(I18N_NOOP( "Mercury" ), "mercury.png");
ksp = new KSPlanet( kstars, I18N_NOOP( "Mercury" ), "mercury.png");
if (ksp->loadData())
planets.append(ksp);
ksp = new KSPlanet(I18N_NOOP( "Venus" ), "venus.png");
ksp = new KSPlanet( kstars, I18N_NOOP( "Venus" ), "venus.png");
if (ksp->loadData())
planets.append(ksp);
ksp = new KSPlanet(I18N_NOOP( "Mars" ), "mars.png");
ksp = new KSPlanet( kstars, I18N_NOOP( "Mars" ), "mars.png");
if (ksp->loadData())
planets.append(ksp);
ksp = new KSPlanet(I18N_NOOP( "Jupiter" ), "jupiter.png");
ksp = new KSPlanet( kstars, I18N_NOOP( "Jupiter" ), "jupiter.png");
if (ksp->loadData())
planets.append(ksp);
ksp = new KSPlanet(I18N_NOOP( "Saturn" ), "saturn.png");
ksp = new KSPlanet( kstars, I18N_NOOP( "Saturn" ), "saturn.png");
if (ksp->loadData())
planets.append(ksp);
ksp = new KSPlanet(I18N_NOOP( "Uranus" ), "uranus.png");
ksp = new KSPlanet( kstars, I18N_NOOP( "Uranus" ), "uranus.png");
if (ksp->loadData())
planets.append(ksp);
ksp = new KSPlanet(I18N_NOOP( "Neptune" ), "neptune.png");
ksp = new KSPlanet( kstars, I18N_NOOP( "Neptune" ), "neptune.png");
if (ksp->loadData())
planets.append(ksp);
......
......@@ -44,13 +44,14 @@
#include <qlist.h>
#endif
class KStars;
class PlanetCatalog : public QObject {
Q_OBJECT
public:
/**Constructor. */
PlanetCatalog();
PlanetCatalog(KStars *ks);
/**Destructor. Delete the Earth object (all others auto-deleted by QList)*/
~PlanetCatalog();
......@@ -87,6 +88,7 @@ class PlanetCatalog : public QObject {
QList<KSPlanetBase> planets;
KSPlanet *Earth;
KSSun *Sun;
KStars *kstars;
};
#endif
......@@ -32,7 +32,7 @@
#include <math.h>
#include <stdlib.h>
#include <iostream.h>
//#include <iostream.h>
#include <unistd.h>
#include "detaildialog.h"
......@@ -52,7 +52,8 @@
SkyMap::SkyMap(QWidget *parent, const char *name )
: QWidget (parent,name), ClickedObject(0), FoundObject(0), computeSkymap (true)
{
ksw = (KStars*) kapp->mainWidget();
// ksw = (KStars*) kapp->mainWidget();
ksw = (KStars*) parent->parent();
pts = new QPointArray( 2000 ); // points for milkyway and horizon
sp = new SkyPoint(); // needed by coordinate grid
......
......@@ -168,19 +168,19 @@ void SkyMap::keyPressEvent( QKeyEvent *e ) {
break;
case Key_0: //center on Sun
setClickedObject( ksw->data()->PC.findByName("Sun") );
setClickedObject( ksw->data()->PC->findByName("Sun") );
setClickedPoint( clickedObject() );
slotCenter();
break;
case Key_1: //center on Mercury
setClickedObject( ksw->data()->PC.findByName("Mercury") );
setClickedObject( ksw->data()->PC->findByName("Mercury") );
setClickedPoint( clickedObject() );
slotCenter();
break;
case Key_2: //center on Venus
setClickedObject( ksw->data()->PC.findByName("Venus") );
setClickedObject( ksw->data()->PC->findByName("Venus") );
setClickedPoint( clickedObject() );
slotCenter();
break;
......@@ -192,37 +192,37 @@ void SkyMap::keyPressEvent( QKeyEvent *e ) {
break;
case Key_4: //center on Mars
setClickedObject( ksw->data()->PC.findByName("Mars") );
setClickedObject( ksw->data()->PC->findByName("Mars") );
setClickedPoint( clickedObject() );
slotCenter();
break;
case Key_5: //center on Jupiter
setClickedObject( ksw->data()->PC.findByName("Jupiter") );
setClickedObject( ksw->data()->PC->findByName("Jupiter") );
setClickedPoint( clickedObject() );
slotCenter();
break;
case Key_6: //center on Saturn
setClickedObject( ksw->data()->PC.findByName("Saturn") );
setClickedObject( ksw->data()->PC->findByName("Saturn") );
setClickedPoint( clickedObject() );
slotCenter();
break;
case Key_7: //center on Uranus
setClickedObject( ksw->data()->PC.findByName("Uranus") );
setClickedObject( ksw->data()->PC->findByName("Uranus") );
setClickedPoint( clickedObject() );
slotCenter();
break;
case Key_8: //center on Neptune
setClickedObject( ksw->data()->PC.findByName("Neptune") );
setClickedObject( ksw->data()->PC->findByName("Neptune") );
setClickedPoint( clickedObject() );
slotCenter();
break;
case Key_9: //center on Pluto
setClickedObject( ksw->data()->PC.findByName("Pluto") );
setClickedObject( ksw->data()->PC->findByName("Pluto") );
setClickedPoint( clickedObject() );
slotCenter();
break;
......@@ -456,7 +456,7 @@ void SkyMap::mousePressEvent( QMouseEvent *e ) {
//Next, find the nearest solar system body within r0
double r = 0.0;
double rsolar_min = r0;
SkyObject *solarminobj = ksw->data()->PC.findClosest(clickedPoint(), r);
SkyObject *solarminobj = ksw->data()->PC->findClosest(clickedPoint(), r);
if ( r < r0 ) {
rsolar_min = r;
......@@ -1299,7 +1299,7 @@ void SkyMap::paintEvent( QPaintEvent * ) {
//Draw Sun
if ( ksw->options()->drawSun && drawPlanets ) {
drawPlanet(psky, ksw->data()->PC.findByName("Sun"), QColor( "Yellow" ), 8, 2.4, 3 );
drawPlanet(psky, ksw->data()->PC->findByName("Sun"), QColor( "Yellow" ), 8, 2.4, 3 );
}
//Draw Moon
......@@ -1309,42 +1309,42 @@ void SkyMap::paintEvent( QPaintEvent * ) {
//Draw Mercury