1 /*
2  *    Copyright 2012 Thomas Schöps
3  *    Copyright 2013, 2017 Kai Pastor
4  *
5  *    This file is part of OpenOrienteering.
6  *
7  *    OpenOrienteering is free software: you can redistribute it and/or modify
8  *    it under the terms of the GNU General Public License as published by
9  *    the Free Software Foundation, either version 3 of the License, or
10  *    (at your option) any later version.
11  *
12  *    OpenOrienteering is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with OpenOrienteering.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #include "template_positioning_dialog.h"
23 
24 #include <Qt>
25 #include <QComboBox>
26 #include <QDialogButtonBox>
27 #include <QDoubleSpinBox>
28 #include <QFlags>
29 #include <QFormLayout>
30 #include <QRadioButton>
31 #include <QSpacerItem>
32 
33 #include "gui/util_gui.h"
34 
35 
36 namespace OpenOrienteering {
37 
TemplatePositioningDialog(QWidget * parent)38 TemplatePositioningDialog::TemplatePositioningDialog(QWidget* parent)
39 : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint)
40 {
41 	setWindowModality(Qt::WindowModal);
42 	setWindowTitle(tr("Track scaling and positioning"));
43 
44 	QFormLayout* layout = new QFormLayout();
45 
46 	coord_system_box = new QComboBox();
47 	layout->addRow(tr("Coordinate system"), coord_system_box);
48 	coord_system_box->addItem(tr("Real"));
49 	coord_system_box->addItem(tr("Map"));
50 	coord_system_box->setCurrentIndex(0);
51 
52 	unit_scale_edit = Util::SpinBox::create(6, 0, 99999.999999, tr("m", "meters"));
53 	unit_scale_edit->setValue(1);
54 	unit_scale_edit->setEnabled(false);
55 	layout->addRow(tr("One coordinate unit equals:"), unit_scale_edit);
56 
57 	original_pos_radio = new QRadioButton(tr("Position track at given coordinates"));
58 	original_pos_radio->setChecked(true);
59 	layout->addRow(original_pos_radio);
60 
61 	view_center_radio = new QRadioButton(tr("Position track at view center"));
62 	layout->addRow(view_center_radio);
63 
64 	layout->addItem(Util::SpacerItem::create(this));
65 
66 	auto button_box = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
67 	layout->addWidget(button_box);
68 
69 	setLayout(layout);
70 
71 	connect(button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
72 	connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
73 }
74 
useRealCoords() const75 bool TemplatePositioningDialog::useRealCoords() const
76 {
77 	return coord_system_box->currentIndex() == 0;
78 }
79 
getUnitScale() const80 double TemplatePositioningDialog::getUnitScale() const
81 {
82 	return unit_scale_edit->value();
83 }
84 
centerOnView() const85 bool TemplatePositioningDialog::centerOnView() const
86 {
87 	return view_center_radio->isChecked();
88 }
89 
90 
91 }  // namespace OpenOrienteering
92