Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a button that allows shutting down both the client and server. #335

Merged
merged 14 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/config/dialog_on_exit_shutdown.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>

<!-- Window -->
<window>
<width>1000</width>
<height>845</height>
<default_exit_action>SHUTDOWN_SERVER</default_exit_action>
<dialog_on_exit>true</dialog_on_exit>
<dialog_on_exit_options>
<prompt_text>really? žřčš</prompt_text>
peci1 marked this conversation as resolved.
Show resolved Hide resolved
<show_shutdown_button>true</show_shutdown_button>
<show_close_gui_button>true</show_close_gui_button>
<shutdown_button_text>Quit Server&amp;GUI</shutdown_button_text>
peci1 marked this conversation as resolved.
Show resolved Hide resolved
<close_gui_button_text>Quit GUI only</close_gui_button_text>
peci1 marked this conversation as resolved.
Show resolved Hide resolved
</dialog_on_exit_options>
</window>

<plugin filename="ShutdownButton">
<ignition-gui>
<title>Shutdown</title>
<property type="int" key="x">500</property>
<property type="int" key="y">950</property>
<property type="int" key="height">180</property>
<property type="int" key="width">240</property>
</ignition-gui>
</plugin>

141 changes: 141 additions & 0 deletions include/ignition/gui/MainWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ namespace ignition
{
namespace gui
{
Q_NAMESPACE
class MainWindowPrivate;
struct WindowConfig;

/// \brief The action executed when GUI is closed without prompt.
enum class ExitAction
{
CLOSE_GUI, //! \brief Close GUI and leave server running
SHUTDOWN_SERVER, //! \brief Close GUI and shutdown server
peci1 marked this conversation as resolved.
Show resolved Hide resolved
};
Q_ENUM_NS(ExitAction)

/// \brief The main window class creates a QQuickWindow and acts as an
/// interface which provides properties and functions which can be called
/// from Main.qml
Expand Down Expand Up @@ -177,6 +186,14 @@ namespace ignition
NOTIFY ShowPluginMenuChanged
)

/// \brief Flag to enable confirmation dialog on exit
Q_PROPERTY(
ExitAction defaultExitAction
READ DefaultExitAction
WRITE SetDefaultExitAction
NOTIFY DefaultExitActionChanged
)

/// \brief Flag to enable confirmation dialog on exit
Q_PROPERTY(
bool showDialogOnExit
Expand All @@ -185,6 +202,46 @@ namespace ignition
NOTIFY ShowDialogOnExitChanged
)

/// \brief Text of the prompt in confirmation dialog on exit
Q_PROPERTY(
QString dialogOnExitText
READ DialogOnExitText
WRITE SetDialogOnExitText
NOTIFY DialogOnExitTextChanged
)

/// \brief Flag to show "shutdown" button in confirmation dialog on exit
Q_PROPERTY(
bool exitDialogShowShutdown
READ ExitDialogShowShutdown
WRITE SetExitDialogShowShutdown
NOTIFY ExitDialogShowShutdownChanged
)

/// \brief Flag to show "close GUI" button in confirmation dialog on exit
Q_PROPERTY(
bool exitDialogShowCloseGui
READ ExitDialogShowCloseGui
WRITE SetExitDialogShowCloseGui
NOTIFY ExitDialogShowCloseGuiChanged
)

/// \brief Text of the "shutdown" button in confirmation dialog on exit
Q_PROPERTY(
QString exitDialogShutdownText
READ ExitDialogShutdownText
WRITE SetExitDialogShutdownText
NOTIFY ExitDialogShutdownTextChanged
)

/// \brief Text of the "Close GUI" button in confirmation dialog on exit
Q_PROPERTY(
QString exitDialogCloseGuiText
READ ExitDialogCloseGuiText
WRITE SetExitDialogCloseGuiText
NOTIFY ExitDialogCloseGuiTextChanged
)

/// \brief Constructor
public: MainWindow();

Expand Down Expand Up @@ -352,6 +409,15 @@ namespace ignition
/// \param[in] _showPluginMenu True to show.
public: Q_INVOKABLE void SetShowPluginMenu(const bool _showPluginMenu);

/// \brief Get the action performed when GUI closes without prompt.
/// \return The action.
public: Q_INVOKABLE ExitAction DefaultExitAction() const;

/// \brief Set the action performed when GUI closes without prompt.
/// \param[in] _defaultExitAction The action.
public: Q_INVOKABLE void SetDefaultExitAction(
enum ExitAction _defaultExitAction);

/// \brief Get the flag to show the plugin menu.
/// \return True to show.
public: Q_INVOKABLE bool ShowDialogOnExit() const;
Expand All @@ -360,6 +426,60 @@ namespace ignition
/// \param[in] _showDialogOnExit True to show.
public: Q_INVOKABLE void SetShowDialogOnExit(bool _showDialogOnExit);

/// \brief Get the text of prompt in exit dialog.
/// \return Prompt text.
public: Q_INVOKABLE QString DialogOnExitText() const;

/// \brief Set the text of the prompt in exit dialog.
/// \param[in] _dialogOnExitText Prompt text.
public: Q_INVOKABLE void SetDialogOnExitText(
const QString& _dialogOnExitText);

/// \brief Get the flag to show "shutdown" button in exit dialog.
/// \return True to show.
public: Q_INVOKABLE bool ExitDialogShowShutdown() const;

/// \brief Set the flag to show "shutdown" button in exit dialog.
/// \param[in] _exitDialogShowShutdown True to show.
public: Q_INVOKABLE void SetExitDialogShowShutdown(
bool _exitDialogShowShutdown);

/// \brief Get the flag to show "Close GUI" button in exit dialog.
/// \return True to show.
public: Q_INVOKABLE bool ExitDialogShowCloseGui() const;

/// \brief Set the flag to show "Close GUI" button in exit dialog.
/// \param[in] _exitDialogShowCloseGui True to show.
public: Q_INVOKABLE void SetExitDialogShowCloseGui(
bool _exitDialogShowCloseGui);

/// \brief Get the text of the "shutdown" button in exit dialog.
/// \return Button text.
public: Q_INVOKABLE QString ExitDialogShutdownText() const;

/// \brief Set the text of the "shutdown" button in exit dialog.
/// \param[in] _exitDialogShutdownText Button text.
public: Q_INVOKABLE void SetExitDialogShutdownText(
const QString& _exitDialogShutdownText);

/// \brief Get the text of the "Close GUI" button in exit dialog.
/// \return Button text.
public: Q_INVOKABLE QString ExitDialogCloseGuiText() const;

/// \brief Set the text of the "Close GUI" button in exit dialog.
/// \param[in] _exitDialogCloseGuiText Button text.
public: Q_INVOKABLE void SetExitDialogCloseGuiText(
const QString& _exitDialogCloseGuiText);

/// \brief Get the topic of the server control service.
/// \return The service topic.
public: Q_INVOKABLE std::string ServerControlService() const;

/// \brief Set the topic of the server control service.
/// \param[in] _service The service topic.
public: Q_INVOKABLE void SetServerControlService(
const std::string& _service);
peci1 marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Callback when load configuration is selected
public slots: void OnLoadConfig(const QString &_path);

Expand All @@ -369,6 +489,9 @@ namespace ignition
/// \brief Callback when "save configuration as" is selected
public slots: void OnSaveConfigAs(const QString &_path);

/// \brief Callback when "shutdown simulation" is called
public slots: void OnStopServer();

/// \brief Notifies when the number of plugins has changed.
signals: void PluginCountChanged();

Expand Down Expand Up @@ -414,9 +537,27 @@ namespace ignition
/// \brief Notifies when the show menu flag has changed.
signals: void ShowPluginMenuChanged();

/// \brief Notifies when the defaultExitAction has changed.
signals: void DefaultExitActionChanged();

/// \brief Notifies when the showDialogOnExit flag has changed.
signals: void ShowDialogOnExitChanged();

/// \brief Notifies when dialogOnExitText has changed.
signals: void DialogOnExitTextChanged();

/// \brief Notifies when the exitDialogShowShutdown flag has changed.
signals: void ExitDialogShowShutdownChanged();

/// \brief Notifies when the exitDialogShowCloseGui flag has changed.
signals: void ExitDialogShowCloseGuiChanged();

/// \brief Notifies when exitDialogShutdownText has changed.
signals: void ExitDialogShutdownTextChanged();

/// \brief Notifies when exitDialogCloseGuiText has changed.
signals: void ExitDialogCloseGuiTextChanged();

/// \brief Notifies when the window config has changed.
signals: void configChanged();

Expand Down
49 changes: 43 additions & 6 deletions include/ignition/gui/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Dialogs 1.0
import QtQuick.Layouts 1.3
import ExitAction 1.0
import "qrc:/qml"

ApplicationWindow
Expand All @@ -45,7 +46,14 @@ ApplicationWindow
property string pluginToolBarTextColorLight: MainWindow.pluginToolBarTextColorLight
property string pluginToolBarColorDark: MainWindow.pluginToolBarColorDark
property string pluginToolBarTextColorDark: MainWindow.pluginToolBarTextColorDark
// Expose config properties to C++
property int defaultExitAction: MainWindow.defaultExitAction
property bool showDialogOnExit: MainWindow.showDialogOnExit
property string dialogOnExitText: MainWindow.dialogOnExitText
property bool exitDialogShowShutdown: MainWindow.exitDialogShowShutdown
property bool exitDialogShowCloseGui: MainWindow.exitDialogShowCloseGui
property string exitDialogShutdownText: MainWindow.exitDialogShutdownText
property string exitDialogCloseGuiText: MainWindow.exitDialogCloseGuiText
/**
* Tool bar background color
*/
Expand Down Expand Up @@ -76,6 +84,8 @@ ApplicationWindow
close.accepted = !showDialogOnExit
if(showDialogOnExit){
confirmationDialogOnExit.open()
} else if (defaultExitAction == ExitAction.SHUTDOWN_SERVER) {
MainWindow.OnStopServer()
}
}

Expand Down Expand Up @@ -325,24 +335,51 @@ ApplicationWindow
}
}

Timer {
id: timer
}

/**
* Confirmation dialog on close button
*/
Dialog {
id: confirmationDialogOnExit
title: "Do you really want to exit?"
title: (dialogOnExitText ? dialogOnExitText : "Do you really want to exit?")

modal: true
focus: true
parent: ApplicationWindow.overlay
width: 300
width: 500
x: (parent.width - width) / 2
y: (parent.height - height) / 2
closePolicy: Popup.CloseOnEscape
standardButtons: Dialog.Ok | Dialog.Cancel

onAccepted: {
Qt.quit()
standardButtons: (exitDialogShowCloseGui ? Dialog.Ok : Dialog.NoButton) | (exitDialogShowShutdown ? Dialog.Discard : Dialog.NoButton) | Dialog.Cancel
peci1 marked this conversation as resolved.
Show resolved Hide resolved

// The button texts need to be changed later than in onCompleted as standardButtons change later
onAboutToShow: function () {
if (exitDialogShowCloseGui)
footer.standardButton(Dialog.Ok).text = (exitDialogCloseGuiText ? exitDialogCloseGuiText : "Close GUI")
if (exitDialogShowShutdown)
footer.standardButton(Dialog.Discard).text = (exitDialogShutdownText ? exitDialogShutdownText : "Shutdown simulation")
peci1 marked this conversation as resolved.
Show resolved Hide resolved
}

footer:
DialogButtonBox {
onClicked: function (btn) {
if (btn == this.standardButton(Dialog.Ok)) {
Qt.quit()
}
else if (btn == this.standardButton(Dialog.Discard)) {
MainWindow.OnStopServer()
// if GUI and server run in the same process, give server opportunity to kill the GUI
timer.interval = 100;
timer.repeat = false;
timer.triggered.connect(function() {
Qt.quit()
});
timer.start();
}
}
}
}
}
Loading