Kstars

eqplotwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "eqplotwidget.h"
8 
9 #include "kstarsdatetime.h"
10 #include "modcalcvizequinox.h"
11 
12 #include <KLocalizedString>
13 
14 #include <QPainter>
15 
16 eqPlotWidget::eqPlotWidget(QWidget *parent) : KPlotWidget(parent)
17 {
18 }
19 
20 //Draw rotated labels and month names on top axis
21 void eqPlotWidget::paintEvent(QPaintEvent *e)
22 {
24 
25  QPainter p;
26  p.begin(this);
27 
28  modCalcEquinox *mc = (modCalcEquinox *)(parent()->parent()->parent()->parent());
29  KStarsDateTime dt(QDate(mc->Year->value(), 1, 1), QTime(0, 0, 0));
30  long double jd0 = dt.djd(); //save JD on Jan 1st
31 
32  QPointF pSpring = mapToWidget(QPointF(mc->dSpring.djd() - jd0 - 4, -28.0));
33  QPointF pSummer = mapToWidget(QPointF(mc->dSummer.djd() - jd0 - 4, -28.0));
34  QPointF pAutumn = mapToWidget(QPointF(mc->dAutumn.djd() - jd0 - 4, -28.0));
35  QPointF pWinter = mapToWidget(QPointF(mc->dWinter.djd() - jd0 - 4, -28.0));
36 
37  p.setPen(Qt::yellow);
38  QFont f = p.font();
39  f.setPointSize(f.pointSize() - 2);
40  p.setFont(f);
41 
42  p.save();
43  p.translate(leftPadding() + pSpring.x(), topPadding() + pSpring.y());
44  p.rotate(-90);
45  p.drawText(0, 0, i18n("Vernal equinox:"));
46  p.drawText(0, 14, QLocale().toString(mc->dSpring, QLocale::LongFormat));
47  p.restore();
48 
49  p.save();
50  p.translate(leftPadding() + pSummer.x(), topPadding() + pSummer.y());
51  p.rotate(-90);
52  p.drawText(0, 0, i18n("Summer solstice:"));
53  p.drawText(0, 14, QLocale().toString(mc->dSummer, QLocale::LongFormat));
54  p.restore();
55 
56  p.save();
57  p.translate(leftPadding() + pAutumn.x(), topPadding() + pAutumn.y());
58  p.rotate(-90);
59  p.drawText(0, 0, i18n("Autumnal equinox:"));
60  p.drawText(0, 14, QLocale().toString(mc->dAutumn, QLocale::LongFormat));
61  p.restore();
62 
63  p.save();
64  p.translate(leftPadding() + pWinter.x(), topPadding() + pWinter.y());
65  p.rotate(-90);
66  p.drawText(0, 0, i18n("Winter solstice:"));
67  p.drawText(0, 14, QLocale().toString(mc->dWinter, QLocale::LongFormat));
68  p.restore();
69 
70  //Draw month labels along top axis
71  p.setPen(Qt::white);
72  p.save();
73  p.translate(leftPadding(), topPadding());
74  double y = mc->Plot->dataRect().bottom() + 1.5;
75  for (int i = 0; i < 12; i++)
76  {
77  QPoint c;
78  if (i < 11)
79  {
80  c = mc->Plot->mapToWidget(QPointF(0.5 * (mc->dmonth(i) + mc->dmonth(i + 1)), y)).toPoint();
81  }
82  else
83  {
84  c = mc->Plot->mapToWidget(QPointF(0.5 * (mc->dmonth(i) + mc->Plot->dataRect().right()), y)).toPoint();
85  }
86  QRect r(-16, -8, 32, 16);
87  r.moveCenter(c);
89  p.drawText(r, Qt::AlignCenter, locale.monthName(i + 1, QLocale::ShortFormat));
90  }
91  p.restore();
92  p.end();
93 }
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
AlignCenter
void setPen(const QColor &color)
long double djd() const
void rotate(qreal angle)
void drawText(const QPointF &position, const QString &text)
void paintEvent(QPaintEvent *) override
bool begin(QPaintDevice *device)
bool end()
QString i18n(const char *text, const TYPE &arg...)
char * toString(const T &value)
LocaleWrapper locale()
qreal x() const const
qreal y() const const
const QFont & font() const const
void translate(const QPointF &offset)
void restore()
void save()
void setFont(const QFont &font)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 03:59:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.