Kstars

eqplotwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Jason Harris <kstars@30doradus.org>
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
16eqPlotWidget::eqPlotWidget(QWidget *parent) : KPlotWidget(parent)
17{
18}
19
20//Draw rotated labels and month names on top axis
21void eqPlotWidget::paintEvent(QPaintEvent *e)
22{
24
25 QPainter p;
26 p.begin(this);
27
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
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
72 p.save();
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}
int leftPadding() const
int topPadding() const
void paintEvent(QPaintEvent *) override
QPointF mapToWidget(const QPointF &p) const
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
long double djd() const
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
QObject * parent() const const
bool begin(QPaintDevice *device)
void drawText(const QPoint &position, const QString &text)
bool end()
const QFont & font() const const
void restore()
void rotate(qreal angle)
void save()
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
void translate(const QPoint &offset)
qreal x() const const
qreal y() const const
AlignCenter
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 12:00:41 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.