File indexing completed on 2024-07-14 07:17:15

0001 /*
0002     SPDX-FileCopyrightText: 2004 Jason Harris <jharris@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opssolarsystem.h"
0008 
0009 #include "kstars.h"
0010 #include "kstarsdata.h"
0011 #include "skymap.h"
0012 
0013 #include <KActionCollection>
0014 #include <KConfigDialog>
0015 
0016 OpsSolarSystem::OpsSolarSystem() : QFrame(KStars::Instance())
0017 {
0018     setupUi(this);
0019 
0020     connect(kcfg_ShowSolarSystem, SIGNAL(toggled(bool)), SLOT(slotAllWidgets(bool)));
0021     connect(kcfg_ShowAsteroids, SIGNAL(toggled(bool)), SLOT(slotAsteroidWidgets(bool)));
0022     connect(kcfg_MagLimitAsteroidDownload, SIGNAL(valueChanged(double)), this, SLOT(slotChangeMagDownload(double)));
0023     connect(kcfg_ShowComets, SIGNAL(toggled(bool)), SLOT(slotCometWidgets(bool)));
0024 
0025     connect(ClearAllTrails, SIGNAL(clicked()), KStars::Instance(), SLOT(slotClearAllTrails()));
0026     connect(showAllPlanets, SIGNAL(clicked()), this, SLOT(slotSelectPlanets()));
0027     connect(showNonePlanets, SIGNAL(clicked()), this, SLOT(slotSelectPlanets()));
0028 
0029     MagLimitAsteroidDownloadWarning->setVisible(false);
0030 
0031     kcfg_MagLimitAsteroid->setMinimum(0.0);
0032     kcfg_MagLimitAsteroid->setMaximum(30.0);
0033     kcfg_MaxRadCometName->setMaximum(100.0);
0034     kcfg_MagLimitAsteroidDownload->setMinimum(0.0);
0035     kcfg_MagLimitAsteroidDownload->setMaximum(30.0);
0036 
0037     slotAsteroidWidgets(kcfg_ShowAsteroids->isChecked());
0038     slotCometWidgets(kcfg_ShowComets->isChecked());
0039 
0040     //Get a pointer to the KConfigDialog
0041     m_ConfigDialog = KConfigDialog::exists("settings");
0042 
0043     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
0044     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
0045     //connect( m_ConfigDialog->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(slotCancel()) );
0046 
0047     #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
0048     connect(solarButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this,
0049             [&]() { isDirty = true; });
0050     #else
0051     connect(solarButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::idPressed), this,
0052             [&]() { isDirty = true; });
0053     #endif
0054 }
0055 
0056 void OpsSolarSystem::slotChangeMagDownload(double mag)
0057 {
0058     if (mag > 12)
0059         MagLimitAsteroidDownloadWarning->setVisible(true);
0060     else
0061         MagLimitAsteroidDownloadWarning->setVisible(false);
0062 }
0063 
0064 void OpsSolarSystem::slotAllWidgets(bool on)
0065 {
0066     MajorBodiesBox->setEnabled(on);
0067     MinorBodiesBox->setEnabled(on);
0068     TrailsBox->setEnabled(on);
0069 }
0070 
0071 void OpsSolarSystem::slotAsteroidWidgets(bool on)
0072 {
0073     kcfg_MagLimitAsteroid->setEnabled(on);
0074     kcfg_ShowAsteroidNames->setEnabled(on);
0075     kcfg_AsteroidLabelDensity->setEnabled(on);
0076     textLabel3->setEnabled(on);
0077     textLabel6->setEnabled(on);
0078     LabelDensity->setEnabled(on);
0079 }
0080 
0081 void OpsSolarSystem::slotCometWidgets(bool on)
0082 {
0083     kcfg_ShowCometNames->setEnabled(on);
0084     kcfg_MaxRadCometName->setEnabled(on);
0085     textLabel4->setEnabled(on);
0086     kcfg_ShowCometComas->setEnabled(on);
0087 }
0088 
0089 void OpsSolarSystem::slotSelectPlanets()
0090 {
0091     bool b = true;
0092     if (QString(sender()->objectName()) == "showNonePlanets")
0093         b = false;
0094 
0095     kcfg_ShowSun->setChecked(b);
0096     kcfg_ShowMoon->setChecked(b);
0097     kcfg_ShowMercury->setChecked(b);
0098     kcfg_ShowVenus->setChecked(b);
0099     kcfg_ShowMars->setChecked(b);
0100     kcfg_ShowJupiter->setChecked(b);
0101     kcfg_ShowSaturn->setChecked(b);
0102     kcfg_ShowUranus->setChecked(b);
0103     kcfg_ShowNeptune->setChecked(b);
0104     //kcfg_ShowPluto->setChecked( b );
0105 }
0106 
0107 void OpsSolarSystem::slotApply()
0108 {
0109     if (isDirty == false)
0110         return;
0111 
0112     isDirty = false;
0113 
0114     // update time for all objects because they might be not initialized
0115     // it's needed when using horizontal coordinates
0116     KStars::Instance()->data()->setFullTimeUpdate();
0117     KStars::Instance()->updateTime();
0118     KStars::Instance()->map()->forceUpdate();
0119 }