QTfrontend/ui/widget/roomnameprompt.cpp
author unc0rr
Wed, 05 Jun 2013 00:26:22 +0400
changeset 9107 4dde5fecffe2
parent 9080 9b42757d7e71
child 9163 67334acaaac7
permissions -rw-r--r--
Less confusion to translators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     1
/*
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9080
9b42757d7e71 bump copyright year for Andrey entries
unc0rr
parents: 8622
diff changeset
     3
 * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     4
 *
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     8
 *
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    12
 * GNU General Public License for more details.
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    13
 *
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    17
 */
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    18
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    19
#include <QDialog>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    20
#include <QVBoxLayout>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    21
#include <QHBoxLayout>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    22
#include <QPushButton>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    23
#include <QLineEdit>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    24
#include <QLabel>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    25
#include <QDebug>
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    26
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    27
#include "roomnameprompt.h"
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    28
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    29
RoomNamePrompt::RoomNamePrompt(QWidget* parent, const QString & roomName) : QDialog(parent)
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    30
{
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    31
    setModal(true);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    32
    setWindowFlags(Qt::Sheet);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    33
    setWindowModality(Qt::WindowModal);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    34
    setMinimumSize(360, 130);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    35
    resize(360, 130);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    36
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    37
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    38
    // Layout
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    39
    QVBoxLayout * dialogLayout = new QVBoxLayout(this);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    40
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    41
    // Label
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    42
    label = new QLabel(tr("Enter a name for your room."));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    43
    label->setWordWrap(true);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    44
    dialogLayout->addWidget(label, 0);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    45
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    46
    // Input box
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    47
    editBox = new QLineEdit();
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    48
    editBox->setText(roomName);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    49
    editBox->setMaxLength(59); // It didn't like 60 :(
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    50
    editBox->setStyleSheet("QLineEdit { padding: 3px; }");
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    51
    editBox->selectAll();
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    52
    dialogLayout->addWidget(editBox, 1);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    53
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    54
    dialogLayout->addStretch(1);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    55
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    56
    // Buttons
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    57
    QHBoxLayout * buttonLayout = new QHBoxLayout();
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    58
    buttonLayout->addStretch(1);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    59
    dialogLayout->addLayout(buttonLayout);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    60
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    61
    QPushButton * btnCancel = new QPushButton(tr("Cancel"));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    62
    QPushButton * btnOkay = new QPushButton(tr("Create room"));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    63
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    64
    connect(btnOkay, SIGNAL(clicked()), this, SLOT(accept()));
8622
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    65
#ifdef Q_WS_MAC
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    66
        buttonLayout->addWidget(btnCancel);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    67
        buttonLayout->addWidget(btnOkay);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    68
#else
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    69
        buttonLayout->addWidget(btnOkay);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    70
        buttonLayout->addWidget(btnCancel);
2045bdf1b11b Resolves issue 528. Fixed platform-specific order of buttons on seed prompt and new room prompt. Fixed height of back button on all pages -- now aligns to bottom. On pagemain, feedback and dlc buttons no longer fixed size.
dag10
parents: 8456
diff changeset
    71
#endif
8456
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    72
    btnOkay->setDefault(true);
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    73
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    74
    setStyleSheet("QPushButton { padding: 5px; }");
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    75
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    76
    connect(btnOkay, SIGNAL(clicked()), this, SLOT(setRoomName()));
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    77
}
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    78
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    79
void RoomNamePrompt::setRoomName()
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    80
{
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    81
    emit roomNameChosen(editBox->text());
cc76826f14c2 Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    82
}