File indexing completed on 2024-04-28 15:39:05
0001 // SPDX-FileCopyrightText: 2020-2024 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 "FixDriftWidget.h" 0007 0008 // Qt includes 0009 #include <QDebug> 0010 #include <QVBoxLayout> 0011 #include <QHBoxLayout> 0012 #include <QLabel> 0013 #include <QSpinBox> 0014 #include <QCheckBox> 0015 #include <QGroupBox> 0016 #include <QComboBox> 0017 0018 // KDE includes 0019 #include <KLocalizedString> 0020 0021 FixDriftWidget::FixDriftWidget(QWidget *parent) : QWidget(parent) 0022 { 0023 auto *layout = new QVBoxLayout(this); 0024 0025 auto *timeZoneBox = new QGroupBox(i18n("Images' time zone")); 0026 auto *timeZoneBoxLayout = new QVBoxLayout(timeZoneBox); 0027 layout->addWidget(timeZoneBox); 0028 0029 timeZoneBoxLayout->addWidget(new QLabel(i18n("The images were taken in the following " 0030 "timezone:"))); 0031 0032 m_timeZone = new QComboBox; 0033 m_timeZone->setEditable(true); 0034 m_timeZone->setInsertPolicy(QComboBox::NoInsert); 0035 0036 const auto systemTimeZoneId = QTimeZone::systemTimeZoneId(); 0037 const auto allTimeZones = QTimeZone::availableTimeZoneIds(); 0038 int index = 0; 0039 int systemIndex = -1; 0040 for (const auto &timeZone : allTimeZones) { 0041 auto currentTimeZone = QTimeZone(timeZone); 0042 m_timeZone->addItem(QString::fromLatin1(timeZone), timeZone); 0043 if (systemIndex == -1 && timeZone == systemTimeZoneId) { 0044 systemIndex = index; 0045 } 0046 index++; 0047 } 0048 0049 timeZoneBoxLayout->addWidget(m_timeZone); 0050 0051 connect(m_timeZone, QOverload<int>::of(&QComboBox::currentIndexChanged), 0052 this, &FixDriftWidget::imagesTimeZoneChanged); 0053 connect(m_timeZone, QOverload<int>::of(&QComboBox::currentIndexChanged), 0054 this, [this] 0055 { 0056 m_imagesTimeZone = QTimeZone(m_timeZone->currentData().toByteArray()); 0057 }); 0058 0059 // We should always find a valid index, as QTimeZone::systemTimeZoneId() will return the 0060 // UTC timezone if the system timezone is not known by Qt. However, to be sure to avoid a 0061 // segfault: 0062 if (systemIndex != -1) { 0063 m_timeZone->setCurrentIndex(systemIndex); 0064 } 0065 0066 auto *driftBox = new QGroupBox(i18n("Camera clock time drift")); 0067 auto *driftBoxLayout = new QVBoxLayout(driftBox); 0068 layout->addWidget(driftBox); 0069 0070 auto *driftLabel = new QLabel(i18n("Deviation between image dates and the (exact) GPS data " 0071 "time:")); 0072 driftLabel->setWordWrap(true); 0073 driftBoxLayout->addWidget(driftLabel); 0074 0075 auto *deviationLayout = new QHBoxLayout; 0076 driftBoxLayout->addLayout(deviationLayout); 0077 0078 m_driftHours = new QSpinBox; 0079 m_driftHours->setMinimum(-24); 0080 m_driftHours->setMaximum(24); 0081 deviationLayout->addWidget(m_driftHours); 0082 deviationLayout->addWidget(new QLabel(i18n("hours"))); 0083 connect(m_driftHours, QOverload<int>::of(&QSpinBox::valueChanged), 0084 this, &FixDriftWidget::cameraDriftSettingsChanged); 0085 0086 m_driftMinutes = new QSpinBox; 0087 m_driftMinutes->setMinimum(-1440); 0088 m_driftMinutes->setMaximum(1440); 0089 deviationLayout->addWidget(m_driftMinutes); 0090 deviationLayout->addWidget(new QLabel(i18n("minutes"))); 0091 connect(m_driftMinutes, QOverload<int>::of(&QSpinBox::valueChanged), 0092 this, &FixDriftWidget::cameraDriftSettingsChanged); 0093 0094 m_driftSeconds = new QSpinBox; 0095 m_driftSeconds->setMinimum(-86400); 0096 m_driftSeconds->setMaximum(86400); 0097 deviationLayout->addWidget(m_driftSeconds); 0098 deviationLayout->addWidget(new QLabel(i18n("seconds"))); 0099 connect(m_driftSeconds, QOverload<int>::of(&QSpinBox::valueChanged), 0100 this, &FixDriftWidget::cameraDriftSettingsChanged); 0101 0102 deviationLayout->addStretch(); 0103 0104 m_displayFixed = new QCheckBox(i18n("Display the fixed dates and times")); 0105 m_displayFixed->setChecked(true); 0106 driftBoxLayout->addWidget(m_displayFixed); 0107 connect(m_displayFixed, &QCheckBox::toggled, this, &FixDriftWidget::cameraDriftSettingsChanged); 0108 0109 m_save = new QCheckBox(i18n("Fix the files' dates and times when saving")); 0110 driftBoxLayout->addWidget(m_save); 0111 0112 layout->addStretch(); 0113 } 0114 0115 int FixDriftWidget::cameraClockDeviation() const 0116 { 0117 return m_driftHours->value() * 3600 0118 + m_driftMinutes->value() * 60 0119 + m_driftSeconds->value(); 0120 } 0121 0122 bool FixDriftWidget::save() const 0123 { 0124 return m_save->isChecked(); 0125 } 0126 0127 QByteArray FixDriftWidget::imagesTimeZoneId() const 0128 { 0129 return m_timeZone->currentData().toByteArray(); 0130 } 0131 0132 const QTimeZone &FixDriftWidget::imagesTimeZone() const 0133 { 0134 return m_imagesTimeZone; 0135 } 0136 0137 bool FixDriftWidget::setImagesTimeZone(const QByteArray &id) 0138 { 0139 const int index = m_timeZone->findData(id); 0140 if (index != -1) { 0141 m_timeZone->setCurrentIndex(index); 0142 return true; 0143 } else { 0144 return false; 0145 } 0146 } 0147 0148 bool FixDriftWidget::displayFixed() const 0149 { 0150 return m_displayFixed->isChecked(); 0151 }