代码拉取完成,页面将自动刷新
#include "snap_timer_mainwindow.h"
#include "ui_snap_timer_mainwindow.h"
#include "option_dialog.h"
#include <QDebug>
#include <QMessageBox>
#include <QSettings>
#include <QtCore/QtCore>
#include <QLabel>
#include <QSystemTrayIcon>
#define timer_interruput 1000
#define xiabn_service_interval 1
QString settingsName = "./Config.ini";
QSettings *settings = new QSettings(settingsName, QSettings::IniFormat);
extern QAction actionAbout ;
extern int is_display_message;
QString exe_file_name;
QString wav_file_name;
extern int is_run_program;
extern int is_play_music;
unsigned int setTime2second,time2second;
extern void run_program_button_slot(QString exe_file_name);
extern void play_music_button_slot(QString wav_file_name);
char is_start_sysbol = 0;
char is_change_time_set = 0;
char is_reset_time = 0;
QString help_msg = "help";
QString time_out_msg ;
//xiaban
QString xiaban_time_out_msg = "下班班!!!";
QString gupiao_begin_msg = "Begin !!!";
QString gupiao_jiaoyi_msg = "Exchange time!!!";
QTime dongjiTime = QTime(17,50,00);
QTime xiajiTime = QTime(18,20,00);
QTime pingshiTime = QTime(18,20,00);
QTime shangWuXiaBanTime = QTime(11,50,00);
QTime *jijieTimeTemp = new QTime;
QTime *currentTime = new QTime;
void SetTaskBarIcon();
snap_timer_MainWindow::snap_timer_MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::snap_timer_MainWindow)
{
ui->setupUi(this);
//default value
if(settings->value ("HOME/time_set").toString ().isEmpty () ){
settings->setValue ("HOME/time_set",QTime(00,45,00).toString ());
}
//set the variable
ui->time_set->setTime(settings->value("HOME/time_set").toTime());
is_display_message = settings->value("Alarm/is_display_message").toInt();
setWindowTitle("SnapTimer");
ui->back_time->setTime(ui->time_set->time());
time_temp = ui->time_set->time();
ui->back_time->setStyleSheet("color:blue");
//open the time_fresh service
connect(timer,SIGNAL(timeout()),this,SLOT(fresh_back_time()));
//current time service
currentTimeTimer->start(xiabn_service_interval);
connect(currentTimeTimer,SIGNAL(timeout()),this,SLOT(setTimeOutHandle() ) );
//qDebug(time_out_msg.to);
SetTaskBarIcon();
}
void SetTaskBarIcon(){
QSystemTrayIcon* pSystemTray = new QSystemTrayIcon();
pSystemTray->setIcon(QIcon(":/16.ico"));
pSystemTray->setToolTip("Powered by @yan9bo");
pSystemTray->show();
}
void snap_timer_MainWindow::help_action(){
QMessageBox msgBox;
///msgBox.set
msgBox.setText("help INFO");
QString msg = "help_msg";
msgBox.setInformativeText(msg);
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.exec();
}
//xiaban notification
void snap_timer_MainWindow::setTimeOutHandle(){
switch (settings ->value("General/jiJie").toInt()) {
case 0:
//dong
*jijieTimeTemp = dongjiTime;
break;
case 1:
//xia
*jijieTimeTemp = xiajiTime;
break;
case 2:
//pingshi
*jijieTimeTemp = pingshiTime;
break;
default:
break;
}
if(currentTime->currentTime() == *jijieTimeTemp || currentTime->currentTime() == shangWuXiaBanTime){
timeout_messagebox_show(xiaban_time_out_msg);
}else if( currentTime->currentTime() == QTime(9,15,00) ){
timeout_messagebox_show(gupiao_begin_msg);
}else if( currentTime->currentTime() == QTime(9,29,00) ){
timeout_messagebox_show(gupiao_jiaoyi_msg);
}
}
void snap_timer_MainWindow::start_action()
{
on_startBtn_clicked();
}
//option menu action
void snap_timer_MainWindow::option_action(){
opt_dialog.show();
}
void snap_timer_MainWindow::exit_action(){
this->close ();
}
void snap_timer_MainWindow::save_setting_action()
{
}
void snap_timer_MainWindow::reset_action()
{
on_stopBtn_clicked();
}
snap_timer_MainWindow::~snap_timer_MainWindow()
{
delete ui;
}
void snap_timer_MainWindow::on_startBtn_clicked()
{
is_start_sysbol = !is_start_sysbol;
time_out_msg = settings->value("Alarm/display_message").toString() ;
if(is_start_sysbol == 1){
timer->start(timer_interruput);
if(time_temp == QTime(00,00,00) ){
//set to the time set
//load the origin
ui->back_time->setTime(ui->time_set->time());
time_temp = ui->time_set->time();
timer->start(timer_interruput);
//progress bar set origin value
int setHour = ui->time_set->time().hour();
int setminute = ui->time_set->time().minute();
int setsecond = ui->time_set->time().second();
setTime2second = setHour * 3600 + setminute * 60 + setsecond;
time2second = setTime2second;
}else{
//start
time_temp = ui->back_time->time();
//settime 2 second
int setHour = ui->time_set->time().hour();
int setminute = ui->time_set->time().minute();
int setsecond = ui->time_set->time().second();
setTime2second = setHour * 3600 + setminute * 60 + setsecond;
//time 2 second
setHour = time_temp.hour();
setminute = time_temp.minute();
setsecond = time_temp.second();
time2second = setHour * 3600 + setminute * 60 + setsecond;
}
}else{
//pause
timer->stop();
}
}
void snap_timer_MainWindow::on_stopBtn_clicked()
{
is_start_sysbol = 0;
timer->stop();
ui->back_time->setTime(ui->time_set->time());
time_temp = ui->time_set->time();
}
void snap_timer_MainWindow::fresh_back_time(){
// print 控件的坐标
// extern snap_timer_MainWindow *w;
// qDebug("x= %d,y= %d",w->pos().x(),w->pos().y());
if(time_temp == QTime(00,00,00)){
is_start_sysbol = 0 ;
timer->stop();
if(is_play_music){
play_music_button_slot (wav_file_name);
}
if(is_run_program){
run_program_button_slot (exe_file_name);
}
if(is_display_message){
timeout_messagebox_show(time_out_msg);
}
}else{
time_temp = time_temp.addSecs(-1);
ui->back_time->setTime(time_temp);
time2second--;
ui->progressbar->setValue(time2second*100/setTime2second);
}
if(is_reset_time == 1){
is_reset_time = 0;
on_stopBtn_clicked();
}
}
void timeout_messagebox_show(QString msg){
QMessageBox msgBox;
msgBox.setWindowFlags (Qt::WindowStaysOnTopHint);
msgBox.setText(msg);
//msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Ok| QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
msgBox.setButtonText (QMessageBox::Cancel,"reset");
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Ok:
// Save was clicked
break;
case QMessageBox::Cancel:
// Cancel was clicked;means reset
is_reset_time = 1;
break;
default:
// should never be reached
break;
}
}
void snap_timer_MainWindow::on_time_set_userTimeChanged(const QTime &time)
{
ui->back_time->setTime(time);
time_temp == time;
settings->setValue("HOME/time_set", ui->time_set->time().toString());
}
void snap_timer_MainWindow::on_time_set_45min_clicked()
{
is_start_sysbol = 0;
timer->stop();
QTime t = QTime(00,45,00);
ui->time_set->setTime (t);
ui->back_time->setTime(t);
time_temp == t;
settings->setValue("HOME/time_set", ui->time_set->time().toString());
}
void snap_timer_MainWindow::on_time_set_30min_clicked()
{
is_start_sysbol = 0;
timer->stop();
QTime t = QTime(00,30,00);
ui->time_set->setTime (t);
ui->back_time->setTime(t);
time_temp == t;
settings->setValue("HOME/time_set", ui->time_set->time().toString());
}
void snap_timer_MainWindow::on_time_set_15min_clicked()
{
is_start_sysbol = 0;
timer->stop();
QTime t = QTime(00,15,00);
ui->time_set->setTime (t);
ui->back_time->setTime(t);
time_temp == t;
settings->setValue("HOME/time_set", ui->time_set->time().toString());
}
void snap_timer_MainWindow::on_time_set_10min_clicked()
{
is_start_sysbol = 0;
timer->stop();
QTime t = QTime(00,10,00);
ui->time_set->setTime (t);
ui->back_time->setTime(t);
time_temp == t;
settings->setValue("HOME/time_set", ui->time_set->time().toString());
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。