• 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/SolarSystemEditor/src/gui/ManualImportWindow.cpp
1
/*
2
 * Solar System editor plug-in for Stellarium
3
 *
4
 * Copyright (C) 2010 Bogdan Marinov
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 "SolarSystemEditor.hpp"
22

23
#include "ManualImportWindow.hpp"
24
#include "ui_manualImportWindow.h"
25

26
#include <QColor>
27
#include <QColorDialog>
28
#include <QFileDialog>
29
#include <QImageReader>
30

31
#include "StelApp.hpp"
32
#include "StelFileMgr.hpp"
33
#include "StelModuleMgr.hpp"
34
#include "StelMainView.hpp"
35
//#include "StelTranslator.hpp"
36

37

38
ManualImportWindow::ManualImportWindow(): StelDialog("SolarSystemEditorManualImport")
×
39
{
40
        ui = new Ui_manualImportWindow();
×
41
        ssoManager = GETSTELMODULE(SolarSystemEditor);
×
42
}
×
43

44
ManualImportWindow::~ManualImportWindow()
×
45
{
46
        delete ui;
×
47
}
×
48

49
void ManualImportWindow::createDialogContent()
×
50
{
51
        ui->setupUi(dialog);
×
52

53
        //Signals
54
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()),
×
55
                this, SLOT(retranslate()));
56
        connect(ui->titleBar, &TitleBar::closeClicked, this, &StelDialog::close);
×
57
        connect(ui->titleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint)));
×
58

59
        connect(ui->lineEditColor, SIGNAL(textChanged(QString)), this, SLOT(parseColorString(QString)));
×
60
        connect(ui->pushButtonSelectColor, SIGNAL(clicked()), this, SLOT(selectColor()));
×
61

62
        connect(ui->pushButtonSelectTexture, SIGNAL(clicked()), this, SLOT(selectPlanetTextureFile()));
×
63
        connect(ui->pushButtonSelectRingTexture, SIGNAL(clicked()), this, SLOT(selectRingTextureFile()));
×
64

65
        ui->labelLongitudeOfTheAscendingNode->setText(QString("Longitude of the ascending node %1:").arg(QChar(0x03A9)));//Capital omega
×
66
        ui->radioButtonArgumentOfPeriapsis->setText(QString("Argument of periapsis %1:").arg(QChar(0x3C9)));//Lowercase omega
×
67
        ui->radioButtonLongitudeOfPeriapsis->setText(QString("Longitude of periapsis %1:").arg(QChar(0x3D6)));
×
68

69
        //TODO: Move to "set defaults" function
70
        ui->lineEditColor->setText("1.0, 1.0, 1.0");
×
71
        ui->lineEditTexture->setText("nomap.png");
×
72
        ui->lineEditRingTexture->setText("saturn_rings_radial.png");
×
73
}
×
74

75
void ManualImportWindow::retranslate()
×
76
{
77
        if (dialog)
×
78
                ui->retranslateUi(dialog);
×
79
}
×
80

81
void ManualImportWindow::selectColor()
×
82
{
83
        QColor color = QColorDialog::getColor(objectColor,&StelMainView::getInstance());
×
84
        objectColor =  color;
×
85
        ui->lineEditColor->setText(QString("%1, %2, %3").arg(color.redF()).arg(color.greenF()).arg(color.blueF()));
×
86
        setColorButtonColor(color);
×
87
}
×
88

89
void ManualImportWindow::parseColorString(QString colorCode)
×
90
{
91
        QStringList colorComponents = colorCode.split(QChar(','));
×
92
        int count = colorComponents.count();
×
93
        if ((count < 3) || (count > 4))
×
94
                return;
×
95

96
        bool ok;
97
        double red = colorComponents.at(0).toDouble(&ok);
×
98
        if (!ok || (red < 0.0) || (red > 1.0))
×
99
                return;
×
100
        double green = colorComponents.at(1).toDouble(&ok);
×
101
        if (!ok || (green < 0.0) || (green > 1.0))
×
102
                return;
×
103
        double blue = colorComponents.at(2).toDouble(&ok);
×
104
        if (!ok || (blue < 0.0) || (blue > 1.0))
×
105
                return;
×
106

107
        QColor color;
×
108
        color.setRedF(red);
×
109
        color.setGreenF(green);
×
110
        color.setBlueF(blue);
×
111

112
        if (count == 4)
×
113
        {
114
                double alpha = colorComponents.at(3).toDouble(&ok);
×
115
                if (!ok || (alpha < 0.0) || (alpha > 1.0))
×
116
                        return;
×
117
                color.setAlphaF(alpha);
×
118
        }
119

120
        objectColor = color;
×
121
        setColorButtonColor(color);
×
122
}
×
123

124
void ManualImportWindow::setColorButtonColor(QColor newColor)
×
125
{
126
        qDebug() << "setColorButtonColor()";
×
127
        QPixmap pixmap(16, 16);
×
128
        pixmap.fill(newColor);
×
129
        ui->pushButtonSelectColor->setIcon(QIcon(pixmap));
×
130
}
×
131

132
void ManualImportWindow::toggleCometOrbit(bool)
×
133
{
134
        //
135
}
×
136

137
void ManualImportWindow::toggleEllipticOrbit(bool)
×
138
{
139
        //
140
}
×
141

142
void ManualImportWindow::toggleObjectSpecificOrbit(bool)
×
143
{
144
        //
145
}
×
146

147
void ManualImportWindow::toggleMeanMotionOrPeriod(bool)
×
148
{
149
        //
150
}
×
151

152
void ManualImportWindow::selectPlanetTextureFile()
×
153
{
154
        selectTextureFile(ui->lineEditTexture);
×
155
}
×
156

157
void ManualImportWindow::selectRingTextureFile()
×
158
{
159
        selectTextureFile(ui->lineEditRingTexture);
×
160
}
×
161

162
void ManualImportWindow::selectTextureFile(QLineEdit * filePathLineEdit)
×
163
{
164
        //Find out the parent directory of the last selected file.
165
        //Open the textures directory if no file have been selected.
166
        QString texturesDirectoryPath;
×
167
        QString currentFileName = filePathLineEdit->text();
×
168
        if (currentFileName.isEmpty())
×
169
        {
170
                texturesDirectoryPath = StelFileMgr::findFile("textures", StelFileMgr::Directory);
×
171
                if (texturesDirectoryPath.isEmpty())
×
172
                        return;
×
173
        }
174
        else
175
        {
176
                QString currentFilePath = StelFileMgr::findFile("textures/" + currentFileName, StelFileMgr::File);
×
177
                if (currentFilePath.isEmpty())
×
178
                {
179
                        filePathLineEdit->clear();
×
180
                        return;
×
181
                }
182
                QFileInfo currentFileInfo(currentFilePath);
×
183
                texturesDirectoryPath = currentFileInfo.canonicalPath();
×
184
        }
×
185

186
        //Select an existing file
187
        QStringList supportedFormats;
×
188
        for (const auto &format : QImageReader::supportedImageFormats())
×
189
        {
190
                supportedFormats.append(QString("*.%1").arg(QString(format)));//It's a wee bit long...
×
191
        }
×
192
        QString fileFilter = QString("Texture files (%1)").arg(supportedFormats.join(" "));
×
193
        QString newFilePath = QFileDialog::getOpenFileName(&StelMainView::getInstance(), QString(), texturesDirectoryPath, fileFilter);
×
194

195
        //Is the file in one of the two "textures" directories?
196
        if (newFilePath.isEmpty())
×
197
                return;
×
198
        QFileInfo newFileInfo(newFilePath);
×
199
        QDir newFileParentDirectory = newFileInfo.dir();
×
200
        if (newFileParentDirectory.dirName() != "textures")
×
201
                return;
×
202
        QDir installedTexturesDirectory(StelFileMgr::getInstallationDir() + "/textures");
×
203
        QDir userTexturesDirectory(StelFileMgr::getUserDir() + "/textures");
×
204
        if (newFileParentDirectory != installedTexturesDirectory && newFileParentDirectory != userTexturesDirectory)
×
205
                return;
×
206

207
        if (verifyTextureFile(newFileInfo.canonicalFilePath()))
×
208
                filePathLineEdit->setText(newFileInfo.fileName());
×
209
}
×
210

211
bool ManualImportWindow::verifyTextureFile(QString filePath)
×
212
{
213
        //TODO: Absolute path? File exists?
214

215
        QPixmap texture(filePath);
×
216

217
        if (texture.isNull())
×
218
        {
219
                qDebug() << "File doesn't exist or is not an accepted texture format:"
×
220
                                << filePath;
×
221
                return false;
×
222
        }
223

224
        if (!verifyPowerOfTwo(texture.height()))
×
225
        {
226
                qDebug() << "Invalid texture height:" << texture.height()
×
227
                                << "for file" << filePath;
×
228
                return false;
×
229
        }
230
        if (!verifyPowerOfTwo(texture.width()))
×
231
        {
232
                qDebug() << "Invalid texture width:" << texture.width()
×
233
                                << "for file" << filePath;
×
234
                return false;
×
235
        }
236

237
        return true;
×
238
}
×
239

240
bool ManualImportWindow::verifyPowerOfTwo(int value)
×
241
{
242
        if (value > 0 && (value & (value-1)) == 0)
×
243
                return true;
×
244
        else
245
                return false;
×
246
}
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