Kstars

opsguides.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "opsguides.h"
8 
9 #include "ksfilereader.h"
10 #include "kstars.h"
11 #include "kstarsdata.h"
12 #include "Options.h"
13 #include "skymap.h"
14 #include "skycomponents/skymapcomposite.h"
15 #include "auxiliary/kspaths.h"
16 
17 #include <KConfigDialog>
18 
19 #include <QPushButton>
20 #include <QFileDialog>
21 
22 OpsGuides::OpsGuides() : QFrame(KStars::Instance())
23 {
24  setupUi(this);
25 
26  foreach (const QString &item, KStarsData::Instance()->skyComposite()->getCultureNames())
27  SkyCultureComboBox->addItem(i18nc("Sky Culture", item.toUtf8().constData()));
28 
29  m_ConfigDialog = KConfigDialog::exists("settings");
30 
31  connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
32  connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
33 
34  // When setting up the widget, update the enabled status of the
35  // checkboxes depending on the options.
36  slotToggleOpaqueGround(Options::showGround());
37  slotToggleConstellOptions(Options::showCNames());
38  slotToggleConstellationArt(Options::showConstellationArt());
39  slotToggleMilkyWayOptions(Options::showMilkyWay());
40  slotToggleAutoSelectGrid(Options::autoSelectGrid());
41  SkyCultureComboBox->setCurrentIndex(KStarsData::Instance()->skyComposite()->getCultureNames().indexOf(
42  Options::skyCulture()));
43 
44  connect(kcfg_ShowCNames, SIGNAL(toggled(bool)), this, SLOT(slotToggleConstellOptions(bool)));
45  connect(kcfg_ShowConstellationArt, SIGNAL(toggled(bool)), this, SLOT(slotToggleConstellationArt(bool)));
46  connect(kcfg_ShowMilkyWay, SIGNAL(toggled(bool)), this, SLOT(slotToggleMilkyWayOptions(bool)));
47  connect(kcfg_ShowGround, SIGNAL(toggled(bool)), this, SLOT(slotToggleOpaqueGround(bool)));
48  connect(kcfg_AutoSelectGrid, SIGNAL(toggled(bool)), this, SLOT(slotToggleAutoSelectGrid(bool)));
49 
50  // Track changes to apply settings
51  #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
52  connect(constellationButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this,
53  [&]()
54  {
55  isDirty = true;
56  });
57  connect(nameButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this,
58  [&]()
59  {
60  isDirty = true;
61  });
62  #else
63  connect(constellationButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idPressed), this,
64  [&]()
65  {
66  isDirty = true;
67  });
68  connect(nameButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idPressed), this,
69  [&]()
70  {
71  isDirty = true;
72  });
73  #endif
74  connect(SkyCultureComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
75  [&]()
76  {
77  Options::setSkyCulture(KStarsData::Instance()->skyComposite()->getCultureName(SkyCultureComboBox->currentIndex()));
78  isDirty = true;
79  });
80 
81  isDirty = false;
82 
83 }
84 
85 void OpsGuides::slotToggleConstellOptions(bool state)
86 {
87  ConstellOptions->setEnabled(state);
88 }
89 
90 void OpsGuides::slotToggleConstellationArt(bool state)
91 {
92  kcfg_ShowConstellationArt->setEnabled(state);
93 }
94 
95 void OpsGuides::slotToggleMilkyWayOptions(bool state)
96 {
97  kcfg_FillMilkyWay->setEnabled(state);
98 }
99 
100 void OpsGuides::slotToggleOpaqueGround(bool state)
101 {
102  kcfg_ShowHorizon->setEnabled(!state);
103 }
104 
105 void OpsGuides::slotToggleAutoSelectGrid(bool state)
106 {
107  kcfg_ShowEquatorialGrid->setEnabled(!state);
108  kcfg_ShowHorizontalGrid->setEnabled(!state);
109 }
110 
111 void OpsGuides::slotApply()
112 {
113  if (isDirty == false)
114  return;
115 
116  isDirty = false;
117 
118  KStarsData *data = KStarsData::Instance();
119  SkyMap *map = SkyMap::Instance();
120 
121  // If the focus object was a constellation and the sky culture has changed, remove the focus object
122  if (map->focusObject() && map->focusObject()->type() == SkyObject::CONSTELLATION)
123  {
124  if (data->skyComposite()->currentCulture() !=
125  data->skyComposite()->getCultureName(SkyCultureComboBox->currentIndex()) ||
126  data->skyComposite()->isLocalCNames() != Options::useLocalConstellNames())
127  {
128  map->setClickedObject(nullptr);
129  map->setFocusObject(nullptr);
130  }
131  }
132 
133  data->skyComposite()->setCurrentCulture(
134  KStarsData::Instance()->skyComposite()->getCultureName(SkyCultureComboBox->currentIndex()));
135  data->skyComposite()->reloadCLines();
136  data->skyComposite()->reloadCNames();
137  data->skyComposite()->reloadConstellationArt();
138 
139  data->setFullTimeUpdate();
141  map->forceUpdate();
142 }
void updateTime(const bool automaticDSTchange=true)
Update time-dependent data and (possibly) repaint the sky map.
Definition: kstars.cpp:567
void setFullTimeUpdate()
The Sky is updated more frequently than the moon, which is updated more frequently than the planets.
Definition: kstarsdata.cpp:313
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
static KStars * Instance()
Definition: kstars.h:125
QByteArray toUtf8() const const
static KConfigDialog * exists(const QString &name)
This is the main window for KStars. In addition to the GUI elements, the class contains the program c...
Definition: kstars.h:92
void setupUi(QWidget *widget)
void buttonPressed(QAbstractButton *button)
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:165
void idPressed(int id)
const char * constData() const const
Canvas widget for displaying the sky bitmap; also handles user interaction events.
Definition: skymap.h:52
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QPushButton * button(QDialogButtonBox::StandardButton which) const
QFuture< void > map(Sequence &sequence, MapFunctor function)
void activated(int index)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 16 2022 04:00:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.