QTfrontend/ui/widget/roomnameprompt.cpp
author dag10
Tue, 29 Jan 2013 01:41:41 -0500
changeset 8458 a7ff58c92d2e
child 8622 2045bdf1b11b
permissions -rw-r--r--
Added roomnameprompt.h/cpp. Sorry 'bout that.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8458
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     1
/*
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     4
 *
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
a7ff58c92d2e 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
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     8
 *
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    12
 * GNU General Public License for more details.
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    13
 *
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    17
 */
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    18
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    19
#include <QDialog>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    20
#include <QVBoxLayout>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    21
#include <QHBoxLayout>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    22
#include <QPushButton>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    23
#include <QLineEdit>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    24
#include <QLabel>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    25
#include <QDebug>
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    26
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    27
#include "roomnameprompt.h"
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    28
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    29
RoomNamePrompt::RoomNamePrompt(QWidget* parent, const QString & roomName) : QDialog(parent)
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    30
{
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    31
    setModal(true);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    32
    setWindowFlags(Qt::Sheet);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    33
    setWindowModality(Qt::WindowModal);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    34
    setMinimumSize(360, 130);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    35
    resize(360, 130);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    36
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    37
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    38
    // Layout
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    39
    QVBoxLayout * dialogLayout = new QVBoxLayout(this);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    40
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    41
    // Label
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    42
    label = new QLabel(tr("Enter a name for your room."));
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    43
    label->setWordWrap(true);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    44
    dialogLayout->addWidget(label, 0);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    45
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    46
    // Input box
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    47
    editBox = new QLineEdit();
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    48
    editBox->setText(roomName);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    49
    editBox->setMaxLength(59); // It didn't like 60 :(
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    50
    editBox->setStyleSheet("QLineEdit { padding: 3px; }");
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    51
    editBox->selectAll();
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    52
    dialogLayout->addWidget(editBox, 1);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    53
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    54
    dialogLayout->addStretch(1);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    55
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    56
    // Buttons
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    57
    QHBoxLayout * buttonLayout = new QHBoxLayout();
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    58
    buttonLayout->addStretch(1);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    59
    dialogLayout->addLayout(buttonLayout);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    60
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    61
    QPushButton * btnCancel = new QPushButton(tr("Cancel"));
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    62
    QPushButton * btnOkay = new QPushButton(tr("Create room"));
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    63
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    64
    connect(btnOkay, SIGNAL(clicked()), this, SLOT(accept()));
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    65
    buttonLayout->addWidget(btnCancel);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    66
    buttonLayout->addWidget(btnOkay);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    67
    btnOkay->setDefault(true);
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    68
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    69
    setStyleSheet("QPushButton { padding: 5px; }");
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    70
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    71
    connect(btnOkay, SIGNAL(clicked()), this, SLOT(setRoomName()));
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    72
}
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    73
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    74
void RoomNamePrompt::setRoomName()
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    75
{
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    76
    emit roomNameChosen(editBox->text());
a7ff58c92d2e Added roomnameprompt.h/cpp. Sorry 'bout that.
dag10
parents:
diff changeset
    77
}