• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • tools
jmoontool.cpp
Go to the documentation of this file.
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( i18n("Io"), page );
62  QLabel *labEu = new QLabel( i18n("Europa"), page );
63  QLabel *labGn = new QLabel( i18n("Ganymede"), page );
64  QLabel *labCa = new QLabel( i18n("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"
KSPlanet
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Definition: ksplanet.h:40
KSSun
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition: kssun.h:31
JMoonTool::JMoonTool
JMoonTool(QWidget *parent=0)
Definition: jmoontool.cpp:41
QWidget
PlanetMoons::x
double x(int i) const
Definition: planetmoons.h:101
JMoonTool::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Definition: jmoontool.cpp:152
KDialog
KStars
This is the main window for KStars.
Definition: kstars.h:94
dms.h
ksplanet.h
skymapcomposite.h
jupitermoons.h
KSPlanetBase::angSize
double angSize() const
Definition: ksplanetbase.h:171
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
KPlotWidget
jmoontool.h
ksnumbers.h
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
simclock.h
JupiterMoons::findPosition
virtual void findPosition(const KSNumbers *num, const KSPlanetBase *jup, const KSSun *sunptr)
Find the positions of each Moon, relative to Jupiter.
Definition: jupitermoons.cpp:42
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
QLabel
JupiterMoons
Implements the four largest moons of Jupiter.
Definition: jupitermoons.h:41
SkyMapComposite::findByName
virtual SkyObject * findByName(const QString &name)
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument...
Definition: skymapcomposite.cpp:426
KStars::data
KStarsData * data() const
Definition: kstars.h:131
kstarsdata.h
KStarsData::ut
const KStarsDateTime & ut() const
Definition: kstarsdata.h:140
QFrame
kstars.h
JMoonTool::~JMoonTool
~JMoonTool()
Definition: jmoontool.cpp:110
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal