1 // BaseDiagram.hxx - 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 #ifndef GUI_BASEDIAGRAM_HXX
22 #define GUI_BASEDIAGRAM_HXX
25 #include <QPainterPath>
28 #include <simgear/math/sg_geodesy.hxx>
30 #include <Navaids/positioned.hxx>
31 #include <Airports/airport.hxx>
32 #include <Navaids/PolyLine.hxx>
34 #include "QtLauncher_fwd.hxx"
36 class BaseDiagram : public QWidget
40 BaseDiagram(QWidget* pr);
46 LargeAirportPlans = 0x2
49 Q_DECLARE_FLAGS(IconOptions, IconOption)
51 static QPixmap iconForPositioned(const FGPositionedRef &pos, const IconOptions& options = NoOptions);
52 static QPixmap iconForAirport(FGAirport *apt, const IconOptions& options = NoOptions);
54 static QVector<QLineF> projectAirportRuwaysIntoRect(FGAirportRef apt, const QRectF& bounds);
55 static QVector<QLineF> projectAirportRuwaysWithCenter(FGAirportRef apt, const SGGeod &c);
57 void setAircraftType(LauncherAircraftType type);
59 virtual void paintEvent(QPaintEvent* pe);
61 virtual void mousePressEvent(QMouseEvent* me);
62 virtual void mouseMoveEvent(QMouseEvent* me);
64 virtual void wheelEvent(QWheelEvent* we);
66 virtual void paintContents(QPainter*);
70 void recomputeBounds(bool resetZoom);
72 virtual void doComputeBounds();
74 void extendBounds(const QPointF& p);
75 QPointF project(const SGGeod& geod) const;
76 QTransform transform() const;
78 void clearIgnoredNavaids();
79 void addIgnoredNavaid(FGPositionedRef pos);
81 SGGeod m_projectionCenter;
85 QPointF m_panOffset, m_lastMousePos;
86 int m_wheelAngleDeltaAccumulator;
88 LauncherAircraftType m_aircraftType;
90 static void extendRect(QRectF& r, const QPointF& p);
92 static QPointF project(const SGGeod &geod, const SGGeod ¢er);
94 static SGGeod unproject(const QPointF &xy, const SGGeod ¢er);
96 void paintAirplaneIcon(QPainter *painter, const SGGeod &geod, int headingDeg);
108 LAST_POSITION // marker value
111 void paintNavaids(QPainter *p);
113 bool isNavaidIgnored(const FGPositionedRef& pos) const;
115 bool isLabelRectAvailable(const QRect& r) const;
116 QRect rectAndFlagsForLabel(PositionedID guid, const QRect &item,
118 int & flags /* out parameter */) const;
119 QRect labelPositioned(const QRect &itemRect, const QSize &bounds, LabelPosition lp) const;
121 QVector<FGPositionedRef> m_ignored;
123 mutable QHash<PositionedID, LabelPosition> m_labelPositions;
124 mutable QVector<QRect> m_labelRects;
126 static int textFlagsForLabelPosition(LabelPosition pos);
128 void splitItems(const FGPositionedList &in, FGPositionedList &navaids, FGPositionedList &ports);
129 void paintNavaid(QPainter *painter,
131 const FGPositionedRef &pos);
132 void paintPolygonData(QPainter *painter);
133 void paintGeodVec(QPainter *painter, const flightgear::SGGeodVec &vec);
134 void fillClosedGeodVec(QPainter *painter, const QColor &color, const flightgear::SGGeodVec &vec);
137 Q_DECLARE_OPERATORS_FOR_FLAGS(BaseDiagram::IconOptions)
139 #endif // of GUI_BASEDIAGRAM_HXX