diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c0a904..8ce555b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ set(PROJECT_SOURCES message.cpp message.h img.qrc + logo.rc ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 9e1837d..2287834 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/logo.rc b/logo.rc new file mode 100644 index 0000000..476151d --- /dev/null +++ b/logo.rc @@ -0,0 +1 @@ +IDI_ICON_LOGO ICON DISCARDABLE "img/ico/64x64.ico" diff --git a/message.cpp b/message.cpp index 670ed7d..a7aeed1 100644 --- a/message.cpp +++ b/message.cpp @@ -9,6 +9,13 @@ message::message(QWidget *parent) : this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);//隐藏标题栏 this->setAttribute(Qt::WA_TranslucentBackground);//背景透明 } + +void message::update(int progress,float money){ + //更新进度条 + ui->labelMoney->setText("预计今日一共挣"+QString::number(money,'f',1)+"元"); + ui->progressBar->setValue(progress); + +} void message::myhide(){ this->hide(); } diff --git a/message.h b/message.h index f156ae6..bb4f726 100644 --- a/message.h +++ b/message.h @@ -13,6 +13,7 @@ class message : public QWidget public: explicit message(QWidget *parent = nullptr); + void update(int progress,float money); ~message(); // QPoint messagePoint; public slots: diff --git a/message.ui b/message.ui index c888447..3f80eda 100644 --- a/message.ui +++ b/message.ui @@ -72,14 +72,17 @@ - 30 + 40 130 231 23 - 24 + 0 + + + true @@ -99,12 +102,12 @@ border-radius:15px; - + - 100 + 60 90 - 111 + 191 31 @@ -123,7 +126,7 @@ border-radius:15px; label labelTitle1 progressBar - labelTitle1_2 + labelMoney diff --git a/moneyprogress.cpp b/moneyprogress.cpp index 86ece58..7448093 100644 --- a/moneyprogress.cpp +++ b/moneyprogress.cpp @@ -4,6 +4,7 @@ #include #include + #include @@ -49,10 +50,27 @@ MoneyProgress::MoneyProgress(QWidget *parent) int posX = pDeskdop->width() / 2; int posY = pDeskdop->height() / 2; + + + // 更新一次数据(默认数据) + workDown = ui->timeWorkdown->time(); + workUp = ui->timeWorkup->time(); + sleepDown = ui->timeSleepdown->time(); + sleepUp = ui->timeSleepup->time(); + money = 300; + days = 24; + + + + + + iconmessage.setGeometry(posX, posY+140, 300, 180); + updateM(); // connect(timer,&QTimer::timeout,this,&MoneyProgress::update); + connect(timer2,&QTimer::timeout,&iconmessage,&message::hide); // this->hide() @@ -68,9 +86,9 @@ void MoneyProgress::onTrayActivated(QSystemTrayIcon::ActivationReason reason){ case QSystemTrayIcon::Trigger: //单击托盘图标 qDebug("click"); - + updateM(); iconmessage.show(); - timer2->start(1500); //每分钟更新一次 后面看看要不要改成可修改的 + timer2->start(2000); //每分钟更新一次 后面看看要不要改成可修改的 break; case QSystemTrayIcon::DoubleClick: //双击托盘图标 @@ -78,6 +96,7 @@ void MoneyProgress::onTrayActivated(QSystemTrayIcon::ActivationReason reason){ this->show(); break; default: + update(); break; } } @@ -85,8 +104,48 @@ void MoneyProgress::onTrayActivated(QSystemTrayIcon::ActivationReason reason){ void MoneyProgress::update(){ // qDebug("update"); + int second = (workUp.secsTo(workDown)-sleepUp.secsTo(sleepDown)); + float hours = second/3600.0; + + float moneyday = money/days; + float moneysecond = moneyday/second; + // 判断两个界面是否可见 + if (this->isVisible() ){ + ui->labelDay->setText("您一月工作"+QString::number(days)+"天;"); + ui->labelMoneyDay->setText("您一天能挣"+QString::number(moneyday,'f',1)+"元;"); + ui->labelHourDay->setText("您一天工作"+QString::number(hours,'f',1)+"小时;"); + ui->labelMoneySecond->setText("您一秒钟能挣"+QString::number(moneysecond,'f',6)+"元;"); + + } + if(iconmessage.isVisible()){ + int progress = 0; + progress = workUp.secsTo(QTime::currentTime())*100/second; + iconmessage.update(progress,moneyday); + + } } +void MoneyProgress::updateM(){ + // + qDebug("update"); + int second = (workUp.secsTo(workDown)-sleepUp.secsTo(sleepDown)); + float hours = second/3600.0; + + float moneyday = money/days; + float moneysecond = moneyday/second; + // 判断两个界面是否可见 + + ui->labelDay->setText("您一月工作"+QString::number(days)+"天;"); + ui->labelMoneyDay->setText("您一天能挣"+QString::number(moneyday,'f',1)+"元;"); + ui->labelHourDay->setText("您一天工作"+QString::number(hours,'f',1)+"小时;"); + ui->labelMoneySecond->setText("您一秒钟能挣"+QString::number(moneysecond,'f',6)+"元;"); + int progress = 0; + progress = workUp.secsTo(QTime::currentTime())*100/second; + iconmessage.update(progress,moneyday); +} + + + void MoneyProgress::createMenu() { @@ -196,7 +255,11 @@ void MoneyProgress::on_Startcalculate_clicked() //启动定时器 //计时器 用来更新 QTimer *timer = new QTimer; - connect(timer,&QTimer::timeout,this,&MoneyProgress::update); +// void (MoneyProgress:: *pup)(int) = &MoneyProgress::update; +// QOverload::of(&QComboBox::currentIndexChanged),[=](int index){ /* … */ }) + + + connect(timer,&QTimer::timeout,this,qOverload<>(&MoneyProgress::update)); timer->start(1000); //每分钟更新一次 后面看看要不要改成可修改的 } @@ -210,6 +273,9 @@ void MoneyProgress::on_timeWorkup_userTimeChanged(const QTime &time) void MoneyProgress::on_timeWorkdown_userTimeChanged(const QTime &time) { workDown = time; + //有效工时计算与显示 + qDebug("工作时间 %f",(workUp.secsTo(workDown)-sleepUp.secsTo(sleepDown))/3600.0); + update(); } @@ -222,17 +288,22 @@ void MoneyProgress::on_timeSleepup_userTimeChanged(const QTime &time) void MoneyProgress::on_timeSleepdown_userTimeChanged(const QTime &time) { sleepDown = time; + update(); + qDebug("午休时间 %f",sleepUp.secsTo(sleepDown)/3600.0); } void MoneyProgress::on_moneyMonth_editingFinished() { money = ui->moneyMonth->text().toInt(); + update(); } void MoneyProgress::on_workDay_editingFinished() { days = ui->workDay->text().toInt(); + update(); + } diff --git a/moneyprogress.h b/moneyprogress.h index 4e2c64e..bbdbb32 100644 --- a/moneyprogress.h +++ b/moneyprogress.h @@ -55,6 +55,8 @@ class MoneyProgress : public QMainWindow //update void update(); + void updateM(); + //定时器 QTimer *timer2 = new QTimer; diff --git a/moneyprogress.ui b/moneyprogress.ui index 2c94f70..eb4f9d9 100644 --- a/moneyprogress.ui +++ b/moneyprogress.ui @@ -91,7 +91,7 @@ - + background-color: rgb(255, 216, 58); 开始计价 @@ -111,7 +111,7 @@ 30 510 - 53 + 171 16 @@ -124,7 +124,7 @@ 30 530 - 53 + 151 16 @@ -137,7 +137,7 @@ 30 550 - 53 + 191 16 @@ -150,7 +150,7 @@ 30 570 - 53 + 191 16 @@ -186,6 +186,29 @@ QAbstractSpinBox::NoButtons + + + 8 + 0 + 0 + 2000 + 1 + 1 + + + + + 0 + 0 + 0 + 2000 + 1 + 1 + + + + Qt::LocalTime + @@ -260,6 +283,9 @@ background-color: rgb(255, 216, 58); + + 300 + @@ -274,6 +300,19 @@ QAbstractSpinBox::NoButtons + + + 17 + 0 + 0 + 2000 + 1 + 1 + + + + Qt::LocalTime + @@ -288,6 +327,19 @@ QAbstractSpinBox::NoButtons + + + 12 + 0 + 0 + 2000 + 1 + 1 + + + + Qt::LocalTime + @@ -302,6 +354,19 @@ QAbstractSpinBox::NoButtons + + + 13 + 0 + 0 + 2000 + 1 + 1 + + + + Qt::LocalTime + @@ -335,6 +400,9 @@ background-color: rgb(255, 216, 58); + + 24 + 100