This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_schedule.cpp
98 lines (84 loc) · 2.67 KB
/
class_schedule.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
#include "class_schedule.h"
#include "ui_class_schedule.h"
Class_Schedule::Class_Schedule(QWidget *parent) :
QWidget(parent),
ui(new Ui::Class_Schedule)
{
ui->setupUi(this);
initTimer();
translucentBg();
if(read()){
initSchedule();
}
}
Class_Schedule::~Class_Schedule()
{
delete ui;
}
void Class_Schedule::translucentBg()
{
//桌面穿透
setAttribute(Qt::WA_TransparentForMouseEvents, true);
setWindowFlags(Qt::SubWindow|Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground, true);
//设置到右中方
QRect screenRect = QGuiApplication::primaryScreen()->geometry();
int screenW = screenRect.width();
int screenH = screenRect.height();
qDebug()<<screenW<<screenH;
this->move(((screenW-this->width())),(screenH-this->height())/2);
setWindowFlag(Qt::FramelessWindowHint); /* 注意:如果单纯开启窗口透明层效果,在Windows系统中必须设置, 其他系统可忽略。*/
setAttribute(Qt::WA_TranslucentBackground);
}
void Class_Schedule::paintEvent(QPaintEvent *)
{
/*From https://cloud.tencent.com/developer/article/1546015*/
QPainter painter(this);
/* 0x20为透明层颜色,可自定义设置为0x0到0xff */
painter.fillRect(this->rect(), QColor(0, 0, 0, 0x0));
}
void Class_Schedule::initTimer()
{
//初始化QTimer
bgTimer = new QTimer(this);
//实现槽函数
connect(bgTimer, SIGNAL(timeout()), this, SLOT(drawSchedule()));
bgTimer->start(1000*60*5); //1000 = 1s| 5min
}
void Class_Schedule::drawSchedule()
{
}
void Class_Schedule::initSchedule()
{
/*循环加入
* day
*/
QString temp;
for(int i = 1 ; i < tod.count() ; i++){
temp = ui->label->text();
ui->label->setText(temp.arg(this->tod[i].simplified()));
qDebug()<<temp;
}
}
bool Class_Schedule::read(){
//Read ./kb.csv
QFile file("./kb.csv");
if(!file.open(QIODevice::ReadOnly))
{
qDebug()<<"OPEN FILE FAILED";
QMessageBox::warning(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("丢失kb.csv文件"));
}
QTextStream * out = new QTextStream(&file);//文本流
QStringList tempOption = out->readAll().split("\n");//每行以\n区分
for(int i = 0 ; i < tempOption.count() ; i++)
{
QStringList tempbar = tempOption.at(i).split(",");//一行中的单元格以,区分
qDebug() << tempbar[0] << QDateTime::currentDateTime().toLocalTime().toString("ddd");
if(tempbar[0] == QDateTime::currentDateTime().toLocalTime().toString("ddd")){
tod = tempbar;
qDebug() << "Found";
return true;
}
}
return false;
}