qt/LedOK/program/wplanitem.cpp

126 lines
4.2 KiB
C++
Raw Normal View History

2022-01-04 18:11:48 +08:00
#include "wplanitem.h"
2023-04-25 16:30:58 +08:00
#include "gutil/qgui.h"
#include <QJsonArray>
2022-01-04 18:11:48 +08:00
2023-04-25 16:30:58 +08:00
wPlanItem::wPlanItem(QListWidgetItem *item, const QJsonObject *json) : m_item(item) {
2022-01-04 18:11:48 +08:00
setAttribute(Qt::WA_DeleteOnClose);
2023-04-25 16:30:58 +08:00
auto vBox = new VBox(this);
vBox->setContentsMargins(6, 6, 0, 6);
auto hBox = new HBox(vBox);
2022-01-04 18:11:48 +08:00
2023-04-25 16:30:58 +08:00
fdIdx = new QLabel("1");
hBox->addWidget(fdIdx);
2022-01-04 18:11:48 +08:00
2023-04-25 16:30:58 +08:00
tStart = new QTimeEdit;
tStart->setDisplayFormat("HH:mm");
hBox->addWidget(tStart);
2022-01-04 18:11:48 +08:00
2023-04-25 16:30:58 +08:00
tEnd = new QTimeEdit;
tEnd->setDisplayFormat("HH:mm");
tEnd->setTime(QTime(23, 59, 59));
2022-01-04 18:11:48 +08:00
2023-04-25 16:30:58 +08:00
hBox->addWidget(tEnd);
2022-01-04 18:11:48 +08:00
2023-04-25 16:30:58 +08:00
bnDel = new QPushButton;
hBox->addWidget(bnDel);
hBox = new HBox(vBox);
sMon = new QPushButton(tr("M"));
sMon ->setCheckable(true);
sMon ->setProperty("ssName", "weeklySelector");
hBox->addWidget(sMon);
hBox->addStretch();
sTues = new QPushButton(tr("Tu"));
sTues->setCheckable(true);
sTues->setProperty("ssName", "weeklySelector");
hBox->addWidget(sTues);
hBox->addStretch();
sWed = new QPushButton(tr("W"));
sWed ->setCheckable(true);
sWed ->setProperty("ssName", "weeklySelector");
hBox->addWidget(sWed);
hBox->addStretch();
sThur = new QPushButton(tr("Th"));
sThur->setCheckable(true);
sThur->setProperty("ssName", "weeklySelector");
hBox->addWidget(sThur);
hBox->addStretch();
sFri = new QPushButton(tr("F"));
sFri ->setCheckable(true);
sFri ->setProperty("ssName", "weeklySelector");
hBox->addWidget(sFri);
hBox->addStretch();
sSat = new QPushButton(tr("Sa"));
sSat ->setCheckable(true);
sSat ->setProperty("ssName", "weeklySelector");
hBox->addWidget(sSat);
hBox->addStretch();
sSun = new QPushButton(tr("Su"));
sSun ->setCheckable(true);
sSun ->setProperty("ssName", "weeklySelector");
hBox->addWidget(sSun);
if(json==0) {
sMon ->setChecked(true);
sTues->setChecked(true);
sWed ->setChecked(true);
sThur->setChecked(true);
sFri ->setChecked(true);
sSat ->setChecked(true);
sSun ->setChecked(true);
} else {
tStart->setTime(QTime::fromString(json->value("start").toString(), "hh:mm"));
tEnd->setTime(QTime::fromString(json->value("end").toString(), "hh:mm"));
auto oWeekly = json->value("weekly").toArray();
sMon ->setChecked(oWeekly.contains(1));
sTues->setChecked(oWeekly.contains(2));
sWed ->setChecked(oWeekly.contains(3));
sThur->setChecked(oWeekly.contains(4));
sFri ->setChecked(oWeekly.contains(5));
sSat ->setChecked(oWeekly.contains(6));
sSun ->setChecked(oWeekly.contains(7));
}
connect(tStart, SIGNAL(timeChanged(const QTime&)), this, SLOT(onItemChanged()));
connect(tEnd, SIGNAL(timeChanged(const QTime&)), this, SLOT(onItemChanged()));
connect(sMon, SIGNAL(toggled(bool)), this, SLOT(onItemChanged()));
connect(sTues, SIGNAL(toggled(bool)), this, SLOT(onItemChanged()));
connect(sWed, SIGNAL(toggled(bool)), this, SLOT(onItemChanged()));
connect(sThur, SIGNAL(toggled(bool)), this, SLOT(onItemChanged()));
connect(sFri, SIGNAL(toggled(bool)), this, SLOT(onItemChanged()));
connect(sSat, SIGNAL(toggled(bool)), this, SLOT(onItemChanged()));
connect(sSun, SIGNAL(toggled(bool)), this, SLOT(onItemChanged()));
connect(bnDel, SIGNAL(clicked(bool)), this, SLOT(onDelete(bool)));
2022-01-04 18:11:48 +08:00
}
2023-04-25 16:30:58 +08:00
void wPlanItem::onItemChanged(){
emit sigItemChanged(m_item);
2022-01-04 18:11:48 +08:00
}
2023-04-25 16:30:58 +08:00
void wPlanItem::onDelete(bool){
emit sigDelete(m_item);
2022-01-04 18:11:48 +08:00
}
2023-04-25 16:30:58 +08:00
QJsonObject wPlanItem::planJson() const {
2022-01-04 18:11:48 +08:00
QJsonObject oRoot;
QJsonArray oWeekly;
2023-04-25 16:30:58 +08:00
if(sMon ->isChecked()) oWeekly.append(QJsonValue(1));
if(sTues->isChecked()) oWeekly.append(QJsonValue(2));
if(sWed ->isChecked()) oWeekly.append(QJsonValue(3));
if(sThur->isChecked()) oWeekly.append(QJsonValue(4));
if(sFri ->isChecked()) oWeekly.append(QJsonValue(5));
if(sSat ->isChecked()) oWeekly.append(QJsonValue(6));
if(sSun ->isChecked()) oWeekly.append(QJsonValue(7));
oRoot["start"] = tStart->time().toString("hh:mm");
oRoot["end"] = tEnd->time().toString("hh:mm");
2022-01-04 18:11:48 +08:00
oRoot["weekly"] = oWeekly;
return oRoot;
}