~ubuntu-branches/ubuntu/oneiric/kstars/oneiric-proposed

« back to all changes in this revision

Viewing changes to kstars/tools/jmoontool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rohan Garg
  • Date: 2011-07-23 23:07:27 UTC
  • Revision ID: james.westby@ubuntu.com-20110723230727-xp70ea7v5eay0wya
Tags: upstream-4.7.0
ImportĀ upstreamĀ versionĀ 4.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          jmoontool.cpp  -  Display overhead view of the solar system
 
3
                             -------------------
 
4
    begin                : Sun May 25 2003
 
5
    copyright            : (C) 2003 by Jason Harris
 
6
    email                : jharris@30doradus.org
 
7
 ***************************************************************************/
 
8
/***************************************************************************
 
9
 *                                                                         *
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 *                                                                         *
 
15
 ***************************************************************************/
 
16
 
 
17
#include "jmoontool.h"
 
18
 
 
19
#include <QVBoxLayout>
 
20
#include <QGridLayout>
 
21
#include <QLayout>
 
22
#include <QFrame>
 
23
#include <QKeyEvent>
 
24
 
 
25
#include <kdebug.h>
 
26
#include <klocale.h>
 
27
#include <KPlotWidget>
 
28
#include <KPlotObject>
 
29
#include <KPlotAxis>
 
30
 
 
31
#include "simclock.h"
 
32
#include "dms.h"
 
33
#include "ksnumbers.h"
 
34
#include "kstars.h"
 
35
#include "kstarsdata.h"
 
36
#include "skyobjects/ksplanet.h"
 
37
#include "skyobjects/jupitermoons.h"
 
38
#include "skycomponents/skymapcomposite.h"
 
39
 
 
40
 
 
41
JMoonTool::JMoonTool(QWidget *parent)
 
42
        : KDialog( parent )
 
43
{
 
44
    ksw = (KStars*)parent;
 
45
    QFrame *page = new QFrame(this);
 
46
    setMainWidget( page );
 
47
    setCaption( i18n("Jupiter Moons Tool") );
 
48
    setButtons( KDialog::Close );
 
49
    setModal( false );
 
50
 
 
51
    QVBoxLayout *vlay = new QVBoxLayout( page );
 
52
    vlay->setMargin( 0 );
 
53
    vlay->setSpacing( 0 );
 
54
 
 
55
    colJp = QColor(Qt::white);
 
56
    colIo = QColor(Qt::red);
 
57
    colEu = QColor(Qt::yellow);
 
58
    colGn = QColor(Qt::cyan);
 
59
    colCa = QColor(Qt::green);
 
60
 
 
61
    QLabel *labIo = new QLabel( "Io", page );
 
62
    QLabel *labEu = new QLabel( "Europa", page );
 
63
    QLabel *labGn = new QLabel( "Ganymede", page );
 
64
    QLabel *labCa = new QLabel( "Callisto", page );
 
65
 
 
66
    labIo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
 
67
    labEu->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
 
68
    labGn->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
 
69
    labCa->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
 
70
    labIo->setAlignment( Qt::AlignHCenter );
 
71
    labEu->setAlignment( Qt::AlignHCenter );
 
72
    labGn->setAlignment( Qt::AlignHCenter );
 
73
    labCa->setAlignment( Qt::AlignHCenter );
 
74
 
 
75
    QPalette p = palette();
 
76
    p.setColor( QPalette::Window, Qt::black );
 
77
    p.setColor( QPalette::WindowText, colIo );
 
78
    labIo->setPalette( p );
 
79
    p.setColor( QPalette::WindowText, colEu );
 
80
    labEu->setPalette( p );
 
81
    p.setColor( QPalette::WindowText, colGn );
 
82
    labGn->setPalette( p );
 
83
    p.setColor( QPalette::WindowText, colCa );
 
84
    labCa->setPalette( p );
 
85
    labIo->setAutoFillBackground( true );
 
86
    labEu->setAutoFillBackground( true );
 
87
    labGn->setAutoFillBackground( true );
 
88
    labCa->setAutoFillBackground( true );
 
89
 
 
90
    QGridLayout *glay = new QGridLayout();
 
91
    glay->addWidget( labIo, 0, 0 );
 
92
    glay->addWidget( labEu, 1, 0 );
 
93
    glay->addWidget( labGn, 0, 1 );
 
94
    glay->addWidget( labCa, 1, 1 );
 
95
 
 
96
    pw = new KPlotWidget( page );
 
97
    pw->setShowGrid( false );
 
98
    pw->setAntialiasing( true );
 
99
    pw->setLimits( -12.0, 12.0, -11.0, 11.0 );
 
100
    pw->axis(KPlotWidget::BottomAxis)->setLabel( i18n( "offset from Jupiter (arcmin)" ) );
 
101
    pw->axis(KPlotWidget::LeftAxis)->setLabel( i18n( "time since now (days)" ) );
 
102
    vlay->addLayout( glay );
 
103
    vlay->addWidget( pw );
 
104
    resize( 350, 600 );
 
105
 
 
106
    initPlotObjects();
 
107
    update();
 
108
}
 
109
 
 
110
JMoonTool::~JMoonTool()
 
111
{
 
112
}
 
113
 
 
114
void JMoonTool::initPlotObjects() {
 
115
    KPlotObject *orbit[4];
 
116
    KPlotObject *jpath;
 
117
    long double jd0 = ksw->data()->ut().djd();
 
118
    KSSun *ksun = (KSSun*)ksw->data()->skyComposite()->findByName( "Sun" );
 
119
    KSPlanet *jup = (KSPlanet*)ksw->data()->skyComposite()->findByName( i18n("Jupiter") );
 
120
    JupiterMoons jm;
 
121
 
 
122
    pw->removeAllPlotObjects();
 
123
 
 
124
    orbit[0] = new KPlotObject( colIo, KPlotObject::Lines, 1.0 );
 
125
    orbit[1] = new KPlotObject( colEu, KPlotObject::Lines, 1.0 );
 
126
    orbit[2] = new KPlotObject( colGn, KPlotObject::Lines, 1.0 );
 
127
    orbit[3] = new KPlotObject( colCa, KPlotObject::Lines, 1.0 );
 
128
    jpath    = new KPlotObject( colJp, KPlotObject::Lines, 1.0 );
 
129
 
 
130
    QRectF dataRect = pw->dataRect();
 
131
    double dy = 0.01*dataRect.height();
 
132
 
 
133
    //t is the offset from jd0, in days.
 
134
    for ( double t=dataRect.y(); t<=dataRect.bottom(); t+=dy ) {
 
135
        KSNumbers num( jd0 + t );
 
136
        jm.findPosition( &num, jup, ksun );
 
137
 
 
138
        //jm.x(i) tells the offset from Jupiter, in units of Jupiter's angular radius.
 
139
        //multiply by 0.5*jup->angSize() to get arcminutes
 
140
        for ( unsigned int i=0; i<4; ++i )
 
141
            orbit[i]->addPoint( 0.5*jup->angSize()*jm.x(i), t );
 
142
 
 
143
        jpath->addPoint( 0.0, t );
 
144
    }
 
145
 
 
146
    for ( unsigned int i=0; i<4; ++i )
 
147
        pw->addPlotObject( orbit[i] );
 
148
 
 
149
    pw->addPlotObject( jpath );
 
150
}
 
151
 
 
152
void JMoonTool::keyPressEvent( QKeyEvent *e ) {
 
153
    QRectF dataRect = pw->dataRect();
 
154
    switch ( e->key() ) {
 
155
    case Qt::Key_BracketRight:
 
156
        {
 
157
            double dy = 0.02*dataRect.height();
 
158
            pw->setLimits( dataRect.x(), dataRect.right(), dataRect.y()+dy, dataRect.bottom()+dy );
 
159
            initPlotObjects();
 
160
            pw->update();
 
161
            break;
 
162
        }
 
163
    case Qt::Key_BracketLeft:
 
164
        {
 
165
            double dy = 0.02*dataRect.height();
 
166
            pw->setLimits( dataRect.x(), dataRect.right(), dataRect.y()-dy, dataRect.bottom()-dy );
 
167
            initPlotObjects();
 
168
            pw->update();
 
169
            break;
 
170
        }
 
171
    case Qt::Key_Plus:
 
172
    case Qt::Key_Equal:
 
173
        {
 
174
            if ( dataRect.height() > 2.0 ) {
 
175
                double dy = 0.45*dataRect.height();
 
176
                double y0 = dataRect.y() + 0.5*dataRect.height();
 
177
                pw->setLimits( dataRect.x(), dataRect.right(), y0-dy, y0+dy );
 
178
                initPlotObjects();
 
179
                pw->update();
 
180
            }
 
181
            break;
 
182
        }
 
183
    case Qt::Key_Minus:
 
184
    case Qt::Key_Underscore:
 
185
        {
 
186
            if ( dataRect.height() < 40.0 ) {
 
187
                double dy = 0.55*dataRect.height();
 
188
                double y0 = dataRect.y() + 0.5*dataRect.height();
 
189
                pw->setLimits( dataRect.x(), dataRect.right(), y0-dy, y0+dy );
 
190
                initPlotObjects();
 
191
                pw->update();
 
192
            }
 
193
            break;
 
194
        }
 
195
    case Qt::Key_Escape:
 
196
        {
 
197
            close();
 
198
            break;
 
199
        }
 
200
 
 
201
    default: { e->ignore(); break; }
 
202
    }
 
203
}
 
204
 
 
205
#include "jmoontool.moc"