-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlatitude_controller_dialog.cpp_BKP
More file actions
82 lines (63 loc) · 1.85 KB
/
latitude_controller_dialog.cpp_BKP
File metadata and controls
82 lines (63 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "latitude_controller_dialog.h"
#include "constants.h"
#include <QBoxLayout>
#include <QLabel>\
#include <iostream>
LatitudeSlider::LatitudeSlider()
{
setOrientation(Qt::Horizontal);
setRange(-90,90);
setValue(DEFAULT_LATITUDE);
}
LatitudeControllerDialog::LatitudeControllerDialog(QWidget * parent, Qt::WindowFlags f) :
QDialog(parent, f), m_latitude_slider(new LatitudeSlider), m_latitude_lbl(new QLabel)
{
setWindowTitle("Latitude Controller");
setModal(false);
connect(m_latitude_slider, SIGNAL(valueChanged(int)), this, SLOT(refresh_labels()));
init_layout();
}
LatitudeControllerDialog::~LatitudeControllerDialog()
{
}
QSize LatitudeControllerDialog::sizeHint() const
{
return QSize(500, 200);
}
void LatitudeControllerDialog::init_layout()
{
refresh_labels(); // Add content to labels
QVBoxLayout * main_layout = new QVBoxLayout;
// Latittude
{
QHBoxLayout * layout (new QHBoxLayout);
// Label
layout->addWidget(new QLabel("Latitude: "),0);
// Slider
layout->addWidget(m_latitude_slider,1);
// Value label
layout->addWidget(m_latitude_lbl, 0);
main_layout->addLayout(layout,0);
}
// Padding
main_layout->addWidget(new QLabel(""),1);
setLayout(main_layout);
}
int LatitudeControllerDialog::getLatitude()
{
return m_latitude_slider->value();
}
void LatitudeControllerDialog::refresh_labels()
{
m_latitude_lbl->setText(format_latitude(getLatitude()));
}
QString LatitudeControllerDialog::format_latitude(int latitude)
{
bool positif(latitude >= 0);
QString two_digit_latitude(get_two_number_digit(std::abs(latitude)));
return ((positif ? "+" : "-") + two_digit_latitude + "°");
}
QString LatitudeControllerDialog::get_two_number_digit(int digit)
{
return QString("%1").arg(digit, 2, 10, QChar('0'));
}