-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the tour guide function to the Navigation menu of the Qt interface. This matches existing setups of win32 and GTK.
- Loading branch information
Showing
8 changed files
with
308 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// qttourguide.cpp | ||
// | ||
// Copyright (C) 2023, the Celestia Development Team | ||
// | ||
// Celestia dialog to activate tour guide. | ||
// | ||
// 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. | ||
|
||
|
||
#include "qttourguide.h" | ||
|
||
#include <celengine/simulation.h> | ||
#include <celengine/selection.h> | ||
#include <celestia/celestiacore.h> | ||
#include <celengine/observer.h> | ||
#include <celutil/gettext.h> | ||
|
||
#include <string> | ||
|
||
#include <Eigen/Core> | ||
|
||
#include <QDialogButtonBox> | ||
#include <QPushButton> | ||
#include <QComboBox> | ||
#include <QString> | ||
#include <QLabel> | ||
#include <QWidget> | ||
|
||
|
||
|
||
TourGuideDialog::TourGuideDialog(QWidget *parent, CelestiaCore *appCore) : | ||
QDialog(parent), | ||
appCore(appCore) | ||
{ | ||
ui.setupUi(this); | ||
|
||
destinations = appCore->getDestinations(); | ||
bool hasDestinations = false; | ||
if (destinations != nullptr) | ||
{ | ||
for (const Destination *dest : *destinations) | ||
{ | ||
if (dest == nullptr) | ||
continue; | ||
hasDestinations = true; | ||
ui.selectionComboBox->addItem(QString::fromStdString(dest->name)); | ||
} | ||
|
||
if (hasDestinations) | ||
{ | ||
auto dest = (*destinations)[0]; | ||
ui.selectionDescription->setText(QString::fromStdString(dest->description)); | ||
} | ||
} | ||
|
||
if ((destinations == nullptr) || !hasDestinations) | ||
{ | ||
ui.selectionDescription->setText(_("No guide destinations were found.")); | ||
ui.gotoButton->setEnabled(false); | ||
ui.selectionComboBox->setEnabled(false); | ||
} | ||
|
||
connect(ui.selectionComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotSelectionChanged())); | ||
connect(ui.gotoButton, SIGNAL(clicked(bool)), SLOT(slotGotoSelection())); | ||
this->setAttribute(Qt::WA_DeleteOnClose, true); | ||
} | ||
|
||
|
||
void | ||
TourGuideDialog::slotSelectionChanged() | ||
{ | ||
int index = ui.selectionComboBox->currentIndex(); | ||
auto dest = (*destinations)[index]; | ||
ui.selectionDescription->setText(QString::fromStdString(dest->description)); | ||
} | ||
|
||
|
||
void | ||
TourGuideDialog::slotGotoSelection() | ||
{ | ||
Simulation *simulation = appCore->getSimulation(); | ||
|
||
int index = ui.selectionComboBox->currentIndex(); | ||
auto dest = (*destinations)[index]; | ||
|
||
Selection sel = simulation->findObjectFromPath(dest->target); | ||
|
||
double distance = dest->distance; | ||
if (distance <= sel.radius()) | ||
distance = sel.radius() * 5.0; | ||
|
||
simulation->setSelection(sel); | ||
simulation->follow(); | ||
simulation->gotoSelection(5.0, distance, Eigen::Vector3f::UnitY(), ObserverFrame::ObserverLocal); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// qttourguide.h | ||
// | ||
// Copyright (C) 2023, the Celestia Development Team | ||
// | ||
// Celestia dialog to activate tour guide. | ||
// | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <QDialog> | ||
#include <QObject> | ||
#include <celestia/destination.h> | ||
|
||
#include "ui_tourguide.h" | ||
|
||
class QWidget; | ||
|
||
class CelestiaCore; | ||
|
||
class TourGuideDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
TourGuideDialog(QWidget *parent, CelestiaCore *appCore); | ||
~TourGuideDialog() = default; | ||
|
||
private slots: | ||
void slotSelectionChanged(); | ||
void slotGotoSelection(); | ||
|
||
private: | ||
Ui_tourGuideDialog ui; | ||
CelestiaCore *appCore; | ||
const DestinationList *destinations{ nullptr }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<ui version="4.0"> | ||
<class>tourGuideDialog</class> | ||
<widget class="QDialog" name="tourGuideDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>464</width> | ||
<height>444</height> | ||
</rect> | ||
</property> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Tour Guide</string> | ||
</property> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>13</x> | ||
<y>390</y> | ||
<width>431</width> | ||
<height>39</height> | ||
</rect> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Close</set> | ||
</property> | ||
</widget> | ||
<widget class="QWidget" name="verticalLayoutWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>9</x> | ||
<y>19</y> | ||
<width>441</width> | ||
<height>361</height> | ||
</rect> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>Select your destination:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QComboBox" name="selectionComboBox"> | ||
<property name="sizeAdjustPolicy"> | ||
<enum>QComboBox::AdjustToContentsOnFirstShow</enum> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="gotoButton"> | ||
<property name="text"> | ||
<string>Go To</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<widget class="QLabel" name="selectionDescription"> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
<property name="alignment"> | ||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> | ||
</property> | ||
<property name="wordWrap"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>40</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>tourGuideDialog</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>407</x> | ||
<y>471</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>8</x> | ||
<y>445</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>tourGuideDialog</receiver> | ||
<slot>close()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>228</x> | ||
<y>409</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>231</x> | ||
<y>221</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |