Skip to content

Commit

Permalink
Add mouse geo coordinates and UTC time to status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulat committed Jan 7, 2024
1 parent 0c8d1ae commit f54f6d1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
58 changes: 57 additions & 1 deletion scwx-qt/source/scwx/qt/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <scwx/common/products.hpp>
#include <scwx/common/vcp.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/time.hpp>

#include <boost/asio/post.hpp>
#include <boost/asio/thread_pool.hpp>
Expand All @@ -42,6 +43,7 @@
#include <QMessageBox>
#include <QSplitter>
#include <QStandardPaths>
#include <QTimer>
#include <QToolButton>

#if !defined(_MSC_VER)
Expand Down Expand Up @@ -125,7 +127,11 @@ class MainWindowImpl : public QObject
positionManager_->TrackLocation(true);
}
}
~MainWindowImpl() { threadPool_.join(); }
~MainWindowImpl()
{
clockTimer_.stop();
threadPool_.join();
}

void AddRadarSitePreset(const std::string& id);
void AsyncSetup();
Expand Down Expand Up @@ -169,6 +175,9 @@ class MainWindowImpl : public QObject

ui::Level3ProductsWidget* level3ProductsWidget_;

QLabel* coordinateLabel_ {nullptr};
QLabel* timeLabel_ {nullptr};

ui::AlertDockWidget* alertDockWidget_;
ui::AnimationDockWidget* animationDockWidget_;
ui::AboutDialog* aboutDialog_;
Expand All @@ -179,6 +188,8 @@ class MainWindowImpl : public QObject
ui::SettingsDialog* settingsDialog_;
ui::UpdateDialog* updateDialog_;

QTimer clockTimer_ {};

std::shared_ptr<manager::AlertManager> alertManager_;
std::shared_ptr<manager::PlacefileManager> placefileManager_;
std::shared_ptr<manager::PositionManager> positionManager_;
Expand Down Expand Up @@ -317,6 +328,25 @@ MainWindow::MainWindow(QWidget* parent) :
ui->radarToolboxScrollAreaContents->layout()->addItem(
ui->radarToolboxSpacer);

// Status Bar
QWidget* statusBarWidget = new QWidget(this);

p->coordinateLabel_ = new QLabel(this);
p->coordinateLabel_->setFrameShape(QFrame::Shape::Box);
p->coordinateLabel_->setFrameShadow(QFrame::Shadow::Sunken);
p->coordinateLabel_->setVisible(false);

p->timeLabel_ = new QLabel(this);
p->timeLabel_->setFrameShape(QFrame::Shape::Box);
p->timeLabel_->setFrameShadow(QFrame::Shadow::Sunken);
p->timeLabel_->setVisible(false);

QGridLayout* statusBarLayout = new QGridLayout(statusBarWidget);
statusBarLayout->setContentsMargins(0, 0, 0, 0);
statusBarLayout->addWidget(p->coordinateLabel_, 0, 0);
statusBarLayout->addWidget(p->timeLabel_, 0, 1);
ui->statusbar->addPermanentWidget(statusBarWidget);

// ImGui Debug Dialog
p->imGuiDebugDialog_ = new ui::ImGuiDebugDialog(this);

Expand Down Expand Up @@ -715,6 +745,21 @@ void MainWindowImpl::ConnectMapSignals()
}
});

connect(mapWidget,
&map::MapWidget::MouseCoordinateChanged,
this,
[this](common::Coordinate coordinate)
{
const QString latitude = QString::fromStdString(
common::GetLatitudeString(coordinate.latitude_));
const QString longitude = QString::fromStdString(
common::GetLongitudeString(coordinate.longitude_));

coordinateLabel_->setText(
QString("%1, %2").arg(latitude).arg(longitude));
coordinateLabel_->setVisible(true);
});

connect(
mapWidget,
&map::MapWidget::RadarSweepUpdated,
Expand Down Expand Up @@ -986,6 +1031,17 @@ void MainWindowImpl::ConnectOtherSignals()
updateDialog_->UpdateReleaseInfo(latestVersion, latestRelease);
updateDialog_->show();
});

connect(&clockTimer_,
&QTimer::timeout,
this,
[this]()
{
timeLabel_->setText(QString("%1 UTC").arg(QString::fromStdString(
util::TimeString(std::chrono::system_clock::now()))));
timeLabel_->setVisible(true);
});
clockTimer_.start(1000);
}

void MainWindowImpl::AddRadarSitePreset(const std::string& siteId)
Expand Down
3 changes: 3 additions & 0 deletions scwx-qt/source/scwx/qt/map/map_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,9 @@ void MapWidgetImpl::RunMousePicking()
util::tooltip::Hide();
}

Q_EMIT widget_->MouseCoordinateChanged(
{coordinate.first, coordinate.second});

lastItemPicked_ = itemPicked;
}

Expand Down
2 changes: 2 additions & 0 deletions scwx-qt/source/scwx/qt/map/map_widget.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <scwx/common/geographic.hpp>
#include <scwx/common/products.hpp>
#include <scwx/qt/config/radar_site.hpp>
#include <scwx/qt/types/map_types.hpp>
Expand Down Expand Up @@ -147,6 +148,7 @@ private slots:
double bearing,
double pitch);
void MapStyleChanged(const std::string& styleName);
void MouseCoordinateChanged(common::Coordinate coordinate);
void RadarSiteRequested(const std::string& id);
void RadarSiteUpdated(std::shared_ptr<config::RadarSite> radarSite);
void RadarSweepUpdated();
Expand Down

0 comments on commit f54f6d1

Please sign in to comment.