forked from AlphaKnot/PlanItTime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolarwidget.cpp
93 lines (71 loc) · 2.72 KB
/
solarwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<QPainter>
#include<QDir>
#include<string>
#include<QTimer>
#include <QLabel>
#include "solarwidget.h"
#include "Planets.h"
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
/**
* @brief SolarWidget::SolarWidget this class implements the solar system of the ui as well as the asteroid
* @param parent the parent widget which it inherits from
*/
SolarWidget::SolarWidget(QWidget *parent) : QWidget(parent){
time_check = time_check.currentDateTime().addYears(-1);
QTimer *timer = new QTimer(this);
connect(timer,&QTimer::timeout,this,&SolarWidget::computePosition);
timer->start(1);
computePosition();
QWidget::update();
resize(600,500);
}
/**
* @brief SolarWidget::paintEvent this widget paints the solar system rings
* @param event the painting event
*/
void SolarWidget::paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.setPen(Qt::darkGray);
for (int i = 1; i < 9; i++){
painter.drawEllipse(QPoint(210,210),i*25,i*25);
}
}
/**
* @brief SolarWidget::computePosition this method adds the planets to the system and animates them to be in real time. it also animates the asteroids
*/
void SolarWidget::computePosition(){
QDateTime dateTime;
dateTime = dateTime.currentDateTime();
if (dateTime.toString("yyyyMddhhmm").toDouble() > time_check.toString("yyyyMddhhmm").toDouble()){
// delete all prior labels
while (QWidget* w = findChild<QWidget*>()){
delete w;
}
// compute planets given time
Planets p = Planets(
dateTime.toString("yyyy").toDouble(),
dateTime.toString("MM").toDouble(),
dateTime.toString("dd").toDouble(),
dateTime.toString("H").toDouble(),
dateTime.toString("mm").toDouble()
);
// set OrbitalElements vector
planets = p.getPlanets();
std::string planetList[8] = {"mercury","venus","earth","mars","jupiter","saturn","uranus","neptune"};
for (int i = 0; i < planets.size(); i++){
QLabel* planet = new QLabel(this);
OrbitalElements current_planet = planets.at(i);
planet->setGeometry(current_planet.getEclipX()+200,(-current_planet.getEclipY())+200,20,20);
QPixmap pixmap = QPixmap(":/assets/"+QString::fromStdString(planetList[i])+".png");
planet->setPixmap(pixmap.scaled(20,20));
planet->show();
}
QLabel* sunLabel = new QLabel(this);
sunLabel->setGeometry(200,200,24,24);
QPixmap pixmap = QPixmap(":/assets/sun.png");
sunLabel->setPixmap(pixmap.scaled(24,24));
sunLabel->show();
time_check = dateTime;
}
}