File indexing completed on 2024-04-14 03:42:58

0001 /*
0002     SPDX-FileCopyrightText: 2004 Jason Harris <jharris@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opscatalog.h"
0008 
0009 #include "kstars.h"
0010 #include "kstarsdata.h"
0011 #include "Options.h"
0012 #include "skymap.h"
0013 #include "skycomponents/catalogscomponent.h"
0014 #include "skycomponents/skymapcomposite.h"
0015 #include "widgets/magnitudespinbox.h"
0016 #include "skyobject.h"
0017 
0018 #include <KActionCollection>
0019 #include <KConfigDialog>
0020 
0021 #include <QList>
0022 #include <QListWidgetItem>
0023 #include <QTextStream>
0024 #include <QFileDialog>
0025 
0026 OpsCatalog::OpsCatalog() : QFrame(KStars::Instance())
0027 {
0028     setupUi(this);
0029 
0030     //Get a pointer to the KConfigDialog
0031     m_ConfigDialog = KConfigDialog::exists("settings");
0032 
0033     //    kcfg_MagLimitDrawStar->setValue( Options::magLimitDrawStar() );
0034     kcfg_StarDensity->setValue(Options::starDensity());
0035     //    kcfg_MagLimitDrawStarZoomOut->setValue( Options::magLimitDrawStarZoomOut() );
0036     //    m_MagLimitDrawStar = kcfg_MagLimitDrawStar->value();
0037     m_StarDensity = kcfg_StarDensity->value();
0038     //    m_MagLimitDrawStarZoomOut = kcfg_MagLimitDrawStarZoomOut->value();
0039 
0040     //    kcfg_MagLimitDrawStar->setMinimum( Options::magLimitDrawStarZoomOut() );
0041     //    kcfg_MagLimitDrawStarZoomOut->setMaximum( 12.0 );
0042 
0043     kcfg_DSOCachePercentage->setValue(Options::dSOCachePercentage());
0044     connect(kcfg_DSOCachePercentage, &QSlider::valueChanged, this,
0045             [&] { isDirty = true; });
0046 
0047     kcfg_DSOMinZoomFactor->setValue(Options::dSOMinZoomFactor());
0048     connect(kcfg_DSOMinZoomFactor, &QSlider::valueChanged, this, [&] { isDirty = true; });
0049 
0050     kcfg_ShowUnknownMagObjects->setChecked(Options::showUnknownMagObjects());
0051     connect(kcfg_ShowUnknownMagObjects, &QCheckBox::stateChanged, this,
0052             [&] { isDirty = true; });
0053 
0054     //disable star-related widgets if not showing stars
0055     if (!kcfg_ShowStars->isChecked())
0056         slotStarWidgets(false);
0057 
0058     /*
0059     connect( kcfg_MagLimitDrawStar, SIGNAL(valueChanged(double)),
0060              SLOT(slotSetDrawStarMagnitude(double)) );
0061     connect( kcfg_MagLimitDrawStarZoomOut, SIGNAL(valueChanged(double)),
0062              SLOT(slotSetDrawStarZoomOutMagnitude(double)) );
0063     */
0064     connect(kcfg_ShowStars, SIGNAL(toggled(bool)), SLOT(slotStarWidgets(bool)));
0065     connect(kcfg_ShowDeepSky, SIGNAL(toggled(bool)), SLOT(slotDeepSkyWidgets(bool)));
0066     connect(kcfg_ShowDeepSkyNames, SIGNAL(toggled(bool)), kcfg_DeepSkyLongLabels,
0067             SLOT(setEnabled(bool)));
0068     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()),
0069             SLOT(slotApply()));
0070     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
0071             SLOT(slotApply()));
0072     connect(m_ConfigDialog->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
0073             SLOT(slotCancel()));
0074 
0075     connect(manageButton, &QPushButton::clicked, KStars::Instance(),
0076             &KStars::slotDSOCatalogGUI);
0077 
0078     // Make sure the zoomed-out limit is always brighter than the
0079     // zoomed-in limit to avoid weird behavior
0080     kcfg_MagLimitDrawDeepSky->setMaximum(FAINTEST_MAGNITUDE);
0081     connect(kcfg_MagLimitDrawDeepSky, &QDoubleSpinBox::editingFinished,
0082             [&]() {
0083                 kcfg_MagLimitDrawDeepSkyZoomOut->setMaximum(kcfg_MagLimitDrawDeepSky->value());
0084             });
0085 
0086     isDirty = false;
0087 }
0088 
0089 void OpsCatalog::slotApply()
0090 {
0091     if (isDirty == false)
0092         return;
0093 
0094     isDirty = false;
0095 
0096     Options::setStarDensity(kcfg_StarDensity->value());
0097     //    Options::setMagLimitDrawStarZoomOut( kcfg_MagLimitDrawStarZoomOut->value() );
0098 
0099     //FIXME: need to add the ShowDeepSky meta-option to the config dialog!
0100     //For now, I'll set showDeepSky to true if any catalog options changed
0101 
0102     KStars::Instance()->data()->skyComposite()->reloadDeepSky();
0103 
0104     // update time for all objects because they might be not initialized
0105     // it's needed when using horizontal coordinates
0106     KStars::Instance()->data()->setFullTimeUpdate();
0107     KStars::Instance()->updateTime();
0108     KStars::Instance()->map()->forceUpdate();
0109 
0110     Options::setDSOCachePercentage(kcfg_DSOCachePercentage->value());
0111     KStars::Instance()->data()->skyComposite()->catalogsComponent()->resizeCache(
0112         kcfg_DSOCachePercentage->value());
0113 
0114     Options::setDSOMinZoomFactor(kcfg_DSOMinZoomFactor->value());
0115     Options::setShowUnknownMagObjects(kcfg_ShowUnknownMagObjects->isChecked());
0116 }
0117 
0118 void OpsCatalog::slotCancel()
0119 {
0120     //Revert all local option placeholders to the values in the global config object
0121     //    m_MagLimitDrawStar = Options::magLimitDrawStar();
0122     m_StarDensity = Options::starDensity();
0123     //    m_MagLimitDrawStarZoomOut = Options::magLimitDrawStarZoomOut();
0124 }
0125 
0126 void OpsCatalog::slotStarWidgets(bool on)
0127 {
0128     //    LabelMagStars->setEnabled(on);
0129     LabelStarDensity->setEnabled(on);
0130     //    LabelMagStarsZoomOut->setEnabled(on);
0131     LabelDensity->setEnabled(on);
0132     //    LabelMag1->setEnabled(on);
0133     //    LabelMag2->setEnabled(on);
0134     //    kcfg_MagLimitDrawStar->setEnabled(on);
0135     kcfg_StarDensity->setEnabled(on);
0136     LabelStarDensity->setEnabled(on);
0137     //    kcfg_MagLimitDrawStarZoomOut->setEnabled(on);
0138     kcfg_StarLabelDensity->setEnabled(on);
0139     kcfg_ShowStarNames->setEnabled(on);
0140     kcfg_ShowStarMagnitudes->setEnabled(on);
0141 }
0142 
0143 void OpsCatalog::slotDeepSkyWidgets(bool on)
0144 {
0145     LabelMagDeepSky->setEnabled(on);
0146     LabelMagDeepSkyZoomOut->setEnabled(on);
0147     kcfg_MagLimitDrawDeepSky->setEnabled(on);
0148     kcfg_MagLimitDrawDeepSkyZoomOut->setEnabled(on);
0149     kcfg_ShowDeepSkyNames->setEnabled(on);
0150     kcfg_ShowDeepSkyMagnitudes->setEnabled(on);
0151     kcfg_DSOCachePercentage->setEnabled(on);
0152     DSOCacheLabel->setEnabled(on);
0153     kcfg_DSOMinZoomFactor->setEnabled(on);
0154     kcfg_ShowUnknownMagObjects->setEnabled(on);
0155     DSOMInZoomLabel->setEnabled(on);
0156     DeepSkyLabelDensityLabel->setEnabled(on);
0157     kcfg_DeepSkyLabelDensity->setEnabled(on);
0158     kcfg_DeepSkyLongLabels->setEnabled(on);
0159     LabelMag3->setEnabled(on);
0160     LabelMag4->setEnabled(on);
0161 }