• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 6685397774

29 Oct 2023 07:37PM UTC coverage: 11.735% (-0.002%) from 11.737%
6685397774

push

github

10110111
Deduplicate title bar implementation

131 of 131 new or added lines in 56 files covered. (100.0%)

14842 of 126472 relevant lines covered (11.74%)

21617.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/plugins/Observability/src/gui/ObservabilityDialog.cpp
1
/*
2
 * Stellarium Observability Plug-in GUI
3
 *
4
 * Copyright (C) 2012 Ivan Marti-Vidal (based on code by Alexander Wolf)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
19
*/
20

21
#include <QDebug>
22
#include <QFileDialog>
23

24
#include "StelApp.hpp"
25
#include "StelCore.hpp"
26
#include "ui_ObservabilityDialog.h"
27
#include "ObservabilityDialog.hpp"
28
#include "Observability.hpp"
29
#include "StelModuleMgr.hpp"
30
#include "StelObjectMgr.hpp"
31
#include "StelMovementMgr.hpp"
32
#include "StelStyle.hpp"
33
#include "StelGui.hpp"
34
#include "StelMainView.hpp"
35
#include "StelFileMgr.hpp"
36
#include "StelTranslator.hpp"
37

38
ObservabilityDialog::ObservabilityDialog() : StelDialog("Observability")
×
39
{
40
        ui = new Ui_ObservabilityDialog;
×
41
}
×
42

43
ObservabilityDialog::~ObservabilityDialog()
×
44
{
45
        delete ui;
×
46
}
×
47

48
void ObservabilityDialog::retranslate()
×
49
{
50
        if (dialog)
×
51
        {
52
                ui->retranslateUi(dialog);
×
53
                setAboutHtml();
×
54
                updateControls(); // Also re-translate the dynamic slider labels
×
55
        }
56
}
×
57

58
// Initialize the dialog widgets and connect the signals/slots
59
void ObservabilityDialog::createDialogContent()
×
60
{
61
        ui->setupUi(dialog);
×
62
        ui->tabs->setCurrentIndex(0);
×
63
        connect(&StelApp::getInstance(),
×
64
                SIGNAL(languageChanged()), this, SLOT(retranslate()));
65

66
        Observability* plugin = GETSTELMODULE(Observability);
×
67

68
        // Kinetic scrolling
69
        kineticScrollingList << ui->aboutTextBrowser;
×
70
        StelGui* gui= dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
71
        if (gui)
×
72
        {
73
                enableKineticScrolling(gui->getFlagUseKineticScrolling());
×
74
                connect(gui, SIGNAL(flagUseKineticScrollingChanged(bool)), this, SLOT(enableKineticScrolling(bool)));
×
75
        }
76

77
        // Settings:
78
        
79
        // clicked() is called only when the user makes an input,
80
        // so we avoid an endless loop when setting the value in updateControls().
81
        connect(ui->todayCheckBox, SIGNAL(clicked(bool)),
×
82
                plugin, SLOT(enableTodayField(bool)));
83
        connect(ui->acroCosCheckBox, SIGNAL(clicked(bool)),
×
84
                plugin, SLOT(enableAcroCosField(bool)));
85
        connect(ui->oppositionCheckBox, SIGNAL(clicked(bool)),
×
86
                plugin, SLOT(enableOppositionField(bool)));
87
        connect(ui->goodNightsCheckBox, SIGNAL(clicked(bool)),
×
88
                plugin, SLOT(enableGoodNightsField(bool)));
89
        connect(ui->fullMoonCheckBox, SIGNAL(clicked(bool)),
×
90
                plugin, SLOT(enableFullMoonField(bool)));
91

92
        connect(ui->redSlider, SIGNAL(sliderMoved(int)),
×
93
                this, SLOT(setColor()));
94
        connect(ui->greenSlider, SIGNAL(sliderMoved(int)),
×
95
                this, SLOT(setColor()));
96
        connect(ui->blueSlider, SIGNAL(sliderMoved(int)),
×
97
                this, SLOT(setColor()));
98
        
99
        // Isn't valueChanged() better? But then we'll have to block
100
        // signals when setting the slider values.
101
        connect(ui->fontSize, SIGNAL(sliderMoved(int)),
×
102
                plugin, SLOT(setFontSize(int)));
103
        connect(ui->sunAltitudeSlider, SIGNAL(sliderMoved(int)),
×
104
                plugin, SLOT(setTwilightAltitude(int)));
105
        connect(ui->sunAltitudeSlider, SIGNAL(sliderMoved(int)),
×
106
                this, SLOT(updateAltitudeLabel(int)));
107
        connect(ui->horizonAltitudeSlider, SIGNAL(sliderMoved(int)),
×
108
                plugin, SLOT(setHorizonAltitude(int)));
109
        connect(ui->horizonAltitudeSlider, SIGNAL(sliderMoved(int)),
×
110
                this, SLOT(updateHorizonLabel(int)));
111

112
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
113
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
114
        connect(ui->restoreDefaultsButton, SIGNAL(clicked()),
×
115
                this, SLOT(restoreDefaults()));
116
        // TODO: The plug-in should emit a signal when settings are changed.
117
        // This works, because slots are called in the order they were connected.
118
        connect(ui->restoreDefaultsButton, SIGNAL(clicked()),
×
119
                this, SLOT(updateControls()));
120
        connect(ui->saveSettingsButton, SIGNAL(clicked()),
×
121
                plugin, SLOT(saveConfiguration()));
122

123
        // About tab
124
        setAboutHtml();
×
125
        if(gui!=Q_NULLPTR)
×
126
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(QString(gui->getStelStyle().htmlStyleSheet));
×
127

128
        updateControls();
×
129
        ui->todayCheckBox->hide(); // DISABLED for 0.21.2. No longer needed.
×
130
}
×
131

132
void ObservabilityDialog::restoreDefaults()
×
133
{
134
        if (askConfirmation())
×
135
        {
136
                qDebug() << "[Observability] restore defaults...";
×
137
                GETSTELMODULE(Observability)->resetConfiguration();
×
138
        }
139
        else
140
                qDebug() << "[Observability] restore defaults is canceled...";
×
141
}
×
142

143
void ObservabilityDialog::setAboutHtml(void)
×
144
{
145
        QString html = "<html><head></head><body>";
×
146

147
        html += "<h2>" + q_("Observability Plug-in") + "</h2><table width=\"90%\">";
×
148
        html += "<tr width=\"30%\"><td><strong>" + q_("Version") + ":</strong></td><td>" + OBSERVABILITY_PLUGIN_VERSION + "</td></tr>";
×
149
        html += "<tr><td><strong>" + q_("License") + ":</strong></td><td>" + OBSERVABILITY_PLUGIN_LICENSE + "</td></tr>";
×
150
        html += "<tr><td><strong>" + q_("Author") + ":</strong></td><td>Ivan Marti-Vidal &lt;i.martividal@gmail.com&gt;</td></tr></table>";
×
151

152
        html += "<p>" + q_("Plugin that analyzes the observability of the selected source (or the screen center, if no source is selected). The plugin can show rise, transit, and set times, as well as the best epoch of the year (i.e., largest angular separation from the Sun), the date range when the source is above the horizon at dark night, and the dates of Acronychal and Cosmical rise/set.<br>Ephemeris of the Solar-System objects and parallax effects are taken into account.<br><br> The author thanks Alexander Wolf and Georg Zotti for their advice.<br><br>Ivan Marti-Vidal (Onsala Space Observatory)") + "</p>";
×
153

154
        html += "<h3>" + q_("Explanation of some parameters") + "</h3><table width=\"90%\">";
×
155
        html += QString("<tr><td>%1</td><td>%2</td></tr>").arg(q_("Sun altitude at twilight:"), q_("Any celestial object will be considered visible when the Sun is below this altitude. The altitude at astronomical twilight ranges usually between -12 and -18 degrees. This parameter is only used for the estimate of the range of observable epochs (see below)."));
×
156

157
        html += QString("<tr><td>%1</td><td>%2</td></tr>").arg(q_("Horizon altitude:"), q_("Minimum observable altitude (due to mountains, buildings, or just a limited telescope mount)."));
×
158

159
        html += QString("<tr><td>%1</td><td>%2</td></tr>").arg(q_("Today ephemeris:"), q_("Self-explanatory. The program will show the rise, set, and culmination (transit) times. The exact times for these ephemeris are given in two ways: as time spans (referred to the current time) and as clock hours (in local time)."));
×
160
        html += QString("<tr><td>%1</td><td>%2</td></tr>").arg(q_("Acronychal/Cosmical/Heliacal rise/set:"), q_("The days of Cosmical rise/set of an object are defined as the days when the object rises (or sets) together with the rise/set of the Sun. The exact dates of these events depend on the Observer's location.  In contrast, the Acronychal rise (or set) happens when the star rises/sets with the setting/rising of the Sun (i.e., opposite to the Sun). On the one hand, it is obvious that the source is hardly observable (or not observable at all) in the dates between Cosmical set and Cosmical rise. On the other hand, the dates around the Acronychal set and rise are those when the altitude of the celestial object uses to be high when the Sun is well below the horizon (hence the object can be well observed). The date of Heliacal rise is the first day of the year when a star becomes visible. It happens when the star rises along the eastern horizon before disappearing in the morning twilight. In the following nights, the star will be visible during longer periods of time, until it reaches its Heliacal set (i.e., the last night of the year when the star is still visible). At the Heliacal set, the star sets after becoming visible for just a moment shortly after sunset."));
×
161
        html += QString("<tr><td>%1</td><td>%2</td></tr>").arg(q_("Largest Sun separation:"), q_("Happens when the angular separation between the Sun and the celestial object are maximum. In most cases, this is equivalent to say that the Equatorial longitudes of the Sun and the object differ by 180 degrees, so the Sun is in opposition to the object. When an object is at its maximum possible angular separation from the Sun (no matter if it is a planet or a star), it culminates roughly at midnight, and on the darkest possible area of the Sky at that declination. Hence, that is the 'best' night to observe a particular object."));
×
162
        html += QString("<tr><td>%1</td><td>%2</td></tr>").arg(q_("Nights with source above horizon:"), q_("The program computes the range of dates when the celestial object is above the horizon at least during one moment of the night. By 'night', the program considers the time span when the Sun altitude is below that of the twilight (which can be set by the user; see above). When the objects are fixed on the sky (or are exterior planets), the range of observable epochs for the current year can have two possible forms: either a range from one date to another (e.g., 20 Jan to 15 Sep) or in two steps (from 1 Jan to a given date and from another date to 31 Dec). In the first case, the first date (20 Jan in our example) shall be close to the so-called 'Heliacal rise of a star' and the second date (15 Sep in our example) shall be close to the 'Heliacal set'. In the second case (e.g., a range in the form 1 Jan to 20 May and 21 Sep to 31 Dec), the first date (20 May in our example) would be close to the Heliacal set and the second one (21 Sep in our example) to the Heliacal rise. More exact equations to estimate the Heliacal rise/set of stars and planets (which will not depend on the mere input of a twilight Sun elevation by the user) will be implemented in future versions of this plugin."));
×
163
        html += QString("<tr><td>%1</td><td>%2</td></tr>").arg(q_("Full Moon:"), q_("When the Moon is selected, the program can compute the exact closest dates of the Moon's opposition to the Sun."));
×
164
        html += "</table>";
×
165
        html += "</body></html>";
×
166

167
        ui->aboutTextBrowser->setHtml(html);
×
168
}
×
169

170
void ObservabilityDialog::updateControls()
×
171
{
172
        Observability* plugin = GETSTELMODULE(Observability);
×
173
        
174
        ui->todayCheckBox->setChecked(plugin->getShowFlags(1));
×
175
        ui->acroCosCheckBox->setChecked(plugin->getShowFlags(2));
×
176
        ui->goodNightsCheckBox->setChecked(plugin->getShowFlags(3));
×
177
        ui->oppositionCheckBox->setChecked(plugin->getShowFlags(4));
×
178
        ui->fullMoonCheckBox->setChecked(plugin->getShowFlags(5));
×
179
//        ui->Crescent->setChecked(GETSTELMODULE(Observability)->getShowFlags(6));
180
//        ui->SuperMoon->setChecked(GETSTELMODULE(Observability)->getShowFlags(7));
181

182
        Vec3f fontColor = plugin->getFontColor();
×
183
        int red = static_cast<int>(100.f*fontColor[0]);
×
184
        int green = static_cast<int>(100.f*fontColor[1]);
×
185
        int blue = static_cast<int>(100.f*fontColor[2]);
×
186
        ui->redSlider->setValue(red);
×
187
        ui->greenSlider->setValue(green);
×
188
        ui->blueSlider->setValue(blue);
×
189

190
        ui->fontSize->setValue(plugin->getFontSize());
×
191
        int sunAltitude = plugin->getTwilightAltitude();
×
192
        ui->sunAltitudeSlider->setValue(sunAltitude);
×
193
        updateAltitudeLabel(sunAltitude);
×
194
        int horizonAltitude = plugin->getHorizonAltitude();
×
195
        ui->horizonAltitudeSlider->setValue(horizonAltitude);
×
196
        updateHorizonLabel(horizonAltitude);
×
197
}
×
198

199
void ObservabilityDialog::setColor()
×
200
{
201
        int red = ui->redSlider->value();
×
202
        int green = ui->greenSlider->value();
×
203
        int blue = ui->blueSlider->value();
×
204

205
        float fRed =   static_cast<float>(red) / 100.f;
×
206
        float fGreen = static_cast<float>(green) / 100.f;
×
207
        float fBlue =  static_cast<float>(blue) / 100.f;
×
208
        
209
        Vec3f color(fRed, fGreen, fBlue);
×
210
        GETSTELMODULE(Observability)->setFontColor(color);
×
211
}
×
212

213
void ObservabilityDialog::updateAltitudeLabel(int altitude)
×
214
{
215
        // This allows translators to use their own conventions for degree signs.
216
        ui->sunAltitudeLabel->setText(q_("Sun altitude at twilight: %1 deg.").arg(altitude));
×
217
}
×
218

219
void ObservabilityDialog::updateHorizonLabel(int horizon)
×
220
{
221
        // This allows translators to use their own conventions for degree signs.
222
        ui->horizonAltitudeLabel->setText(q_("Horizon altitude: %1 deg.").arg(horizon));
×
223
}
×
224

225

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc