2021-01-22 09:54:22 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2021 Jon Beniston, M7RCE //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QDebug>
|
2021-02-26 15:30:59 -05:00
|
|
|
#include <QColorDialog>
|
|
|
|
#include <QColor>
|
2021-01-22 09:54:22 -05:00
|
|
|
|
|
|
|
#include "util/units.h"
|
|
|
|
|
|
|
|
#include "mapsettingsdialog.h"
|
|
|
|
#include "maplocationdialog.h"
|
|
|
|
|
2021-02-26 15:30:59 -05:00
|
|
|
static QString rgbToColor(quint32 rgb)
|
|
|
|
{
|
|
|
|
QColor color = QColor::fromRgb(rgb);
|
|
|
|
return QString("%1,%2,%3").arg(color.red()).arg(color.green()).arg(color.blue());
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString backgroundCSS(quint32 rgb)
|
|
|
|
{
|
|
|
|
return QString("QToolButton { background:rgb(%1); }").arg(rgbToColor(rgb));
|
|
|
|
}
|
|
|
|
|
2021-01-22 09:54:22 -05:00
|
|
|
MapSettingsDialog::MapSettingsDialog(MapSettings *settings, QWidget* parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
m_settings(settings),
|
|
|
|
ui(new Ui::MapSettingsDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->mapProvider->setCurrentIndex(MapSettings::m_mapProviders.indexOf(settings->m_mapProvider));
|
2021-11-23 11:44:07 -05:00
|
|
|
ui->thunderforestAPIKey->setText(settings->m_thunderforestAPIKey);
|
|
|
|
ui->maptilerAPIKey->setText(settings->m_maptilerAPIKey);
|
|
|
|
ui->mapBoxAPIKey->setText(settings->m_mapBoxAPIKey);
|
|
|
|
ui->osmURL->setText(settings->m_osmURL);
|
2021-01-22 09:54:22 -05:00
|
|
|
ui->mapBoxStyles->setText(settings->m_mapBoxStyles);
|
2021-11-23 11:44:07 -05:00
|
|
|
for (int i = 0; i < ui->sourceList->count(); i++) {
|
2021-01-22 09:54:22 -05:00
|
|
|
ui->sourceList->item(i)->setCheckState((m_settings->m_sources & (1 << i)) ? Qt::Checked : Qt::Unchecked);
|
2021-11-23 11:44:07 -05:00
|
|
|
}
|
2021-02-26 15:30:59 -05:00
|
|
|
ui->groundTrackColor->setStyleSheet(backgroundCSS(m_settings->m_groundTrackColor));
|
|
|
|
ui->predictedGroundTrackColor->setStyleSheet(backgroundCSS(m_settings->m_predictedGroundTrackColor));
|
2021-01-22 09:54:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MapSettingsDialog::~MapSettingsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapSettingsDialog::accept()
|
|
|
|
{
|
|
|
|
QString mapProvider = MapSettings::m_mapProviders[ui->mapProvider->currentIndex()];
|
2021-11-23 11:44:07 -05:00
|
|
|
QString mapBoxAPIKey = ui->mapBoxAPIKey->text();
|
|
|
|
QString osmURL = ui->osmURL->text();
|
2021-01-22 09:54:22 -05:00
|
|
|
QString mapBoxStyles = ui->mapBoxStyles->text();
|
2021-11-23 11:44:07 -05:00
|
|
|
QString thunderforestAPIKey = ui->thunderforestAPIKey->text();
|
|
|
|
QString maptilerAPIKey = ui->maptilerAPIKey->text();
|
|
|
|
m_osmURLChanged = osmURL != m_settings->m_osmURL;
|
2021-01-22 09:54:22 -05:00
|
|
|
if ((mapProvider != m_settings->m_mapProvider)
|
2021-11-23 11:44:07 -05:00
|
|
|
|| (thunderforestAPIKey != m_settings->m_thunderforestAPIKey)
|
|
|
|
|| (maptilerAPIKey != m_settings->m_maptilerAPIKey)
|
|
|
|
|| (mapBoxAPIKey != m_settings->m_mapBoxAPIKey)
|
|
|
|
|| (mapBoxStyles != m_settings->m_mapBoxStyles)
|
|
|
|
|| (osmURL != m_settings->m_osmURL))
|
2021-01-22 09:54:22 -05:00
|
|
|
{
|
|
|
|
m_settings->m_mapProvider = mapProvider;
|
2021-11-23 11:44:07 -05:00
|
|
|
m_settings->m_thunderforestAPIKey = thunderforestAPIKey;
|
|
|
|
m_settings->m_maptilerAPIKey = maptilerAPIKey;
|
|
|
|
m_settings->m_mapBoxAPIKey = mapBoxAPIKey;
|
|
|
|
m_settings->m_osmURL = osmURL;
|
2021-01-22 09:54:22 -05:00
|
|
|
m_settings->m_mapBoxStyles = mapBoxStyles;
|
|
|
|
m_mapSettingsChanged = true;
|
|
|
|
}
|
|
|
|
else
|
2021-11-23 11:44:07 -05:00
|
|
|
{
|
2021-01-22 09:54:22 -05:00
|
|
|
m_mapSettingsChanged = false;
|
2021-11-23 11:44:07 -05:00
|
|
|
}
|
2021-01-22 09:54:22 -05:00
|
|
|
m_settings->m_sources = 0;
|
|
|
|
quint32 sources = MapSettings::SOURCE_STATION;
|
2021-11-23 11:44:07 -05:00
|
|
|
for (int i = 0; i < ui->sourceList->count(); i++) {
|
2021-01-22 09:54:22 -05:00
|
|
|
sources |= (ui->sourceList->item(i)->checkState() == Qt::Checked) << i;
|
2021-11-23 11:44:07 -05:00
|
|
|
}
|
2021-01-22 09:54:22 -05:00
|
|
|
m_sourcesChanged = sources != m_settings->m_sources;
|
|
|
|
m_settings->m_sources = sources;
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
2021-02-26 15:30:59 -05:00
|
|
|
|
|
|
|
void MapSettingsDialog::on_groundTrackColor_clicked()
|
|
|
|
{
|
|
|
|
QColorDialog dialog(QColor::fromRgb(m_settings->m_groundTrackColor), this);
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
m_settings->m_groundTrackColor = dialog.selectedColor().rgb();
|
|
|
|
ui->groundTrackColor->setStyleSheet(backgroundCSS(m_settings->m_groundTrackColor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapSettingsDialog::on_predictedGroundTrackColor_clicked()
|
|
|
|
{
|
|
|
|
QColorDialog dialog(QColor::fromRgb(m_settings->m_predictedGroundTrackColor), this);
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
m_settings->m_predictedGroundTrackColor = dialog.selectedColor().rgb();
|
|
|
|
ui->predictedGroundTrackColor->setStyleSheet(backgroundCSS(m_settings->m_predictedGroundTrackColor));
|
|
|
|
}
|
|
|
|
}
|