1 // NavaidDiagram.cxx - part of GUI launcher using Qt5
3 // Written by James Turner, started October 2015.
5 // Copyright (C) 2014 James Turner <zakalawe@mac.com>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "NavaidDiagram.hxx"
28 #include <QMouseEvent>
30 NavaidDiagram::NavaidDiagram(QWidget* pr) :
32 m_offsetEnabled(false),
33 m_offsetDistanceNm(5.0),
34 m_offsetBearingDeg(0),
40 void NavaidDiagram::setNavaid(FGPositionedRef nav)
43 m_projectionCenter = nav ? nav->geod() : SGGeod();
45 recomputeBounds(true);
48 void NavaidDiagram::setGeod(const SGGeod &geod)
52 m_projectionCenter = m_geod;
53 recomputeBounds(true);
56 void NavaidDiagram::setOffsetEnabled(bool offset)
58 if (m_offsetEnabled == offset)
60 m_offsetEnabled = offset;
61 recomputeBounds(true);
64 void NavaidDiagram::setOffsetDistanceNm(double distanceNm)
66 m_offsetDistanceNm = distanceNm;
70 void NavaidDiagram::setOffsetBearingDeg(int bearingDeg)
72 m_offsetBearingDeg = bearingDeg;
76 void NavaidDiagram::paintContents(QPainter *painter)
78 QPointF base = project(m_geod);
80 QPointF airplaneIconPos = base;
82 if (m_offsetEnabled) {
83 double d = m_offsetDistanceNm * SG_NM_TO_METER;
84 SGGeod offsetGeod = SGGeodesy::direct(m_geod, m_offsetBearingDeg, d);
85 QPointF offset = project(offsetGeod);
88 pen.setCosmetic(true);
90 painter->drawLine(base, offset);
92 airplaneIconPos = offset;
95 QPixmap pix(":/airplane-icon");
96 airplaneIconPos = painter->transform().map(airplaneIconPos);
97 painter->resetTransform();
98 QRect airplaneIconRect = pix.rect();
99 airplaneIconRect.moveCenter(airplaneIconPos.toPoint());
100 painter->drawPixmap(airplaneIconRect, pix);
103 void NavaidDiagram::doComputeBounds()
105 extendBounds(project(m_geod));
107 // project three points around the base location at 40nm to give some
109 for (int i=0; i<3; ++i) {
110 SGGeod pt = SGGeodesy::direct(m_geod, i * 120, SG_NM_TO_METER * 40.0);
111 extendBounds(project(pt));
114 if (m_offsetEnabled) {
115 double d = m_offsetDistanceNm * SG_NM_TO_METER;
116 SGGeod offsetPos = SGGeodesy::direct(m_geod, m_offsetBearingDeg, d);
117 extendBounds(project(offsetPos));