From 6cb5478c5c21828eb8eaff53d86af85a9584fdd4 Mon Sep 17 00:00:00 2001 From: Roland Rossgotterer Date: Mon, 29 Jul 2019 10:54:35 +0200 Subject: [PATCH] Synchronize radar screen with own aircraft heading ref T653 --- src/blackgui/components/radarcomponent.cpp | 27 ++++++++ src/blackgui/components/radarcomponent.h | 3 + src/blackgui/components/radarcomponent.ui | 74 +++++++++------------- 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/blackgui/components/radarcomponent.cpp b/src/blackgui/components/radarcomponent.cpp index 16607553b..87ebf47fc 100644 --- a/src/blackgui/components/radarcomponent.cpp +++ b/src/blackgui/components/radarcomponent.cpp @@ -11,6 +11,7 @@ #include "blackgui/infoarea.h" #include "blackgui/components/radarcomponent.h" #include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" #include "blackmisc/simulation/simulatedaircraft.h" #include @@ -50,6 +51,7 @@ namespace BlackGui connect(ui->gv_RadarView, &CRadarView::radarViewResized, this, &CRadarComponent::fitInView); connect(ui->gv_RadarView, &CRadarView::zoomEvent, this, &CRadarComponent::changeRangeInSteps); connect(&m_updateTimer, &QTimer::timeout, this, &CRadarComponent::refreshTargets); + connect(&m_headingTimer, &QTimer::timeout, this, &CRadarComponent::rotateView); connect(ui->cb_RadarRange, qOverload(&QComboBox::currentIndexChanged), this, &CRadarComponent::changeRangeFromUserSelection); connect(ui->cb_Callsign, &QCheckBox::toggled, this, &CRadarComponent::refreshTargets); @@ -61,6 +63,7 @@ namespace BlackGui prepareScene(); m_updateTimer.start(5000); + m_headingTimer.start(50); } CRadarComponent::~CRadarComponent() @@ -197,6 +200,30 @@ namespace BlackGui } } + void CRadarComponent::rotateView() + { + if (sGui->getIContextOwnAircraft()) + { + if (isVisibleWidget()) + { + int headingDegree = 0; + if (! ui->cb_LockNorth->isChecked()) + { + headingDegree = sGui->getIContextOwnAircraft()->getOwnAircraftSituation().getHeading().valueInteger(CAngleUnit::deg()); + } + + if (m_rotatenAngle != headingDegree) + { + // Rotations are summed up, hence rotate back before applying the new rotation. + // Doing a global transformation reset will not work as it resets also zooming. + ui->gv_RadarView->rotate(-m_rotatenAngle); + ui->gv_RadarView->rotate(headingDegree); + m_rotatenAngle = headingDegree; + } + } + } + } + void CRadarComponent::toggleGrid(bool checked) { m_macroGraticule.setVisible(checked); diff --git a/src/blackgui/components/radarcomponent.h b/src/blackgui/components/radarcomponent.h index 1105b0ced..84212f57e 100644 --- a/src/blackgui/components/radarcomponent.h +++ b/src/blackgui/components/radarcomponent.h @@ -49,6 +49,7 @@ namespace BlackGui void addRadials(); void refreshTargets(); + void rotateView(); void toggleGrid(bool checked); @@ -70,8 +71,10 @@ namespace BlackGui QPen m_radarTargetPen = { Qt::green, 1 }; qreal m_rangeNM = 10.0; + int m_rotatenAngle = 0; QTimer m_updateTimer; + QTimer m_headingTimer; }; } // ns } // ns diff --git a/src/blackgui/components/radarcomponent.ui b/src/blackgui/components/radarcomponent.ui index 9db0ab241..06ec74418 100644 --- a/src/blackgui/components/radarcomponent.ui +++ b/src/blackgui/components/radarcomponent.ui @@ -6,7 +6,7 @@ 0 0 - 270 + 342 259 @@ -44,6 +44,13 @@ 2 + + + + Lock North + + + @@ -54,17 +61,7 @@ - - - - Grid - - - true - - - - + Altitude (FL) @@ -74,7 +71,7 @@ - + GroundSpeed @@ -95,34 +92,26 @@ - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Range - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - + + + Grid + + + true + + + + + + + + + + Range + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -140,11 +129,8 @@ gv_RadarView cb_Callsign - cb_Heading - cb_Altitude cb_GroundSpeed cb_Grid - cb_RadarRange