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