7#include "skycalendar.h"
9#include "geolocation.h"
10#include "ksplanetbase.h"
11#include "kstarsdata.h"
12#include "dialogs/locationdialog.h"
13#include "skycomponents/skymapcomposite.h"
19#include <QPrintDialog>
23#include <QtConcurrent>
36 scUI =
new SkyCalendarUI(
this);
41 setLayout(mainLayout);
43 geo = KStarsData::Instance()->
geo();
45 setWindowTitle(
i18nc(
"@title:window",
"Sky Calendar"));
49 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
54 connect(printB, SIGNAL(clicked()),
this, SLOT(slotPrint()));
61 scUI->CalendarView->setMinimumSize(400, 600);
64 scUI->CalendarView->setShowGrid(
false);
65 scUI->Year->setValue(KStarsData::Instance()->lt().date().year());
67 scUI->LocationButton->setText(
geo->fullName());
69 scUI->CalendarView->setHorizon();
71 plotButtonText = scUI->CreateButton->text();
74 scUI->CreateButton->setText(i18n(
"Please Wait") +
"...");
78 connect(scUI->LocationButton, SIGNAL(clicked()),
this, SLOT(slotLocation()));
81int SkyCalendar::year()
83 return scUI->Year->value();
86void SkyCalendar::slotFillCalendar()
90 scUI->CalendarView->resetPlot();
91 scUI->CalendarView->setHorizon();
93#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
94 if (scUI->checkBox_Mercury->isChecked())
96 if (scUI->checkBox_Venus->isChecked())
98 if (scUI->checkBox_Mars->isChecked())
100 if (scUI->checkBox_Jupiter->isChecked())
102 if (scUI->checkBox_Saturn->isChecked())
104 if (scUI->checkBox_Uranus->isChecked())
106 if (scUI->checkBox_Neptune->isChecked())
109 if (scUI->checkBox_Mercury->isChecked())
111 if (scUI->checkBox_Venus->isChecked())
113 if (scUI->checkBox_Mars->isChecked())
115 if (scUI->checkBox_Jupiter->isChecked())
117 if (scUI->checkBox_Saturn->isChecked())
119 if (scUI->checkBox_Uranus->isChecked())
121 if (scUI->checkBox_Neptune->isChecked())
125 scUI->CreateButton->setText(
i18n(
"Plot Planetary Almanac"));
130void SkyCalendar::slotCalculating()
139 scUI->CreateButton->setText(
i18n(
"Please Wait") +
". ");
142 scUI->CreateButton->setText(
i18n(
"Please Wait") +
".. ");
149 scUI->CreateButton->setText(plotButtonText);
177void SkyCalendar::addPlanetEvents(
int nPlanet)
182 std::vector<QPointF> vRise, vSet, vTransit;
185 kdt = kdt.addDays(scUI->spinBox_Interval->value()))
187 float rTime, sTime, tTime;
194 QTime midday(12, 0, 0);
197 if (tmp_rTime == tmp_sTime)
205 rTime = tmp_rTime.
secsTo(midday) * 24.0 / 86400.0;
206 sTime = tmp_sTime.
secsTo(midday) * 24.0 / 86400.0;
208 if (tmp_rTime <= midday)
209 rTime = 12.0 - rTime;
211 rTime = -12.0 - rTime;
213 if (tmp_sTime <= midday)
214 sTime = 12.0 - sTime;
216 sTime = -12.0 - sTime;
232 tTime = tmp_tTime.
secsTo(midday) * 24.0 / 86400.0;
233 if (tmp_tTime <= midday)
234 tTime = 12.0 - tTime;
236 tTime = -12.0 - tTime;
238 float dy = kdt.date().daysInYear() - kdt.date().dayOfYear();
239 vRise.push_back(
QPointF(rTime, dy));
240 vSet.push_back(
QPointF(sTime, dy));
241 vTransit.push_back(
QPointF(tTime, dy));
251 float defaultSetTime = -10.0;
252 float defaultRiseTime = 8.0;
254 bool initialRise =
true;
255 bool initialSet =
true;
256 bool initialTransit =
true;
257 bool extraCheckRise =
true;
258 bool extraCheckSet =
true;
259 bool extraCheckTransit =
true;
260 bool needRiseLabel =
false;
261 bool needSetLabel =
false;
262 bool needTransertLabel =
false;
264 float maxRiseTime = 0.0;
265 for (
auto &item : vRise)
267 if (item.x() >= maxRiseTime)
268 maxRiseTime = item.x();
270 maxRiseTime = qFloor(maxRiseTime) - 1.0;
272 for (uint32_t i = 0; i < vRise.size(); ++i)
274 if (initialRise && (vRise.at(i).x() > defaultSetTime && vRise.at(i).x() < defaultRiseTime))
276 needRiseLabel =
true;
279 else if (vRise.at(i).x() < defaultSetTime || vRise.at(i).x() > defaultRiseTime)
282 needRiseLabel =
false;
285 needRiseLabel =
false;
287 if (extraCheckRise && vRise.at(i).x() > defaultRiseTime && vRise.at(i).x() < maxRiseTime)
289 needRiseLabel =
true;
290 extraCheckRise =
false;
293 if (initialSet && (vSet.at(i).x() > defaultSetTime && vSet.at(i).x() < defaultRiseTime))
298 else if (vSet.at(i).x() < defaultSetTime || vSet.at(i).x() > defaultRiseTime)
301 needSetLabel =
false;
304 needSetLabel =
false;
306 if (extraCheckSet && vSet.at(i).x() > defaultRiseTime && vSet.at(i).x() < maxRiseTime)
309 extraCheckSet =
false;
312 if (initialTransit && (vTransit.at(i).x() > defaultSetTime && vTransit.at(i).x() < defaultRiseTime))
314 needTransertLabel =
true;
315 initialTransit =
false;
317 else if (vTransit.at(i).x() < defaultSetTime || vTransit.at(i).x() > defaultRiseTime)
319 initialTransit =
true;
320 needTransertLabel =
false;
324 needTransertLabel =
false;
326 if (extraCheckTransit && vTransit.at(i).x() > defaultRiseTime && vTransit.at(i).x() < maxRiseTime)
328 needTransertLabel =
true;
329 extraCheckTransit =
false;
332 if (vRise.at(i).x() > -23.0 && vRise.at(i).x() < 23.0)
334 if (i > 0 && fabs(vRise.at(i).x() - vRise.at(i - 1).x()) > 6.0)
336 scUI->CalendarView->addPlotObject(oRise);
338 extraCheckRise =
true;
342 label =
i18nc(
"A planet rises from the horizon",
"%1 rises", ksp->
name());
346 oRise->
addPoint(vRise.at(i), label);
350 scUI->CalendarView->addPlotObject(oRise);
354 if (vSet.at(i).x() > -23.0 && vSet.at(i).x() < 23.0)
356 if (i > 0 && fabs(vSet.at(i).x() - vSet.at(i - 1).x()) > 6.0)
358 scUI->CalendarView->addPlotObject(oSet);
360 extraCheckSet =
true;
364 label =
i18nc(
"A planet sets from the horizon",
"%1 sets", ksp->
name());
372 scUI->CalendarView->addPlotObject(oSet);
376 if (vTransit.at(i).x() > -23.0 && vTransit.at(i).x() < 23.0)
378 if (i > 0 && fabs(vTransit.at(i).x() - vTransit.at(i - 1).x()) > 6.0)
380 scUI->CalendarView->addPlotObject(oTransit);
382 extraCheckTransit =
true;
385 if (needTransertLabel)
386 label =
i18nc(
"A planet transits across the meridian",
"%1 transits", ksp->
name());
390 oTransit->
addPoint(vTransit.at(i), label);
394 scUI->CalendarView->addPlotObject(oTransit);
400 scUI->CalendarView->addPlotObject(oRise);
401 scUI->CalendarView->addPlotObject(oSet);
402 scUI->CalendarView->addPlotObject(oTransit);
405void SkyCalendar::slotPrint()
411 int text_height = 200;
414 int calendar_font_size;
423 dialog.setWindowTitle(
i18nc(
"@title:window",
"Print sky calendar"));
430 calendar_font = scUI->CalendarView->
font();
432 calendar_font_size = calendar_font.
pointSize();
434 calendar_size = scUI->CalendarView->
size();
438 str_legend =
i18n(
"Sky Calendar");
442 str_legend += str_year;
445 QRect text_rect(0, 0, printer.
width(), text_height);
449 scUI->CalendarView->
setFont(calendar_font);
455 scUI->CalendarView->
render(&pixmap);
468 scUI->CalendarView->
setFont(calendar_font);
470 scUI->CalendarView->
resize(calendar_size);
478void SkyCalendar::slotLocation()
487 scUI->LocationButton->setText(geo->
fullName());
492 scUI->CalendarView->setHorizon();
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
void addPoint(const QPointF &p, const QString &label=QString(), double barWidth=0.0)
A subclass of TrailObject that provides additional information needed for most solar system objects.
SkyMapComposite * skyComposite()
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
Dialog for changing the geographic location of the observer.
virtual QString name(void) const
dms transitAltitude(const KStarsDateTime &dt, const GeoLocation *geo) const
QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo) const
The same iteration technique described in riseSetTime() is used here.
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true) const
Determine the time at which the point will rise or set.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
GeoCoordinates geo(const QVariant &location)
QString label(StandardShortcut id)
int pointSize() const const
void setPointSize(int pointSize)
void restoreOverrideCursor()
void setOverrideCursor(const QCursor &cursor)
QIcon fromTheme(const QString &name)
bool begin(QPaintDevice *device)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void drawText(const QPoint &position, const QString &text)
void setResolution(int dpi)
QString & setNum(double n, char format, int precision)
QFuture< T > run(Function function,...)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void msleep(unsigned long msecs)
bool isValid(int h, int m, int s, int ms)
int secsTo(QTime t) const const