]> git.mxchange.org Git - flightgear.git/commitdiff
Work on the launcher
authorJames Turner <zakalawe@mac.com>
Fri, 16 Oct 2015 01:05:17 +0000 (20:05 -0500)
committerJames Turner <zakalawe@mac.com>
Mon, 23 Nov 2015 00:45:21 +0000 (00:45 +0000)
12 files changed:
src/GUI/AircraftModel.cxx
src/GUI/AircraftModel.hxx
src/GUI/CMakeLists.txt
src/GUI/Launcher.ui
src/GUI/QtLauncher.cxx
src/GUI/QtLauncher.hxx
src/GUI/QtLauncher_private.hxx [new file with mode: 0644]
src/Main/fg_commands.cxx
src/Main/main.cxx
src/Main/options.cxx
src/Navaids/NavDataCache.cxx
src/Navaids/NavDataCache.hxx

index 943bbe76c5efc85fb344c3c5cb42b75b5c01a77c..2b424e5d7cb40df15583e5e21f5fab2c6f5878cc 100644 (file)
@@ -402,7 +402,7 @@ private:
     AircraftItemModel* m_model;
 };
 
-AircraftItemModel::AircraftItemModel(QObject* pr, simgear::pkg::RootRef& rootRef) :
+AircraftItemModel::AircraftItemModel(QObject* pr, const simgear::pkg::RootRef& rootRef) :
     QAbstractListModel(pr),
     m_scanThread(NULL),
     m_packageRoot(rootRef)
index e717ea1150ee4724f2b09de57160eef764a90115..975e6808c7823ca0f553205859377b602e308bf0 100644 (file)
@@ -97,7 +97,7 @@ class AircraftItemModel : public QAbstractListModel
 {
     Q_OBJECT
 public:
-    AircraftItemModel(QObject* pr, simgear::pkg::RootRef& root);
+    AircraftItemModel(QObject* pr, const simgear::pkg::RootRef& root);
 
     ~AircraftItemModel();
 
index 74b7bd960f50455fb0d198a865a72219c76b7e85..b8475f81c4aa2923cf21c801d7761cd02c28aaa0 100644 (file)
@@ -1,57 +1,57 @@
 include(FlightGearComponent)
 
 set(SOURCES
-       AirportList.cxx
-       CanvasWidget.cxx
-       MapWidget.cxx
-       WaypointList.cxx
-       dialog.cxx
-       FGPUIDialog.cxx
-       fonts.cxx
-       gui.cxx
-       gui_funcs.cxx
-       layout-props.cxx
-       layout.cxx
-       menubar.cxx
-       FGPUIMenuBar.cxx
-       new_gui.cxx
-       property_list.cxx
-       FGFontCache.cxx
-       FGColor.cxx
+  AirportList.cxx
+  CanvasWidget.cxx
+  MapWidget.cxx
+  WaypointList.cxx
+  dialog.cxx
+  FGPUIDialog.cxx
+  fonts.cxx
+  gui.cxx
+  gui_funcs.cxx
+  layout-props.cxx
+  layout.cxx
+  menubar.cxx
+  FGPUIMenuBar.cxx
+  new_gui.cxx
+  property_list.cxx
+  FGFontCache.cxx
+  FGColor.cxx
     FileDialog.cxx
     PUIFileDialog.cxx
     MouseCursor.cxx
     MessageBox.cxx
-       )
+  )
 
 set(HEADERS
-       AirportList.hxx
-       CanvasWidget.hxx
-       MapWidget.hxx
-       WaypointList.hxx
-       dialog.hxx
-       FGPUIDialog.hxx
-       gui.h
-       layout.hxx
-       menubar.hxx
-       FGPUIMenuBar.hxx
-       new_gui.hxx
-       property_list.hxx
-       FGFontCache.hxx
-       FGColor.hxx
+  AirportList.hxx
+  CanvasWidget.hxx
+  MapWidget.hxx
+  WaypointList.hxx
+  dialog.hxx
+  FGPUIDialog.hxx
+  gui.h
+  layout.hxx
+  menubar.hxx
+  FGPUIMenuBar.hxx
+  new_gui.hxx
+  property_list.hxx
+  FGFontCache.hxx
+  FGColor.hxx
     FileDialog.hxx
     PUIFileDialog.hxx
     MouseCursor.hxx
     MessageBox.hxx
-       )
+  )
 
 if(WIN32)
-       list(APPEND HEADERS WindowsMouseCursor.hxx
-                                               FGWindowsMenuBar.hxx
-                                               WindowsFileDialog.hxx)
-       list(APPEND SOURCES WindowsMouseCursor.cxx
-                                               FGWindowsMenuBar.cxx
-                                               WindowsFileDialog.cxx)
+  list(APPEND HEADERS WindowsMouseCursor.hxx
+            FGWindowsMenuBar.hxx
+            WindowsFileDialog.hxx)
+  list(APPEND SOURCES WindowsMouseCursor.cxx
+            FGWindowsMenuBar.cxx
+            WindowsFileDialog.cxx)
 endif()
 
 if (APPLE)
@@ -70,7 +70,7 @@ endif()
 
 
 if (HAVE_QT)
-    qt5_wrap_ui(uic_sources Launcher.ui 
+    qt5_wrap_ui(uic_sources Launcher.ui
                             EditRatingsFilterDialog.ui
                             SetupRootDialog.ui
                             AddCatalogDialog.ui
@@ -81,6 +81,7 @@ if (HAVE_QT)
 
     add_library(fglauncher QtLauncher.cxx
                             QtLauncher.hxx
+                            QtLauncher_private.hxx
                             AirportDiagram.cxx
                             AirportDiagram.hxx
                             EditRatingsFilterDialog.cxx
index e19a135d1b74d53b20b89de3c8579e0e6d111b80..1eb88520487551d5832a2bead01b195dbf0cefa9 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>700</width>
-    <height>700</height>
+    <width>800</width>
+    <height>800</height>
    </rect>
   </property>
   <property name="windowTitle">
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>2</number>
+      <number>0</number>
      </property>
-     <widget class="QWidget" name="tab">
+     <widget class="QWidget" name="aircraftTab">
       <attribute name="title">
        <string>Aircraft</string>
       </attribute>
        </item>
       </layout>
      </widget>
-     <widget class="QWidget" name="tab_2">
+     <widget class="QWidget" name="locationTab">
       <attribute name="title">
        <string>Location</string>
       </attribute>
          <item>
           <widget class="QLineEdit" name="airportEdit">
            <property name="placeholderText">
-            <string>Enter an ICAO code or search by name</string>
+            <string>Enter an ICAO code, navaid or search by name</string>
            </property>
           </widget>
          </item>
           <number>0</number>
          </property>
          <widget class="QWidget" name="diagramPage">
-          <layout class="QGridLayout" name="gridLayout">
+          <layout class="QGridLayout" name="gridLayout" columnstretch="0,1,1,0">
            <property name="leftMargin">
             <number>0</number>
            </property>
            <property name="bottomMargin">
             <number>0</number>
            </property>
-           <item row="0" column="0" colspan="2">
-            <widget class="AirportDiagram" name="airportDiagram" native="true">
-             <property name="sizePolicy">
-              <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
-               <horstretch>0</horstretch>
-               <verstretch>0</verstretch>
-              </sizepolicy>
+           <item row="3" column="0">
+            <widget class="QRadioButton" name="parkingRadio">
+             <property name="text">
+              <string>Parking:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="2" column="1">
+            <widget class="QCheckBox" name="onFinalCheckbox">
+             <property name="text">
+              <string>On 10-mile final</string>
              </property>
             </widget>
            </item>
              </property>
             </widget>
            </item>
-           <item row="1" column="1">
+           <item row="6" column="2">
+            <widget class="QSpinBox" name="offsetBearingSpinbox">
+             <property name="wrapping">
+              <bool>true</bool>
+             </property>
+             <property name="maximum">
+              <number>359</number>
+             </property>
+             <property name="singleStep">
+              <number>5</number>
+             </property>
+            </widget>
+           </item>
+           <item row="3" column="1" colspan="3">
+            <widget class="QComboBox" name="parkingCombo"/>
+           </item>
+           <item row="1" column="1" colspan="3">
             <widget class="QComboBox" name="runwayCombo"/>
            </item>
-           <item row="2" column="0" rowspan="2">
-            <widget class="QRadioButton" name="parkingRadio">
+           <item row="6" column="3">
+            <widget class="QCheckBox" name="trueBearing">
              <property name="text">
-              <string>Parking:</string>
+              <string>True</string>
              </property>
             </widget>
            </item>
-           <item row="2" column="1">
-            <widget class="QCheckBox" name="onFinalCheckbox">
+           <item row="6" column="1">
+            <widget class="QLabel" name="offsetBearingLabel">
+             <property name="enabled">
+              <bool>true</bool>
+             </property>
              <property name="text">
-              <string>On 10-mile final</string>
+              <string>Bearing:</string>
+             </property>
+             <property name="alignment">
+              <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
              </property>
             </widget>
            </item>
-           <item row="3" column="1">
-            <widget class="QComboBox" name="parkingCombo"/>
+           <item row="5" column="0">
+            <widget class="QRadioButton" name="offsetRadioButton">
+             <property name="text">
+              <string>Bearing and distance offset:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="5" column="1">
+            <widget class="QLabel" name="offsetDistanceLabel">
+             <property name="text">
+              <string>Distance:</string>
+             </property>
+             <property name="alignment">
+              <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+             </property>
+            </widget>
+           </item>
+           <item row="5" column="2">
+            <widget class="QDoubleSpinBox" name="offsetNmSpinbox">
+             <property name="suffix">
+              <string>nm</string>
+             </property>
+             <property name="decimals">
+              <number>1</number>
+             </property>
+             <property name="maximum">
+              <double>10000.000000000000000</double>
+             </property>
+             <property name="value">
+              <double>10.000000000000000</double>
+             </property>
+            </widget>
+           </item>
+           <item row="0" column="0" colspan="4">
+            <widget class="AirportDiagram" name="airportDiagram" native="true">
+             <property name="sizePolicy">
+              <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+               <horstretch>0</horstretch>
+               <verstretch>0</verstretch>
+              </sizepolicy>
+             </property>
+            </widget>
            </item>
           </layout>
          </widget>
        </item>
       </layout>
      </widget>
-     <widget class="QWidget" name="tab_3">
+     <widget class="QWidget" name="settingsTab">
       <attribute name="title">
        <string>Settings</string>
       </attribute>
          <property name="text">
           <string>Enable deferred rendering (Rembrandt)</string>
          </property>
+         <property name="startupOnly" stdset="0">
+          <bool>true</bool>
+         </property>
         </widget>
        </item>
        <item row="4" column="1">
          <property name="text">
           <string>Start full-screen</string>
          </property>
+         <property name="startupOnly" stdset="0">
+          <bool>true</bool>
+         </property>
         </widget>
        </item>
        <item row="4" column="0">
          <property name="text">
           <string>Enable Multi-sample anti-aliasing</string>
          </property>
+         <property name="startupOnly" stdset="0">
+          <bool>true</bool>
+         </property>
         </widget>
        </item>
        <item row="5" column="0">
          <property name="text">
           <string>Start paused</string>
          </property>
+         <property name="startupOnly" stdset="0">
+          <bool>true</bool>
+         </property>
         </widget>
        </item>
        <item row="3" column="0" colspan="2">
          <property name="title">
           <string>Additional options</string>
          </property>
+         <property name="startupOnly" stdset="0">
+          <bool>true</bool>
+         </property>
          <layout class="QVBoxLayout" name="verticalLayout_7">
           <item>
            <widget class="QPlainTextEdit" name="commandLineArgs"/>
          <property name="text">
           <string>Configure add-on aircraft and scenery</string>
          </property>
+         <property name="startupOnly" stdset="0">
+          <bool>true</bool>
+         </property>
         </widget>
        </item>
       </layout>
index d16479e83bc1bc8be095fffbc850a2488386effc..a96ed7abb36c2627415211dafe1a1995eac8f6a4 100644 (file)
@@ -19,6 +19,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #include "QtLauncher.hxx"
+#include "QtLauncher_private.hxx"
 
 // Qt
 #include <QProgressDialog>
@@ -41,6 +42,8 @@
 #include <QMessageBox>
 #include <QDateTime>
 #include <QApplication>
+#include <QSpinBox>
+#include <QDoubleSpinBox>
 
 // Simgear
 #include <simgear/timing/timestamp.hxx>
@@ -62,6 +65,8 @@
 #include <Navaids/NavDataCache.hxx>
 #include <Airports/airport.hxx>
 #include <Airports/dynamics.hxx> // for parking
+#include <Navaids/navrecord.hxx>
+
 #include <Main/options.hxx>
 #include <Main/fg_init.hxx>
 #include <Viewer/WindowBuilder.hxx>
@@ -92,7 +97,7 @@ void initNavCache()
             // sleep to give the rebuild thread more time
             SGTimeStamp::sleepForMSec(50);
             phase = cache->rebuild();
-            
+
             switch (phase) {
             case NavDataCache::REBUILD_AIRPORTS:
                 rebuildProgress.setLabelText(QT_TR_NOOP("Loading airport data"));
@@ -249,16 +254,17 @@ public:
         std::string term(t.toUpper().toStdString());
         // try ICAO lookup first
         FGAirportRef ref = FGAirport::findByIdent(term);
+
         if (ref) {
             m_ids.push_back(ref->guid());
             m_airports.push_back(ref);
-        } else {
-            m_search.reset(new NavDataCache::ThreadedAirportSearch(term));
-            QTimer::singleShot(100, this, SLOT(onSearchResultsPoll()));
-            m_searchActive = true;
+            endResetModel();
+            return;
         }
 
-        endResetModel();
+        m_search.reset(new NavDataCache::ThreadedGUISearch(term));
+        QTimer::singleShot(100, this, SLOT(onSearchResultsPoll()));
+        m_searchActive = true;
     }
 
     bool isSearchActive() const
@@ -276,7 +282,7 @@ public:
     {
         if (!index.isValid())
             return QVariant();
-        
+
         FGAirportRef apt = m_airports[index.row()];
         if (!apt.valid()) {
             apt = FGPositioned::loadById<FGAirport>(m_ids[index.row()]);
@@ -318,7 +324,7 @@ private slots:
     void onSearchResultsPoll()
     {
         PositionedIDVec newIds = m_search->results();
-        
+
         beginInsertRows(QModelIndex(), m_ids.size(), newIds.size() - 1);
         for (unsigned int i=m_ids.size(); i < newIds.size(); ++i) {
             m_ids.push_back(newIds[i]);
@@ -339,7 +345,7 @@ private:
     PositionedIDVec m_ids;
     mutable std::vector<FGAirportRef> m_airports;
     bool m_searchActive;
-    QScopedPointer<NavDataCache::ThreadedAirportSearch> m_search;
+    QScopedPointer<NavDataCache::ThreadedGUISearch> m_search;
 };
 
 class AircraftProxyModel : public QSortFilterProxyModel
@@ -396,9 +402,97 @@ private:
     int m_ratings[4];
 };
 
+static void initQtResources()
+{
+    Q_INIT_RESOURCE(resources);
+}
+
+namespace flightgear
+{
+
+void initApp(int& argc, char** argv)
+{
+    static bool qtInitDone = false;
+    if (!qtInitDone) {
+        qtInitDone = true;
+
+        QApplication* app = new QApplication(argc, argv);
+        app->setOrganizationName("FlightGear");
+        app->setApplicationName("FlightGear");
+        app->setOrganizationDomain("flightgear.org");
+
+        // avoid double Apple menu and other weirdness if both Qt and OSG
+        // try to initialise various Cocoa structures.
+        flightgear::WindowBuilder::setPoseAsStandaloneApp(false);
+
+        Qt::KeyboardModifiers mods = app->queryKeyboardModifiers();
+        if (mods & Qt::AltModifier) {
+            qWarning() << "Alt pressed during launch";
+
+            // wipe out our settings
+            QSettings settings;
+            settings.clear();
+
+
+            Options::sharedInstance()->addOption("restore-defaults", "");
+        }
+    }
+}
+
+bool runLauncherDialog()
+{
+    sglog().setLogLevels( SG_ALL, SG_INFO );
+
+
+    initQtResources(); // can't be called inside a namespaceb
+
+    // startup the nav-cache now. This pre-empts normal startup of
+    // the cache, but no harm done. (Providing scenery paths are consistent)
+
+    initNavCache();
+
+
+    fgInitPackageRoot();
+
+    // startup the HTTP system now since packages needs it
+    FGHTTPClient* http = new FGHTTPClient;
+    globals->add_subsystem("http", http);
+    // we guard against re-init in the global phase; bind and postinit
+    // will happen as normal
+    http->init();
+
+
+    // setup scenery paths now, especially TerraSync path for airport
+    // parking locations (after they're downloaded)
+
+    QtLauncher dlg;
+    dlg.exec();
+    if (dlg.result() != QDialog::Accepted) {
+        return false;
+    }
+
+    return true;
+}
+
+bool runInAppLauncherDialog()
+{
+    QtLauncher dlg;
+    dlg.setInAppMode();
+    dlg.exec();
+    if (dlg.result() != QDialog::Accepted) {
+        return false;
+    }
+
+    return true;
+}
+
+} // of namespace flightgear
+
 QtLauncher::QtLauncher() :
     QDialog(),
-    m_ui(NULL)
+    m_ui(NULL),
+    m_subsystemIdleTimer(NULL),
+    m_inAppMode(false)
 {
     m_ui.reset(new Ui::Launcher);
     m_ui->setupUi(this);
@@ -447,7 +541,7 @@ QtLauncher::QtLauncher() :
     connect(m_ui->onFinalCheckbox, SIGNAL(toggled(bool)),
             this, SLOT(updateAirportDescription()));
 
-    
+
     connect(m_ui->airportDiagram, &AirportDiagram::clickedRunway,
             this, &QtLauncher::onAirportDiagramClicked);
 
@@ -496,17 +590,7 @@ QtLauncher::QtLauncher() :
             this, &QtLauncher::onToggleTerrasync);
     updateSettingsSummary();
 
-    fgInitPackageRoot();
-    RootRef r(globals->packageRoot());
-
-    FGHTTPClient* http = new FGHTTPClient;
-    globals->add_subsystem("http", http);
-
-    // we guard against re-init in the global phase; bind and postinit
-    // will happen as normal
-    http->init();
-
-    m_aircraftModel = new AircraftItemModel(this, r);
+    m_aircraftModel = new AircraftItemModel(this, RootRef(globals->packageRoot()));
     m_aircraftProxy->setSourceModel(m_aircraftModel);
 
     m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -532,10 +616,19 @@ QtLauncher::QtLauncher() :
             this, &QtLauncher::onAircraftInstalledCompleted);
     connect(m_aircraftModel, &AircraftItemModel::aircraftInstallFailed,
             this, &QtLauncher::onAircraftInstallFailed);
-    
+
     connect(m_ui->pathsButton, &QPushButton::clicked,
             this, &QtLauncher::onEditPaths);
 
+
+    connect(m_ui->trueBearing, &QCheckBox::toggled, this, &QtLauncher::onOffsetBearingTrueChanged);
+    connect(m_ui->offsetRadioButton, &QRadioButton::toggled,
+            this, &QtLauncher::onOffsetRadioToggled);
+    connect(m_ui->trueBearing, &QCheckBox::toggled, this, &QtLauncher::onOffsetDataChanged);
+    connect(m_ui->offsetBearingSpinbox, SIGNAL(valueChanged(int)), this, SLOT(onOffsetDataChanged()));
+    connect(m_ui->offsetNmSpinbox, SIGNAL(valueChanged(double)),
+            this, SLOT(onOffsetDataChanged()));
+
     restoreSettings();
 
     QSettings settings;
@@ -545,11 +638,25 @@ QtLauncher::QtLauncher() :
 
 QtLauncher::~QtLauncher()
 {
-    
+
+}
+
+void QtLauncher::setInAppMode()
+{
+  m_inAppMode = true;
+  m_ui->tabWidget->removeTab(2);
+  m_ui->runButton->setText(tr("Apply"));
+  m_ui->quitButton->setText(tr("Cancel"));
+
+  disconnect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onRun()));
+  connect(m_ui->runButton, SIGNAL(clicked()), this, SLOT(onApply()));
 }
 
-void QtLauncher::initApp(int& argc, char** argv)
+bool QtLauncher::runLauncherDialog()
 {
+    sglog().setLogLevels( SG_ALL, SG_INFO );
+    Q_INIT_RESOURCE(resources);
+
     static bool qtInitDone = false;
     static int s_argc;
     if (!qtInitDone) {
@@ -575,18 +682,11 @@ void QtLauncher::initApp(int& argc, char** argv)
             QSettings settings;
             settings.clear();
 
-
             Options::sharedInstance()->addOption("restore-defaults", "");
         }
     }
-}
-
-bool QtLauncher::runLauncherDialog()
-{
-    sglog().setLogLevels( SG_ALL, SG_INFO );
-    Q_INIT_RESOURCE(resources);
 
-    // startup the nav-cache now. This pre-empts normal startup of
+    // startup the nav-cache now. This preempts normal startup of
     // the cache, but no harm done. (Providing scenery paths are consistent)
 
     initNavCache();
@@ -599,8 +699,6 @@ bool QtLauncher::runLauncherDialog()
     if (dlg.result() != QDialog::Accepted) {
         return false;
     }
-
-    return true;
 }
 
 void QtLauncher::restoreSettings()
@@ -712,7 +810,7 @@ void QtLauncher::onRun()
         } else {
             qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft;
         }
-        
+
       // manage aircraft history
         if (m_recentAircraft.contains(m_selectedAircraft))
           m_recentAircraft.removeOne(m_selectedAircraft);
@@ -799,6 +897,46 @@ void QtLauncher::onRun()
     saveSettings();
 }
 
+void QtLauncher::onApply()
+{
+    accept();
+
+    // aircraft
+    if (!m_selectedAircraft.isEmpty()) {
+        std::string aircraftPropValue,
+            aircraftDir;
+
+        if (m_selectedAircraft.isLocalFile()) {
+            QFileInfo setFileInfo(m_selectedAircraft.toLocalFile());
+            QString setFile = setFileInfo.fileName();
+            Q_ASSERT(setFile.endsWith("-set.xml"));
+            setFile.truncate(setFile.count() - 8); // drop the '-set.xml' portion
+            aircraftDir = setFileInfo.dir().absolutePath().toStdString();
+            aircraftPropValue = setFile.toStdString();
+        } else if (m_selectedAircraft.scheme() == "package") {
+            PackageRef pkg = packageForAircraftURI(m_selectedAircraft);
+            // no need to set aircraft-dir, handled by the corresponding code
+            // in fgInitAircraft
+            aircraftPropValue = pkg->qualifiedId();
+        } else {
+            qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft;
+        }
+
+        // manage aircraft history
+        if (m_recentAircraft.contains(m_selectedAircraft))
+            m_recentAircraft.removeOne(m_selectedAircraft);
+        m_recentAircraft.prepend(m_selectedAircraft);
+        if (m_recentAircraft.size() > MAX_RECENT_AIRCRAFT)
+            m_recentAircraft.pop_back();
+
+        globals->get_props()->setStringValue("/sim/aircraft", aircraftPropValue);
+        globals->get_props()->setStringValue("/sim/aircraft-dir", aircraftDir);
+    }
+
+
+    saveSettings();
+}
+
 void QtLauncher::onQuit()
 {
     reject();
@@ -881,6 +1019,15 @@ void QtLauncher::onAirportChanged()
     }
 }
 
+void QtLauncher::onOffsetRadioToggled(bool on)
+{
+    m_ui->offsetNmSpinbox->setEnabled(on);
+    m_ui->offsetBearingSpinbox->setEnabled(on);
+    m_ui->trueBearing->setEnabled(on);
+    m_ui->offsetBearingLabel->setEnabled(on);
+    m_ui->offsetDistanceLabel->setEnabled(on);
+}
+
 void QtLauncher::onAirportDiagramClicked(FGRunwayRef rwy)
 {
     if (rwy) {
@@ -888,7 +1035,7 @@ void QtLauncher::onAirportDiagramClicked(FGRunwayRef rwy)
         int rwyIndex = m_ui->runwayCombo->findText(QString::fromStdString(rwy->ident()));
         m_ui->runwayCombo->setCurrentIndex(rwyIndex);
     }
-    
+
     updateAirportDescription();
 }
 
@@ -912,7 +1059,7 @@ void QtLauncher::onToggleTerrasync(bool enabled)
             msg.addButton(QMessageBox::Cancel);
             msg.addButton(tr("Change location"), QMessageBox::ActionRole);
             int result = msg.exec();
-  
+
             if (result == QMessageBox::Cancel) {
                 m_ui->terrasyncCheck->setChecked(false);
                 return;
@@ -937,7 +1084,7 @@ void QtLauncher::onAircraftInstalledCompleted(QModelIndex index)
 void QtLauncher::onAircraftInstallFailed(QModelIndex index, QString errorMessage)
 {
     qWarning() << Q_FUNC_INFO << index.data(AircraftURIRole) << errorMessage;
-    
+
     QMessageBox msg;
     msg.setWindowTitle(tr("Aircraft installation failed"));
     msg.setText(tr("An error occurred installing the aircraft %1: %2").
@@ -970,7 +1117,7 @@ void QtLauncher::updateAirportDescription()
         } else {
             locationOnAirport = QString("on %1").arg(runwayName);
         }
-        
+
         int runwayIndex = m_ui->runwayCombo->itemData(comboIndex).toInt();
         FGRunwayRef rwy = (runwayIndex >= 0) ?
             m_selectedAirport->getRunwayByIndex(runwayIndex) : FGRunwayRef();
@@ -988,6 +1135,12 @@ void QtLauncher::onAirportChoiceSelected(const QModelIndex& index)
     setAirport(FGPositioned::loadById<FGAirport>(index.data(Qt::UserRole).toULongLong()));
 }
 
+void QtLauncher::onOffsetBearingTrueChanged(bool on)
+{
+    m_ui->offsetBearingLabel->setText(on ? tr("True bearing:") :
+                                      tr("Magnetic bearing:"));
+}
+
 void QtLauncher::onAircraftSelected(const QModelIndex& index)
 {
     m_selectedAircraft = index.data(AircraftURIRole).toUrl();
@@ -1011,7 +1164,6 @@ void QtLauncher::onRequestPackageInstall(const QModelIndex& index)
 void QtLauncher::onCancelDownload(const QModelIndex& index)
 {
     QString pkg = index.data(AircraftPackageIdRole).toString();
-    qDebug() << "cancel download of" << pkg;
     simgear::pkg::PackageRef pref = globals->packageRoot()->getPackageById(pkg.toStdString());
     simgear::pkg::InstallRef i = pref->existingInstall();
     i->cancelDownload();
@@ -1033,7 +1185,7 @@ void QtLauncher::updateSelectedAircraft()
         QPixmap pm = index.data(Qt::DecorationRole).value<QPixmap>();
         m_ui->thumbnail->setPixmap(pm);
         m_ui->aircraftDescription->setText(index.data(Qt::DisplayRole).toString());
-        
+
         int status = index.data(AircraftPackageStatusRole).toInt();
         bool canRun = (status == PackageInstalled);
         m_ui->runButton->setEnabled(canRun);
@@ -1218,10 +1370,14 @@ simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const
         qWarning() << "invalid URL scheme:" << uri;
         return simgear::pkg::PackageRef();
     }
-    
+
     QString ident = uri.path();
     return globals->packageRoot()->getPackageById(ident.toStdString());
 }
 
-#include "QtLauncher.moc"
+void QtLauncher::onOffsetDataChanged()
+{
+    qDebug() << "implement me";
+}
 
+#include "QtLauncher.moc"
index c0412bf40a26c949d83e7c6e5b5ecd9ba3502f73..bc9d844df3fd61dd9667d9b7e7ab7d4851440757 100644 (file)
 #ifndef FG_QTLAUNCHER_HXX
 #define FG_QTLAUNCHER_HXX
 
-#include <QDialog>
-#include <QScopedPointer>
-#include <QStringList>
-#include <QModelIndex>
-#include <QTimer>
-#include <QUrl>
-
-
-#include <Airports/airport.hxx>
-#include <simgear/package/Package.hxx>
-#include <simgear/package/Catalog.hxx>
-
-namespace Ui
-{
-    class Launcher;
-}
-
-class AirportSearchModel;
-class QModelIndex;
-class AircraftProxyModel;
-class AircraftItemModel;
-class QCheckBox;
-class CatalogListModel;
-
-class QtLauncher : public QDialog
+namespace flightgear
 {
-    Q_OBJECT
-public:
-    QtLauncher();
-    virtual ~QtLauncher();
-
-    static void initApp(int& argc, char** argv);
-
-    static bool runLauncherDialog();
-
-private slots:
-    void onRun();
-    void onQuit();
-
-    void onSearchAirports();
-
-    void onAirportChanged();
-
-    void onAirportChoiceSelected(const QModelIndex& index);
-    void onAircraftSelected(const QModelIndex& index);
-    void onRequestPackageInstall(const QModelIndex& index);
-    void onCancelDownload(const QModelIndex& index);
-    
-    void onPopupAirportHistory();
-    void onPopupAircraftHistory();
+  void initApp(int& argc, char** argv);
 
-    void onEditRatingsFilter();
+  bool runLauncherDialog();
 
-    void updateAirportDescription();
-    void updateSettingsSummary();
-
-    void onAirportSearchComplete();
-
-    void onRembrandtToggled(bool b);
-    void onToggleTerrasync(bool enabled);
-
-    void onSubsytemIdleTimeout();
-
-    void onEditPaths();
-    
-    void onAirportDiagramClicked(FGRunwayRef rwy);
-
-    void onAircraftInstalledCompleted(QModelIndex index);
-    void onAircraftInstallFailed(QModelIndex index, QString errorMessage);
-private:
-    void setAirport(FGAirportRef ref);
-
-    /**
-     * Check if the passed index is the selected aircraft, and if so, refresh
-     * the associated UI data
-     */
-    void maybeUpdateSelectedAircraft(QModelIndex index);
-    void updateSelectedAircraft();
-
-    void restoreSettings();
-    void saveSettings();
-    
-    QModelIndex proxyIndexForAircraftURI(QUrl uri) const;
-    QModelIndex sourceIndexForAircraftURI(QUrl uri) const;
-
-    void setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const;
-
-    simgear::pkg::PackageRef packageForAircraftURI(QUrl uri) const;
-    
-    QScopedPointer<Ui::Launcher> m_ui;
-    AirportSearchModel* m_airportsModel;
-    AircraftProxyModel* m_aircraftProxy;
-    AircraftItemModel* m_aircraftModel;
-    FGAirportRef m_selectedAirport;
-
-    QUrl m_selectedAircraft;
-    QList<QUrl> m_recentAircraft;
-    QStringList m_recentAirports;
-    QTimer* m_subsystemIdleTimer;
-
-    int m_ratingFilters[4];
-};
+  bool runInAppLauncherDialog();
+}
 
 #endif // of FG_QTLAUNCHER_HXX
diff --git a/src/GUI/QtLauncher_private.hxx b/src/GUI/QtLauncher_private.hxx
new file mode 100644 (file)
index 0000000..17f7a1c
--- /dev/null
@@ -0,0 +1,136 @@
+// QtLauncher_private.hxx - GUI launcher dialog using Qt5
+//
+// Written by James Turner, started October 2015.
+//
+// Copyright (C) 2015 James Turner <zakalawe@mac.com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+#ifndef FG_QTLAUNCHER_PRIVATE_HXX
+#define FG_QTLAUNCHER_PRIVATE_HXX
+
+#include <QDialog>
+#include <QScopedPointer>
+#include <QStringList>
+#include <QModelIndex>
+#include <QTimer>
+#include <QUrl>
+
+
+#include <Airports/airport.hxx>
+#include <simgear/package/Package.hxx>
+#include <simgear/package/Catalog.hxx>
+
+namespace Ui
+{
+    class Launcher;
+}
+
+class AirportSearchModel;
+class QModelIndex;
+class AircraftProxyModel;
+class AircraftItemModel;
+class QCheckBox;
+class CatalogListModel;
+
+class QtLauncher : public QDialog
+{
+    Q_OBJECT
+public:
+    QtLauncher();
+    virtual ~QtLauncher();
+
+    void setInAppMode();
+private slots:
+    // run is used when the launcher is invoked before the main app is
+    // started
+    void onRun();
+
+    // apply is used in-app, where we must set properties and trigger
+    // a reset; setting command line options won't help us.
+    void onApply();
+    
+    void onQuit();
+
+    void onSearchAirports();
+
+    void onAirportChanged();
+
+    void onAirportChoiceSelected(const QModelIndex& index);
+    void onAircraftSelected(const QModelIndex& index);
+    void onRequestPackageInstall(const QModelIndex& index);
+    void onCancelDownload(const QModelIndex& index);
+
+    void onPopupAirportHistory();
+    void onPopupAircraftHistory();
+
+    void onEditRatingsFilter();
+
+    void updateAirportDescription();
+    void updateSettingsSummary();
+
+    void onAirportSearchComplete();
+
+    void onRembrandtToggled(bool b);
+    void onToggleTerrasync(bool enabled);
+
+    void onSubsytemIdleTimeout();
+
+    void onEditPaths();
+
+    void onAirportDiagramClicked(FGRunwayRef rwy);
+    void onOffsetBearingTrueChanged(bool on);
+
+    void onOffsetDataChanged();
+    void onOffsetRadioToggled(bool on);
+
+    void onAircraftInstalledCompleted(QModelIndex index);
+    void onAircraftInstallFailed(QModelIndex index, QString errorMessage);
+private:
+    void setAirport(FGAirportRef ref);
+
+    /**
+     * Check if the passed index is the selected aircraft, and if so, refresh
+     * the associated UI data
+     */
+    void maybeUpdateSelectedAircraft(QModelIndex index);
+    void updateSelectedAircraft();
+
+    void restoreSettings();
+    void saveSettings();
+
+    QModelIndex proxyIndexForAircraftURI(QUrl uri) const;
+    QModelIndex sourceIndexForAircraftURI(QUrl uri) const;
+
+    void setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const;
+
+    simgear::pkg::PackageRef packageForAircraftURI(QUrl uri) const;
+
+    QScopedPointer<Ui::Launcher> m_ui;
+    AirportSearchModel* m_airportsModel;
+    AircraftProxyModel* m_aircraftProxy;
+    AircraftItemModel* m_aircraftModel;
+    FGAirportRef m_selectedAirport;
+
+    QUrl m_selectedAircraft;
+    QList<QUrl> m_recentAircraft;
+    QStringList m_recentAirports;
+    QTimer* m_subsystemIdleTimer;
+    bool m_inAppMode;
+
+    int m_ratingFilters[4];
+};
+
+#endif // of FG_QTLAUNCHER_PRIVATE_HXX
index 1eb5185629c20c908fa8334bbe5e82a95a15a9ef..f0b8de09b3e73254983c784909f7b4e12172c11b 100644 (file)
 # include <google/profiler.h>
 #endif
 
+#if defined(HAVE_QT)
+#include <GUI/QtLauncher.hxx>
+#endif
+
 using std::string;
 using std::ifstream;
 using std::ofstream;
@@ -992,6 +996,21 @@ do_open_browser (const SGPropertyNode * arg)
     return openBrowser(path);
 }
 
+static bool
+do_open_launcher(const SGPropertyNode *)
+{
+#if defined(HAVE_QT)
+    bool ok = flightgear::runInAppLauncherDialog();
+    if (ok) {
+        // start a full reset
+        fgResetIdleState();
+    }
+    return ok;
+#else
+    return false;
+#endif
+}
+
 /**
  * Apply a value in the active XML-configured dialog.
  *
@@ -1472,6 +1491,7 @@ static struct {
     { "presets-commit", do_presets_commit },
     { "log-level", do_log_level },
     { "replay", do_replay },
+    { "open-launcher", do_open_launcher },
     /*
     { "decrease-visibility", do_decrease_visibility },
     { "increase-visibility", do_increase_visibility },
index c19881438450f38e3133d5439c562014dde1744f..2434d2058adcd3c46d4c18aeea3e09395ef427d1 100644 (file)
@@ -449,8 +449,8 @@ int fgMainInit( int argc, char **argv )
     showLauncher |= (::getenv("FG_LAUNCHER") != 0);
 
     if (showLauncher) {
-        QtLauncher::initApp(argc, argv);
-        if (!QtLauncher::runLauncherDialog()) {
+        flightgear::initApp(argc, argv);
+        if (!flightgear::runLauncherDialog()) {
             return EXIT_SUCCESS;
         }
     }
index 00f2352a1736ebec59c2e63f59989594a3e1111e..e4f1b212a5ed5d87b1df86940c6fd407e827f8ba 100644 (file)
@@ -2512,7 +2512,7 @@ void Options::setupRoot(int argc, char **argv)
 
 #if defined(HAVE_QT)
     if (base_version != required_version) {
-        QtLauncher::initApp(argc, argv);
+        flightgear::initApp(argc, argv);
         if (SetupRootDialog::restoreUserSelectedRoot()) {
             SG_LOG(SG_GENERAL, SG_INFO, "restored user selected fg_root = " << globals->get_fg_root() );
             return;
index 1746ece4e3a091b27149e8e537b2ef23d0dc6813..e18c382bc29e13607c2bf908f55918883ed2a3ef 100644 (file)
@@ -2276,10 +2276,10 @@ void NavDataCache::Transaction::commit()
 
 /////////////////////////////////////////////////////////////////////////////
 
-class NavDataCache::ThreadedAirportSearch::ThreadedAirportSearchPrivate : public SGThread
+class NavDataCache::ThreadedGUISearch::ThreadedGUISearchPrivate : public SGThread
 {
 public:
-    ThreadedAirportSearchPrivate() :
+    ThreadedGUISearchPrivate() :
         db(NULL),
         isComplete(false),
         quit(false)
@@ -2300,7 +2300,7 @@ public:
                 SGTimeStamp::sleepForMSec(1);
             } else {
                 std::string errMsg = sqlite3_errmsg(db);
-                SG_LOG(SG_NAVCACHE, SG_ALERT, "Sqlite error:" << errMsg << " running threaded airport query");
+                SG_LOG(SG_NAVCACHE, SG_ALERT, "Sqlite error:" << errMsg << " running threaded search query");
             }
         }
 
@@ -2316,8 +2316,8 @@ public:
     bool quit;
 };
 
-NavDataCache::ThreadedAirportSearch::ThreadedAirportSearch(const std::string& term) :
-    d(new ThreadedAirportSearchPrivate)
+NavDataCache::ThreadedGUISearch::ThreadedGUISearch(const std::string& term) :
+    d(new ThreadedGUISearchPrivate)
 {
     SGPath p = NavDataCache::instance()->path();
     int openFlags = SQLITE_OPEN_READONLY;
@@ -2331,7 +2331,7 @@ NavDataCache::ThreadedAirportSearch::ThreadedAirportSearch(const std::string& te
     d->start();
 }
 
-NavDataCache::ThreadedAirportSearch::~ThreadedAirportSearch()
+NavDataCache::ThreadedGUISearch::~ThreadedGUISearch()
 {
     {
         SGGuard<SGMutex> g(d->lock);
@@ -2343,7 +2343,7 @@ NavDataCache::ThreadedAirportSearch::~ThreadedAirportSearch()
     sqlite3_close_v2(d->db);
 }
 
-PositionedIDVec NavDataCache::ThreadedAirportSearch::results() const
+PositionedIDVec NavDataCache::ThreadedGUISearch::results() const
 {
     PositionedIDVec r;
     {
@@ -2353,7 +2353,7 @@ PositionedIDVec NavDataCache::ThreadedAirportSearch::results() const
     return r;
 }
 
-bool NavDataCache::ThreadedAirportSearch::isComplete() const
+bool NavDataCache::ThreadedGUISearch::isComplete() const
 {
     SGGuard<SGMutex> g(d->lock);
     return d->isComplete;
index 5c8bbbc8abb2805fdc1b2200df60151569e0df60..a59257848dc5cc9323b5b9d8f4250213a080109e 100644 (file)
@@ -295,18 +295,18 @@ public:
     
     bool isReadOnly() const;
 
-    class ThreadedAirportSearch
+    class ThreadedGUISearch
     {
     public:
-        ThreadedAirportSearch(const std::string& term);
-        ~ThreadedAirportSearch();
+        ThreadedGUISearch(const std::string& term);
+        ~ThreadedGUISearch();
         
         PositionedIDVec results() const;
 
         bool isComplete() const;
     private:
-        class ThreadedAirportSearchPrivate;
-        std::auto_ptr<ThreadedAirportSearchPrivate> d;
+        class ThreadedGUISearchPrivate;
+        std::auto_ptr<ThreadedGUISearchPrivate> d;
     };
 private:
   NavDataCache();