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

0001 /*
0002     SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "opsterrain.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 OpsTerrain::OpsTerrain() : QFrame(KStars::Instance())
0023 {
0024     setupUi(this);
0025 
0026     m_ConfigDialog = KConfigDialog::exists("settings");
0027 
0028     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
0029     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
0030 
0031     selectTerrainFileB->setIcon(QIcon::fromTheme("document-open"));
0032     selectTerrainFileB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
0033     connect(selectTerrainFileB, SIGNAL(clicked()), this, SLOT(saveTerrainFilename()));
0034 }
0035 
0036 void OpsTerrain::syncOptions()
0037 {
0038     kcfg_ShowTerrain->setChecked(Options::showTerrain());
0039     kcfg_TerrainPanning->setChecked(Options::terrainPanning());
0040     kcfg_TerrainSkipSpeedup->setChecked(Options::terrainSkipSpeedup());
0041     kcfg_TerrainSmoothPixels->setChecked(Options::terrainSmoothPixels());
0042     kcfg_TerrainTransparencySpeedup->setChecked(Options::terrainTransparencySpeedup());
0043 }
0044 
0045 
0046 void OpsTerrain::saveTerrainFilename()
0047 {
0048     QDir dir = QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/terrain");
0049     dir.mkpath(".");
0050 
0051     QUrl dirPath = QUrl::fromLocalFile(dir.path());
0052     QUrl fileUrl =
0053         QFileDialog::getOpenFileUrl(KStars::Instance(), i18nc("@title:window", "Terrain Image Filename"), dirPath,
0054                                     i18n("PNG Files (*.png)"));
0055 
0056     if (!fileUrl.isEmpty())
0057         kcfg_TerrainSource->setText(fileUrl.toLocalFile());
0058 }
0059 
0060 void OpsTerrain::slotApply()
0061 {
0062     KStarsData *data = KStarsData::Instance();
0063     SkyMap *map      = SkyMap::Instance();
0064 
0065     data->setFullTimeUpdate();
0066     KStars::Instance()->updateTime();
0067     map->forceUpdate();
0068 }