From: James Turner Date: Tue, 24 Nov 2015 22:14:22 +0000 (+0000) Subject: Graphical picking of parking/helipads too. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a63fff14cc5f39047296e54fe16579121c57b74a;p=flightgear.git Graphical picking of parking/helipads too. --- diff --git a/src/GUI/AirportDiagram.cxx b/src/GUI/AirportDiagram.cxx index dbe4fc353..4e23b072b 100644 --- a/src/GUI/AirportDiagram.cxx +++ b/src/GUI/AirportDiagram.cxx @@ -405,6 +405,12 @@ void AirportDiagram::drawILS(QPainter* painter, FGRunwayRef runway) const painter->drawLine(endR, endCentre); } +static double pointDistance(const QPointF& p1, const QPointF& p2) +{ + QPointF d = p2 - p1; + return ::sqrt((d.x() * d.x()) + (d.y() * d.y())); +} + void AirportDiagram::mouseReleaseEvent(QMouseEvent* me) { if (m_didPan) @@ -413,7 +419,9 @@ void AirportDiagram::mouseReleaseEvent(QMouseEvent* me) QTransform t(transform()); double minDist = std::numeric_limits::max(); FGRunwayRef bestRunway; - + FGHelipadRef bestHelipad; + FGParkingRef bestParking; + Q_FOREACH(const RunwayData& r, m_runways) { QPointF p1(t.map(r.p1)), p2(t.map(r.p2)); double t; @@ -429,9 +437,34 @@ void AirportDiagram::mouseReleaseEvent(QMouseEvent* me) minDist = d; } } + + Q_FOREACH(const ParkingData& parking, m_parking) { + double d = pointDistance(me->pos(), t.map(parking.pt)); + if (d < minDist) { + bestParking = parking.parking; + bestRunway.clear(); + minDist = d; + } + } + + Q_FOREACH(const HelipadData& pad, m_helipads) { + double d = pointDistance(me->pos(), t.map(pad.pt)); + if (d < minDist) { + bestHelipad = pad.helipad; + bestRunway.clear(); + bestParking.clear(); + minDist = d; + } + } + if (minDist < 16.0) { - emit clickedRunway(bestRunway); + if (bestRunway) + emit clickedRunway(bestRunway); + else if (bestParking) + emit clickedParking(bestParking); + else if (bestHelipad) + emit clickedHelipad(bestHelipad); } } diff --git a/src/GUI/AirportDiagram.hxx b/src/GUI/AirportDiagram.hxx index 207a14dee..24c254b6a 100644 --- a/src/GUI/AirportDiagram.hxx +++ b/src/GUI/AirportDiagram.hxx @@ -48,7 +48,7 @@ public: void setApproachExtensionDistance(double distanceNm); Q_SIGNALS: void clickedRunway(FGRunwayRef rwy); - + void clickedHelipad(FGHelipadRef pad); void clickedParking(FGParkingRef park); protected: @@ -100,7 +100,7 @@ private: struct HelipadData { QPointF pt; - FGHelipadRef parking; + FGHelipadRef helipad; }; QVector m_helipads; diff --git a/src/GUI/LocationWidget.cxx b/src/GUI/LocationWidget.cxx index f4e2e96e2..f3f6d8dfa 100644 --- a/src/GUI/LocationWidget.cxx +++ b/src/GUI/LocationWidget.cxx @@ -376,7 +376,9 @@ LocationWidget::LocationWidget(QWidget *parent) : this, SLOT(updateDescription())); connect(m_ui->airportDiagram, &AirportDiagram::clickedRunway, - this, &LocationWidget::onAirportDiagramClicked); + this, &LocationWidget::onAirportRunwayClicked); + connect(m_ui->airportDiagram, &AirportDiagram::clickedParking, + this, &LocationWidget::onAirportParkingClicked); connect(m_ui->locationSearchEdit, &QLineEdit::returnPressed, this, &LocationWidget::onSearch); @@ -732,7 +734,7 @@ void LocationWidget::onOffsetEnabledToggled(bool on) updateDescription(); } -void LocationWidget::onAirportDiagramClicked(FGRunwayRef rwy) +void LocationWidget::onAirportRunwayClicked(FGRunwayRef rwy) { if (rwy) { m_ui->runwayRadio->setChecked(true); @@ -744,6 +746,18 @@ void LocationWidget::onAirportDiagramClicked(FGRunwayRef rwy) updateDescription(); } +void LocationWidget::onAirportParkingClicked(FGParkingRef park) +{ + if (park) { + m_ui->parkingRadio->setChecked(true); + int parkingIndex = m_ui->parkingCombo->findText(QString::fromStdString(park->name())); + m_ui->parkingCombo->setCurrentIndex(parkingIndex); + m_ui->airportDiagram->setSelectedRunway(FGRunwayRef()); + } + + updateDescription(); +} + QString compassPointFromHeading(int heading) { const int labelArc = 360 / 8; diff --git a/src/GUI/LocationWidget.hxx b/src/GUI/LocationWidget.hxx index 5dd0eb65e..0aed3e59e 100644 --- a/src/GUI/LocationWidget.hxx +++ b/src/GUI/LocationWidget.hxx @@ -70,7 +70,9 @@ private: void onSearchResultSelected(const QModelIndex& index); void onSearchComplete(); - void onAirportDiagramClicked(FGRunwayRef rwy); + void onAirportRunwayClicked(FGRunwayRef rwy); + void onAirportParkingClicked(FGParkingRef park); + void onOffsetBearingTrueChanged(bool on); void addToRecent(FGPositionedRef pos);