]> git.mxchange.org Git - flightgear.git/commitdiff
Graphical picking of parking/helipads too.
authorJames Turner <zakalawe@mac.com>
Tue, 24 Nov 2015 22:14:22 +0000 (22:14 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 24 Nov 2015 22:14:22 +0000 (22:14 +0000)
src/GUI/AirportDiagram.cxx
src/GUI/AirportDiagram.hxx
src/GUI/LocationWidget.cxx
src/GUI/LocationWidget.hxx

index dbe4fc3531cd2e35324b57455cf1661c5be64089..4e23b072b4a8e2fe86d1f1e4b5e89d0211c4319e 100644 (file)
@@ -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<double>::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);
     }
 }
 
index 207a14deebaf2b9f2858d35d8641afb834ce332d..24c254b6a980b83a1cbf50621464deacfcf59e77 100644 (file)
@@ -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<HelipadData> m_helipads;
index f4e2e96e2c7c5413109804df2d762c19e7503141..f3f6d8dfa80b1b72013bffc6d60855d0af00d44f 100644 (file)
@@ -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;
index 5dd0eb65ed8b13db0679c55704fb22d55a37d7ea..0aed3e59e465241e4e651cb820bfdeae99e2d331 100644 (file)
@@ -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);