-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhourlytab.cpp
222 lines (162 loc) · 5.84 KB
/
hourlytab.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "hourlytab.h"
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QStandardItemModel>
#include <QAbstractItemView>
HourlyTab::HourlyTab(const Reminder &reminder, QWidget *parent) : QWidget(parent), _reminder(reminder)
{
if (_reminder.repeatMode() == Reminder::Hourly)
{
if (_reminder.time().isEmpty()) _reminder.setTime("00分");
if (_reminder.dnd() == Reminder::OpenDND)
{
QString dndStart = _reminder.dndDuration().mid(0, 3);
QString dndEnd = _reminder.dndDuration().mid(6, 3);
_dndDuration.replace(0, dndStart);
_dndDuration.replace(1, dndEnd);
}
}
else
{
_resetReminder();
}
_buildUI();
_connectSlots();
}
void HourlyTab::resetReminder()
{
_resetReminder();
emit tabChanged(_reminder);
_minutes->setCurrentText(_reminder.time().replace("分", ""));
_dndStart->setCurrentIndex(0);
_dndEnd->setCurrentIndex(0);
}
// Private Methods
void HourlyTab::_resetReminder()
{
_reminder.setTime("00分");
_reminder.setRepeatMode(Reminder::Hourly);
}
void HourlyTab::_buildUI()
{
QLabel *titleLabel = new QLabel("标题");
_titleEdit = new QLineEdit(_reminder.title());
QLabel *minuteLabel = new QLabel("指定分钟");
_minutes = new ACComboBox;
for (int i = 0; i < 60; ++i)
{
QString item;
if (i < 10) item = "0" + QString::number(i);
else item = QString::number(i);
_minutes->addItem(item);
qobject_cast<QStandardItemModel *>(_minutes->view()->model())->item(i)->setTextAlignment(Qt::AlignCenter);
}
_minutes->setCurrentText(_reminder.time().replace("分", ""));
QLabel *dndLabel = new QLabel("指定时段启用免打扰");
_dndSwitch = new StatusSwitch<Reminder::DND>(_reminder.dnd(), Reminder::OpenDND);
_dndStart = new ACComboBox;
_dndStart->setFixedWidth(200);
_dndEnd = new ACComboBox;
_dndEnd->setFixedWidth(200);
for (int i = 0; i < 24; ++i)
{
QString item;
if (i < 10) item = "0" + QString::number(i);
else item = QString::number(i);
_dndStart->addItem(item + "点");
_dndEnd->addItem(item + "点");
qobject_cast<QStandardItemModel *>(_dndStart->view()->model())->item(i)->setTextAlignment(Qt::AlignCenter);
qobject_cast<QStandardItemModel *>(_dndEnd->view()->model())->item(i)->setTextAlignment(Qt::AlignCenter);
}
_dndStart->setCurrentText(_dndDuration.at(0));
_dndEnd->setCurrentText(_dndDuration.at(1));
_dndContainer = new QWidget(this);
QHBoxLayout *dndLayout = new QHBoxLayout(_dndContainer);
dndLayout->setSpacing(0);
dndLayout->setContentsMargins(0, 0, 0, 0);
dndLayout->addWidget(_dndStart);
dndLayout->addStretch();
dndLayout->addWidget(new QLabel(" ~ "));
dndLayout->addStretch();
dndLayout->addWidget(_dndEnd);
_dndContainer->setVisible(_reminder.isOpenDND());
QLabel *statusLabel = new QLabel("是否启用");
_statusSwitch = new StatusSwitch<Reminder::Status>(_reminder.status(), Reminder::Enabled);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(titleLabel);
mainLayout->addWidget(_titleEdit);
mainLayout->addSpacerItem(new QSpacerItem(width(), 10));
mainLayout->addWidget(minuteLabel);
mainLayout->addWidget(_minutes);
mainLayout->addSpacerItem(new QSpacerItem(width(), 10));
mainLayout->addWidget(dndLabel);
mainLayout->addWidget(_dndSwitch);
mainLayout->addWidget(_dndContainer);
mainLayout->addSpacerItem(new QSpacerItem(width(), 10));
mainLayout->addWidget(statusLabel);
mainLayout->addWidget(_statusSwitch);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
void HourlyTab::_connectSlots()
{
connect(_titleEdit, &QLineEdit::textChanged, this, &HourlyTab::_textChanged);
connect(_minutes, &ACComboBox::currentIndexChanged, this, &HourlyTab::_minuteChanged);
connect(_dndSwitch, &StatusSwitch<Reminder::DND>::clicked, this, &HourlyTab::_dndClicked);
connect(_dndStart, &ACComboBox::currentIndexChanged, this, &HourlyTab::_dndStartChanged);
connect(_dndEnd, &ACComboBox::currentIndexChanged, this, &HourlyTab::_dndEndChanged);
connect(_statusSwitch, &StatusSwitch<Reminder::Status>::clicked, this, &HourlyTab::_statusClicked);
}
// Private Slots
void HourlyTab::_textChanged(const QString &text)
{
_reminder.setTitle(text);
emit tabChanged(_reminder);
}
void HourlyTab::_minuteChanged(int minute)
{
_reminder.setTime(_minutes->itemText(minute) + "分");
// qDebug() << "_reminder.time():" << _reminder.time();
emit tabChanged(_reminder);
}
void HourlyTab::_dndClicked()
{
if (_reminder.isOpenDND())
{
_reminder.setDND(Reminder::ClosedDND);
_reminder.setDNDDuration("");
_dndContainer->setVisible(false);
_dndStart->setCurrentIndex(0);
_dndEnd->setCurrentIndex(0);
}
else
{
_reminder.setDND(Reminder::OpenDND);
_reminder.setDNDDuration(_dndDuration.join(" ~ "));
_dndContainer->setVisible(true);
}
_dndSwitch->setStatus(_reminder.dnd());
emit tabChanged(_reminder);
}
void HourlyTab::_dndStartChanged(int dndStart)
{
// qDebug() << "dndStart:" << dndStart;
_dndDuration.replace(0, _dndStart->itemText(dndStart));
_reminder.setDNDDuration(_dndDuration.join(" ~ "));
emit tabChanged(_reminder);
}
void HourlyTab::_dndEndChanged(int dndEnd)
{
// qDebug() << "dndEnd:" << dndEnd;
_dndDuration.replace(1, _dndEnd->itemText(dndEnd));
_reminder.setDNDDuration(_dndDuration.join(" ~ "));
emit tabChanged(_reminder);
}
void HourlyTab::_statusClicked()
{
if (_reminder.isEnabled()) _reminder.setStatus(Reminder::Disabled);
else _reminder.setStatus(Reminder::Enabled);
_statusSwitch->setStatus(_reminder.status());
emit tabChanged(_reminder);
}