File indexing completed on 2024-04-28 03:44:37

0001 /*
0002     SPDX-FileCopyrightText: 2023 Hy Murveit <hy@murveit.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opsimageoverlay.h"
0008 
0009 #include "ksfilereader.h"
0010 #include "kspaths.h"
0011 #include "kstars.h"
0012 #include "kstarsdata.h"
0013 #include "Options.h"
0014 #include "skymap.h"
0015 #include "skycomponents/skymapcomposite.h"
0016 #include "skycomponents/imageoverlaycomponent.h"
0017 
0018 #include <KConfigDialog>
0019 
0020 #include <QPushButton>
0021 #include <QFileDialog>
0022 #include <QPushButton>
0023 #include <QDesktopServices>
0024 
0025 OpsImageOverlay::OpsImageOverlay() : QFrame(KStars::Instance())
0026 {
0027     setupUi(this);
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     ImageOverlayComponent *overlayComponent = dynamic_cast<ImageOverlayComponent*>(
0035                 KStarsData::Instance()->skyComposite()->imageOverlay());
0036     connect(solveButton, &QPushButton::clicked, overlayComponent, &ImageOverlayComponent::startSolving,
0037             Qt::UniqueConnection);
0038     connect(refreshB, &QPushButton::clicked, overlayComponent, &ImageOverlayComponent::reload,
0039             Qt::UniqueConnection);
0040     connect(kcfg_ShowImageOverlays, &QCheckBox::stateChanged, [](int state)
0041     {
0042         Options::setShowImageOverlays(state);
0043     });
0044     connect(kcfg_ShowSelectedImageOverlay, &QCheckBox::stateChanged, [](int state)
0045     {
0046         Options::setShowSelectedImageOverlay(state);
0047     });
0048     connect(kcfg_ImageOverlayMaxDimension, QOverload<int>::of(&QSpinBox::valueChanged), [](int value)
0049     {
0050         Options::setImageOverlayMaxDimension(value);
0051     });
0052     connect(kcfg_ImageOverlayTimeout, QOverload<int>::of(&QSpinBox::valueChanged), [](int value)
0053     {
0054         Options::setImageOverlayTimeout(value);
0055     });
0056     connect(kcfg_ImageOverlayDefaultScale, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [](double value)
0057     {
0058         Options::setImageOverlayDefaultScale(value);
0059     });
0060     connect(imageOverlayShowDirButton, &QPushButton::clicked, []()
0061     {
0062         QDesktopServices::openUrl(QUrl::fromLocalFile(QDir(KSPaths::writableLocation(
0063                                       QStandardPaths::AppLocalDataLocation)).filePath("imageOverlays")));
0064     });
0065 
0066     syncOptions();
0067 }
0068 
0069 QTableWidget *OpsImageOverlay::table ()
0070 {
0071     return imageOverlayTable;
0072 }
0073 
0074 QGroupBox *OpsImageOverlay::tableTitleBox()
0075 {
0076     return ImageOverlayTableBox;
0077 }
0078 
0079 QPlainTextEdit *OpsImageOverlay::statusDisplay ()
0080 {
0081     return imageOverlayStatus;
0082 }
0083 
0084 QPushButton *OpsImageOverlay::solvePushButton ()
0085 {
0086     return solveButton;
0087 }
0088 QComboBox *OpsImageOverlay::solverProfile ()
0089 {
0090     return imageOverlaySolverProfile;
0091 }
0092 
0093 void OpsImageOverlay::syncOptions()
0094 {
0095     kcfg_ShowImageOverlays->setChecked(Options::showImageOverlays());
0096     kcfg_ImageOverlayMaxDimension->setValue(Options::imageOverlayMaxDimension());
0097     kcfg_ImageOverlayTimeout->setValue(Options::imageOverlayTimeout());
0098     kcfg_ImageOverlayDefaultScale->setValue(Options::imageOverlayDefaultScale());
0099 }
0100 
0101 void OpsImageOverlay::slotApply()
0102 {
0103     KStarsData *data = KStarsData::Instance();
0104     SkyMap *map      = SkyMap::Instance();
0105 
0106     data->setFullTimeUpdate();
0107     KStars::Instance()->updateTime();
0108     map->forceUpdate();
0109 }