File indexing completed on 2024-04-28 15:39:05
0001 // SPDX-FileCopyrightText: 2020 Tobias Leupold <tl at stonemx dot de> 0002 // 0003 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 0005 // Local includes 0006 #include "CoordinatesDialog.h" 0007 0008 // KDE includes 0009 #include <KLocalizedString> 0010 0011 // Qt includes 0012 #include <QApplication> 0013 #include <QVBoxLayout> 0014 #include <QGridLayout> 0015 #include <QLabel> 0016 #include <QLineEdit> 0017 #include <QDoubleSpinBox> 0018 #include <QDialogButtonBox> 0019 #include <QDebug> 0020 0021 CoordinatesDialog::CoordinatesDialog(Mode mode, bool hideAlt, const Coordinates &coordinates, 0022 const QString &target) 0023 : QDialog(QApplication::activeWindow()) 0024 { 0025 auto *layout = new QVBoxLayout(this); 0026 auto *grid = new QGridLayout; 0027 layout->addLayout(grid); 0028 0029 int row = -1; 0030 0031 auto *titleLabel = new QLabel; 0032 titleLabel->setWordWrap(true); 0033 grid->addWidget(titleLabel, ++row, 0, 1, 2); 0034 0035 auto *labelLabel = new QLabel(i18n("Label:")); 0036 grid->addWidget(labelLabel, ++row, 0); 0037 m_label = new QLineEdit; 0038 grid->addWidget(m_label, row, 1); 0039 0040 auto *lonLabel = new QLabel(i18n("Longitude:")); 0041 grid->addWidget(lonLabel, ++row, 0); 0042 m_lon = new QDoubleSpinBox; 0043 m_lon->setDecimals(KGeoTag::degreesPrecision); 0044 m_lon->setRange(-180.0, 180.0); 0045 m_lon->setSuffix(i18nc("Degrees symbol", "\u2009°")); 0046 m_lon->setValue(coordinates.lon()); 0047 grid->addWidget(m_lon, row, 1); 0048 0049 auto *latLabel = new QLabel(i18n("Latitude:")); 0050 grid->addWidget(latLabel, ++row, 0); 0051 m_lat = new QDoubleSpinBox; 0052 m_lat->setDecimals(KGeoTag::degreesPrecision); 0053 m_lat->setRange(-90.0, 90.0); 0054 m_lat->setSuffix(i18nc("Degrees symbol", "\u2009°")); 0055 m_lat->setValue(coordinates.lat()); 0056 grid->addWidget(m_lat, row, 1); 0057 0058 0059 auto *altLabel = new QLabel(i18n("Altitude:")); 0060 grid->addWidget(altLabel, ++row, 0); 0061 altLabel->setVisible(! hideAlt); 0062 m_alt = new QDoubleSpinBox; 0063 m_alt->setDecimals(KGeoTag::altitudePrecision); 0064 m_alt->setRange(KGeoTag::minimalAltitude, KGeoTag::maximalAltitude); 0065 m_alt->setSuffix(i18nc("Meters abbreviation", "\u2009m")); 0066 m_alt->setValue(coordinates.alt()); 0067 grid->addWidget(m_alt, row, 1); 0068 m_alt->setVisible(! hideAlt); 0069 0070 auto *automaticAltLabel = new QLabel(i18n("<i>The altitude is looked up automatically</i>")); 0071 automaticAltLabel->setWordWrap(true); 0072 grid->addWidget(automaticAltLabel, ++row, 0, 1, 2); 0073 automaticAltLabel->setVisible(hideAlt); 0074 0075 switch (mode) { 0076 0077 case Mode::ManualBookmark: 0078 setWindowTitle(i18n("New bookmark")); 0079 titleLabel->setText(i18n("Data for the new bookmark:")); 0080 break; 0081 0082 case Mode::EditCoordinates: 0083 labelLabel->hide(); 0084 m_label->hide(); 0085 setWindowTitle(i18n("Manual coordinates")); 0086 titleLabel->setText(i18n("Coordinates for %1:", target)); 0087 break; 0088 0089 } 0090 0091 auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0092 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0093 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0094 layout->addWidget(buttonBox); 0095 } 0096 0097 QString CoordinatesDialog::label() const 0098 { 0099 const auto text = m_label->text().simplified(); 0100 return text.isEmpty() ? i18n("Untitled") : text; 0101 } 0102 0103 double CoordinatesDialog::lon() const 0104 { 0105 return m_lon->value(); 0106 } 0107 0108 double CoordinatesDialog::lat() const 0109 { 0110 return m_lat->value(); 0111 } 0112 0113 double CoordinatesDialog::alt() const 0114 { 0115 return m_alt->value(); 0116 } 0117 0118 Coordinates CoordinatesDialog::coordinates() const 0119 { 0120 return Coordinates(m_lon->value(), m_lat->value(), m_alt->value(), true); 0121 }