📄 qiqiweatherappview.cpp
字号:
/*
============================================================================
Name : QiQiWeatherAppView.cpp
Author : Richie Chyi
Copyright : Copyright?2008
Description : Application view implementation
============================================================================
*/
// INCLUDE FILES
#include <coemain.h>
#include <eiklabel.h>
#include <stringloader.h>
#include <QiQiWeather_0xE6E51F33.rsg>
#include "QiQiWeatherAppView.h"
#include "QiQiWeatherAppUi.h"
#include "Util.h"
#include "Setting.h"
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CQiQiWeatherAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CQiQiWeatherAppView* CQiQiWeatherAppView::NewL(CQiQiWeatherAppUi* aAppUi, const TRect& aRect)
{
CQiQiWeatherAppView* self = CQiQiWeatherAppView::NewLC(aAppUi, aRect);
CleanupStack::Pop(self);
return self;
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CQiQiWeatherAppView* CQiQiWeatherAppView::NewLC(CQiQiWeatherAppUi* aAppUi, const TRect& aRect)
{
CQiQiWeatherAppView* self = new ( ELeave ) CQiQiWeatherAppView(aAppUi);
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CQiQiWeatherAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
iCity = new (ELeave) CEikLabel();
iCity->SetParent(this);
iCity->SetPosition(TPoint(0, 5));
iCity->SetTextL(_L(""));
iLabelSize = TSize(aRect.Width(), iCity->MinimumSize().iHeight);
iCity->SetLabelAlignment(EHCenter);
iCity->SetSize(iLabelSize);
iLow = new (ELeave) CEikLabel();
iLow->SetParent(this);
iLow->SetPosition(iCity->Position() + TPoint(0, iCity->MinimumSize().iHeight + 2));
iLow->SetTextL(_L(""));
iLow->SetLabelAlignment(EHCenter);
iLow->SetSize(iLabelSize);
iHigh = new (ELeave) CEikLabel();
iHigh->SetParent(this);
iHigh->SetPosition(iLow->Position() + TPoint(0, iLow->MinimumSize().iHeight + 2));
iHigh->SetTextL(_L(""));
iHigh->SetAlignment(EHCenterVCenter);
iHigh->SetSize(iLabelSize);
iCondition = new (ELeave) CEikLabel();
iCondition->SetParent(this);
iCondition->SetPosition(iHigh->Position() + TPoint(0, iHigh->MinimumSize().iHeight + 2));
iCondition->SetTextL(_L(""));
iCondition->SetAlignment(EHCenterVCenter);
iCondition->SetSize(iLabelSize);
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppView::CQiQiWeatherAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CQiQiWeatherAppView::CQiQiWeatherAppView(CQiQiWeatherAppUi* aAppUi)
:iAppUi(aAppUi)
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppView::~CQiQiWeatherAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CQiQiWeatherAppView::~CQiQiWeatherAppView()
{
if(iCity)
{
delete iCity;
iCity = NULL;
}
if(iLow)
{
delete iLow;
iLow = NULL;
}
if(iHigh)
{
delete iHigh;
iHigh = NULL;
}
if(iCondition)
{
delete iCondition;
iCondition = NULL;
}
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CQiQiWeatherAppView::Draw(const TRect& /*aRect*/) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Gets the control's extent
TRect drawRect(Rect());
// Clears the screen
gc.Clear(drawRect);
}
// -----------------------------------------------------------------------------
// CQiQiWeatherAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CQiQiWeatherAppView::SizeChanged()
{
/*iCity->SetExtent(iCity->Position(), iCity->Size());
iLow->SetExtent(iLow->Position(),iLow->Size());
iHigh->SetExtent(iHigh->Position(),iHigh->Size());
iCondition->SetExtent(iCondition->Position(),iCondition->Size());*/
iCity->SetExtent(iCity->Position(), iCity->MinimumSize());
iLow->SetExtent(iLow->Position(),iLow->MinimumSize());
iHigh->SetExtent(iHigh->Position(),iHigh->MinimumSize());
iCondition->SetExtent(iCondition->Position(),iCondition->MinimumSize());
DrawNow();
}
TInt CQiQiWeatherAppView::CountComponentControls() const
{
return EControlCount;
}
CCoeControl* CQiQiWeatherAppView::ComponentControl(TInt aIndex) const
{
switch(aIndex)
{
case EControlCity:
return iCity;
case EControlLow:
return iLow;
case EControlHigh:
return iHigh;
case EControlCondition:
return iCondition;
default:
return NULL;
}
}
void CQiQiWeatherAppView::UpdateWeather(TInt aTabIndex)
{
if(aTabIndex < iAppUi->WeatherDetails().Count())
{
TBuf<30> buf;
HBufC* city = StringLoader::LoadLC(R_WEATHER_CITY);
buf.Append(*city);
CleanupStack::PopAndDestroy(city);
CSetting* setting = CSetting::NewLC();
setting->ReadFromFileL();
CSetting::CityNameForIndex(setting->CityIndex(), buf);
CleanupStack::PopAndDestroy(setting);
// 将"City:Shanghai,China"转变成"City:Shanghai"
TInt pos = buf.Find(_L(","));
if (KErrNotFound != pos)
{
buf.SetLength(pos);
}
iCity->SetTextL(buf);
iCity->SetSize(iLabelSize);
buf.Zero();
HBufC* low = StringLoader::LoadLC(R_WEATHER_LOW);
buf.Append(*low);
CleanupStack::PopAndDestroy(low);
QiQiWeatherUtil::fToc(iAppUi->WeatherDetails()[aTabIndex].iLow, buf);
iLow->SetTextL(buf);
iLow->SetSize(iLabelSize);
buf.Zero();
HBufC* high = StringLoader::LoadLC(R_WEATHER_HIGH);
buf.Append(*high);
CleanupStack::PopAndDestroy(high);
QiQiWeatherUtil::fToc(iAppUi->WeatherDetails()[aTabIndex].iHigh, buf);
iHigh->SetTextL(buf);
iHigh->SetSize(iLabelSize);
buf.Zero();
HBufC* condition = StringLoader::LoadLC(R_WEATHER_CONDITION);
buf.Append(*condition);
CleanupStack::PopAndDestroy(condition);
buf.Append(iAppUi->WeatherDetails()[aTabIndex].iCondition);
iCondition->SetTextL(buf);
iCondition->SetSize(iLabelSize);
DrawDeferred();
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -