20 #include <QDesktopWidget>
24 #include <QPrintDialog>
26 #include <kdeprintdialog.h>
28 #include <KPlotObject>
29 #include <KPushButton>
41 float timeToHours(QTime t) {
42 float h = t.secsTo(QTime()) * -24.0 / 86400.0;
49 inline bool isAxisCrossed(
const QVector<QPointF>& vec,
int i) {
50 return i > 0 && vec.at(i-1).x() * vec.at(i).x() <= 0;
53 inline bool isAtExtremum(
const QVector<QPointF>& vec,
int i) {
55 i > 0 && i < vec.size() - 1 &&
56 (vec.at(i-1).x() - vec.at(i).x()) * (vec.at(i).x() - vec.at(i+1).x()) < 0;
70 setMainWidget( scUI );
74 setCaption( i18n(
"Sky Calendar" ) );
75 setButtons( KDialog::User1 | KDialog::Close );
79 if ( QApplication::desktop()->availableGeometry().height() <= scUI->CalendarView->height() ) {
80 scUI->CalendarView->setMinimumSize( 400, 600 );
83 scUI->CalendarView->setShowGrid(
false );
86 scUI->LocationButton->setText( geo->
fullName() );
87 setButtonGuiItem( KDialog::User1, KGuiItem( i18n(
"&Print..."),
"document-print", i18n(
"Print the Sky Calendar") ) );
89 scUI->CalendarView->setHorizon();
91 connect( scUI->CreateButton, SIGNAL(clicked()),
this, SLOT(
slotFillCalendar()) );
92 connect( scUI->LocationButton, SIGNAL(clicked()),
this, SLOT(
slotLocation()) );
93 connect(
this, SIGNAL( user1Clicked() ),
this, SLOT(
slotPrint() ) );
102 scUI->CalendarView->resetPlot();
103 scUI->CalendarView->setHorizon();
105 if ( scUI->checkBox_Mercury->isChecked() )
107 if ( scUI->checkBox_Venus->isChecked() )
109 if ( scUI->checkBox_Mars->isChecked() )
111 if ( scUI->checkBox_Jupiter->isChecked() )
113 if ( scUI->checkBox_Saturn->isChecked() )
115 if ( scUI->checkBox_Uranus->isChecked() )
117 if ( scUI->checkBox_Neptune->isChecked() )
119 if ( scUI->checkBox_Pluto->isChecked() )
122 scUI->CalendarView->update();
149 void SkyCalendar::addPlanetEvents(
int nPlanet ) {
151 QColor pColor = ksp->
color();
152 QVector<QPointF> vRise, vSet, vTransit;
154 for(
KStarsDateTime kdt( QDate( year(), 1, 1 ), QTime( 12, 0, 0 ) );
155 kdt.date().year() == year();
156 kdt = kdt.addDays( scUI->spinBox_Interval->value() ) )
158 float rTime, sTime, tTime;
162 QTime tmp_rTime = ksp->
riseSetTime( kdt, geo,
true,
true );
163 QTime tmp_sTime = ksp->
riseSetTime( kdt, geo,
false,
true );
165 QTime midday( 12, 0, 0 );
168 if ( tmp_rTime == tmp_sTime ) {
173 if ( tmp_rTime.isValid() && tmp_sTime.isValid() ) {
174 rTime = tmp_rTime.secsTo( midday ) * 24.0 / 86400.0;
175 sTime = tmp_sTime.secsTo( midday ) * 24.0 / 86400.0;
177 if ( tmp_rTime <= midday )
178 rTime = 12.0 - rTime;
180 rTime = -12.0 - rTime;
182 if ( tmp_sTime <= midday )
183 sTime = 12.0 - sTime;
185 sTime = -12.0 - sTime;
196 tTime = tmp_tTime.secsTo( midday ) * 24.0 / 86400.0;
197 if ( tmp_tTime <= midday )
198 tTime = 12.0 - tTime;
200 tTime = -12.0 - tTime;
202 float dy = kdt.date().daysInYear() - kdt.date().dayOfYear();
203 vRise << QPointF( rTime, dy );
204 vSet << QPointF( sTime, dy );
205 vTransit << QPointF( tTime, dy );
211 KPlotObject *oRise =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
212 KPlotObject *oSet =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
213 KPlotObject *oTransit =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
214 bool needRiseLabel =
true;
215 bool needSetLabel =
true;
216 bool needTransertLabel =
true;
219 for (
int i=0; i<vRise.size(); ++i ) {
222 if ( vRise.at( i ).x() > -23.0 && vRise.at( i ).x() < 23.0 ) {
226 if ( i > 0 && fabs( vRise.at( i ).x() - vRise.at( i-1 ).x() ) > 6.0 ) {
227 scUI->CalendarView->addPlotObject( oRise );
228 oRise =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
229 needRiseLabel =
true;
233 && vRise.at(i).x() > scUI->CalendarView->getSetTime( i )
234 && vRise.at(i).x() < scUI->CalendarView->getRiseTime( i ) ) {
235 label =
i18nc(
"A planet rises from the horizon",
"%1 rises", ksp->
name() );
236 needRiseLabel =
false;
241 if ( vRise.at(i).x() >= scUI->CalendarView->getRiseTime( i ) )
242 needRiseLabel =
true;
244 oRise->addPoint( vRise.at(i), label );
246 scUI->CalendarView->addPlotObject( oRise );
247 oRise =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
248 needRiseLabel =
true;
252 if ( vSet.at( i ).x() > -23.0 && vSet.at( i ).x() < 23.0) {
253 if ( i > 0 && fabs( vSet.at( i ).x() - vSet.at( i-1 ).x() ) > 6.0 ) {
254 scUI->CalendarView->addPlotObject( oSet );
255 oSet =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
258 if ( needSetLabel && vSet.at(i).x() > scUI->CalendarView->getSetTime( i ) && vSet.at(i).x() < scUI->CalendarView->getRiseTime( i ) ){
259 label =
i18nc(
"A planet sets from the horizon",
"%1 sets", ksp->
name() );
260 needSetLabel =
false;
263 if ( vSet.at(i).x() <= scUI->CalendarView->getSetTime( i ) )
265 oSet->addPoint( vSet.at(i), label );
267 scUI->CalendarView->addPlotObject( oSet );
268 oSet =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
273 if ( vTransit.at( i ).x() > -23.0 && vTransit.at( i ).x() < 23.0) {
274 if ( i > 0 && fabs( vTransit.at( i ).x() - vTransit.at( i-1 ).x() ) > 6.0 ) {
275 scUI->CalendarView->addPlotObject( oTransit );
276 oTransit =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
277 needTransertLabel =
true;
279 if ( needTransertLabel && vTransit.at(i).x() > scUI->CalendarView->getSetTime( i ) && vTransit.at(i).x() < scUI->CalendarView->getRiseTime( i ) ) {
280 label =
i18nc(
"A planet transits across the meridian",
"%1 transits", ksp->
name() );
281 needTransertLabel =
false;
284 if ( vTransit.at(i).x() <= scUI->CalendarView->getSetTime( i ) || vTransit.at(i).x() >= scUI->CalendarView->getRiseTime( i ) )
285 needTransertLabel =
true;
286 oTransit->addPoint( vTransit.at(i), label );
288 scUI->CalendarView->addPlotObject( oTransit );
289 oTransit =
new KPlotObject( pColor, KPlotObject::Lines, 2.0 );
290 needTransertLabel =
true;
295 scUI->CalendarView->addPlotObject( oRise );
296 scUI->CalendarView->addPlotObject( oSet );
297 scUI->CalendarView->addPlotObject( oTransit );
305 int text_height = 200;
308 int calendar_font_size;
311 printer.setResolution( 300 );
314 QPointer<QPrintDialog> dialog( KdePrint::createPrintDialog( &printer,
this ) );
315 dialog->setWindowTitle( i18n(
"Print sky calendar" ) );
316 if ( dialog->exec() == QDialog::Accepted ) {
318 QApplication::setOverrideCursor( Qt::WaitCursor );
321 calendar_font = scUI->CalendarView->font();
323 calendar_font_size = calendar_font.pointSize();
325 calendar_size = scUI->CalendarView->size();
328 str_year.setNum( year() );
329 str_legend = i18n(
"Sky Calendar" );
331 str_legend += geo->fullName();
333 str_legend += str_year;
336 QRect text_rect( 0, 0, printer.width(), text_height );
339 calendar_font.setPointSize( calendar_font_size * 3 );
340 scUI->CalendarView->setFont( calendar_font );
342 scUI->CalendarView->resize( printer.width(), printer.height() - text_height );
345 QPixmap pixmap( scUI->CalendarView->size() );
346 scUI->CalendarView->render( &pixmap );
351 p.drawText( text_rect, Qt::AlignLeft, str_legend );
353 p.drawPixmap( 0, text_height, pixmap );
358 calendar_font.setPointSize( calendar_font_size );
359 scUI->CalendarView->setFont( calendar_font );
361 scUI->CalendarView->resize( calendar_size );
364 QApplication::restoreOverrideCursor();
371 if ( ld->exec() == QDialog::Accepted ) {
375 scUI->LocationButton->setText( geo->fullName() );
380 scUI->CalendarView->setHorizon();
389 #include "skycalendar.moc"
dms transitAltitude(const KStarsDateTime &dt, const GeoLocation *geo)
Dialog for changing the geographic location of the observer.
SkyCalendarUI(QWidget *p=0)
static KStarsData * Instance()
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true)
Determine the time at which the point will rise or set.
QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo)
The same iteration technique described in riseSetTime() is used here.
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
i18nc("string from libindi, used in the config dialog","100x")
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
SkyMapComposite * skyComposite()
KSPlanetBase * planet(int n)
A subclass of TrailObject that provides additional information needed for most solar system objects...
virtual QString name(void) const
SkyCalendar(QWidget *parent=0)