Skip to content

Commit dc6b4a4

Browse files
committed
finish
1 parent 3a440c9 commit dc6b4a4

9 files changed

+169
-15
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(PROJECT_SOURCES
2323
message.cpp
2424
message.h
2525
img.qrc
26+
logo.rc
2627
)
2728

2829
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)

CMakeLists.txt.user

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 8.0.2, 2023-04-04T23:00:15. -->
3+
<!-- Written by QtCreator 8.0.2, 2023-04-05T00:40:58. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>

logo.rc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IDI_ICON_LOGO ICON DISCARDABLE "img/ico/64x64.ico"

message.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ message::message(QWidget *parent) :
99
this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);//隐藏标题栏
1010
this->setAttribute(Qt::WA_TranslucentBackground);//背景透明
1111
}
12+
13+
void message::update(int progress,float money){
14+
//更新进度条
15+
ui->labelMoney->setText("预计今日一共挣"+QString::number(money,'f',1)+"");
16+
ui->progressBar->setValue(progress);
17+
18+
}
1219
void message::myhide(){
1320
this->hide();
1421
}

message.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class message : public QWidget
1313

1414
public:
1515
explicit message(QWidget *parent = nullptr);
16+
void update(int progress,float money);
1617
~message();
1718
// QPoint messagePoint;
1819
public slots:

message.ui

+9-6
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,17 @@
7272
<widget class="QProgressBar" name="progressBar">
7373
<property name="geometry">
7474
<rect>
75-
<x>30</x>
75+
<x>40</x>
7676
<y>130</y>
7777
<width>231</width>
7878
<height>23</height>
7979
</rect>
8080
</property>
8181
<property name="value">
82-
<number>24</number>
82+
<number>0</number>
83+
</property>
84+
<property name="textVisible">
85+
<bool>true</bool>
8386
</property>
8487
</widget>
8588
<widget class="QLabel" name="label_2">
@@ -99,12 +102,12 @@ border-radius:15px;</string>
99102
<string/>
100103
</property>
101104
</widget>
102-
<widget class="QLabel" name="labelTitle1_2">
105+
<widget class="QLabel" name="labelMoney">
103106
<property name="geometry">
104107
<rect>
105-
<x>100</x>
108+
<x>60</x>
106109
<y>90</y>
107-
<width>111</width>
110+
<width>191</width>
108111
<height>31</height>
109112
</rect>
110113
</property>
@@ -123,7 +126,7 @@ border-radius:15px;</string>
123126
<zorder>label</zorder>
124127
<zorder>labelTitle1</zorder>
125128
<zorder>progressBar</zorder>
126-
<zorder>labelTitle1_2</zorder>
129+
<zorder>labelMoney</zorder>
127130
</widget>
128131
</widget>
129132
<resources/>

moneyprogress.cpp

+74-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QMouseEvent>
55
#include <QKeyEvent>
66

7+
78
#include <QDesktopWidget>
89

910

@@ -49,10 +50,27 @@ MoneyProgress::MoneyProgress(QWidget *parent)
4950
int posX = pDeskdop->width() / 2;
5051
int posY = pDeskdop->height() / 2;
5152

53+
54+
55+
// 更新一次数据(默认数据)
56+
workDown = ui->timeWorkdown->time();
57+
workUp = ui->timeWorkup->time();
58+
sleepDown = ui->timeSleepdown->time();
59+
sleepUp = ui->timeSleepup->time();
60+
money = 300;
61+
days = 24;
62+
63+
64+
65+
66+
67+
5268
iconmessage.setGeometry(posX, posY+140, 300, 180);
69+
updateM();
5370

5471

5572
// connect(timer,&QTimer::timeout,this,&MoneyProgress::update);
73+
5674
connect(timer2,&QTimer::timeout,&iconmessage,&message::hide);
5775

5876
// this->hide()
@@ -68,25 +86,66 @@ void MoneyProgress::onTrayActivated(QSystemTrayIcon::ActivationReason reason){
6886
case QSystemTrayIcon::Trigger:
6987
//单击托盘图标
7088
qDebug("click");
71-
89+
updateM();
7290
iconmessage.show();
73-
timer2->start(1500); //每分钟更新一次 后面看看要不要改成可修改的
91+
timer2->start(2000); //每分钟更新一次 后面看看要不要改成可修改的
7492
break;
7593
case QSystemTrayIcon::DoubleClick:
7694
//双击托盘图标
7795
//双击后显示主程序窗口
7896
this->show();
7997
break;
8098
default:
99+
update();
81100
break;
82101
}
83102
}
84103

85104
void MoneyProgress::update(){
86105
//
87106
qDebug("update");
107+
int second = (workUp.secsTo(workDown)-sleepUp.secsTo(sleepDown));
108+
float hours = second/3600.0;
109+
110+
float moneyday = money/days;
111+
float moneysecond = moneyday/second;
112+
// 判断两个界面是否可见
113+
if (this->isVisible() ){
114+
ui->labelDay->setText("您一月工作"+QString::number(days)+"天;");
115+
ui->labelMoneyDay->setText("您一天能挣"+QString::number(moneyday,'f',1)+"元;");
116+
ui->labelHourDay->setText("您一天工作"+QString::number(hours,'f',1)+"小时;");
117+
ui->labelMoneySecond->setText("您一秒钟能挣"+QString::number(moneysecond,'f',6)+"元;");
118+
119+
}
120+
if(iconmessage.isVisible()){
121+
int progress = 0;
122+
progress = workUp.secsTo(QTime::currentTime())*100/second;
123+
iconmessage.update(progress,moneyday);
124+
125+
}
88126

89127
}
128+
void MoneyProgress::updateM(){
129+
//
130+
qDebug("update");
131+
int second = (workUp.secsTo(workDown)-sleepUp.secsTo(sleepDown));
132+
float hours = second/3600.0;
133+
134+
float moneyday = money/days;
135+
float moneysecond = moneyday/second;
136+
// 判断两个界面是否可见
137+
138+
ui->labelDay->setText("您一月工作"+QString::number(days)+"天;");
139+
ui->labelMoneyDay->setText("您一天能挣"+QString::number(moneyday,'f',1)+"元;");
140+
ui->labelHourDay->setText("您一天工作"+QString::number(hours,'f',1)+"小时;");
141+
ui->labelMoneySecond->setText("您一秒钟能挣"+QString::number(moneysecond,'f',6)+"元;");
142+
int progress = 0;
143+
progress = workUp.secsTo(QTime::currentTime())*100/second;
144+
iconmessage.update(progress,moneyday);
145+
}
146+
147+
148+
90149

91150
void MoneyProgress::createMenu()
92151
{
@@ -196,7 +255,11 @@ void MoneyProgress::on_Startcalculate_clicked()
196255
//启动定时器
197256
//计时器 用来更新
198257
QTimer *timer = new QTimer;
199-
connect(timer,&QTimer::timeout,this,&MoneyProgress::update);
258+
// void (MoneyProgress:: *pup)(int) = &MoneyProgress::update;
259+
// QOverload::of(&QComboBox::currentIndexChanged),[=](int index){ /* … */ })
260+
261+
262+
connect(timer,&QTimer::timeout,this,qOverload<>(&MoneyProgress::update));
200263
timer->start(1000); //每分钟更新一次 后面看看要不要改成可修改的
201264
}
202265

@@ -210,6 +273,9 @@ void MoneyProgress::on_timeWorkup_userTimeChanged(const QTime &time)
210273
void MoneyProgress::on_timeWorkdown_userTimeChanged(const QTime &time)
211274
{
212275
workDown = time;
276+
//有效工时计算与显示
277+
qDebug("工作时间 %f",(workUp.secsTo(workDown)-sleepUp.secsTo(sleepDown))/3600.0);
278+
update();
213279
}
214280

215281

@@ -222,17 +288,22 @@ void MoneyProgress::on_timeSleepup_userTimeChanged(const QTime &time)
222288
void MoneyProgress::on_timeSleepdown_userTimeChanged(const QTime &time)
223289
{
224290
sleepDown = time;
291+
update();
292+
qDebug("午休时间 %f",sleepUp.secsTo(sleepDown)/3600.0);
225293
}
226294

227295

228296
void MoneyProgress::on_moneyMonth_editingFinished()
229297
{
230298
money = ui->moneyMonth->text().toInt();
299+
update();
231300
}
232301

233302

234303
void MoneyProgress::on_workDay_editingFinished()
235304
{
236305
days = ui->workDay->text().toInt();
306+
update();
307+
237308
}
238309

moneyprogress.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class MoneyProgress : public QMainWindow
5555

5656
//update
5757
void update();
58+
void updateM();
59+
5860

5961
//定时器
6062
QTimer *timer2 = new QTimer;

moneyprogress.ui

+73-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</rect>
9292
</property>
9393
<property name="styleSheet">
94-
<string notr="true"/>
94+
<string notr="true">background-color: rgb(255, 216, 58);</string>
9595
</property>
9696
<property name="text">
9797
<string>开始计价</string>
@@ -111,7 +111,7 @@
111111
<rect>
112112
<x>30</x>
113113
<y>510</y>
114-
<width>53</width>
114+
<width>171</width>
115115
<height>16</height>
116116
</rect>
117117
</property>
@@ -124,7 +124,7 @@
124124
<rect>
125125
<x>30</x>
126126
<y>530</y>
127-
<width>53</width>
127+
<width>151</width>
128128
<height>16</height>
129129
</rect>
130130
</property>
@@ -137,7 +137,7 @@
137137
<rect>
138138
<x>30</x>
139139
<y>550</y>
140-
<width>53</width>
140+
<width>191</width>
141141
<height>16</height>
142142
</rect>
143143
</property>
@@ -150,7 +150,7 @@
150150
<rect>
151151
<x>30</x>
152152
<y>570</y>
153-
<width>53</width>
153+
<width>191</width>
154154
<height>16</height>
155155
</rect>
156156
</property>
@@ -186,6 +186,29 @@
186186
<property name="buttonSymbols">
187187
<enum>QAbstractSpinBox::NoButtons</enum>
188188
</property>
189+
<property name="dateTime">
190+
<datetime>
191+
<hour>8</hour>
192+
<minute>0</minute>
193+
<second>0</second>
194+
<year>2000</year>
195+
<month>1</month>
196+
<day>1</day>
197+
</datetime>
198+
</property>
199+
<property name="minimumDateTime">
200+
<datetime>
201+
<hour>0</hour>
202+
<minute>0</minute>
203+
<second>0</second>
204+
<year>2000</year>
205+
<month>1</month>
206+
<day>1</day>
207+
</datetime>
208+
</property>
209+
<property name="timeSpec">
210+
<enum>Qt::LocalTime</enum>
211+
</property>
189212
</widget>
190213
</item>
191214
<item row="1" column="0">
@@ -260,6 +283,9 @@
260283
<property name="styleSheet">
261284
<string notr="true">background-color: rgb(255, 216, 58);</string>
262285
</property>
286+
<property name="text">
287+
<string>300</string>
288+
</property>
263289
</widget>
264290
</item>
265291
<item row="0" column="2">
@@ -274,6 +300,19 @@
274300
<property name="buttonSymbols">
275301
<enum>QAbstractSpinBox::NoButtons</enum>
276302
</property>
303+
<property name="dateTime">
304+
<datetime>
305+
<hour>17</hour>
306+
<minute>0</minute>
307+
<second>0</second>
308+
<year>2000</year>
309+
<month>1</month>
310+
<day>1</day>
311+
</datetime>
312+
</property>
313+
<property name="timeSpec">
314+
<enum>Qt::LocalTime</enum>
315+
</property>
277316
</widget>
278317
</item>
279318
<item row="1" column="1">
@@ -288,6 +327,19 @@
288327
<property name="buttonSymbols">
289328
<enum>QAbstractSpinBox::NoButtons</enum>
290329
</property>
330+
<property name="dateTime">
331+
<datetime>
332+
<hour>12</hour>
333+
<minute>0</minute>
334+
<second>0</second>
335+
<year>2000</year>
336+
<month>1</month>
337+
<day>1</day>
338+
</datetime>
339+
</property>
340+
<property name="timeSpec">
341+
<enum>Qt::LocalTime</enum>
342+
</property>
291343
</widget>
292344
</item>
293345
<item row="1" column="2">
@@ -302,6 +354,19 @@
302354
<property name="buttonSymbols">
303355
<enum>QAbstractSpinBox::NoButtons</enum>
304356
</property>
357+
<property name="dateTime">
358+
<datetime>
359+
<hour>13</hour>
360+
<minute>0</minute>
361+
<second>0</second>
362+
<year>2000</year>
363+
<month>1</month>
364+
<day>1</day>
365+
</datetime>
366+
</property>
367+
<property name="timeSpec">
368+
<enum>Qt::LocalTime</enum>
369+
</property>
305370
</widget>
306371
</item>
307372
<item row="3" column="0">
@@ -335,6 +400,9 @@
335400
<string notr="true">background-color: rgb(255, 216, 58);
336401
</string>
337402
</property>
403+
<property name="text">
404+
<string>24</string>
405+
</property>
338406
<property name="maxLength">
339407
<number>100</number>
340408
</property>

0 commit comments

Comments
 (0)