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

0001 /*
0002     SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opsfits.h"
0008 
0009 #include "Options.h"
0010 #include "kstars.h"
0011 #include "kstarsdata.h"
0012 
0013 #ifdef HAVE_STELLARSOLVER
0014 #include "kspaths.h"
0015 #include "ekos/auxiliary/stellarsolverprofile.h"
0016 #include <stellarsolver.h>
0017 #endif
0018 
0019 OpsFITS::OpsFITS() : QFrame(KStars::Instance())
0020 {
0021     setupUi(this);
0022 
0023     connect(kcfg_LimitedResourcesMode, &QCheckBox::toggled, this, [this](bool toggled)
0024     {
0025         if (toggled)
0026         {
0027             kcfg_Auto3DCube->setChecked(false);
0028             kcfg_AutoDebayer->setChecked(false);
0029             kcfg_AutoWCS->setChecked(false);
0030         }
0031     });
0032     connect(kcfg_Auto3DCube, &QCheckBox::toggled, this, [this](bool toggled)
0033     {
0034         if (toggled)
0035             kcfg_LimitedResourcesMode->setChecked(false);
0036     });
0037     connect(kcfg_AutoDebayer, &QCheckBox::toggled, this, [this](bool toggled)
0038     {
0039         if (toggled)
0040             kcfg_LimitedResourcesMode->setChecked(false);
0041     });
0042     connect(kcfg_AutoWCS, &QCheckBox::toggled, this, [this](bool toggled)
0043     {
0044         if (toggled)
0045             kcfg_LimitedResourcesMode->setChecked(false);
0046     });
0047     hipsOpacity->setValue(Options::hIPSOpacity() * 100);
0048     connect(hipsOpacity, &QSlider::valueChanged, this, [](int value)
0049     {
0050         Options::setHIPSOpacity(value / 100.0);
0051     });
0052     hipsOffsetX->setValue(Options::hIPSOffsetX());
0053     connect(hipsOffsetX, QOverload<int>::of(&QSpinBox::valueChanged), this, [](int value)
0054     {
0055         Options::setHIPSOffsetX(value);
0056     });
0057     connect(hipsOffsetY, QOverload<int>::of(&QSpinBox::valueChanged), this, [](int value)
0058     {
0059         Options::setHIPSOffsetY(value);
0060     });
0061 
0062 #ifdef HAVE_STELLARSOLVER
0063     setupHFROptions();
0064 #else
0065     editHfrProfile->setEnabled(false);
0066     HfrOptionsProfiles->setEnabled(false);
0067 #endif
0068 }
0069 
0070 #ifdef HAVE_STELLARSOLVER
0071 
0072 void OpsFITS::loadStellarSolverProfiles()
0073 {
0074     QString savedOptionsProfiles = QDir(KSPaths::writableLocation(
0075                                             QStandardPaths::AppLocalDataLocation)).filePath("SavedHFRProfiles.ini");
0076     if(QFile(savedOptionsProfiles).exists())
0077         m_StellarSolverProfiles = StellarSolver::loadSavedOptionsProfiles(savedOptionsProfiles);
0078     else
0079         m_StellarSolverProfiles = Ekos::getDefaultHFROptionsProfiles();
0080     HfrOptionsProfiles->clear();
0081     for(auto param : m_StellarSolverProfiles)
0082         HfrOptionsProfiles->addItem(param.listName);
0083     HfrOptionsProfiles->setCurrentIndex(Options::hFROptionsProfile());
0084 }
0085 
0086 void OpsFITS::setupHFROptions()
0087 {
0088     editHfrProfile->setEnabled(true);
0089     HfrOptionsProfiles->setEnabled(true);
0090 
0091     editHfrProfile->setIcon(QIcon::fromTheme("document-edit"));
0092     editHfrProfile->setAttribute(Qt::WA_LayoutUsesWidgetRect);
0093 
0094     connect(editHfrProfile, &QAbstractButton::clicked, this, [this]()
0095     {
0096         KConfigDialog *optionsEditor = new KConfigDialog(this, "OptionsProfileEditor", Options::self());
0097         optionsProfileEditor = new Ekos::StellarSolverProfileEditor(this, Ekos::HFRProfiles, optionsEditor);
0098 #ifdef Q_OS_OSX
0099         optionsEditor->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
0100 #endif
0101         KPageWidgetItem *mainPage = optionsEditor->addPage(optionsProfileEditor, i18n("HFR Options Profile Editor"));
0102         mainPage->setIcon(QIcon::fromTheme("configure"));
0103         connect(optionsProfileEditor, &Ekos::StellarSolverProfileEditor::optionsProfilesUpdated, this,
0104                 &OpsFITS::loadStellarSolverProfiles);
0105         optionsProfileEditor->loadProfile(HfrOptionsProfiles->currentText());
0106         optionsEditor->show();
0107     });
0108 
0109     loadStellarSolverProfiles();
0110 
0111     connect(HfrOptionsProfiles, QOverload<int>::of(&QComboBox::activated), this, [](int index)
0112     {
0113         Options::setHFROptionsProfile(index);
0114     });
0115 }
0116 
0117 #endif