Kstars

jmoontool.cpp
1/*
2 SPDX-FileCopyrightText: 2003 Jason Harris <jharris@30doradus.org>
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
26JMoonTool::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
33 setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
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
57 labIo->setAlignment(Qt::AlignHCenter);
58 labEu->setAlignment(Qt::AlignHCenter);
59 labGn->setAlignment(Qt::AlignHCenter);
60 labCa->setAlignment(Qt::AlignHCenter);
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
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
101void JMoonTool::initPlotObjects()
102{
103 KPlotObject *orbit[4];
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
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
154void 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 }
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:
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}
Implements the four largest moons of Jupiter.
void findPosition(const KSNumbers *num, const KSPlanetBase *jup, const KSSun *sunptr) override
Find the positions of each Moon, relative to Jupiter.
QRectF dataRect() const
void setLimits(double x1, double x2, double y1, double y2)
void addPlotObject(KPlotObject *object)
void removeAllPlotObjects()
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Definition ksplanet.h:33
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition kssun.h:24
double x(int i) const
Definition planetmoons.h:92
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void update(Part *part, const QByteArray &data, qint64 dataSize)
void addLayout(QLayout *layout, int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setSpacing(int spacing)
void ignore()
int key() const const
void setContentsMargins(int left, int top, int right, int bottom)
void setColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QColor &color)
qreal bottom() const const
qreal height() const const
qreal right() const const
qreal x() const const
qreal y() const const
AlignHCenter
Key_BracketRight
bool close()
void update()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Feb 24 2024 19:53:39 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.