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"
15 #include <KPlotObject>
19 #include <QPrintDialog>
21 #include <QPushButton>
23 #include <QtConcurrent>
25 SkyCalendarUI::SkyCalendarUI(
QWidget *parent) :
QFrame(parent)
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") +
"...");
75 QtConcurrent::run(this, &SkyCalendar::slotFillCalendar);
78 connect(scUI->LocationButton, SIGNAL(clicked()),
this, SLOT(slotLocation()));
81 int SkyCalendar::year()
83 return scUI->Year->value();
86 void SkyCalendar::slotFillCalendar()
88 scUI->CreateButton->setEnabled(
false);
90 scUI->CalendarView->resetPlot();
91 scUI->CalendarView->setHorizon();
93 if (scUI->checkBox_Mercury->isChecked())
94 addPlanetEvents(KSPlanetBase::MERCURY);
95 if (scUI->checkBox_Venus->isChecked())
96 addPlanetEvents(KSPlanetBase::VENUS);
97 if (scUI->checkBox_Mars->isChecked())
98 addPlanetEvents(KSPlanetBase::MARS);
99 if (scUI->checkBox_Jupiter->isChecked())
100 addPlanetEvents(KSPlanetBase::JUPITER);
101 if (scUI->checkBox_Saturn->isChecked())
102 addPlanetEvents(KSPlanetBase::SATURN);
103 if (scUI->checkBox_Uranus->isChecked())
104 addPlanetEvents(KSPlanetBase::URANUS);
105 if (scUI->checkBox_Neptune->isChecked())
106 addPlanetEvents(KSPlanetBase::NEPTUNE);
108 scUI->CreateButton->setText(
i18n(
"Plot Planetary Almanac"));
109 scUI->CreateButton->setEnabled(
true);
126 void SkyCalendar::slotCalculating()
135 scUI->CreateButton->setText(
i18n(
"Please Wait") +
". ");
136 scUI->CreateButton->repaint();
138 scUI->CreateButton->setText(
i18n(
"Please Wait") +
".. ");
139 scUI->CreateButton->repaint();
142 scUI->CreateButton->repaint();
145 scUI->CreateButton->setText(plotButtonText);
173 void SkyCalendar::addPlanetEvents(
int nPlanet)
178 std::vector<QPointF> vRise, vSet, vTransit;
181 kdt = kdt.
addDays(scUI->spinBox_Interval->value()))
183 float rTime, sTime, tTime;
190 QTime midday(12, 0, 0);
193 if (tmp_rTime == tmp_sTime)
201 rTime = tmp_rTime.
secsTo(midday) * 24.0 / 86400.0;
202 sTime = tmp_sTime.
secsTo(midday) * 24.0 / 86400.0;
204 if (tmp_rTime <= midday)
205 rTime = 12.0 - rTime;
207 rTime = -12.0 - rTime;
209 if (tmp_sTime <= midday)
210 sTime = 12.0 - sTime;
212 sTime = -12.0 - sTime;
228 tTime = tmp_tTime.
secsTo(midday) * 24.0 / 86400.0;
229 if (tmp_tTime <= midday)
230 tTime = 12.0 - tTime;
232 tTime = -12.0 - tTime;
234 float dy = kdt.date().daysInYear() - kdt.date().dayOfYear();
235 vRise.push_back(
QPointF(rTime, dy));
236 vSet.push_back(
QPointF(sTime, dy));
237 vTransit.push_back(
QPointF(tTime, dy));
247 float defaultSetTime = -10.0;
248 float defaultRiseTime = 8.0;
250 bool initialRise =
true;
251 bool initialSet =
true;
252 bool initialTransit =
true;
253 bool extraCheckRise =
true;
254 bool extraCheckSet =
true;
255 bool extraCheckTransit =
true;
256 bool needRiseLabel =
false;
257 bool needSetLabel =
false;
258 bool needTransertLabel =
false;
260 float maxRiseTime = 0.0;
261 for (
auto &item : vRise)
263 if (item.x() >= maxRiseTime)
264 maxRiseTime = item.x();
266 maxRiseTime = qFloor(maxRiseTime) - 1.0;
268 for (uint32_t i = 0; i < vRise.size(); ++i)
270 if (initialRise && (vRise.at(i).x() > defaultSetTime && vRise.at(i).x() < defaultRiseTime))
272 needRiseLabel =
true;
275 else if (vRise.at(i).x() < defaultSetTime || vRise.at(i).x() > defaultRiseTime)
278 needRiseLabel =
false;
281 needRiseLabel =
false;
283 if (extraCheckRise && vRise.at(i).x() > defaultRiseTime && vRise.at(i).x() < maxRiseTime)
285 needRiseLabel =
true;
286 extraCheckRise =
false;
289 if (initialSet && (vSet.at(i).x() > defaultSetTime && vSet.at(i).x() < defaultRiseTime))
294 else if (vSet.at(i).x() < defaultSetTime || vSet.at(i).x() > defaultRiseTime)
297 needSetLabel =
false;
300 needSetLabel =
false;
302 if (extraCheckSet && vSet.at(i).x() > defaultRiseTime && vSet.at(i).x() < maxRiseTime)
305 extraCheckSet =
false;
308 if (initialTransit && (vTransit.at(i).x() > defaultSetTime && vTransit.at(i).x() < defaultRiseTime))
310 needTransertLabel =
true;
311 initialTransit =
false;
313 else if (vTransit.at(i).x() < defaultSetTime || vTransit.at(i).x() > defaultRiseTime)
315 initialTransit =
true;
316 needTransertLabel =
false;
320 needTransertLabel =
false;
322 if (extraCheckTransit && vTransit.at(i).x() > defaultRiseTime && vTransit.at(i).x() < maxRiseTime)
324 needTransertLabel =
true;
325 extraCheckTransit =
false;
328 if (vRise.at(i).x() > -23.0 && vRise.at(i).x() < 23.0)
330 if (i > 0 && fabs(vRise.at(i).x() - vRise.at(i - 1).x()) > 6.0)
332 scUI->CalendarView->addPlotObject(oRise);
334 extraCheckRise =
true;
338 label =
i18nc(
"A planet rises from the horizon",
"%1 rises", ksp->
name());
342 oRise->
addPoint(vRise.at(i), label);
346 scUI->CalendarView->addPlotObject(oRise);
350 if (vSet.at(i).x() > -23.0 && vSet.at(i).x() < 23.0)
352 if (i > 0 && fabs(vSet.at(i).x() - vSet.at(i - 1).x()) > 6.0)
354 scUI->CalendarView->addPlotObject(oSet);
356 extraCheckSet =
true;
360 label =
i18nc(
"A planet sets from the horizon",
"%1 sets", ksp->
name());
368 scUI->CalendarView->addPlotObject(oSet);
372 if (vTransit.at(i).x() > -23.0 && vTransit.at(i).x() < 23.0)
374 if (i > 0 && fabs(vTransit.at(i).x() - vTransit.at(i - 1).x()) > 6.0)
376 scUI->CalendarView->addPlotObject(oTransit);
378 extraCheckTransit =
true;
381 if (needTransertLabel)
382 label =
i18nc(
"A planet transits across the meridian",
"%1 transits", ksp->
name());
386 oTransit->
addPoint(vTransit.at(i), label);
390 scUI->CalendarView->addPlotObject(oTransit);
396 scUI->CalendarView->addPlotObject(oRise);
397 scUI->CalendarView->addPlotObject(oSet);
398 scUI->CalendarView->addPlotObject(oTransit);
401 void SkyCalendar::slotPrint()
407 int text_height = 200;
410 int calendar_font_size;
419 dialog.setWindowTitle(
i18nc(
"@title:window",
"Print sky calendar"));
426 calendar_font = scUI->CalendarView->font();
428 calendar_font_size = calendar_font.
pointSize();
430 calendar_size = scUI->CalendarView->size();
434 str_legend =
i18n(
"Sky Calendar");
436 str_legend +=
geo->fullName();
438 str_legend += str_year;
441 QRect text_rect(0, 0, printer.
width(), text_height);
445 scUI->CalendarView->setFont(calendar_font);
447 scUI->CalendarView->resize(printer.
width(), printer.
height() - text_height);
450 QPixmap pixmap(scUI->CalendarView->size());
451 scUI->CalendarView->render(&pixmap);
464 scUI->CalendarView->setFont(calendar_font);
466 scUI->CalendarView->resize(calendar_size);
474 void SkyCalendar::slotLocation()
483 scUI->LocationButton->setText(
geo->fullName());
488 scUI->CalendarView->setHorizon();