Debian Codegraph @

src/editor/targetnodesizedlg.cpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2012 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 "targetnodesizedlg.hpp"
17 #include "tracktile.hpp"
18
19 #include <QHBoxLayout>
20 #include <QIntValidator>
21 #include <QLabel>
22 #include <QLineEdit>
23 #include <QPushButton>
24 #include <QVBoxLayout>
25
26 TargetNodeSizeDlg::TargetNodeSizeDlg(QSizeF defaultSize, 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_widthEdit(new QLineEdit)
32 , m_widthLabel(new QLabel(tr("Width:")))
33 , m_heightEdit(new QLineEdit)
34 , m_heightLabel(new QLabel(tr("Height:")))
35 {
36 setWindowTitle(tr("Set target node size"));
37
38 QIntValidator * widthValidator = new QIntValidator(this);
39 widthValidator->setRange(TrackTile::width() / 2, TrackTile::width() * 4);
40 m_widthEdit->setValidator(widthValidator);
41 m_widthEdit->setText(QString("%1").arg(defaultSize.width()));
42
43 QIntValidator * heightValidator = new QIntValidator(this);
44 heightValidator->setRange(TrackTile::height() / 2, TrackTile::height() * 4);
45 m_heightEdit->setValidator(widthValidator);
46 m_heightEdit->setText(QString("%1").arg(defaultSize.height()));
47
48 m_layout->addWidget(m_widthLabel, 0, 0);
49 m_layout->addWidget(m_widthEdit, 0, 1);
50 m_layout->addWidget(m_heightLabel, 1, 0);
51 m_layout->addWidget(m_heightEdit, 1, 1);
52 m_layout->addWidget(m_okButton, 3, 0);
53 m_layout->addWidget(m_cancelButton, 3, 1);
54
55 connect(m_okButton, &QPushButton::clicked, this, &TargetNodeSizeDlg::accept);
56 connect(m_cancelButton, &QPushButton::clicked, this, &TargetNodeSizeDlg::reject);
57 }
58
59 QSizeF TargetNodeSizeDlg::targetNodeSize() const
60 {
61 return QSizeF(m_widthEdit->text().toInt(), m_heightEdit->text().toInt());
62 }