• 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/OnlineQueries/src/gui/OnlineQueriesDialog.cpp
1
/*
2
 * Stellarium OnlineQueries Plug-in
3
 *
4
 * Copyright (C) 2020-21 Georg Zotti
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 "OnlineQueriesDialog.hpp"
22
#include "OnlineQueries.hpp"
23
#include "StelWebEngineView.hpp"
24

25
#include <QPushButton>
26
#include <QDesktopServices>
27
#include "StelModuleMgr.hpp"
28
#include "StelApp.hpp"
29
#include "StelGui.hpp"
30
#include "StelTranslator.hpp"
31

32
OnlineQueriesDialog::OnlineQueriesDialog(QObject* parent) :
×
33
        StelDialogSeparate("OnlineQueries", parent),
34
        plugin(nullptr),
×
35
        view(nullptr)
×
36
{
37
        setObjectName("OnlineQueriesDialog");
×
38
        ui = new Ui_onlineQueriesDialogForm;
×
39
}
×
40

41
OnlineQueriesDialog::~OnlineQueriesDialog()
×
42
{
43
        delete ui;
×
44
        if (view) delete view;
×
45
}
×
46

47
void OnlineQueriesDialog::retranslate()
×
48
{
49
        if (dialog)
×
50
        {
51
                ui->retranslateUi(dialog);
×
52
                setAboutHtml();
×
53
        }
54
}
×
55

56
void OnlineQueriesDialog::createDialogContent()
×
57
{
58
        plugin = GETSTELMODULE(OnlineQueries);
×
59
        Q_ASSERT(plugin);
×
60

61
        //load UI from form file
62
        ui->setupUi(dialog);
×
63
        // Given possible unavailability of QtWebEngine on some platforms,
64
        // we must add this dynamically here. In addition, there are platforms where QtWebEngine appears to be available,
65
        // but fails to initialize properly at runtime. We therefore can only add this as QWidget.
66
        // If manually disabled, we use a QTextBrowser.
67
        if (plugin->webEngineDisabled())
×
68
        {
69
                view = new QTextBrowser();
×
70
        }
71
        else
72
        {
73
                view = new StelWebEngineView();
×
74
        }
75
        Q_ASSERT(view);
×
76
        view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
×
77
        view->setMinimumSize(0, 180);
×
78
        ui->verticalLayout->addWidget(view);
×
79

80
        //hook up retranslate event
81
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
×
82
        //connect UI events
83
        connect(ui->titleBar, &TitleBar::closeClicked, plugin, [=]{ plugin->setEnabled(false);});
×
84
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
85

86
        // Kinetic scrolling and style sheet for output
87
        kineticScrollingList << view;
×
88
        StelGui* gui= dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
89
        if (gui)
×
90
        {
91
                enableKineticScrolling(gui->getFlagUseKineticScrolling());
×
92
                connect(gui, SIGNAL(flagUseKineticScrollingChanged(bool)), this, SLOT(enableKineticScrolling(bool)));
×
93
        }
94
        setAboutHtml();
×
95

96
        connect(ui->wikipediaPushButton,    SIGNAL(clicked()), plugin, SLOT(queryWikipedia()));
×
97
        connect(ui->aavsoPushButton,        SIGNAL(clicked()), plugin, SLOT(queryAAVSO()));
×
98
        connect(ui->gcvsPushButton,         SIGNAL(clicked()), plugin, SLOT(queryGCVS()));
×
99
        // Unfortunately, Ancient-Skies did not resurface so far. Keep this here, maybe re-activate ~2025.
100
        //connect(ui->ancientSkiesPushButton, SIGNAL(clicked()), plugin, SLOT(queryAncientSkies()));
101
        ui->ancientSkiesPushButton->hide();
×
102
        // set custom tab buttons to hostnames, or deactivate unconfigured buttons
103
        if (!plugin->getCustomUrl1().isEmpty())
×
104
        {
105
                ui->custom1PushButton->setText(QUrl(plugin->getCustomUrl1()).host());
×
106
                connect(ui->custom1PushButton, SIGNAL(clicked()), plugin, SLOT(queryCustomSite1()));
×
107
        }
108
        else {
109
                ui->custom1PushButton->setText(qc_("(Custom 1)", "GUI label"));
×
110
                ui->custom1PushButton->setEnabled(false);
×
111
        }
112
        if (!plugin->getCustomUrl2().isEmpty())
×
113
        {
114
                ui->custom2PushButton->setText(QUrl(plugin->getCustomUrl2()).host());
×
115
                connect(ui->custom2PushButton, SIGNAL(clicked()), plugin, SLOT(queryCustomSite2()));
×
116
        }
117
        else {
118
                ui->custom2PushButton->setText(qc_("(Custom 2)", "GUI label"));
×
119
                ui->custom2PushButton->setEnabled(false);
×
120
        }
121
        if (!plugin->getCustomUrl3().isEmpty())
×
122
        {
123
                ui->custom3PushButton->setText(QUrl(plugin->getCustomUrl3()).host());
×
124
                connect(ui->custom3PushButton, SIGNAL(clicked()), plugin, SLOT(queryCustomSite3()));
×
125
        }
126
        else {
127
                ui->custom3PushButton->setText(qc_("(Custom 3)", "GUI label"));
×
128
                ui->custom3PushButton->setEnabled(false);
×
129
        }
130

131
#ifdef WITH_QTWEBENGINE
132
        if (plugin->webEngineDisabled())
×
133
        {
134
                ui->backPushButton->hide();
×
135
                ui->forwardPushButton->hide();
×
136
        }
137
        else
138
        {
139
                connect(ui->backPushButton,    &QPushButton::clicked, this, [=]{static_cast<StelWebEngineView*>(view)->triggerPageAction(QWebEnginePage::Back);});
×
140
                connect(ui->forwardPushButton, &QPushButton::clicked, this, [=]{static_cast<StelWebEngineView*>(view)->triggerPageAction(QWebEnginePage::Forward);});
×
141
        }
142
#else
143
        ui->backPushButton->hide();
144
        ui->forwardPushButton->hide();
145
#endif
146
}
×
147

148
void OnlineQueriesDialog::setOutputHtml(QString html) const
×
149
{
150
        if (plugin->webEngineDisabled())
×
151
        {
152
                static_cast<QTextBrowser*>(view)->setHtml(html);
×
153
        }
154
        else
155
        {
156
                static_cast<StelWebEngineView*>(view)->setHtml(html);
×
157
        }
158
}
×
159

160
void OnlineQueriesDialog::setOutputUrl(QUrl url) const
×
161
{
162
#ifdef WITH_QTWEBENGINE
163
        if (plugin->webEngineDisabled())
×
164
        {
165
                QDesktopServices::openUrl(url);
×
166
                static_cast<QTextBrowser*>(view)->setHtml(QString("<p>" + qc_("Opened %1 in your web browser", "OnlineQueries") + "</p>").arg(url.host()));
×
167
        }
168
        else
169
        {
170
                static_cast<StelWebEngineView*>(view)->setUrl(url);
×
171
        }
172
#else
173
        QDesktopServices::openUrl(url);
174
        static_cast<StelWebEngineView*>(view)->setHtml(QString("<p>" + qc_("Opened %1 in your web browser", "OnlineQueries") + "</p>").arg(url.host()));
175
#endif
176
}
×
177

178
void OnlineQueriesDialog::setAboutHtml()
×
179
{
180
        QString html = "<html><head></head><body>";
×
181
        html += "<h2>" + q_("OnlineQueries Plug-in") + "</h2><table width=\"90%\">";
×
182
        html += "<tr width=\"30%\"><td><strong>" + q_("Version") + ":</strong></td><td>" + ONLINEQUERIES_PLUGIN_VERSION + "</td></tr>";
×
183
        html += "<tr><td><strong>" + q_("License") + ":</strong></td><td>" + ONLINEQUERIES_PLUGIN_LICENSE + "</td></tr>";
×
184
        html += "<tr><td><strong>" + q_("Author") + ":</strong></td><td>Georg Zotti</td></tr>";
×
185
        //html += "<tr><td><strong>" + q_("Contributors") + ":</strong></td><td> List with br separators </td></tr>";
186
        html += "</table>";
×
187

188
        html += "<p>" + q_("The OnlineQueries plugin provides an interface to various online sources for astronomical information.") + "</p>";
×
189
        html += "<ul><li>" + q_("Wikipedia, the free online encyclopedia") + "</li>";
×
190
        html += "<li>" + q_("AAVSO, the International Variable Star Index of the American Association for Variable Star Observers") + "</li>";
×
191
        html += "<li>" + q_("GCVS, the General Catalogue of Variable Stars of the Sternberg Astronomical Institute and the Institute of Astronomy of the Russian Academy of Sciences in Moscow") + "</li>";
×
192
        // Unfortunately, the website this plugin was made for has not come up again. Maybe later, though.
193
        //html += "<li>" + q_("Ancient-Skies, a private project which collects information about star names and their mythologies") + "</li>";
194
        html += "<li>" + q_("3 custom websites of your choice") + "</li>";
×
195
        html += "</ul>";
×
196
        html += "<p>" + q_("Regardless of the current program language, the result is always presented in English or the language of the respective website.") + "</p>";
×
197

198
        html += "<h3>" + q_("Publications") + "</h3>";
×
199
        html += "<p>"  + q_("If you use this plugin in your publications, please cite:") + "</p>";
×
200
        html += "<ul>";
×
201
        html += "<li>" + QString("Georg Zotti, Susanne M. Hoffmann, Doris Vickers, RĂ¼diger Schultz, Alexander Wolf: Revisiting Star Names: Stellarium and the Ancient Skies Database. "
×
202
                                 "In: P. Maglova & Alexey Stoev (eds.). Cultural Astronomy & Ancient Skywatching. Proc. SEAC2021, Plovdiv 2023.").toHtmlEscaped() + "</li>";
×
203
        html += "</ul>";
×
204

205
        html += StelApp::getInstance().getModuleMgr().getStandardSupportLinksInfo("OnlineQueries plugin");
×
206
        html += "</body></html>";
×
207

208
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
×
209
        if(gui!=nullptr)
×
210
        {
211
                QString htmlStyleSheet(gui->getStelStyle().htmlStyleSheet);
×
212
                ui->aboutTextBrowser->document()->setDefaultStyleSheet(htmlStyleSheet);
×
213
        }
×
214
        ui->aboutTextBrowser->setHtml(html);
×
215
}
×
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