QTfrontend/ui/widget/seedprompt.cpp
author koda
Thu, 28 Feb 2013 22:59:22 +0100
changeset 8609 3f6c08223aa1
parent 8434 4821897a0f10
child 8622 2045bdf1b11b
permissions -rw-r--r--
use NETGAME_DEFAULT_PORT macro across frontend sources
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     1
/*
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     4
 *
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     8
 *
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    12
 * GNU General Public License for more details.
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    13
 *
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    17
 */
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    18
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    19
#include <QDialog>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    20
#include <QVBoxLayout>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    21
#include <QHBoxLayout>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    22
#include <QPushButton>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    23
#include <QLineEdit>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    24
#include <QLabel>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    25
#include <QDebug>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    26
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    27
#include "seedprompt.h"
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    28
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    29
SeedPrompt::SeedPrompt(QWidget* parent, const QString & seed, bool editable) : QDialog(parent)
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    30
{
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    31
    setModal(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    32
    setWindowFlags(Qt::Sheet);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    33
    setWindowModality(Qt::WindowModal);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    34
    setMinimumSize(360, 160);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    35
    resize(360, 160);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    36
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    37
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    38
    // Layout
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    39
    QVBoxLayout * dialogLayout = new QVBoxLayout(this);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    40
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    41
    // Label
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    42
    QLabel * label = new QLabel(tr("The map seed is the basis for all random values generated by the game."));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    43
    label->setWordWrap(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    44
    dialogLayout->addWidget(label, 0);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    45
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    46
    // Input box
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    47
    editBox = new QLineEdit();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    48
    editBox->setText(seed);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    49
    editBox->setReadOnly(!editable);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    50
    editBox->setStyleSheet("QLineEdit { padding: 3px; }");
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    51
    dialogLayout->addWidget(editBox, 1);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    52
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    53
    dialogLayout->addStretch(1);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    54
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    55
    // Buttons
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    56
    QHBoxLayout * buttonLayout = new QHBoxLayout();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    57
    buttonLayout->addStretch(1);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    58
    dialogLayout->addLayout(buttonLayout);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    59
    if (editable)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    60
    {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    61
        QPushButton * btnCancel = new QPushButton(tr("Cancel"));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    62
        QPushButton * btnOkay = new QPushButton(tr("Set seed"));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    63
        connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    64
        connect(btnOkay, SIGNAL(clicked()), this, SLOT(accept()));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    65
        buttonLayout->addWidget(btnCancel);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    66
        buttonLayout->addWidget(btnOkay);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    67
        btnOkay->setDefault(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    68
    }
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    69
    else
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    70
    {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    71
        QPushButton * btnClose = new QPushButton(tr("Close"));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    72
        connect(btnClose, SIGNAL(clicked()), this, SLOT(reject()));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    73
        buttonLayout->addWidget(btnClose);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    74
        btnClose->setDefault(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    75
    }
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    76
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    77
    setStyleSheet("QPushButton { padding: 5px; }");
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    78
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    79
    connect(this, SIGNAL(accepted()), this, SLOT(setSeed()));
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    80
}
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    81
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    82
void SeedPrompt::setSeed()
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    83
{
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    84
    emit seedSelected(editBox->text());
8386
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8377
diff changeset
    85
}