~ubuntu-branches/debian/jessie/stellarium/jessie

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * Stellarium
 * Copyright (C) 2008 Nigel Kerr
 * Copyright (C) 2012 Timothy Reaves
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
*/

#include "Dialog.hpp"
#include "DateTimeDialog.hpp"
#include "StelApp.hpp"
#include "StelCore.hpp"
#include "StelLocaleMgr.hpp"
#include "StelUtils.hpp"

#include "ui_dateTimeDialogGui.h"

#include <QDebug>
#include <QFrame>
#include <QLineEdit>

DateTimeDialog::DateTimeDialog(QObject* parent) :
  StelDialog(parent),
  year(0),
  month(0),
  day(0),
  hour(0),
  minute(0),
  second(0),
  jd(0),
  mjd(0)
{
	ui = new Ui_dateTimeDialogForm;
}

DateTimeDialog::~DateTimeDialog()
{
	delete ui;
	ui=NULL;
}

void DateTimeDialog::createDialogContent()
{
	ui->setupUi(dialog);
	double cjd = StelApp::getInstance().getCore()->getJDay();
	// UTC -> local tz
	// Add in a DeltaT correction. Divide DeltaT by 86400 to convert from seconds to days.
	double deltaT = 0.;
	if (StelApp::getInstance().getCore()->getCurrentLocation().planetName=="Earth")
		deltaT = StelApp::getInstance().getCore()->getDeltaT(cjd)/86400.;
	setDateTime(cjd + (StelApp::getInstance().getLocaleMgr().getGMTShift(cjd)/24.0)-deltaT);

	connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
	connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close()));

	connectSpinnerEvents();
}

void DateTimeDialog::connectSpinnerEvents() const
{
	connect(ui->spinner_year, SIGNAL(valueChanged(int)), this, SLOT(yearChanged(int)));
	connect(ui->spinner_month, SIGNAL(valueChanged(int)), this, SLOT(monthChanged(int)));
	connect(ui->spinner_day, SIGNAL(valueChanged(int)), this, SLOT(dayChanged(int)));
	connect(ui->spinner_hour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)));
	connect(ui->spinner_minute, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)));
	connect(ui->spinner_second, SIGNAL(valueChanged(int)), this, SLOT(secondChanged(int)));
	connect(ui->spinner_jd, SIGNAL(valueChanged(double)), this, SLOT(jdChanged(double)));
	connect(ui->spinner_mjd, SIGNAL(valueChanged(double)), this, SLOT(mjdChanged(double)));
}

void DateTimeDialog::disconnectSpinnerEvents()const
{
	disconnect(ui->spinner_year, SIGNAL(valueChanged(int)), this, SLOT(yearChanged(int)));
	disconnect(ui->spinner_month, SIGNAL(valueChanged(int)), this, SLOT(monthChanged(int)));
	disconnect(ui->spinner_day, SIGNAL(valueChanged(int)), this, SLOT(dayChanged(int)));
	disconnect(ui->spinner_hour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)));
	disconnect(ui->spinner_minute, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)));
	disconnect(ui->spinner_second, SIGNAL(valueChanged(int)), this, SLOT(secondChanged(int)));
	disconnect(ui->spinner_jd, SIGNAL(valueChanged(double)), this, SLOT(jdChanged(double)));
	disconnect(ui->spinner_mjd, SIGNAL(valueChanged(double)), this, SLOT(mjdChanged(double)));
}


//! take in values, adjust for calendrical correctness if needed, and push to
//! the widgets and signals
bool DateTimeDialog::valid(int y, int m, int d, int h, int min, int s)
{
	int dy, dm, dd, dh, dmin, ds;

	if (!StelUtils::changeDateTimeForRollover(y, m, d, h, min, s, &dy, &dm, &dd, &dh, &dmin, &ds)) {
		dy = y;
		dm = m;
		dd = d;
		dh = h;
		dmin = min;
		ds = s;
	}

	year = dy;
	month = dm;
	day = dd;
	hour = dh;
	minute = dmin;
	second = ds;
	pushToWidgets();
	StelApp::getInstance().getCore()->setJDay(newJd());
	return true;
}

bool DateTimeDialog::validJd(double jday)
{
	pushToWidgets();
	// local tz -> UTC
	StelApp::getInstance().getCore()->setJDay(jday-StelApp::getInstance().getLocaleMgr().getGMTShift(jday)/24.+StelApp::getInstance().getCore()->getDeltaT(jday)/86400.);
	return true;
}

bool DateTimeDialog::validMjd(double mjday)
{
	pushToWidgets();
	// local tz -> UTC
	StelApp::getInstance().getCore()->setMJDay(mjday-StelApp::getInstance().getLocaleMgr().getGMTShift(mjday)/24.+StelApp::getInstance().getCore()->getDeltaT(mjday)/86400.);
	return true;
}

void DateTimeDialog::retranslate()
{
	if (dialog) {
		ui->retranslateUi(dialog);
	}
}

void DateTimeDialog::styleChanged()
{
	// Nothing for now
}

void DateTimeDialog::close()
{
	ui->dateTimeBox->setFocus();
	StelDialog::close();
}

/************************************************************************
 year slider or dial changed
************************************************************************/

void DateTimeDialog::yearChanged(int newyear)
{
	if ( year != newyear )
	{
		valid( newyear, month, day, hour, minute, second );
	}
}
void DateTimeDialog::monthChanged(int newmonth)
{
	if ( month != newmonth )
	{
		valid( year, newmonth, day, hour, minute, second );
	}
}
void DateTimeDialog::dayChanged(int newday)
{
	if ( day != newday )
	{
		valid( year, month, newday, hour, minute, second );
	}
}
void DateTimeDialog::hourChanged(int newhour)
{
	if ( hour != newhour )
	{
		valid( year, month, day, newhour, minute, second );
	}
}
void DateTimeDialog::minuteChanged(int newminute)
{
	if ( minute != newminute )
	{
		valid( year, month, day, hour, newminute, second );
	}
}
void DateTimeDialog::secondChanged(int newsecond)
{
	if ( second != newsecond )
	{
		valid( year, month, day, hour, minute, newsecond );
	}
}
void DateTimeDialog::jdChanged(double njd)
{
	if ( jd != njd)
	{
		validJd(njd);
	}
}
void DateTimeDialog::mjdChanged(double nmjd)
{
	if ( mjd != nmjd)
	{
		validMjd(nmjd);
	}
}


double DateTimeDialog::newJd()
{
	double cjd;
	StelUtils::getJDFromDate(&cjd, year, month, day, hour, minute, second);
	// Add in a DeltaT correction. Divide DeltaT by 86400 to convert from seconds to days.
	double deltaT = 0.;
	if (StelApp::getInstance().getCore()->getCurrentLocation().planetName=="Earth")
		deltaT = StelApp::getInstance().getCore()->getDeltaT(cjd)/86400.;
	cjd -= (StelApp::getInstance().getLocaleMgr().getGMTShift(cjd)/24.0-deltaT); // local tz -> UTC
	return cjd;
}

void DateTimeDialog::pushToWidgets()
{
	disconnectSpinnerEvents();
	ui->spinner_year->setValue(year);
	ui->spinner_month->setValue(month);
	ui->spinner_day->setValue(day);
	ui->spinner_hour->setValue(hour);
	if (!ui->spinner_minute->hasFocus() || (ui->spinner_minute->value() == -1) || (ui->spinner_minute->value() == 60))
	{
		ui->spinner_minute->setValue(minute);
	}
	if (!ui->spinner_second->hasFocus() || (ui->spinner_second->value() == -1) || (ui->spinner_second->value() == 60))
	{
		ui->spinner_second->setValue(second);
	}
	if (!ui->spinner_jd->hasFocus())
	{
		ui->spinner_jd->setValue(jd);
	}
	if (!ui->spinner_mjd->hasFocus())
	{
		ui->spinner_mjd->setValue(mjd);
	}
	connectSpinnerEvents();
}

/************************************************************************
Send newJd to spinner_*
 ************************************************************************/
void DateTimeDialog::setDateTime(double newJd)
{
	if (this->visible()) {
		// Add in a DeltaT correction. Divide DeltaT by 86400 to convert from seconds to days.
		double deltaT = 0.;
		if (StelApp::getInstance().getCore()->getCurrentLocation().planetName=="Earth")
			deltaT = StelApp::getInstance().getCore()->getDeltaT(newJd)/86400.;
		newJd += (StelApp::getInstance().getLocaleMgr().getGMTShift(newJd)/24.0-deltaT); // UTC -> local tz
		StelUtils::getDateFromJulianDay(newJd, &year, &month, &day);
		StelUtils::getTimeFromJulianDay(newJd, &hour, &minute, &second);
		jd = newJd;
		mjd = newJd-2400000.5;
		pushToWidgets();
	}
}