Kstars

jmoontool.cpp
1 /*
2  SPDX-FileCopyrightText: 2003 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "jmoontool.h"
8 
9 #include "ksnumbers.h"
10 #include "kstars.h"
11 
12 #include "skymapcomposite.h"
13 #include "skyobjects/jupitermoons.h"
14 #include "skyobjects/ksplanet.h"
15 #include "skyobjects/kssun.h"
16 
17 #include <KPlotting/KPlotObject>
18 #include <KPlotting/KPlotWidget>
19 #include <KPlotAxis>
20 
21 #include <QFrame>
22 #include <QGridLayout>
23 #include <QKeyEvent>
24 #include <QVBoxLayout>
25 
26 JMoonTool::JMoonTool(QWidget *parent) : QDialog(parent)
27 {
28  QFrame *page = new QFrame(this);
29 
30  setWindowTitle(i18nc("@title:window", "Jupiter Moons Tool"));
31  setModal(false);
32 #ifdef Q_OS_OSX
34 #endif
35 
36  QVBoxLayout *vlay = new QVBoxLayout;
37  vlay->setContentsMargins(0, 0, 0, 0);
38  vlay->setSpacing(0);
39 
40  setLayout(vlay);
41 
42  colJp = QColor(Qt::white);
43  colIo = QColor(Qt::red);
44  colEu = QColor(Qt::yellow);
45  colGn = QColor(Qt::cyan);
46  colCa = QColor(Qt::green);
47 
48  QLabel *labIo = new QLabel(i18n("Io"), page);
49  QLabel *labEu = new QLabel(i18n("Europa"), page);
50  QLabel *labGn = new QLabel(i18n("Ganymede"), page);
51  QLabel *labCa = new QLabel(i18n("Callisto"), page);
52 
61 
62  QPalette p = palette();
65  labIo->setPalette(p);
67  labEu->setPalette(p);
69  labGn->setPalette(p);
71  labCa->setPalette(p);
72  labIo->setAutoFillBackground(true);
73  labEu->setAutoFillBackground(true);
74  labGn->setAutoFillBackground(true);
75  labCa->setAutoFillBackground(true);
76 
77  QGridLayout *glay = new QGridLayout();
78  glay->addWidget(labIo, 0, 0);
79  glay->addWidget(labEu, 1, 0);
80  glay->addWidget(labGn, 0, 1);
81  glay->addWidget(labCa, 1, 1);
82 
83  pw = new KPlotWidget(page);
84  pw->setShowGrid(false);
85  pw->setAntialiasing(true);
86  pw->setLimits(-12.0, 12.0, -11.0, 11.0);
87  pw->axis(KPlotWidget::BottomAxis)->setLabel(i18n("offset from Jupiter (arcmin)"));
88  pw->axis(KPlotWidget::LeftAxis)->setLabel(i18n("time since now (days)"));
89  vlay->addLayout(glay);
90  vlay->addWidget(pw);
91  resize(350, 600);
92 
94  vlay->addWidget(buttonBox);
95  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
96 
97  initPlotObjects();
98  update();
99 }
100 
101 void JMoonTool::initPlotObjects()
102 {
103  KPlotObject *orbit[4];
104  KPlotObject *jpath;
105  long double jd0 = KStarsData::Instance()->ut().djd();
106  KSSun *ksun = dynamic_cast<KSSun *>(KStarsData::Instance()->skyComposite()->findByName(i18n("Sun")));
107  KSPlanet *jup = dynamic_cast<KSPlanet *>(KStarsData::Instance()->skyComposite()->findByName(i18n("Jupiter")));
108  JupiterMoons jm;
109 
110  pw->removeAllPlotObjects();
111 
112  orbit[0] = new KPlotObject(colIo, KPlotObject::Lines, 1.0);
113  orbit[1] = new KPlotObject(colEu, KPlotObject::Lines, 1.0);
114  orbit[2] = new KPlotObject(colGn, KPlotObject::Lines, 1.0);
115  orbit[3] = new KPlotObject(colCa, KPlotObject::Lines, 1.0);
116  jpath = new KPlotObject(colJp, KPlotObject::Lines, 1.0);
117 
118  QRectF dataRect = pw->dataRect();
119  double dy = 0.01 * dataRect.height();
120 
121  /*Debug
122  //For testing position of each satellite
123  for(double t = dataRect.y(); t <= dataRect.bottom(); t += 1){
124  KSNumbers num(jd0 + t);
125  jm.findPosition(&num, jup, ksun);
126 
127  qDebug() << Q_FUNC_INFO << "Position [Io] : " << 0.5 * jup->angSize() * jm.x(0) << " at " << t << " arcmin";
128  qDebug() << Q_FUNC_INFO << "Position [Europa] : " << 0.5 * jup->angSize() * jm.x(1) << " at " << t << " arcmin";
129  qDebug() << Q_FUNC_INFO << "Position [Ganymede] : " << 0.5 * jup->angSize() * jm.x(2) << " at " << t << " arcmin";
130  qDebug() << Q_FUNC_INFO << "Position [Callisto] : " << 0.5 * jup->angSize() * jm.x(3) << " at " << t << " arcmin";
131  }
132  */
133 
134  //t is the offset from jd0, in days.
135  for (double t = dataRect.y(); t <= dataRect.bottom(); t += dy)
136  {
137  KSNumbers num(jd0 + t);
138  jm.findPosition(&num, jup, ksun);
139 
140  //jm.x(i) tells the offset from Jupiter, in units of Jupiter's angular radius.
141  //multiply by 0.5*jup->angSize() to get arcminutes
142  for (unsigned int i = 0; i < 4; ++i)
143  orbit[i]->addPoint(0.5 * jup->angSize() * jm.x(i), t);
144 
145  jpath->addPoint(0.0, t);
146  }
147 
148  for (unsigned int i = 0; i < 4; ++i)
149  pw->addPlotObject(orbit[i]);
150 
151  pw->addPlotObject(jpath);
152 }
153 
154 void JMoonTool::keyPressEvent(QKeyEvent *e)
155 {
156  QRectF dataRect = pw->dataRect();
157  switch (e->key())
158  {
160  {
161  double dy = 0.02 * dataRect.height();
162  pw->setLimits(dataRect.x(), dataRect.right(), dataRect.y() + dy, dataRect.bottom() + dy);
163  initPlotObjects();
164  pw->update();
165  break;
166  }
167  case Qt::Key_BracketLeft:
168  {
169  double dy = 0.02 * dataRect.height();
170  pw->setLimits(dataRect.x(), dataRect.right(), dataRect.y() - dy, dataRect.bottom() - dy);
171  initPlotObjects();
172  pw->update();
173  break;
174  }
175  case Qt::Key_Plus:
176  case Qt::Key_Equal:
177  {
178  if (dataRect.height() > 2.0)
179  {
180  double dy = 0.45 * dataRect.height();
181  double y0 = dataRect.y() + 0.5 * dataRect.height();
182  pw->setLimits(dataRect.x(), dataRect.right(), y0 - dy, y0 + dy);
183  initPlotObjects();
184  pw->update();
185  }
186  break;
187  }
188  case Qt::Key_Minus:
189  case Qt::Key_Underscore:
190  {
191  if (dataRect.height() < 40.0)
192  {
193  double dy = 0.55 * dataRect.height();
194  double y0 = dataRect.y() + 0.5 * dataRect.height();
195  pw->setLimits(dataRect.x(), dataRect.right(), y0 - dy, y0 + dy);
196  initPlotObjects();
197  pw->update();
198  }
199  break;
200  }
201  case Qt::Key_Escape:
202  {
203  close();
204  break;
205  }
206 
207  default:
208  {
209  e->ignore();
210  break;
211  }
212  }
213 }
AlignHCenter
long double djd() const
void setSizePolicy(QSizePolicy)
qreal x() const const
qreal y() const const
void update()
QRectF dataRect() const
bool close()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
Provides necessary information about the Sun.
Definition: kssun.h:23
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument.
QString i18n(const char *text, const TYPE &arg...)
void findPosition(const KSNumbers *num, const KSPlanetBase *jup, const KSSun *sunptr) override
Find the positions of each Moon, relative to Jupiter.
void setWindowFlags(Qt::WindowFlags type)
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
void setAlignment(Qt::Alignment)
void setWindowTitle(const QString &)
void removeAllPlotObjects()
qreal bottom() const const
Key_BracketRight
Provides necessary information about objects in the solar system.
Definition: ksplanet.h:32
void setColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QColor &color)
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:165
qreal right() const const
void setLimits(double x1, double x2, double y1, double y2)
double angSize() const
Definition: ksplanetbase.h:184
const KStarsDateTime & ut() const
Definition: kstarsdata.h:156
void addPoint(const QPointF &p, const QString &label=QString(), double barWidth=0.0)
void resize(int w, int h)
int key() const const
void addPlotObject(KPlotObject *object)
void setSpacing(int spacing)
void ignore()
void setContentsMargins(int left, int top, int right, int bottom)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment)
void setAutoFillBackground(bool enabled)
double x(int i) const
Definition: planetmoons.h:92
void addLayout(QLayout *layout, int stretch)
void setLayout(QLayout *layout)
qreal height() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 16 2022 04:00:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.