From a7e5a976075e3ff9be59acb761a86975a9003788 Mon Sep 17 00:00:00 2001 From: skyjake Date: Mon, 9 Sep 2013 22:20:33 +0300 Subject: [PATCH] UI|MessageDialog: Added InputDialog for querying text from user Also, both MessageDialog and InputDialog can now be constructed as local variables; they will reinitialize themselves automatically in their destructors. --- doomsday/client/client.pro | 2 + .../client/include/ui/dialogs/inputdialog.h | 44 +++++++++++++ .../client/include/ui/dialogs/messagedialog.h | 1 + .../client/src/ui/dialogs/inputdialog.cpp | 63 +++++++++++++++++++ .../client/src/ui/dialogs/messagedialog.cpp | 5 ++ 5 files changed, 115 insertions(+) create mode 100644 doomsday/client/include/ui/dialogs/inputdialog.h create mode 100644 doomsday/client/src/ui/dialogs/inputdialog.cpp diff --git a/doomsday/client/client.pro b/doomsday/client/client.pro index 2b7d26d2e1..d9d6b1c5d9 100644 --- a/doomsday/client/client.pro +++ b/doomsday/client/client.pro @@ -358,6 +358,7 @@ DENG_HEADERS += \ include/ui/dialogs/aboutdialog.h \ include/ui/dialogs/audiosettingsdialog.h \ include/ui/dialogs/coloradjustmentdialog.h \ + include/ui/dialogs/inputdialog.h \ include/ui/dialogs/inputsettingsdialog.h \ include/ui/dialogs/messagedialog.h \ include/ui/dialogs/networksettingsdialog.h \ @@ -699,6 +700,7 @@ SOURCES += \ src/ui/dialogs/aboutdialog.cpp \ src/ui/dialogs/audiosettingsdialog.cpp \ src/ui/dialogs/coloradjustmentdialog.cpp \ + src/ui/dialogs/inputdialog.cpp \ src/ui/dialogs/inputsettingsdialog.cpp \ src/ui/dialogs/messagedialog.cpp \ src/ui/dialogs/networksettingsdialog.cpp \ diff --git a/doomsday/client/include/ui/dialogs/inputdialog.h b/doomsday/client/include/ui/dialogs/inputdialog.h new file mode 100644 index 0000000000..2629e08fd2 --- /dev/null +++ b/doomsday/client/include/ui/dialogs/inputdialog.h @@ -0,0 +1,44 @@ +/** @file inputdialog.h Dialog for querying a string text from the user. + * + * @authors Copyright (c) 2013 Jaakko Keränen + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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, see: + * http://www.gnu.org/licenses + */ + +#ifndef DENG_CLIENT_INPUTDIALOG_H +#define DENG_CLIENT_INPUTDIALOG_H + +#include "ui/dialogs/messagedialog.h" +#include "ui/widgets/lineeditwidget.h" + +/** + * Dialog for querying a string of text from the user. + */ +class InputDialog : public MessageDialog +{ +public: + InputDialog(de::String const &name = ""); + ~InputDialog(); + + LineEditWidget &editor(); + +protected: + void preparePanelForOpening(); + void panelClosing(); + +private: + DENG2_PRIVATE(d) +}; + +#endif // DENG_CLIENT_INPUTDIALOG_H diff --git a/doomsday/client/include/ui/dialogs/messagedialog.h b/doomsday/client/include/ui/dialogs/messagedialog.h index 93c2e31f9d..523e602e6c 100644 --- a/doomsday/client/include/ui/dialogs/messagedialog.h +++ b/doomsday/client/include/ui/dialogs/messagedialog.h @@ -28,6 +28,7 @@ class MessageDialog : public DialogWidget { public: MessageDialog(de::String const &name = ""); + ~MessageDialog(); LabelWidget &title(); LabelWidget &message(); diff --git a/doomsday/client/src/ui/dialogs/inputdialog.cpp b/doomsday/client/src/ui/dialogs/inputdialog.cpp new file mode 100644 index 0000000000..de252a6c93 --- /dev/null +++ b/doomsday/client/src/ui/dialogs/inputdialog.cpp @@ -0,0 +1,63 @@ +/** @file inputdialog.cpp Dialog for querying a string text from the user. + * + * @authors Copyright (c) 2013 Jaakko Keränen + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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, see: + * http://www.gnu.org/licenses + */ + +#include "ui/dialogs/inputdialog.h" + +using namespace de; + +DENG2_PIMPL_NOREF(InputDialog) +{ + LineEditWidget *editor; +}; + +InputDialog::InputDialog(String const &name) + : MessageDialog(name), d(new Instance) +{ + // Create the editor. + area().add(d->editor = new LineEditWidget); + d->editor->setSignalOnEnter(true); + connect(d->editor, SIGNAL(enterPressed(QString)), this, SLOT(accept())); + + buttons().items() + << new DialogButtonItem(Default | Accept) + << new DialogButtonItem(Reject); + + updateLayout(); +} + +InputDialog::~InputDialog() +{ + deinitialize(); +} + +LineEditWidget &InputDialog::editor() +{ + return *d->editor; +} + +void InputDialog::preparePanelForOpening() +{ + MessageDialog::preparePanelForOpening(); + root().setFocus(d->editor); +} + +void InputDialog::panelClosing() +{ + MessageDialog::panelClosing(); + root().setFocus(0); +} diff --git a/doomsday/client/src/ui/dialogs/messagedialog.cpp b/doomsday/client/src/ui/dialogs/messagedialog.cpp index aefcee1f35..e109d16400 100644 --- a/doomsday/client/src/ui/dialogs/messagedialog.cpp +++ b/doomsday/client/src/ui/dialogs/messagedialog.cpp @@ -71,6 +71,11 @@ MessageDialog::MessageDialog(String const &name) : DialogWidget(name), d(new Instance(this)) {} +MessageDialog::~MessageDialog() +{ + deinitialize(); +} + LabelWidget &MessageDialog::title() { return *d->title;