summaryrefslogtreecommitdiff
path: root/src/gui/register.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-18 17:39:16 +0100
committerIra Rice <irarice@gmail.com>2009-01-18 14:17:43 -0700
commit845934e41d27e143ac3555da51a3a09664516405 (patch)
treefa1f4a39639f6d19ef7687f542ab2b5190537f7a /src/gui/register.cpp
parent4e481047718a4728549ae65128e42912b747c86d (diff)
downloadmana-845934e41d27e143ac3555da51a3a09664516405.tar.gz
mana-845934e41d27e143ac3555da51a3a09664516405.tar.bz2
mana-845934e41d27e143ac3555da51a3a09664516405.tar.xz
mana-845934e41d27e143ac3555da51a3a09664516405.zip
Used dynamic layout for registration window
The dialog looks nicer now and the layout problems when the dialog is translated have been fixed. Signed-off-by: Bjørn Lindeijer <bjorn@lindeijer.nl>
Diffstat (limited to 'src/gui/register.cpp')
-rw-r--r--src/gui/register.cpp98
1 files changed, 37 insertions, 61 deletions
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index 568ec5ff..a9cf57cf 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -40,9 +40,24 @@
#include "../utils/tostring.h"
+#include "widgets/layout.h"
+
#include "../utils/gettext.h"
#include "../utils/strprintf.h"
+/**
+ * Listener used while dealing with wrong data. It is used to direct the focus
+ * to the field which contained wrong data when the Ok button was pressed on
+ * the error notice.
+ */
+class WrongDataNoticeListener : public gcn::ActionListener {
+ public:
+ void setTarget(gcn::TextField *textField);
+ void action(const gcn::ActionEvent &event);
+ private:
+ gcn::TextField *mTarget;
+};
+
void WrongDataNoticeListener::setTarget(gcn::TextField *textField)
{
mTarget = textField;
@@ -56,9 +71,10 @@ void WrongDataNoticeListener::action(const gcn::ActionEvent &event)
}
}
+
RegisterDialog::RegisterDialog(LoginData *loginData):
Window(_("Register")),
- mWrongDataNoticeListener(new WrongDataNoticeListener()),
+ mWrongDataNoticeListener(new WrongDataNoticeListener),
mLoginData(loginData)
{
gcn::Label *userLabel = new gcn::Label(_("Name:"));
@@ -68,7 +84,7 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
gcn::Label *portLabel = new gcn::Label(_("Port:"));
mUserField = new TextField(loginData->username);
mPasswordField = new PasswordField(loginData->password);
- mConfirmField = new PasswordField();
+ mConfirmField = new PasswordField;
mServerField = new TextField(loginData->hostname);
mPortField = new TextField(toString(loginData->port));
mMaleButton = new RadioButton(_("Male"), "sex", true);
@@ -76,47 +92,24 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mRegisterButton = new Button(_("Register"), "register", this);
mCancelButton = new Button(_("Cancel"), "cancel", this);
- const int WIDTH = 220;
- const int HEIGHT = 170;
- const int FIELD_WIDTH = WIDTH - 70;
-
- setContentSize(WIDTH, HEIGHT);
-
- const int USER_TOP = 5;
- userLabel->setPosition(5, USER_TOP);
- mUserField->setPosition(65, USER_TOP);
- mUserField->setWidth(FIELD_WIDTH);
-
- const int PASS_TOP = 9 + USER_TOP + userLabel->getHeight();
- passwordLabel->setPosition(5, PASS_TOP);
- mPasswordField->setPosition(65, PASS_TOP);
- mPasswordField->setWidth(FIELD_WIDTH);
-
- const int CONFIRM_TOP = 9 + PASS_TOP + passwordLabel->getHeight();
- confirmLabel->setPosition(5, CONFIRM_TOP);
- mConfirmField->setPosition(65, CONFIRM_TOP);
- mConfirmField->setWidth(FIELD_WIDTH);
-
- const int SEX_TOP = 9 + CONFIRM_TOP + confirmLabel->getHeight();
- mMaleButton->setPosition(70, SEX_TOP);
- mFemaleButton->setPosition(80 + mMaleButton->getWidth(), SEX_TOP);
-
- const int SERVER_TOP = 9 + SEX_TOP + mMaleButton->getHeight() + 5;
- serverLabel->setPosition(5, SERVER_TOP);
- mServerField->setPosition(65, SERVER_TOP);
- mServerField->setWidth(FIELD_WIDTH);
-
- const int PORT_TOP = 9 + SERVER_TOP + serverLabel->getHeight();
- portLabel->setPosition(5, PORT_TOP);
- mPortField->setPosition(65, PORT_TOP);
- mPortField->setWidth(FIELD_WIDTH);
-
- mCancelButton->setPosition(
- WIDTH - mCancelButton->getWidth() - 5,
- HEIGHT - mCancelButton->getHeight() - 5);
- mRegisterButton->setPosition(
- mCancelButton->getX() - mRegisterButton->getWidth() - 5,
- HEIGHT - mRegisterButton->getHeight() - 5);
+ ContainerPlacer place;
+ place = getPlacer(0, 0);
+ place(0, 0, userLabel);
+ place(0, 1, passwordLabel);
+ place(0, 2, confirmLabel);
+ place(1, 3, mMaleButton);
+ place(2, 3, mFemaleButton);
+ place(0, 4, serverLabel);
+ place(0, 5, portLabel);
+ place(1, 0, mUserField, 3).setPadding(2);
+ place(1, 1, mPasswordField, 3).setPadding(2);
+ place(1, 2, mConfirmField, 3).setPadding(2);
+ place(1, 4, mServerField, 3).setPadding(2);
+ place(1, 5, mPortField, 3).setPadding(2);
+ place = getPlacer(0, 2);
+ place(1, 0, mRegisterButton);
+ place(2, 0, mCancelButton);
+ reflowLayout(250, 0);
mUserField->addKeyListener(this);
mPasswordField->addKeyListener(this);
@@ -141,23 +134,6 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mServerField->addActionListener(this);
mPortField->addActionListener(this);
- add(userLabel);
- add(passwordLabel);
- add(confirmLabel);
- add(serverLabel);
- add(portLabel);
-
- add(mUserField);
- add(mPasswordField);
- add(mConfirmField);
- add(mServerField);
- add(mPortField);
-
- add(mMaleButton);
- add(mFemaleButton);
- add(mRegisterButton);
- add(mCancelButton);
-
setLocationRelativeTo(getParent());
setVisible(true);
mUserField->requestFocus();
@@ -265,7 +241,7 @@ void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent)
mRegisterButton->setEnabled(canSubmit());
}
-bool RegisterDialog::canSubmit()
+bool RegisterDialog::canSubmit() const
{
return !mUserField->getText().empty() &&
!mPasswordField->getText().empty() &&