?? worldtimer.cpp
字號:
/****************************************************************************** File: 'worldtimer.cpp'**** Created: Sat Dec 2 15:58:32 2006** by: Wya ($Id: edited Sat Dec 2 15:58:32 2006 $)**** WARNING! All changes made by wya**-------------------------------------------------------------------------****-------------------------------------------------------------------------**Modifier:** 2006 12 09 --correct the display of AM, PM , when euro to china** @revesion 22**-------------------------------------------------------------------------******************************************************************************/#include "worldtimer.h"#include "stopwatch.h"#include "analogclock.h"#include "digitalclock.h"#include "yconfigure.h"/***** construction*****/YWorldTimer::YWorldTimer(QWidget *parent ) : QDialog(parent){ setupUi(this); m_digitalClock = NULL; m_analogClock = NULL; m_OffsetTime=0; m_StopWatchCounter=0;//start 0 stopwatch m_SynchroEnable=false; m_LogStream=NULL; m_Log=NULL; //disable the synchron checkbox setSynchroEnable (false);#if CHINA_TIME m_eTimeZone=eCHINA; //china#endif#if EURO_TIME m_eTimeZone=eEUROPE; //europe#endif m_conf=new YConfigure(this);//init the world //activity log stream openLogStream(); connect(btSetLocalTime, SIGNAL(clicked(bool)), this, SLOT(slotSetLocalTimeButton(bool))); connect(sliderWorldTimer, SIGNAL(valueChanged (int)), this, SLOT(slotSlideWorldTimer(int))); connect(slideTimerStopWatch,SIGNAL(sliderReleased ()),this, SLOT(slotStartOneStopWatch())); connect(cbSychron,SIGNAL(stateChanged ( int) ),this, SLOT(slotSynchroCheckBox(int))); slotActivityAnalogTimer(); //set the ok time QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(slotActivityDigitalTimer())); timer->start(1000);}/***** deconstruction*****/YWorldTimer::~YWorldTimer(){ }/********/void YWorldTimer::slotActivityAnalogTimer(){ if( m_digitalClock) { delete m_digitalClock; m_digitalClock=NULL; } m_analogClock = new AnalogClock(frameTimer); }/********/void YWorldTimer::slotActivityDigitalTimer(){ //every second will check the offset value slotUpdateOffset();//check whether AM or PM and update the time QTime time = QTime::currentTime(); if(time.hour()+getTheOffsetTimeValue() >=24 ) { lbIndicateTimer->setText("AM"); } else if(time.hour()+getTheOffsetTimeValue() >=12 ) { lbIndicateTimer->setText("PM"); } else if (time.hour()+getTheOffsetTimeValue() <0 ) { lbIndicateTimer->setText("PM"); } else { lbIndicateTimer->setText("AM"); } timeEditConfigue->setTime(time);}/**********/void YWorldTimer::slotSetLocalTimeButton(bool ok){ // start the set time dialog YSetLocalTime * set; switch (m_eTimeZone ) { case eCHINA: set = new YSetLocalTime(this,m_conf,eCHINA); set->show(); break; case eEUROPE: set = new YSetLocalTime(this,m_conf,eEUROPE); set->show(); break; case eUSA: set = new YSetLocalTime(this,m_conf,eUSA); set->show(); break; case eERROR: default: set = new YSetLocalTime(this,m_conf,eERROR); set->show(); break; }; }/**********/void YWorldTimer::slotSlideWorldTimer(int i){ QTime time = QTime::currentTime(); int j=time.hour(); switch(i) { case eCHINA: //china m_eTimeZone=eCHINA; m_OffsetTime=m_conf->getChinaTimeOffset(0); m_analogClock->setOffsetTimeValue(m_OffsetTime); if( time.hour()+m_OffsetTime >=24) { lbIndicateTimer->setText("AM"); } else if( time.hour()+m_OffsetTime >=12) { lbIndicateTimer->setText("PM"); } else { lbIndicateTimer->setText("AM"); } break; case eEUROPE: //europe m_eTimeZone=eEUROPE; m_OffsetTime=m_conf->getEuropeTimeOffset(0);//get the value from conf m_analogClock->setOffsetTimeValue( m_OffsetTime); if( time.hour()+m_OffsetTime >=12) { lbIndicateTimer->setText("PM"); } else { lbIndicateTimer->setText("AM"); } break; case eUSA: //USA m_eTimeZone=eUSA; m_OffsetTime=m_conf->getUsaTimeOffset(0); m_analogClock->setOffsetTimeValue( m_OffsetTime); if( time.hour()+m_OffsetTime ) { lbIndicateTimer->setText("AM"); } else if(time.hour()+m_OffsetTime <=0 ) { lbIndicateTimer->setText("PM"); } else if( time.hour()+m_OffsetTime <=12) { lbIndicateTimer->setText("PM"); } else { lbIndicateTimer->setText("AM"); } break; };}/***** after change the offet value , we need update the offset value for analog time *****/void YWorldTimer::slotUpdateOffset(){ switch (m_eTimeZone ) { case eCHINA: m_OffsetTime=m_conf->getChinaTimeOffset(0); m_analogClock->setOffsetTimeValue(m_OffsetTime); break; case eEUROPE: m_OffsetTime=m_conf->getEuropeTimeOffset(0);//get the value from conf m_analogClock->setOffsetTimeValue( m_OffsetTime); break; case eUSA: m_OffsetTime=m_conf->getUsaTimeOffset(0); m_analogClock->setOffsetTimeValue( m_OffsetTime); break; case eERROR: default: break; }; }/***** event close windows*****/void YWorldTimer::closeEvent( QCloseEvent* ce ){ qDeleteAll(watchList.begin(), watchList.end()); watchList.clear(); m_conf->saveConf(); //delete the stream if(m_Log!=NULL) { m_Log->close(); delete m_LogStream; delete m_Log; m_LogStream=NULL; m_Log=NULL; } //start close win ce->accept(); }/***** activity or disable the widget of checkbox*****/void YWorldTimer::setSynchroEnable(bool b){ if(b==true) { cbSychron->setDisabled (!b); //ennable the synchro check box } else { cbSychron->setDisabled (!b); //disable the synchro checkbox cbSychron->setCheckState(Qt::Unchecked);//uncheck the checkbox if check ,because is disable }}/***** open one stop watch*****/void YWorldTimer::slotStartOneStopWatch(){ slideTimerStopWatch->setSliderPosition(1);//return back slider YStopWatch *stopwatch1; switch(getStopWatchCounter()) { case 0: stopwatch1=new YStopWatch(this); stopwatch1->setIndication(1); //set indication in the class stopwatch stopwatch1->setTitleName(); //set windows title display the indication stopwatch1->setTextStream( m_LogStream); watchList.append(stopwatch1); //save to the value setStopWatchCounter(1); //save the counter of stop watch in this class stopwatch1->show(); connect(stopwatch1,SIGNAL(closeStopWatch(int)),this,SLOT(slotCloseStopWatch(int))); break; case 1: setSynchroEnable (true);//activity the synchro check box stopwatch1=new YStopWatch(this); stopwatch1->setIndication(2);//set indication in the class stopwatch stopwatch1->setTitleName();//set windows title display the indication stopwatch1->setTextStream( m_LogStream);// set stream in order to save the stream watchList.append(stopwatch1); //save to the value setStopWatchCounter(2);//save the counter of stop watch in this class stopwatch1->show(); connect(stopwatch1,SIGNAL(closeStopWatch(int)),this,SLOT(slotCloseStopWatch(int))); break; case 2: stopwatch1=new YStopWatch(this); stopwatch1->setIndication(3);//set indication in the class stopwatch stopwatch1->setTitleName();//set windows title display the indication stopwatch1->setTextStream( m_LogStream);// set stream in order to save the stream watchList.append(stopwatch1); //save to the value setStopWatchCounter(3);//save the counter of stop watch in this class stopwatch1->show(); connect(stopwatch1,SIGNAL(closeStopWatch(int)),this,SLOT(slotCloseStopWatch(int))); break; case 3: default: QMessageBox::warning(this, "No StopWatch", "Could not launch a new StopWatch,\n" "because the Max value of Stop watch are 3. You can only delete\n" "one Stop Watch,if you want a new."); break; }; }/**********/void YWorldTimer::slotSynchroCheckBox(int i){ if(i==Qt::Unchecked) { if(m_SynchroEnable==true) { disSynchroStopWatchList(); } m_SynchroEnable = false; } else { m_SynchroEnable = true; synchroStopWatchList(); }}/***** delete the stop watch in the list when receive the signal "close windows*****/void YWorldTimer::slotCloseStopWatch(int ind){ int i=0; //check we have how much stop watch switch(ind) { case 1: watchList.removeAt(0);//remove from the list,it seem while delete the object setStopWatchCounter(getStopWatchCounter()-1); //reset the indication for(i=0;i<watchList.count();i++) { watchList.at(i)->setIndication(i+1);//set indication in the class stopwatch watchList.at(i)->setTitleName(); } //we will set sychron is disable if(i<2) { setSynchroEnable(false); } break; case 2: watchList.removeAt(1);//remove form the list setStopWatchCounter(getStopWatchCounter()-1); //reset the indication for(i=0;i<watchList.count();i++) { watchList.at(i)->setIndication(i+1);//set indication in the class stopwatch watchList.at(i)->setTitleName(); } //we will set sychron is disable if(i<2) { setSynchroEnable(false); } break; case 3: watchList.removeAt(2);//remove form the list setStopWatchCounter(getStopWatchCounter()-1); break; case 0: default: break; };}/***** synchro the stop watch list*****/void YWorldTimer::synchroStopWatchList(){ YStopWatch * sw0,*sw1,*sw2; switch(getStopWatchCounter()) { case 2: sw0= watchList.at(0); sw1= watchList.at(1); connect( sw0,SIGNAL(stopStopWatch(bool)), sw1,SLOT(slotStartButton(bool))); break; case 3: sw0= watchList.at(0); sw1= watchList.at(1); sw2= watchList.at(2); connect(sw0,SIGNAL(stopStopWatch(bool)), sw1,SLOT(slotStartButton(bool))); connect( sw1,SIGNAL(stopStopWatch(bool)), sw2,SLOT(slotStartButton(bool))); break; default: break; }; }/***** disconnect the slot function*****/void YWorldTimer::disSynchroStopWatchList(){ YStopWatch * sw0,*sw1,*sw2; switch(getStopWatchCounter()) { case 2: sw0= watchList.at(0); sw1= watchList.at(1); disconnect( sw0,SIGNAL(stopStopWatch(bool)), sw1,SLOT(slotStartButton(bool))); break; case 3: sw0= watchList.at(0); sw1= watchList.at(1); sw2= watchList.at(2); disconnect(sw0,SIGNAL(stopStopWatch(bool)), sw1,SLOT(slotStartButton(bool))); disconnect( sw1,SIGNAL(stopStopWatch(bool)), sw2,SLOT(slotStartButton(bool))); break; default: break; };}/***** open the stream*****/bool YWorldTimer::openLogStream(){ bool res=false; //just for clean the text QDateTime t; t=QDateTime::currentDateTime (); QFile f(m_conf->getStopWatchLogFile()); if (f.open(QFile::WriteOnly | QFile::Truncate)) { QTextStream stream(&f); stream<<"###"<<char(0x0d)<<char(0x0a)<<"##"<<" World Time and Stopwatch log File, by wya. "<<t.toString("yyyy MM dd hh:mm:ss")<<char(0x0d)<<char(0x0a)<<"###"<<char(0x0d)<<char(0x0a); } else { QMessageBox::warning(this, "Can't open the stopwatch log file", "Error when open a new StopWatch log file"); return res=false; } f.close(); m_Log=new QFile(m_conf->getStopWatchLogFile()); if (m_Log->open(QFile::WriteOnly|QIODevice::Append)) { m_LogStream =new QTextStream(m_Log); *m_LogStream<<"******************************************************************************"<<char(0x0d)<<char(0x0a); res=true; } return res;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -