📄 countdowntimer.cpp
字号:
/*
* ============================================================================
* Name : CCountdownTimer from CountdownTimer.cpp
* Part of : Timer
* Created : 05.02.2006 by ToBeReplacedByAuthor
* Implementation notes:
*
* Version :
* Copyright: ToBeReplacedByCopyright
* ============================================================================
*/
// INCLUDES
#include "CountdownTimer.h"
// CONSTANTS
const TInt CCountdownTimer::KInterval = 10000;
// public standard construction sequence
CCountdownTimer* CCountdownTimer::NewL(MObserver& aObserver)
{
CCountdownTimer* self = CCountdownTimer::NewLC(aObserver);
CleanupStack::Pop();
return self;
}
CCountdownTimer* CCountdownTimer::NewLC(MObserver& aObserver) //observer = appui
{
CCountdownTimer* self = new (ELeave) CCountdownTimer(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CCountdownTimer::~CCountdownTimer()
{
// No implementation required
}
// public new functions
void CCountdownTimer::Start(const TTime& aTime)
{
Cancel();
TTime now;
now.HomeTime();
iTargetTime = now.Int64() + aTime.Int64();
After(KInterval);
}
void CCountdownTimer::Stop()
{
Cancel();
}
// private standard construction sequence
CCountdownTimer::CCountdownTimer(MObserver& aObserver)
:CTimer(EPriorityStandard),iObserver(aObserver)
{
// No implementation required
}
void CCountdownTimer::ConstructL()
{
// This is explicitly decareded in the CTimer document
CTimer::ConstructL();
// The following line is also essencial!
CActiveScheduler::Add(this);
}
// private from CTimer
void CCountdownTimer::RunL()
{
TTime now;
now.HomeTime();
TTime time = iTargetTime.Int64() - now.Int64();
if(time.Int64()>0)
{
After(KInterval);
}
else
{
time = 0;
}
iObserver.OnTimerL(time);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -