void AirportDiagram::paintContents(QPainter* p)
{
- // fit bounds within our available space, allowing for a margin
-// const int MARGIN = 32; // pixels
- // double ratioInX = (width() - MARGIN * 2) / m_bounds.width();
- // double ratioInY = (height() - MARGIN * 2) / m_bounds.height();
- // double scale = std::min(ratioInX, ratioInY);
-
- QTransform t(transform());
- p->setTransform(t);
+ QTransform t = p->transform();
// pavements
QBrush brush(QColor(0x9f, 0x9f, 0x9f));
m_autoScalePan = false;
int delta = we->angleDelta().y();
+ if (delta == 0)
+ return;
+
if (intSign(m_wheelAngleDeltaAccumulator) != intSign(delta)) {
m_wheelAngleDeltaAccumulator = 0;
}
if (m_wheelAngleDeltaAccumulator > 120) {
m_wheelAngleDeltaAccumulator = 0;
m_scale *= 2.0;
- } else if (m_wheelAngleDeltaAccumulator < 120) {
+ } else if (m_wheelAngleDeltaAccumulator < -120) {
m_wheelAngleDeltaAccumulator = 0;
m_scale *= 0.5;
}
{
m_navaid = nav;
m_projectionCenter = nav ? nav->geod() : SGGeod();
- m_scale = 1.0;
- m_bounds = QRectF(); // clear
+ m_geod = nav->geod();
+ recomputeBounds(true);
+}
+
+void NavaidDiagram::setGeod(const SGGeod &geod)
+{
+ m_navaid.clear();
+ m_geod = geod;
+ m_projectionCenter = m_geod;
+ recomputeBounds(true);
+}
+
+void NavaidDiagram::setOffsetEnabled(bool offset)
+{
+ if (m_offsetEnabled == offset)
+ return;
+ m_offsetEnabled = offset;
+ recomputeBounds(true);
+}
+
+void NavaidDiagram::setOffsetDistanceNm(double distanceNm)
+{
+ m_offsetDistanceNm = distanceNm;
update();
}
-void NavaidDiagram::paintContents(QPainter *)
+void NavaidDiagram::setOffsetBearingDeg(int bearingDeg)
{
+ m_offsetBearingDeg = bearingDeg;
+ update();
+}
+
+void NavaidDiagram::paintContents(QPainter *painter)
+{
+ QPointF base = project(m_geod);
+
+ if (m_offsetEnabled) {
+ double d = m_offsetDistanceNm * SG_NM_TO_METER;
+ SGGeod offsetGeod = SGGeodesy::direct(m_geod, m_offsetBearingDeg, d);
+ QPointF offset = project(offsetGeod);
+
+ qDebug() << base << offset;
+
+ QPen pen(Qt::green);
+ pen.setCosmetic(true);
+ painter->setPen(pen);
+ painter->drawLine(base, offset);
+ }
+}
+
+void NavaidDiagram::doComputeBounds()
+{
+ extendBounds(project(m_geod));
+
+// project three points around the base location at 40nm to give some
+// coverage
+ for (int i=0; i<3; ++i) {
+ SGGeod pt = SGGeodesy::direct(m_geod, i * 120, SG_NM_TO_METER * 40.0);
+ extendBounds(project(pt));
+ }
+
+ if (m_offsetEnabled) {
+ double d = m_offsetDistanceNm * SG_NM_TO_METER;
+ SGGeod offsetPos = SGGeodesy::direct(m_geod, m_offsetBearingDeg, d);
+ extendBounds(project(offsetPos));
+ }
}
void setNavaid(FGPositionedRef nav);
+ void setGeod(const SGGeod& geod);
+
bool isOffsetEnabled() const;
- void setOffsetEnabled(bool m_offset);
+ void setOffsetEnabled(bool offset);
void setOffsetDistanceNm(double distanceNm);
double offsetDistanceNm() const;
protected:
void paintContents(QPainter *) Q_DECL_OVERRIDE;
+ void doComputeBounds() Q_DECL_OVERRIDE;
private:
FGPositionedRef m_navaid;
+ SGGeod m_geod;
bool m_offsetEnabled;
double m_offsetDistanceNm;