📄 stopwatchtimer.cpp
字号:
/*
* ============================================================================
* Name : CStopwatchTimer from StopwatchTimer.cpp
* Part of : Stopwatch
* Created : 05.02.2006 by ToBeReplacedByAuthor
* Implementation notes:
*
* Version :
* Copyright: ToBeReplacedByCopyright
* ============================================================================
*/
// INCLUDES
#include "StopwatchTimer.h"
// CONSTANTS
const TInt CStopwatchTimer::KInterval = 10000;
// public standard construction sequence
CStopwatchTimer* CStopwatchTimer::NewL(CStopwatchTimer::MObserver& aObserver)
{
CStopwatchTimer* self = CStopwatchTimer::NewLC(aObserver);
CleanupStack::Pop();
return self;
}
CStopwatchTimer* CStopwatchTimer::NewLC(CStopwatchTimer::MObserver& aObserver)
{
CStopwatchTimer* self = new (ELeave) CStopwatchTimer(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CStopwatchTimer::~CStopwatchTimer()
{
Cancel();
iTimer.Close();
}
// public new functions
void CStopwatchTimer::Start()
{
Reset();
iStartTime.HomeTime();
After(KInterval);
}
void CStopwatchTimer::Stop()
{
Cancel();
TTime now;
now.HomeTime();
iTime = now.Int64() - iStartTime.Int64() + iTime.Int64();
}
void CStopwatchTimer::Resume()
{
iStartTime.HomeTime();
After(KInterval);
}
void CStopwatchTimer::Reset()
{
Cancel();
iTime = 0;
iObserver.OnTimerL(iTime);
}
// private standard construction sequence
CStopwatchTimer::CStopwatchTimer(CStopwatchTimer::MObserver& aObserver)
:CActive(EPriorityStandard),iObserver(aObserver)
{
// No implementation required
}
void CStopwatchTimer::ConstructL()
{
User::LeaveIfError(iTimer.CreateLocal());
// The following line is also essential!
CActiveScheduler::Add(this);
}
// private from CTimer
void CStopwatchTimer::RunL()
{
After(KInterval);
TTime now;
now.HomeTime();
TTime time(now.Int64() - iStartTime.Int64() + iTime.Int64());
TDateTime t(time.DateTime());
if(t.Hour()>0)
{
iTime = 0;
iStartTime.HomeTime();
time = 0;
}
iObserver.OnTimerL(time);
}
void CStopwatchTimer::DoCancel()
{
iTimer.Cancel();
}
void CStopwatchTimer::After(TTimeIntervalMicroSeconds32 aInterval)
{
iTimer.After(iStatus, aInterval);
SetActive();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -