📄 stopwatchcontainer.cpp
字号:
/*
* ============================================================================
* Name : CStopwatchContainer from StopwatchContainer.h
* Part of : Stopwatch
* Created : 05.02.2006 by ToBeReplacedByAuthor
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version :
* Copyright: ToBeReplacedByCopyright
* ============================================================================
*/
// INCLUDE FILES
#include <e32std.h>
#include <eiklabel.h> // for CEikLabel
#include "StopwatchContainer.h"
#include "StopwatchModel.h"
// CONSTANTS
const TInt CStopwatchContainer::KTimeStringLength = 7;
// ================= MEMBER FUNCTIONS =======================
CStopwatchContainer* CStopwatchContainer::NewL(const TRect& aRect, const CStopwatchModel& aModel)
{
CStopwatchContainer* self = new (ELeave) CStopwatchContainer(aModel);
CleanupStack::PushL(self);
self->ConstructL(aRect);
CleanupStack::Pop();
return self;
}
// Destructor
CStopwatchContainer::~CStopwatchContainer()
{
delete iLabel;
}
// public new functions
void CStopwatchContainer::RefreshL()
{
TBuf<KTimeStringLength> timeString;
const TTime& time = iModel.Time();
time.FormatL(timeString, KTimeFormat);
iLabel->SetTextL(timeString);
DrawDeferred();
}
// ---------------------------------------------------------
// CStopwatchContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CStopwatchContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CStopwatchContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CStopwatchContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CStopwatchContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CStopwatchContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
CStopwatchContainer::CStopwatchContainer(const CStopwatchModel& aModel)
: iModel(aModel)
{
// No Implementation Required
}
// ---------------------------------------------------------
// CStopwatchContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CStopwatchContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
iLabel = new(ELeave) CEikLabel;
TBuf<KTimeStringLength> timeString;
const TTime& time = iModel.Time();
time.FormatL(timeString, KTimeFormat);
iLabel->SetTextL(timeString);
TSize size(iLabel->MinimumSize());
TPoint position((aRect.Width()-size.iWidth)/2, (aRect.Height()-size.iHeight)/2);
iLabel->SetPosition(position);
ActivateL();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -