QTfrontend/ui/widget/seedprompt.cpp
author Wuzzy <almikes@aol.com>
Sat, 21 Nov 2015 21:11:13 +0100
changeset 11495 fb7817a5c2b1
parent 11046 47a8c19ecb60
child 13681 05fde8e30041
permissions -rw-r--r--
Add window titles for title-less windows
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
8377
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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
8377
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);
11495
fb7817a5c2b1 Add window titles for title-less windows
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    34
    setWindowTitle(tr("Seed"));
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    35
    setMinimumSize(360, 160);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    36
    resize(360, 160);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    37
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    38
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    39
    // Layout
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    40
    QVBoxLayout * dialogLayout = new QVBoxLayout(this);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    41
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    42
    // Label
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    43
    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
    44
    label->setWordWrap(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    45
    dialogLayout->addWidget(label, 0);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    46
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    47
    // Input box
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    48
    editBox = new QLineEdit();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    49
    editBox->setText(seed);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    50
    editBox->setReadOnly(!editable);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    51
    editBox->setStyleSheet("QLineEdit { padding: 3px; }");
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    52
    dialogLayout->addWidget(editBox, 1);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    53
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    54
    dialogLayout->addStretch(1);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    55
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    56
    // Buttons
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    57
    QHBoxLayout * buttonLayout = new QHBoxLayout();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    58
    buttonLayout->addStretch(1);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    59
    dialogLayout->addLayout(buttonLayout);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    60
    if (editable)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    61
    {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    62
        QPushButton * btnCancel = new QPushButton(tr("Cancel"));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    63
        QPushButton * btnOkay = new QPushButton(tr("Set seed"));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    64
        connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    65
        connect(btnOkay, SIGNAL(clicked()), this, SLOT(accept()));
9163
67334acaaac7 port all Q_WS_* to Q_OS_* so that we are forward compatible with Qt5
koda
parents: 9080
diff changeset
    66
#ifdef Q_OS_MAC
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    67
        buttonLayout->addWidget(btnCancel);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    68
        buttonLayout->addWidget(btnOkay);
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: 8434
diff changeset
    69
#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: 8434
diff changeset
    70
        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: 8434
diff changeset
    71
        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: 8434
diff changeset
    72
#endif
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    73
        btnOkay->setDefault(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    74
    }
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    75
    else
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    76
    {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    77
        QPushButton * btnClose = new QPushButton(tr("Close"));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    78
        connect(btnClose, SIGNAL(clicked()), this, SLOT(reject()));
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    79
        buttonLayout->addWidget(btnClose);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    80
        btnClose->setDefault(true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    81
    }
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    82
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    83
    setStyleSheet("QPushButton { padding: 5px; }");
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    84
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    85
    connect(this, SIGNAL(accepted()), this, SLOT(setSeed()));
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    86
}
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    87
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    88
void SeedPrompt::setSeed()
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    89
{
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    90
    emit seedSelected(editBox->text());
8386
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8377
diff changeset
    91
}