Kstars

astrocalc.cpp
1/*
2 SPDX-FileCopyrightText: 2001-2005 Pablo de Vicente <p.devicente@wanadoo.es>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "astrocalc.h"
8
9#include "modcalcjd.h"
10#include "modcalcgeodcoord.h"
11#include "modcalcgalcoord.h"
12#include "modcalcsidtime.h"
13#include "modcalcapcoord.h"
14#include "modcalcdaylength.h"
15#include "modcalcaltaz.h"
16#include "modcalcsimple.h"
17#include "modcalcplanets.h"
18#include "modcalceclipticcoords.h"
19#include "modcalcangdist.h"
20#include "modcalcvizequinox.h"
21#include "modcalcvlsr.h"
22#include "conjunctions.h"
23#include "eclipsetool.h"
24
25#include <QDialogButtonBox>
26#include <QSplitter>
27#include <QStackedWidget>
28#include <QTextEdit>
29#include <QTreeWidget>
30#include <QTreeWidgetItem>
31
32AstroCalc::AstroCalc(QWidget *parent) : QDialog(parent)
33{
34#ifdef Q_OS_MACOS
35 setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
36#endif
37
38 // List of messages. Maybe there is better place for it...
39 QString message = i18n("<QT>"
40 "<H2>KStars Astrocalculator</H2>"
41 "<P>"
42 "The KStars Astrocalculator contains several <B>modules</b> "
43 "which perform a variety of astronomy-related calculations. "
44 "The modules are organized into several categories: "
45 "<UL>"
46 "<LI><B>Time calculators: </B>"
47 "Convert between time systems, and predict the timing of celestial events</LI>"
48 "<LI><B>Coordinate converters: </B>"
49 "Convert between various coordinate systems</LI>"
50 "<LI><B>Solar system: </B>"
51 "Predict the position of any planet, from a given location on Earth at a given time</LI>"
52 "</UL>"
53 "</QT>");
54 QString messageTime = i18n("<QT>"
55 "Section which includes algorithms for computing time ephemeris"
56 "<UL><LI>"
57 "<B>Julian Day:</B> Julian Day/Calendar conversion"
58 "</LI><LI>"
59 "<B>Sidereal Time:</B> Sidereal/Universal time conversion"
60 "</LI><LI>"
61 "<B>Almanac:</B> Rise/Set/Transit timing and position data "
62 "for the Sun and Moon"
63 "</LI><LI>"
64 "<B>Equinoxes & Solstices:</B> Equinoxes, Solstices and duration of the "
65 "seasons"
66 "</LI></UL>"
67 "</QT>");
68 QString messageCoord = i18n("<QT>"
69 "Section with algorithms for the conversion of "
70 "different astronomical systems of coordinates"
71 "<UL><LI>"
72 "<B>Galactic:</B> Galactic/Equatorial coordinates conversion"
73 "</LI><LI>"
74 "<B>Apparent:</B> Computation of current equatorial coordinates"
75 " from a given epoch"
76 "</LI><LI>"
77 "<B>Ecliptic:</B> Ecliptic/Equatorial coordinates conversion"
78 "</LI><LI>"
79 "<B>Horizontal:</B> Computation of azimuth and elevation for a "
80 "given source, time, and location on the Earth"
81 "</LI><LI>"
82 "<B>Simple:</B> Conversion between angles in hrs and degrees."
83 "</LI><LI>"
84 "<B>Angular Distance:</B> Computation of angular distance between "
85 "two objects whose positions are given in equatorial coordinates"
86 "</LI><LI>"
87 "<B>Geodetic Coords:</B> Geodetic/XYZ coordinate conversion"
88 "</LI><LI>"
89 "<B>LSR Velocity:</B> Computation of the heliocentric, geocentric "
90 "and topocentric radial velocity of a source from its LSR velocity"
91 "</LI></UL>"
92 "</QT>");
93 QString messageSolar = i18n("<QT>"
94 "Section with algorithms regarding information "
95 "on solar system bodies coordinates and times"
96 "<UL><LI>"
97 "<B>Planets Coords:</B> Coordinates for the planets, moon and sun "
98 "at a given time and from a given position on Earth "
99 "</LI></UL>"
100 "</QT>");
101
102 QSplitter *split = new QSplitter(this);
103
104 QVBoxLayout *mainLayout = new QVBoxLayout;
105 mainLayout->addWidget(split);
106 setLayout(mainLayout);
107
109 mainLayout->addWidget(buttonBox);
110 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
111
112 setWindowTitle(i18nc("@title:window", "Calculator"));
113
114 // Create navigation panel
115 navigationPanel = new QTreeWidget(split);
116 navigationPanel->setColumnCount(1);
117 navigationPanel->setHeaderLabels(QStringList(i18n("Calculator modules")));
118 navigationPanel->setSortingEnabled(false);
119 //FIXME: Would be better to make the navigationPanel fit its contents,
120 //but I wasn't able to make it work
121 navigationPanel->setMinimumWidth(200);
122
123 acStack = new QStackedWidget(split);
124
125 splashScreen = new QTextEdit(message, acStack);
126 splashScreen->setReadOnly(true);
127 //FIXME: Minimum size is set to resize calculator to correct size
128 //when no modules is loaded. This is simply biggest size of
129 //calculator modules. I think it should be set in more cleverly.
130 splashScreen->setMinimumSize(640, 550);
131 acStack->addWidget(splashScreen);
132
133 // Load icons
134 // JM 2016-10-02: Those are missing, disabling the icons for now
135 /*
136 QIcon jdIcon = QIcon ("jd.png");
137 QIcon geodIcon = QIcon ("geodetic.png");
138 QIcon solarIcon = QIcon ("geodetic.png");
139 // QIcon sunsetIcon = QIcon ("sunset.png"); // Its usage is commented out.
140 QIcon timeIcon = QIcon ("sunclock.png");*/
141
142 /* Populate the tree widget and widget stack */
143 // Time-related entries
144 QTreeWidgetItem *timeItem = addTreeTopItem(navigationPanel, i18n("Time Calculators"), messageTime);
145 //timeItem->setIcon(0,timeIcon);
146
147 //addTreeItem<modCalcJD> (timeItem, i18n("Julian Day"))->setIcon(0,jdIcon);
148 addTreeItem<modCalcJD>(timeItem, i18n("Julian Day"));
149 addTreeItem<modCalcSidTime>(timeItem, i18n("Sidereal Time"));
150 addTreeItem<modCalcDayLength>(timeItem, i18n("Almanac"));
151 addTreeItem<modCalcEquinox>(timeItem, i18n("Equinoxes & Solstices"));
152 // dayItem->setIcon(0,sunsetIcon);
153
154 // Coordinate-related entries
155 QTreeWidgetItem *coordItem = addTreeTopItem(navigationPanel, i18n("Coordinate Converters"), messageCoord);
156 addTreeItem<modCalcGalCoord>(coordItem, i18n("Equatorial/Galactic"));
157 addTreeItem<modCalcApCoord>(coordItem, i18n("Apparent Coordinates"));
158 addTreeItem<modCalcAltAz>(coordItem, i18n("Horizontal Coordinates"));
159 addTreeItem<modCalcSimple>(coordItem, i18n("Simple Coordinates"));
160 addTreeItem<modCalcEclCoords>(coordItem, i18n("Ecliptic Coordinates"));
161 addTreeItem<modCalcAngDist>(coordItem, i18n("Angular Distance"));
162 addTreeItem<modCalcGeodCoord>(coordItem, i18n("Geodetic Coordinates"));
163 addTreeItem<modCalcVlsr>(coordItem, i18n("LSR Velocity"));
164
165 // Solar System related entries
166 QTreeWidgetItem *solarItem = addTreeTopItem(navigationPanel, i18n("Solar System"), messageSolar);
167 //solarItem->setIcon(0,solarIcon);
168 addTreeItem<modCalcPlanets>(solarItem, i18n("Planets Coordinates"));
169 addTreeItem<ConjunctionsTool>(solarItem, i18n("Conjunctions"));
170 addTreeItem<EclipseTool>(solarItem, i18n("Eclipses"));
171
172 acStack->setCurrentWidget(splashScreen);
173 connect(navigationPanel, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this,
174 SLOT(slotItemSelection(QTreeWidgetItem*)));
175}
176
177template <typename T>
178QWidget *AstroCalc::addToStack()
179{
180 T *t = new T(acStack);
181 acStack->addWidget(t);
182 return t;
183}
184
185template <typename T>
186QTreeWidgetItem *AstroCalc::addTreeItem(QTreeWidgetItem *parent, const QString &title)
187{
189 dispatchTable.insert(item, WidgetThunk(this, &AstroCalc::addToStack<T>));
190 return item;
191}
192
193QTreeWidgetItem *AstroCalc::addTreeTopItem(QTreeWidget *parent, const QString &title, const QString &html)
194{
196
197 htmlTable.insert(item, html);
198 return item;
199}
200
202{
203 if (item == nullptr)
204 return;
205 // Lookup in HTML table
206 QMap<QTreeWidgetItem *, QString>::iterator iterHTML = htmlTable.find(item);
207 if (iterHTML != htmlTable.end())
208 {
209 splashScreen->setHtml(*iterHTML);
210 acStack->setCurrentWidget(splashScreen);
211 return;
212 }
213 // Lookup in frames table
214 QMap<QTreeWidgetItem *, WidgetThunk>::iterator iter = dispatchTable.find(item);
215 if (iter != dispatchTable.end())
216 {
217 acStack->setCurrentWidget(iter->eval());
218 }
219}
220
222{
223 return QSize(640, 430);
224}
225
226QWidget *AstroCalc::WidgetThunk::eval()
227{
228 if (widget == nullptr)
229 {
230 // This is pointer to member function call.
231 widget = (calc->*func)();
232 }
233 return widget;
234}
QSize sizeHint() const override
void slotItemSelection(QTreeWidgetItem *it)
Display calculator module or help text based on item selected.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
iterator end()
iterator find(const Key &key)
iterator insert(const Key &key, const T &value)
QObject * parent() const const
int addWidget(QWidget *widget)
void setCurrentWidget(QWidget *widget)
void setHtml(const QString &text)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.