-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwork.cpp
More file actions
184 lines (154 loc) · 5.87 KB
/
Copy pathwork.cpp
File metadata and controls
184 lines (154 loc) · 5.87 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
175
176
177
178
179
180
181
182
183
184
#include "work.h"
#include "ui_work.h"
work::work(QWidget *parent)
: QWidget(parent)
, ui(new Ui::work)
{
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint|Qt::Tool);//去掉窗口的标题栏
setStyleSheet("background: rgba(255, 255, 255, 93%);");
init();
}
work::~work()
{
delete ui;
}
void work::mouseMoveEvent(QMouseEvent *event){//长按移动
if(event->buttons() & Qt::LeftButton){//只要按下了左键,按位与
this->move(event->globalPos()-topleft);
}
}
void work::mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton) {
topleft = event->globalPos() - this->pos(); // 计算并存储偏移量
}
}
void work::init(){
worktime = 1500;
relaxtime = 300;
workrelaxcondition = 0;//工作状态
setting_window = new worksetting(this);
setting_window->setWindowFlags(Qt::Window); // 设置为顶级窗口
setting_window->setWindowTitle("番茄钟设置"); // 设置窗口标题
setting_window->setFixedSize(400,250);//设置窗口固定大小
setting_window->move(800,500);//窗口移动
settingbtn = new QPushButton(this);
startbtn = new QPushButton(this);
removebtn = new QPushButton(this);
pausebtn = new QPushButton(this);
settingbtn->setGeometry(20,40,50,50);
startbtn->setGeometry(20,130,50,50);
pausebtn->setGeometry(20,130,50,50);
removebtn->setGeometry(20,220,50,50);
settingbtn->setIconSize(QSize(40,40));
startbtn->setIconSize(QSize(40,40));
pausebtn->setIconSize(QSize(40,40));
removebtn->setIconSize(QSize(40,40));
pausebtn->hide();
settingbtn->setIcon(QIcon(":/image/work/settings.svg"));
startbtn->setIcon(QIcon(":/image/work/start.svg"));
removebtn->setIcon(QIcon(":/image/work/remove.svg"));
pausebtn->setIcon(QIcon(":/image/work/pause.svg"));
settingbtn->setStyleSheet("QPushButton { border: none; background: transparent; }"
"QPushButton:hover { background-color: #f0f0f0; }");
startbtn->setStyleSheet("QPushButton { border: none; background: transparent; }"
"QPushButton:hover { background-color: #f0f0f0; }");
removebtn->setStyleSheet("QPushButton { border: none; background: transparent; }"
"QPushButton:hover { background-color: #f0f0f0; }");
pausebtn->setStyleSheet("QPushButton { border: none; background: transparent; }"
"QPushButton:hover { background-color: #f0f0f0; }");
connect(startbtn,&QPushButton::clicked,this,&work::startbtn_push);
connect(pausebtn,&QPushButton::clicked,this,&work::pausebtn_push);
connect(removebtn,&QPushButton::clicked,this,&work::removebtn_push);
connect(settingbtn,&QPushButton::clicked,this,&work::settingbtn_push);
connect(setting_window,&worksetting::sendata,this,&work::receivedata);
timelabel = new QLabel(this);
timelabel->setAlignment(Qt::AlignCenter);
timelabel->move(70,80);
timelabel->setFixedSize(QSize(400,100));
timelabel->setStyleSheet("color:#E84A4A;background: transparent;");
QFont font("Arial", 55, QFont::Bold); // 选择字体、大小和粗细
timelabel->setFont(font);
statelabel = new QLabel(this);
statelabel->setAlignment(Qt::AlignCenter);
statelabel->move(170,220);
statelabel->setStyleSheet("color:#E8B49C;background: transparent;");
QFont font1("微软雅黑", 15, QFont::Bold); // 选择字体、大小和粗细
statelabel->setFont(font1);
int m = worktime/60;
int s = worktime%60;
statelabel->setText(QString("番茄时钟READY"));
timelabel->setText(QString("%1:%2").arg(m, 2, 10, QLatin1Char('0')).arg(s, 2, 10, QLatin1Char('0')));
timer = new QTimer(this);
connect(timer,&QTimer::timeout,this,&work::updatetime);
}
void work::updatetime(){
if(workrelaxcondition){//休息状态
if(relaxtime==0){
timer->stop();
timelabel->setText("时间到!");
workrelaxcondition = 0;
}
else{
int m = relaxtime/60;
int s = relaxtime%60;
statelabel->setText(QString("休息中"));
timelabel->setText(QString("%1:%2").arg(m, 2, 10, QLatin1Char('0')).arg(s, 2, 10, QLatin1Char('0')));
}
relaxtime--;
}
else{//工作状态
if(worktime==0){
workrelaxcondition = 1;//调整为休息状态
}
else{
int m = worktime/60;
int s = worktime%60;
statelabel->setText(QString("工作中"));
timelabel->setText(QString("%1:%2").arg(m, 2, 10, QLatin1Char('0')).arg(s, 2, 10, QLatin1Char('0')));
}
worktime--;
}
}
void work::startbtn_push(){
statelabel->setText(QString("工作中"));
timer->start(1000);
pausebtn->show();
startbtn->hide();
}
void work::removebtn_push(){
timer->stop();
worktime = worktimeconst;
relaxtime = relaxtimeconst;
workrelaxcondition = 0;
int m = worktime/60;
int s = worktime%60;
statelabel->setText(QString("番茄时钟READY"));
timelabel->setText(QString("%1:%2").arg(m, 2, 10, QLatin1Char('0')).arg(s, 2, 10, QLatin1Char('0')));
pausebtn->hide();
startbtn->show();
}
void work::pausebtn_push(){
timer->stop();
statelabel->setText(QString("暂停中"));
pausebtn->hide();
startbtn->show();
}
void work::settingbtn_push(){
setting_window->show();
pausebtn_push();
}
void work::receivedata(int setworktime,int setrelaxtime){
qDebug()<<setworktime<<setrelaxtime;
worktimeconst = setworktime;
relaxtimeconst = setrelaxtime;
worktime = setworktime;
relaxtime = setrelaxtime;
int m = worktime/60;
int s = worktime%60;
statelabel->setText(QString("番茄时钟READY"));
timelabel->setText(QString("%1:%2").arg(m, 2, 10, QLatin1Char('0')).arg(s, 2, 10, QLatin1Char('0')));
timer->stop();
}
void work::setstylesheet(){
}