Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
wxydejoy committed Apr 5, 2023
1 parent 3a440c9 commit dc6b4a4
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(PROJECT_SOURCES
message.cpp
message.h
img.qrc
logo.rc
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 8.0.2, 2023-04-04T23:00:15. -->
<!-- Written by QtCreator 8.0.2, 2023-04-05T00:40:58. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
1 change: 1 addition & 0 deletions logo.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON_LOGO ICON DISCARDABLE "img/ico/64x64.ico"
7 changes: 7 additions & 0 deletions message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions message.ui
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@
<widget class="QProgressBar" name="progressBar">
<property name="geometry">
<rect>
<x>30</x>
<x>40</x>
<y>130</y>
<width>231</width>
<height>23</height>
</rect>
</property>
<property name="value">
<number>24</number>
<number>0</number>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_2">
Expand All @@ -99,12 +102,12 @@ border-radius:15px;</string>
<string/>
</property>
</widget>
<widget class="QLabel" name="labelTitle1_2">
<widget class="QLabel" name="labelMoney">
<property name="geometry">
<rect>
<x>100</x>
<x>60</x>
<y>90</y>
<width>111</width>
<width>191</width>
<height>31</height>
</rect>
</property>
Expand All @@ -123,7 +126,7 @@ border-radius:15px;</string>
<zorder>label</zorder>
<zorder>labelTitle1</zorder>
<zorder>progressBar</zorder>
<zorder>labelTitle1_2</zorder>
<zorder>labelMoney</zorder>
</widget>
</widget>
<resources/>
Expand Down
77 changes: 74 additions & 3 deletions moneyprogress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QMouseEvent>
#include <QKeyEvent>


#include <QDesktopWidget>


Expand Down Expand Up @@ -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()
Expand All @@ -68,25 +86,66 @@ void MoneyProgress::onTrayActivated(QSystemTrayIcon::ActivationReason reason){
case QSystemTrayIcon::Trigger:
//单击托盘图标
qDebug("click");

updateM();
iconmessage.show();
timer2->start(1500); //每分钟更新一次 后面看看要不要改成可修改的
timer2->start(2000); //每分钟更新一次 后面看看要不要改成可修改的
break;
case QSystemTrayIcon::DoubleClick:
//双击托盘图标
//双击后显示主程序窗口
this->show();
break;
default:
update();
break;
}
}

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()
{
Expand Down Expand Up @@ -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); //每分钟更新一次 后面看看要不要改成可修改的
}

Expand All @@ -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();
}


Expand All @@ -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();

}

2 changes: 2 additions & 0 deletions moneyprogress.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class MoneyProgress : public QMainWindow

//update
void update();
void updateM();


//定时器
QTimer *timer2 = new QTimer;
Expand Down
78 changes: 73 additions & 5 deletions moneyprogress.ui
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
<string notr="true">background-color: rgb(255, 216, 58);</string>
</property>
<property name="text">
<string>开始计价</string>
Expand All @@ -111,7 +111,7 @@
<rect>
<x>30</x>
<y>510</y>
<width>53</width>
<width>171</width>
<height>16</height>
</rect>
</property>
Expand All @@ -124,7 +124,7 @@
<rect>
<x>30</x>
<y>530</y>
<width>53</width>
<width>151</width>
<height>16</height>
</rect>
</property>
Expand All @@ -137,7 +137,7 @@
<rect>
<x>30</x>
<y>550</y>
<width>53</width>
<width>191</width>
<height>16</height>
</rect>
</property>
Expand All @@ -150,7 +150,7 @@
<rect>
<x>30</x>
<y>570</y>
<width>53</width>
<width>191</width>
<height>16</height>
</rect>
</property>
Expand Down Expand Up @@ -186,6 +186,29 @@
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="dateTime">
<datetime>
<hour>8</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
</datetime>
</property>
<property name="minimumDateTime">
<datetime>
<hour>0</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
</datetime>
</property>
<property name="timeSpec">
<enum>Qt::LocalTime</enum>
</property>
</widget>
</item>
<item row="1" column="0">
Expand Down Expand Up @@ -260,6 +283,9 @@
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 216, 58);</string>
</property>
<property name="text">
<string>300</string>
</property>
</widget>
</item>
<item row="0" column="2">
Expand All @@ -274,6 +300,19 @@
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="dateTime">
<datetime>
<hour>17</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
</datetime>
</property>
<property name="timeSpec">
<enum>Qt::LocalTime</enum>
</property>
</widget>
</item>
<item row="1" column="1">
Expand All @@ -288,6 +327,19 @@
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="dateTime">
<datetime>
<hour>12</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
</datetime>
</property>
<property name="timeSpec">
<enum>Qt::LocalTime</enum>
</property>
</widget>
</item>
<item row="1" column="2">
Expand All @@ -302,6 +354,19 @@
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="dateTime">
<datetime>
<hour>13</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
</datetime>
</property>
<property name="timeSpec">
<enum>Qt::LocalTime</enum>
</property>
</widget>
</item>
<item row="3" column="0">
Expand Down Expand Up @@ -335,6 +400,9 @@
<string notr="true">background-color: rgb(255, 216, 58);
</string>
</property>
<property name="text">
<string>24</string>
</property>
<property name="maxLength">
<number>100</number>
</property>
Expand Down

0 comments on commit dc6b4a4

Please sign in to comment.