File indexing completed on 2024-04-28 15:39:07
0001 // SPDX-FileCopyrightText: 2021-2023 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 "MapCenterInfo.h" 0007 #include "SharedObjects.h" 0008 #include "Coordinates.h" 0009 #include "CoordinatesFormatter.h" 0010 0011 // KDE includes 0012 #include <KLocalizedString> 0013 0014 // Qt includes 0015 #include <QDebug> 0016 #include <QHBoxLayout> 0017 #include <QLabel> 0018 #include <QLocale> 0019 0020 MapCenterInfo::MapCenterInfo(SharedObjects *sharedObjects, QWidget *parent) 0021 : QWidget(parent), 0022 m_formatter(sharedObjects->coordinatesFormatter()), 0023 m_locale(sharedObjects->locale()) 0024 { 0025 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); 0026 0027 auto *layout = new QHBoxLayout(this); 0028 layout->setContentsMargins(0, 0, 0, 0); 0029 0030 m_coordinatesLabel = new QLabel; 0031 layout->addWidget(m_coordinatesLabel); 0032 0033 layout->addStretch(); 0034 0035 m_dateTimeLabel = new QLabel; 0036 layout->addWidget(m_dateTimeLabel); 0037 } 0038 0039 void MapCenterInfo::displayCoordinates(const Coordinates &coordinates) 0040 { 0041 m_coordinatesLabel->setText(i18nc("This displays the coordinates of the current map center", 0042 "Map center position: %1, %2", 0043 m_formatter->lon(coordinates), 0044 m_formatter->lat(coordinates))); 0045 } 0046 0047 void MapCenterInfo::mapMoved(const Coordinates ¢er) 0048 { 0049 displayCoordinates(center); 0050 m_dateTimeLabel->clear(); 0051 } 0052 0053 void MapCenterInfo::trackPointCentered(const Coordinates &coordinates, const QDateTime &dateTime) 0054 { 0055 displayCoordinates(coordinates); 0056 m_dateTimeLabel->setText(dateTime.toString(m_locale->dateTimeFormat())); 0057 }