-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_new_event_dialog.cpp
More file actions
173 lines (149 loc) · 6.32 KB
/
add_new_event_dialog.cpp
File metadata and controls
173 lines (149 loc) · 6.32 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "add_new_event_dialog.h"
void AddNewEventDialog::okayButtonClicked()
{
try
{
QString summary = summaryLineEdit -> text();
if(summary.isEmpty())
throw QString("You did not enter the summary.");
QString comment = commentTextEdit -> toPlainText();
TMPriority priority;
QString pr = priorityComboBox -> currentText();
if(pr == "None")
priority = None;
else if(pr == "Low")
priority = Low;
else if(pr == "Medium")
priority = Medium;
else if(pr == "High")
priority = High;
QDateTime startingTime = startingTimeEdit -> dateTime();
QDateTime endingTime = endingTimeEdit -> dateTime();
if(startingTime > endingTime)
throw QString("Invalid dates: ending time before starting time.");
QDateTime whenStartToRemind = whenStartToRemindEdit -> dateTime();
qint64 intervalOfReminding = (minutesSpinBox -> value()) * 1000 * 60 +
(hoursSpinBox -> value()) * 1000 * 60 * 60 + (daysSpinBox -> value()) * 1000 * 60 * 60 * 24;
if(intervalOfReminding == 0)
throw QString("Invalid interval of reminding.");
bool remindDuringEvent = remindDuringEventCheckBox -> isChecked();
newEvent = new Event(summary, comment, priority, startingTime, endingTime,
whenStartToRemind, intervalOfReminding, remindDuringEvent);
accept();
close();
}catch(QString error)
{
QMessageBox errorMessageBox;
errorMessageBox.setText(error);
errorMessageBox.exec();
}
}
void AddNewEventDialog::cancelButtonClicked()
{
reject();
close();
}
Event* AddNewEventDialog::getNewEvent(bool &isNewEventHere)
{
int code = exec();
if(code == QDialog::Accepted)
{
isNewEventHere = true;
return newEvent;
}
else
{
isNewEventHere = false;
return new Event();
}
}
void AddNewEventDialog::editEvent(bool &isNewEventHere, Event *event)
{
summaryLineEdit -> insert(event -> summary());
commentTextEdit -> setPlainText(event -> comment());
TMPriority priority = event -> priority();
if(priority == None)
priorityComboBox -> setCurrentText("None");
else if(priority == Low)
priorityComboBox -> setCurrentText("Low");
else if(priority == Medium)
priorityComboBox -> setCurrentText("Medium");
else if(priority == High)
priorityComboBox -> setCurrentText("High");
startingTimeEdit -> setDateTime(event -> startingTime());
endingTimeEdit -> setDateTime(event -> endingTime());
whenStartToRemindEdit -> setDateTime(event -> whenStartToRemind());
daysSpinBox -> setValue(event -> intervalOfReminding() / (1000 * 60 * 60 * 24));
hoursSpinBox -> setValue(event -> intervalOfReminding() / (1000 * 60 * 60));
minutesSpinBox -> setValue(event -> intervalOfReminding() / (1000 * 60));
remindDuringEventCheckBox -> setChecked(event -> remindDuringEvent());
int code = exec();
if(code == QDialog::Accepted)
{
event -> setText(newEvent -> summary());
event -> setSummary(newEvent -> summary());
event -> setComment(newEvent -> comment());
event -> setPriority(newEvent -> priority());
event -> setStartingTime(newEvent -> startingTime());
event -> setEndingTime(newEvent -> endingTime());
event -> setWhenStartToRemind(newEvent -> whenStartToRemind());
event -> setIntervalOfReminding(newEvent -> intervalOfReminding());
event -> setRemindDuringEvent(newEvent -> remindDuringEvent());
event -> updateParameters();
isNewEventHere = true;
}
else
isNewEventHere = false;
}
AddNewEventDialog::AddNewEventDialog(QWidget *parent): QDialog(parent)
{
setWindowTitle("Add new event");
setModal(true);
mainLayout = new QVBoxLayout;
formsBox = new QGroupBox;
formsLayout = new QFormLayout;
summaryLineEdit = new QLineEdit;
formsLayout -> addRow(new QLabel("Summary"), summaryLineEdit);
commentTextEdit = new QTextEdit;
formsLayout -> addRow(new QLabel("Сomment"), commentTextEdit);
priorityComboBox = new QComboBox;
priorityComboBox -> addItem("None");
priorityComboBox -> addItem("Low");
priorityComboBox -> addItem("Medium");
priorityComboBox -> addItem("High");
formsLayout -> addRow(new QLabel("Priority"), priorityComboBox);
QDateTime currentDateTime(QDateTime::currentDateTime());
currentDateTime.setTime(QTime(currentDateTime.time().hour(), currentDateTime.time().minute(), 0, 0));
startingTimeEdit = new QDateTimeEdit(currentDateTime);
startingTimeEdit -> setDisplayFormat("dd.MM.yyyy h:mm");
formsLayout -> addRow(new QLabel("Starting time"), startingTimeEdit);
endingTimeEdit = new QDateTimeEdit(currentDateTime);
endingTimeEdit -> setDisplayFormat("dd.MM.yyyy h:mm");
formsLayout -> addRow(new QLabel("Ending time"), endingTimeEdit);
whenStartToRemindEdit = new QDateTimeEdit(currentDateTime);
whenStartToRemindEdit -> setDisplayFormat("dd.MM.yyyy h:mm");
formsLayout -> addRow(new QLabel("When start to remind"), whenStartToRemindEdit);
iORLayout = new QHBoxLayout;
daysSpinBox = new QSpinBox;
daysSpinBox -> setRange(0, std::numeric_limits<int>::max());
iORLayout -> addWidget(daysSpinBox);
iORLayout -> addWidget(new QLabel(" days and "));
hoursSpinBox = new QSpinBox;
hoursSpinBox -> setRange(0, 23);
iORLayout -> addWidget(hoursSpinBox);
iORLayout -> addWidget(new QLabel(" hours and "));
minutesSpinBox = new QSpinBox;
minutesSpinBox -> setRange(0, 59);
iORLayout -> addWidget(minutesSpinBox);
iORLayout -> addWidget(new QLabel(" minutes."));
formsLayout -> addRow(new QLabel("Repeat every "), iORLayout);
formsBox -> setLayout(formsLayout);
mainLayout -> addWidget(formsBox);
remindDuringEventCheckBox = new QCheckBox("Remind during the event");
mainLayout -> addWidget(remindDuringEventCheckBox);
standardButtonsBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(standardButtonsBox, SIGNAL(accepted()), this, SLOT(okayButtonClicked()));
connect(standardButtonsBox, SIGNAL(rejected()), this, SLOT(cancelButtonClicked()));
mainLayout -> addWidget(standardButtonsBox);
setLayout(mainLayout);
}