File indexing completed on 2024-04-21 03:44:27

0001 /*
0002     SPDX-FileCopyrightText: 2005 Jason Harris <jharris@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opsguides.h"
0008 
0009 #include "ksfilereader.h"
0010 #include "kstars.h"
0011 #include "kstarsdata.h"
0012 #include "Options.h"
0013 #include "skymap.h"
0014 #include "skycomponents/skymapcomposite.h"
0015 #include "auxiliary/kspaths.h"
0016 
0017 #include <KConfigDialog>
0018 
0019 #include <QPushButton>
0020 #include <QFileDialog>
0021 
0022 OpsGuides::OpsGuides() : QFrame(KStars::Instance())
0023 {
0024     setupUi(this);
0025 
0026     foreach (const QString &item, KStarsData::Instance()->skyComposite()->getCultureNames())
0027         SkyCultureComboBox->addItem(i18nc("Sky Culture", item.toUtf8().constData()));
0028 
0029     m_ConfigDialog = KConfigDialog::exists("settings");
0030 
0031     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
0032     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
0033 
0034     // When setting up the widget, update the enabled status of the
0035     // checkboxes depending on the options.
0036     slotToggleOpaqueGround(Options::showGround());
0037     slotToggleConstellOptions(Options::showCNames());
0038     slotToggleConstellationArt(Options::showConstellationArt());
0039     slotToggleMilkyWayOptions(Options::showMilkyWay());
0040     slotToggleAutoSelectGrid(Options::autoSelectGrid());
0041     SkyCultureComboBox->setCurrentIndex(KStarsData::Instance()->skyComposite()->getCultureNames().indexOf(
0042                                             Options::skyCulture()));
0043 
0044     connect(kcfg_ShowCNames, SIGNAL(toggled(bool)), this, SLOT(slotToggleConstellOptions(bool)));
0045     connect(kcfg_ShowConstellationArt, SIGNAL(toggled(bool)), this, SLOT(slotToggleConstellationArt(bool)));
0046     connect(kcfg_ShowMilkyWay, SIGNAL(toggled(bool)), this, SLOT(slotToggleMilkyWayOptions(bool)));
0047     connect(kcfg_ShowGround, SIGNAL(toggled(bool)), this, SLOT(slotToggleOpaqueGround(bool)));
0048     connect(kcfg_AutoSelectGrid, SIGNAL(toggled(bool)), this, SLOT(slotToggleAutoSelectGrid(bool)));
0049 
0050     // Track changes to apply settings
0051     #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
0052     connect(constellationButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this,
0053             [&]()
0054     {
0055         isDirty = true;
0056     });
0057     connect(nameButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this,
0058             [&]()
0059     {
0060         isDirty = true;
0061     });
0062     #else
0063     connect(constellationButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idPressed), this,
0064             [&]()
0065     {
0066         isDirty = true;
0067     });
0068     connect(nameButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idPressed), this,
0069             [&]()
0070     {
0071         isDirty = true;
0072     });
0073     #endif
0074     connect(SkyCultureComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
0075             [&]()
0076     {
0077         Options::setSkyCulture(KStarsData::Instance()->skyComposite()->getCultureName(SkyCultureComboBox->currentIndex()));
0078         isDirty = true;
0079     });
0080 
0081     isDirty = false;
0082 
0083 }
0084 
0085 void OpsGuides::slotToggleConstellOptions(bool state)
0086 {
0087     ConstellOptions->setEnabled(state);
0088 }
0089 
0090 void OpsGuides::slotToggleConstellationArt(bool state)
0091 {
0092     kcfg_ShowConstellationArt->setEnabled(state);
0093 }
0094 
0095 void OpsGuides::slotToggleMilkyWayOptions(bool state)
0096 {
0097     kcfg_FillMilkyWay->setEnabled(state);
0098 }
0099 
0100 void OpsGuides::slotToggleOpaqueGround(bool state)
0101 {
0102     kcfg_ShowHorizon->setEnabled(!state);
0103 }
0104 
0105 void OpsGuides::slotToggleAutoSelectGrid(bool state)
0106 {
0107     kcfg_ShowEquatorialGrid->setEnabled(!state);
0108     kcfg_ShowHorizontalGrid->setEnabled(!state);
0109 }
0110 
0111 void OpsGuides::slotApply()
0112 {
0113     if (isDirty == false)
0114         return;
0115 
0116     isDirty = false;
0117 
0118     KStarsData *data = KStarsData::Instance();
0119     SkyMap *map      = SkyMap::Instance();
0120 
0121     // If the focus object was a constellation and the sky culture has changed, remove the focus object
0122     if (map->focusObject() && map->focusObject()->type() == SkyObject::CONSTELLATION)
0123     {
0124         if (data->skyComposite()->currentCulture() !=
0125                 data->skyComposite()->getCultureName(SkyCultureComboBox->currentIndex()) ||
0126                 data->skyComposite()->isLocalCNames() != Options::useLocalConstellNames())
0127         {
0128             map->setClickedObject(nullptr);
0129             map->setFocusObject(nullptr);
0130         }
0131     }
0132 
0133     data->skyComposite()->setCurrentCulture(
0134         KStarsData::Instance()->skyComposite()->getCultureName(SkyCultureComboBox->currentIndex()));
0135     data->skyComposite()->reloadCLines();
0136     data->skyComposite()->reloadCNames();
0137     data->skyComposite()->reloadConstellationArt();
0138 
0139     data->setFullTimeUpdate();
0140     KStars::Instance()->updateTime();
0141     map->forceUpdate();
0142 }