⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stopwatchtimer.cpp

📁 基于Symbian OS的手机开发与应用实践第12章代码。主要讲各种时钟
💻 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 + -