| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2011 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #include "newtrackdialog.hpp" |
| 17 | |
| 18 | #include <QCheckBox> |
| 19 | #include <QHBoxLayout> |
| 20 | #include <QIntValidator> |
| 21 | #include <QLabel> |
| 22 | #include <QLineEdit> |
| 23 | #include <QPushButton> |
| 24 | #include <QVBoxLayout> |
| 25 | |
| 26 | NewTrackDialog::NewTrackDialog(QWidget * parent) |
| 27 | : QDialog(parent) |
| 28 | , m_layout(new QGridLayout(this)) |
| 29 | , m_okButton(new QPushButton(tr("Ok"))) |
| 30 | , m_cancelButton(new QPushButton(tr("Cancel"))) |
| 31 | , m_colsEdit(new QLineEdit) |
| 32 | , m_rowsEdit(new QLineEdit) |
| 33 | , m_nameEdit(new QLineEdit) |
| 34 | , m_colsLabel(new QLabel(tr("Number of tile columns:"))) |
| 35 | , m_rowsLabel(new QLabel(tr("Number of tile rows:"))) |
| 36 | , m_nameLabel(new QLabel(tr("Track name:"))) |
| 37 | , m_userLabel(new QLabel(tr("User track:"))) |
| 38 | , m_userCheck(new QCheckBox) |
| 39 | { |
| 40 | setWindowTitle(tr("Create a new track")); |
| 41 | |
| 42 | m_userCheck->setChecked(true); |
| 43 | m_okButton->setEnabled(false); |
| 44 | |
| 45 | m_layout->addWidget(m_nameLabel, 0, 0); |
| 46 | m_layout->addWidget(m_nameEdit, 0, 1); |
| 47 | m_layout->addWidget(m_userLabel, 1, 0); |
| 48 | m_layout->addWidget(m_userCheck, 1, 1); |
| 49 | m_layout->addWidget(m_colsLabel, 2, 0); |
| 50 | m_layout->addWidget(m_colsEdit, 2, 1); |
| 51 | m_layout->addWidget(m_rowsLabel, 3, 0); |
| 52 | m_layout->addWidget(m_rowsEdit, 3, 1); |
| 53 | m_layout->addWidget(m_okButton, 4, 0); |
| 54 | m_layout->addWidget(m_cancelButton, 4, 1); |
| 55 | |
| 56 | connect(m_nameEdit, &QLineEdit::textChanged, this, &NewTrackDialog::validateData); |
| 57 | connect(m_rowsEdit, &QLineEdit::textChanged, this, &NewTrackDialog::validateData); |
| 58 | connect(m_colsEdit, &QLineEdit::textChanged, this, &NewTrackDialog::validateData); |
| 59 | connect(m_okButton, &QPushButton::clicked, this, &NewTrackDialog::accept); |
| 60 | connect(m_cancelButton, &QPushButton::clicked, this, &NewTrackDialog::reject); |
| 61 | } |
| 62 | |
| 63 | unsigned int NewTrackDialog::cols() const |
| 64 | { |
| 65 | return m_colsEdit->text().toInt(); |
| 66 | } |
| 67 | |
| 68 | unsigned int NewTrackDialog::rows() const |
| 69 | { |
| 70 | return m_rowsEdit->text().toInt(); |
| 71 | } |
| 72 | |
| 73 | QString NewTrackDialog::name() const |
| 74 | { |
| 75 | return m_nameEdit->text(); |
| 76 | } |
| 77 | |
| 78 | bool NewTrackDialog::isUserTrack() const |
| 79 | { |
| 80 | return m_userCheck->isChecked(); |
| 81 | } |
| 82 | |
| 83 | void NewTrackDialog::validateData() |
| 84 | { |
| 85 | m_okButton->setEnabled( |
| 86 | m_nameEdit->text().length() > 0 && m_colsEdit->text().toInt() > 1 && m_rowsEdit->text().toInt() > 1); |
| 87 | } |