-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdailytab.cpp
More file actions
174 lines (128 loc) · 4.12 KB
/
dailytab.cpp
File metadata and controls
174 lines (128 loc) · 4.12 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
174
#include "dailytab.h"
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QStandardItemModel>
#include <QAbstractItemView>
DailyTab::DailyTab(const Reminder &reminder, QWidget *parent) : QWidget(parent), _reminder(reminder)
{
if (_reminder.repeatMode() == Reminder::Daily)
{
if (_reminder.time().isEmpty())
{
_reminder.setTime("00点00分");
}
else
{
QString hour = _reminder.time().mid(0, 2);
QString minute = _reminder.time().mid(3, 2);
_times.replace(0, hour);
_times.replace(1, minute);
_setTime();
}
}
else
{
_resetReminder();
}
_buildUI();
_connectSlots();
}
void DailyTab::resetReminder()
{
_resetReminder();
emit tabChanged(_reminder);
_hours->setCurrentText(_times.at(0));
_minutes->setCurrentText(_times.at(1));
}
// Private Methods
void DailyTab::_resetReminder()
{
_times = QStringList({ "00", "00" });
_reminder.setTime("00点00分");
_reminder.setRepeatMode(Reminder::Daily);
}
void DailyTab::_buildUI()
{
QLabel *titleLabel = new QLabel("标题");
_titleEdit = new QLineEdit(_reminder.title());
QLabel *hourLabel = new QLabel("指定小时");
_hours = new ACComboBox;
for (int i = 0; i < 24; ++i)
{
QString item;
if (i < 10) item = "0" + QString::number(i);
else item = QString::number(i);
_hours->addItem(item);
qobject_cast<QStandardItemModel *>(_hours->view()->model())->item(i)->setTextAlignment(Qt::AlignCenter);
}
_hours->setCurrentText(_times.at(0));
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(_times.at(1));
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(hourLabel);
mainLayout->addWidget(_hours);
mainLayout->addWidget(minuteLabel);
mainLayout->addWidget(_minutes);
mainLayout->addSpacerItem(new QSpacerItem(width(), 10));
mainLayout->addWidget(statusLabel);
mainLayout->addWidget(_statusSwitch);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
void DailyTab::_connectSlots()
{
connect(_titleEdit, &QLineEdit::textChanged, this, &DailyTab::_textChanged);
connect(_hours, &ACComboBox::currentIndexChanged, this, &DailyTab::_hourChanged);
connect(_minutes, &ACComboBox::currentIndexChanged, this, &DailyTab::_minuteChanged);
connect(_statusSwitch, &StatusSwitch<Reminder::Status>::clicked, this, &DailyTab::_statusClicked);
}
void DailyTab::_setTime()
{
QString time;
if (!_times.first().isEmpty()) time += _times.first() + "点";
if (!_times.last().isEmpty()) time += _times.last() + "分";
_reminder.setTime(time);
// qDebug() << "_reminder.time():" << _reminder.time();
}
// Private Slots
void DailyTab::_textChanged(const QString &text)
{
_reminder.setTitle(text);
emit tabChanged(_reminder);
}
void DailyTab::_hourChanged(int hour)
{
// qDebug() << "hour:" << hour;
_times.replace(0, _hours->itemText(hour));
_setTime();
emit tabChanged(_reminder);
}
void DailyTab::_minuteChanged(int minute)
{
// qDebug() << "minute:" << minute;
_times.replace(1, _minutes->itemText(minute));
_setTime();
emit tabChanged(_reminder);
}
void DailyTab::_statusClicked()
{
if (_reminder.isEnabled()) _reminder.setStatus(Reminder::Disabled);
else _reminder.setStatus(Reminder::Enabled);
_statusSwitch->setStatus(_reminder.status());
emit tabChanged(_reminder);
}