Skip to content

Commit

Permalink
UI|MessageDialog: Added InputDialog for querying text from user
Browse files Browse the repository at this point in the history
Also, both MessageDialog and InputDialog can now be constructed
as local variables; they will reinitialize themselves automatically
in their destructors.
  • Loading branch information
skyjake committed Sep 9, 2013
1 parent 43b3b63 commit a7e5a97
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
44 changes: 44 additions & 0 deletions 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 <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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</small>
*/

#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
1 change: 1 addition & 0 deletions doomsday/client/include/ui/dialogs/messagedialog.h
Expand Up @@ -28,6 +28,7 @@ class MessageDialog : public DialogWidget
{
public:
MessageDialog(de::String const &name = "");
~MessageDialog();

LabelWidget &title();
LabelWidget &message();
Expand Down
63 changes: 63 additions & 0 deletions 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 <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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</small>
*/

#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);
}
5 changes: 5 additions & 0 deletions doomsday/client/src/ui/dialogs/messagedialog.cpp
Expand Up @@ -71,6 +71,11 @@ MessageDialog::MessageDialog(String const &name)
: DialogWidget(name), d(new Instance(this))
{}

MessageDialog::~MessageDialog()
{
deinitialize();
}

LabelWidget &MessageDialog::title()
{
return *d->title;
Expand Down

0 comments on commit a7e5a97

Please sign in to comment.