-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameters_dialog.cpp
78 lines (71 loc) · 2.92 KB
/
parameters_dialog.cpp
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
#include "parameters_dialog.hpp"
#include <QSpinBox>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDebug>
#define DEB qDebug()
ParametersDialog::ParametersDialog (QWidget* parent)
: QDialog{parent} {
createGui();
}
ClockParameters ParametersDialog::clockParameters () const {
ClockParameters parameters;
parameters.workTime = m_workTimeSpinbox->value() * 60;
parameters.shortBreakTime = m_shortBreakSpinbox->value() * 60;
parameters.longBreakTime = m_longBreakSpinbox->value() * 60;
parameters.maxShortBreaks = m_maxShortBreaksSpinbox->value();
return parameters;
}
void ParametersDialog::setClockParameters (const ClockParameters& parameters) {
m_workTimeSpinbox->setValue(parameters.workTime / 60);
m_shortBreakSpinbox->setValue(parameters.shortBreakTime / 60);
m_longBreakSpinbox->setValue(parameters.longBreakTime / 60);
DEB << "ParametersDialog::setClockParameters" << parameters.maxShortBreaks;
m_maxShortBreaksSpinbox->setValue(parameters.maxShortBreaks);
}
void ParametersDialog::createGui () {
auto* verticalLayout = new QVBoxLayout { this };
// Work time
auto* horizontalLayout = new QHBoxLayout {};
auto* label = new QLabel { "Work time", };
horizontalLayout->addWidget(label);
m_workTimeSpinbox = new QSpinBox {};
m_workTimeSpinbox->setRange(1, 60);
horizontalLayout->addWidget(m_workTimeSpinbox);
verticalLayout->addLayout(horizontalLayout);
// Short break
horizontalLayout = new QHBoxLayout {};
label = new QLabel { "Short break", };
horizontalLayout->addWidget(label);
m_shortBreakSpinbox = new QSpinBox {};
m_shortBreakSpinbox->setRange(1, 60);
horizontalLayout->addWidget(m_shortBreakSpinbox);
verticalLayout->addLayout(horizontalLayout);
// Long break
horizontalLayout = new QHBoxLayout {};
label = new QLabel { "Long break", };
horizontalLayout->addWidget(label);
m_longBreakSpinbox = new QSpinBox {};
m_longBreakSpinbox->setRange(1, 60);
horizontalLayout->addWidget(m_longBreakSpinbox);
verticalLayout->addLayout(horizontalLayout);
// Short breaks count
horizontalLayout = new QHBoxLayout {};
label = new QLabel { "Short breaks count", };
horizontalLayout->addWidget(label);
m_maxShortBreaksSpinbox = new QSpinBox {};
horizontalLayout->addWidget(m_maxShortBreaksSpinbox);
verticalLayout->addLayout(horizontalLayout);
// Buttons
horizontalLayout = new QHBoxLayout {};
auto cancelButton = new QPushButton { "Cancel" };
connect(cancelButton, &QPushButton::clicked, this, &ParametersDialog::reject);
horizontalLayout->addWidget(cancelButton);
auto acceptButton = new QPushButton { "Accept" };
connect(acceptButton, &QPushButton::clicked, this, &ParametersDialog::accept);
horizontalLayout->addWidget(acceptButton);
verticalLayout->addLayout(horizontalLayout);
setLayout(verticalLayout);
}