Skip to content

Commit

Permalink
[qt] - Add tour guide
Browse files Browse the repository at this point in the history
Add the tour guide function to the Navigation menu of the Qt interface.
This matches existing setups of win32 and GTK.
  • Loading branch information
dave-kaye authored Oct 11, 2023
1 parent f0596ce commit 70255cd
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/celestia/qt/CelestiaQtCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function(GetQtSources UseWayland)
qtsettimedialog.cpp
qtsolarsystembrowser.cpp
qttimetoolbar.cpp
qttourguide.cpp
xbel.cpp
)

Expand All @@ -43,6 +44,7 @@ function(GetQtSources UseWayland)
qtsettimedialog.h
qtsolarsystembrowser.h
qttimetoolbar.h
qttourguide.h
xbel.h
)

Expand Down
Binary file added src/celestia/qt/data/tour.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/celestia/qt/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
<file alias="clip_paste.png">data/clip_paste.png</file>
<file alias="picture_copy.png">data/picture_copy.png</file>
<file alias="split-cycle.png">data/split-cycle.png</file>
<file alias="tour.png">data/tour.png</file>
</qresource>
</RCC>
</RCC>
18 changes: 18 additions & 0 deletions src/celestia/qt/qtappwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
#include "qtsettimedialog.h"
#include "qtsolarsystembrowser.h"
#include "qttimetoolbar.h"
#include "qttourguide.h"

#ifndef CONFIG_DATA_DIR
#define CONFIG_DATA_DIR "./"
Expand Down Expand Up @@ -863,6 +864,15 @@ CelestiaAppWindow::gotoObject()
}


void
CelestiaAppWindow::tourGuide()
{
// use show() to display dialog in non-modal format since exec() is automatically modal
TourGuideDialog *tourDialog = new TourGuideDialog(this, m_appCore);
tourDialog->show();
}


void
CelestiaAppWindow::slotPreferences()
{
Expand Down Expand Up @@ -1448,6 +1458,14 @@ CelestiaAppWindow::createMenus()
connect(gotoObjAct, SIGNAL(triggered()), this, SLOT(gotoObject()));
navMenu->addAction(gotoObjAct);

navMenu->addSeparator();

QAction *tourAct = new QAction(QIcon(":/icons/tour.png"), _("Tour Guide"), this);
connect(tourAct, SIGNAL(triggered()), this, SLOT(tourGuide()));
navMenu->addAction(tourAct);

navMenu->addSeparator();

QAction *copyAction = new QAction(QIcon(":/icons/clip_copy.png"), _("Copy URL / console text"), this);
copyAction->setShortcut(QString("Ctrl+C"));
connect(copyAction, &QAction::triggered, this, &CelestiaAppWindow::copyTextOrURL);
Expand Down
2 changes: 2 additions & 0 deletions src/celestia/qt/qtappwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class EventFinder;
class InfoPanel;
class PreferencesDialog;
class TimeToolBar;
class TourGuideDialog;

class CelestiaAppWindow : public QMainWindow, public CelestiaCore::ContextMenuHandler
{
Expand Down Expand Up @@ -80,6 +81,7 @@ private slots:
void gotoSelection();
void gotoObject();
void selectSun();
void tourGuide();

void slotPreferences();

Expand Down
98 changes: 98 additions & 0 deletions src/celestia/qt/qttourguide.cpp
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);
}
40 changes: 40 additions & 0 deletions src/celestia/qt/qttourguide.h
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 };
};
146 changes: 146 additions & 0 deletions src/celestia/qt/tourguide.ui
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>

0 comments on commit 70255cd

Please sign in to comment.