Kstars

opsxplanet.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Jerome SONRIER <jsid@emor3j.fr.eu.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "opsxplanet.h"
8
9#include "kstars.h"
10#include "kstarsdata.h"
11#include "Options.h"
12#include <QDesktopServices>
13#include <QFileDialog>
14
15OpsXplanet::OpsXplanet(KStars *_ks) : QFrame(_ks), ksw(_ks)
16{
17 setupUi(this);
18
19#ifdef Q_OS_MACOS
20 connect(kcfg_xplanetIsInternal, SIGNAL(clicked()), this, SLOT(toggleXPlanetInternal()));
21 kcfg_xplanetIsInternal->setToolTip(i18n("Internal or External XPlanet?"));
22
23 if (Options::xplanetIsInternal())
24 kcfg_XplanetPath->setEnabled(false);
25
26#else
27 kcfg_xplanetIsInternal->setVisible(false);
28#endif
29
30 // Init projections combobox
31 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "No projection"), "no projection");
32 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Ancient"), "ancient");
33 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Azimuthal"), "azimuthal");
34 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Bonne"), "bonne");
35 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Gnomonic"), "gnomonic");
36 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Hemisphere"), "hemisphere");
37 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Lambert"), "lambert");
38 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Mercator"), "mercator");
39 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Mollweide"), "mollweide");
40 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Orthographic"), "orthographic");
41 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Peters"), "peters");
42 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Polyconic"), "polyconic");
43 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "Rectangular"), "rectangular");
44 kcfg_XplanetProjection->addItem(i18nc("Map projection method", "TSC"), "tsc");
45
46 // Enable/Disable somme widgets
47 connect(kcfg_XplanetConfigFile, SIGNAL(toggled(bool)), SLOT(slotConfigFileWidgets(bool)));
48 connect(kcfg_XplanetStarmap, SIGNAL(toggled(bool)), SLOT(slotStarmapFileWidgets(bool)));
49 connect(kcfg_XplanetArcFile, SIGNAL(toggled(bool)), SLOT(slotArcFileWidgets(bool)));
50 connect(kcfg_XplanetLabel, SIGNAL(toggled(bool)), SLOT(slotLabelWidgets(bool)));
51 connect(kcfg_XplanetMarkerFile, SIGNAL(toggled(bool)), SLOT(slotMarkerFileWidgets(bool)));
52 connect(kcfg_XplanetMarkerBounds, SIGNAL(toggled(bool)), SLOT(slotMarkerBoundsWidgets(bool)));
53 connect(kcfg_XplanetProjection, SIGNAL(currentIndexChanged(int)), SLOT(slotProjectionWidgets(int)));
54 connect(kcfg_XplanetBackground, SIGNAL(toggled(bool)), SLOT(slotBackgroundWidgets(bool)));
55
56 kcfg_XplanetConfigFilePath->setEnabled(Options::xplanetConfigFile());
57 configFileB->setEnabled(Options::xplanetConfigFile());
58 configFileB->setIcon(QIcon::fromTheme("document-open-folder"));
59 configFileB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
60 connect(configFileB, SIGNAL(clicked()), this, SLOT(slotSelectConfigFile()));
61 kcfg_XplanetStarmapPath->setEnabled(Options::xplanetStarmap());
62 starmapFileB->setEnabled(Options::xplanetStarmap());
63 starmapFileB->setIcon(QIcon::fromTheme("document-open-folder"));
64 starmapFileB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
65 connect(starmapFileB, SIGNAL(clicked()), this, SLOT(slotSelectStarMapFile()));
66 kcfg_XplanetArcFilePath->setEnabled(Options::xplanetArcFile());
67 arcFileB->setEnabled(Options::xplanetArcFile());
68 arcFileB->setIcon(QIcon::fromTheme("document-open-folder"));
69 arcFileB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
70 connect(arcFileB, SIGNAL(clicked()), this, SLOT(slotSelectArcFile()));
71 kcfg_XplanetLabelLocalTime->setEnabled(Options::xplanetLabel());
72 kcfg_XplanetLabelGMT->setEnabled(Options::xplanetLabel());
73 textLabelXplanetLabelString->setEnabled(Options::xplanetLabel());
74 kcfg_XplanetLabelString->setEnabled(Options::xplanetLabel());
75 textLabelXplanetDateFormat->setEnabled(Options::xplanetLabel());
76 kcfg_XplanetDateFormat->setEnabled(Options::xplanetLabel());
77 textLabelXplanetFontSize->setEnabled(Options::xplanetLabel());
78 kcfg_XplanetFontSize->setEnabled(Options::xplanetLabel());
79 textLabelXplanetColor->setEnabled(Options::xplanetLabel());
80 kcfg_XplanetColor->setEnabled(Options::xplanetLabel());
81 textLabelLabelPos->setEnabled(Options::xplanetLabel());
82 kcfg_XplanetLabelTL->setEnabled(Options::xplanetLabel());
83 kcfg_XplanetLabelTR->setEnabled(Options::xplanetLabel());
84 kcfg_XplanetLabelBR->setEnabled(Options::xplanetLabel());
85 kcfg_XplanetLabelBL->setEnabled(Options::xplanetLabel());
86 kcfg_XplanetMarkerFilePath->setEnabled(Options::xplanetMarkerFile());
87 kcfg_XplanetMarkerBounds->setEnabled(Options::xplanetMarkerFile());
88 if (Options::xplanetMarkerFile() && Options::xplanetMarkerBounds())
89 kcfg_XplanetMarkerBoundsPath->setEnabled(true);
90 else
91 kcfg_XplanetMarkerBoundsPath->setEnabled(false);
92 if (Options::xplanetProjection() == 0)
93 groupBoxBackground->setEnabled(false);
94 kcfg_XplanetBackgroundImage->setEnabled(Options::xplanetBackgroundImage());
95 kcfg_XplanetBackgroundImagePath->setEnabled(Options::xplanetBackgroundImage());
96 kcfg_XplanetBackgroundColor->setEnabled(Options::xplanetBackgroundImage());
97 kcfg_XplanetBackgroundColorValue->setEnabled(Options::xplanetBackgroundImage());
98 if (Options::xplanetProjection() == 0)
99 groupBoxBackground->setEnabled(false);
100
101 #ifdef Q_OS_WIN
102 kcfg_XplanetUseFIFO->setChecked(false);
103 kcfg_XplanetUseFIFO->setDisabled(true);
104 kcfg_XplanetUseFIFO->setToolTip(i18n("FIFO files are not supported on Windows"));
105 #endif
106
107 connect(openXPlanetMaps, SIGNAL(clicked()),this,SLOT(showXPlanetMapsDirectory()));
108}
109
110void OpsXplanet::showXPlanetMapsDirectory()
111{
112
113 QString xplanetMapsDir = XPlanetShareDirectory() + QDir::separator() + "images";
114
115 QUrl path = QUrl::fromLocalFile(xplanetMapsDir);
117}
118
119QString OpsXplanet::XPlanetShareDirectory()
120{
121 #ifdef Q_OS_WIN
122 const QFileInfo xPlanetLocationInfo(Options::xplanetPath());
123 return xPlanetLocationInfo.dir().absolutePath() + QDir::separator() + "xplanet";
124 #endif
125
126 if (Options::xplanetIsInternal())
128 else
129 return Options::xplanetPath() + "../share/xplanet";
130}
131
132void OpsXplanet::toggleXPlanetInternal()
133{
134 kcfg_XplanetPath->setEnabled(!kcfg_xplanetIsInternal->isChecked());
135 if (kcfg_xplanetIsInternal->isChecked())
136 kcfg_XplanetPath->setText("*Internal XPlanet*");
137 else
138 kcfg_XplanetPath->setText(KSUtils::getDefaultPath("XplanetPath"));
139}
140
141void OpsXplanet::slotConfigFileWidgets(bool on)
142{
143 kcfg_XplanetConfigFilePath->setEnabled(on);
144 configFileB->setEnabled(on);
145}
146
147void OpsXplanet::slotStarmapFileWidgets(bool on)
148{
149 kcfg_XplanetStarmapPath->setEnabled(on);
150 starmapFileB->setEnabled(on);
151}
152
153void OpsXplanet::slotArcFileWidgets(bool on)
154{
155 kcfg_XplanetArcFilePath->setEnabled(on);
156 arcFileB->setEnabled(on);
157}
158
159void OpsXplanet::slotLabelWidgets(bool on)
160{
161 kcfg_XplanetLabelLocalTime->setEnabled(on);
162 kcfg_XplanetLabelGMT->setEnabled(on);
163 textLabelXplanetLabelString->setEnabled(on);
164 kcfg_XplanetLabelString->setEnabled(on);
165 textLabelXplanetDateFormat->setEnabled(on);
166 kcfg_XplanetDateFormat->setEnabled(on);
167 textLabelXplanetFontSize->setEnabled(on);
168 kcfg_XplanetFontSize->setEnabled(on);
169 textLabelXplanetColor->setEnabled(on);
170 kcfg_XplanetColor->setEnabled(on);
171 textLabelLabelPos->setEnabled(on);
172 kcfg_XplanetLabelTL->setEnabled(on);
173 kcfg_XplanetLabelTR->setEnabled(on);
174 kcfg_XplanetLabelBR->setEnabled(on);
175 kcfg_XplanetLabelBL->setEnabled(on);
176}
177
178void OpsXplanet::slotMarkerFileWidgets(bool on)
179{
180 kcfg_XplanetMarkerFilePath->setEnabled(on);
181 kcfg_XplanetMarkerBounds->setEnabled(on);
182 if (kcfg_XplanetMarkerBounds->isChecked())
183 kcfg_XplanetMarkerBoundsPath->setEnabled(on);
184}
185
186void OpsXplanet::slotMarkerBoundsWidgets(bool on)
187{
188 kcfg_XplanetMarkerBoundsPath->setEnabled(on);
189}
190
191void OpsXplanet::slotProjectionWidgets(int index)
192{
193 if (index == 0)
194 groupBoxBackground->setEnabled(false);
195 else
196 groupBoxBackground->setEnabled(true);
197
198 if (!kcfg_XplanetBackground->isChecked())
199 {
200 kcfg_XplanetBackgroundImage->setEnabled(false);
201 kcfg_XplanetBackgroundImagePath->setEnabled(false);
202 kcfg_XplanetBackgroundColor->setEnabled(false);
203 kcfg_XplanetBackgroundColorValue->setEnabled(false);
204 }
205}
206
207void OpsXplanet::slotBackgroundWidgets(bool on)
208{
209 kcfg_XplanetBackgroundImage->setEnabled(on);
210 kcfg_XplanetBackgroundImagePath->setEnabled(on);
211 kcfg_XplanetBackgroundColor->setEnabled(on);
212 kcfg_XplanetBackgroundColorValue->setEnabled(on);
213}
214
215void OpsXplanet::slotSelectConfigFile()
216{
217 QString xplanetConfig = XPlanetShareDirectory() + QDir::separator() + "config";
218 QString file =
219 QFileDialog::getOpenFileName(KStars::Instance(), i18nc("@title:window", "Select XPlanet Config File"), xplanetConfig);
220
221 if (!file.isEmpty())
222 kcfg_XplanetConfigFilePath->setText(QFileInfo(file).completeBaseName());
223
224}
225
226void OpsXplanet::slotSelectStarMapFile()
227{
228 QString xplanetStarMap = XPlanetShareDirectory() + QDir::separator() + "stars";
229
230 QString file =
231 QFileDialog::getOpenFileName(KStars::Instance(), i18nc("@title:window", "Select XPlanet Star Map File"), xplanetStarMap);
232
233 if (!file.isEmpty())
234 kcfg_XplanetStarmapPath->setText(QFileInfo(file).completeBaseName());
235
236}
237
238void OpsXplanet::slotSelectArcFile()
239{
240
241 QString xplanetArc = XPlanetShareDirectory() + QDir::separator() + "arcs";
242
243 QString file =
244 QFileDialog::getOpenFileName(KStars::Instance(), i18nc("@title:window", "Select XPlanet Arc File"), xplanetArc);
245
246 if (!file.isEmpty())
247 kcfg_XplanetArcFilePath->setText(QFileInfo(file).completeBaseName());
248
249}
This is the main window for KStars.
Definition kstars.h:89
static KStars * Instance()
Definition kstars.h:121
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString path(const QString &relativePath)
bool openUrl(const QUrl &url)
QChar separator()
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
QIcon fromTheme(const QString &name)
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
bool isEmpty() const const
WA_LayoutUsesWidgetRect
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromLocalFile(const QString &localFile)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.