Kstars

polarishourangle.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2017 Pavel Mraz
3 
4  SPDX-FileCopyrightText: 2017 Jasem Mutlaq
5 
6  SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #include "polarishourangle.h"
10 
11 #include "skyobject.h"
12 #include "kstarsdata.h"
13 #include "skymapcomposite.h"
14 
15 #include <QPainter>
16 #include <QPen>
17 
18 float hbase = 24;
19 float vangle = 15;
20 
21 PolarisHourAngle::PolarisHourAngle(QWidget *parent) :
22  QDialog(parent),
23  m_polarisHourAngle(0)
24 {
25  setupUi(this);
27 
28  SkyObject *polaris = KStarsData::Instance()->skyComposite()->findByName(i18nc("star name", "Polaris"));
29  Q_ASSERT_X(polaris != nullptr, "PolarisHourAngle", "Unable to find Polaris!");
30  m_polaris = polaris->clone();
31 
32  m_reticle12.reset(new QPixmap(":/images/reticle12.png"));
33  m_reticle24.reset(new QPixmap(":/images/reticle24.png"));
34 
35  connect(dateTimeEdit, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(onTimeUpdated(QDateTime)));
36  connect(currentTimeB, &QPushButton::clicked, this, [this]() { dateTimeEdit->setDateTime(KStarsData::Instance()->lt()); });
37  connect(twelveHourR, SIGNAL(toggled(bool)), this, SLOT(update()));
38 
39  dateTimeEdit->setDateTime(KStarsData::Instance()->lt());
40 }
41 
42 void PolarisHourAngle::paintEvent(QPaintEvent *)
43 {
44  QPainter p(this);
45  QPointF center = frame->rect().center();
46  double r1 = 175;
47 
48  p.setRenderHint(QPainter::Antialiasing);
49  p.setRenderHint(QPainter::SmoothPixmapTransform);
50 
51  p.drawPixmap(frame->pos(), twelveHourR->isChecked() ? *(m_reticle12.get()) : *(m_reticle24.get()));
52  p.setPen(Qt::yellow);
53  p.setBrush(Qt::white);
54  p.translate(frame->pos());
55 
56 // double angle = (24.0 - m_polarisHourAngle) * 15.0;
57  double angle = (hbase - m_polarisHourAngle) * vangle;
58  p.save();
59 
60  p.translate(center);
61  p.rotate(angle);
62 
63  QPolygon poly;
64 
66  p.setBrush(p.pen().color());
67 
68  poly << QPoint(0, r1);
69  poly << QPoint(10, -10);
70  poly << QPoint(5, -14);
71  poly << QPoint(-5, -14);
72  poly << QPoint(-10, -10);
73  poly << QPoint(0, r1);
74 
75  p.drawPolygon(poly);
76 
77  p.restore();
78 }
79 
80 void PolarisHourAngle::onTimeUpdated(QDateTime newDateTime)
81 {
82  KStarsDateTime lt(newDateTime);
83  KSNumbers num(lt.djd());
84  m_polaris->updateCoords(&num, false);
85  dms lst = KStarsData::Instance()->geo()->GSTtoLST(lt.gst());
86 /*
87  m_polarisHourAngle = (lst.Degrees() - m_polaris->ra().Degrees())/15.0;
88  while (m_polarisHourAngle > 24)
89  m_polarisHourAngle -= 24;
90  while (m_polarisHourAngle < 0)
91  m_polarisHourAngle += 24;
92 */
93  m_polarisHourAngle = (lst.Degrees() - m_polaris->ra().Degrees())/vangle;
94  while (m_polarisHourAngle > hbase)
95  m_polarisHourAngle -= hbase;
96  while (m_polarisHourAngle < hbase)
97  m_polarisHourAngle += hbase;
98 
99  labelPolarisHA->setText(dms(m_polarisHourAngle*vangle).toHMSString());
100  labelDate->setText(newDateTime.date().toString());
101  labelTime->setText(newDateTime.time().toString());
102 
103  update();
104 }
QTextStream & center(QTextStream &s)
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
MiterJoin
void update()
QTime time() const const
void clicked(bool checked)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
const QString toHMSString(const bool machineReadable=false, const bool highPrecision=false) const
Definition: dms.cpp:370
virtual SkyObject * clone() const
Create copy of object.
Definition: skyobject.cpp:50
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument.
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
SquareCap
GeoLocation * geo()
Definition: kstarsdata.h:229
void setupUi(QWidget *widget)
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:165
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
void setFixedHeight(int h)
const double & Degrees() const
Definition: dms.h:141
void update(Part *part, const QByteArray &data, qint64 dataSize)
QDate date() const const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString toString(Qt::DateFormat format) const const
QString toString(Qt::DateFormat format) const const
QTextStream & center(QTextStream &stream)
SolidLine
Information about an object in the sky.
Definition: skyobject.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.