📄 gpsinfo.cpp
字号:
#include <EikEnv.h>
#include <BluetoothGPS.rsg>
#include "gps/impl/BtGpsReceiver.h"
#include "views/GpsInfo.h"
CGpsInfo::CGpsInfo( ) {
}
CGpsInfo::~CGpsInfo( ) {
if ( iGpsReceiver ) iGpsReceiver->RemoveListenerL( this );
delete( iGpsReceiver );
delete( iGpsText ); iGpsText = NULL;
}
CGpsInfo * CGpsInfo::NewL( const TRect & aRect ) {
CGpsInfo * self = CGpsInfo::NewLC( aRect );
CleanupStack::Pop( );
return( self );
}
CGpsInfo * CGpsInfo::NewLC( const TRect & aRect ) {
CGpsInfo * self = new ( ELeave ) CGpsInfo( );
CleanupStack::PushL( self );
self->ConstructL( aRect );
return( self );
}
void CGpsInfo::ConstructL( const TRect & aRect ) {
BaseConstructL( aRect, R_TEXT_GPSINFO_TITLE );
// Texte aus den Resourcen laden.
iGpsText = iEikonEnv->AllocReadResourceL( R_GPS_INFO_LABEL );
// Bestimme den benutzerkonfigurierten GPS Receiver und melde "this" als
// Listener an.
iGpsReceiver = CBtGpsReceiver::NewL( );
iGpsReceiver->AddListenerL( this );
// Activate the window, which makes it ready to be drawn.
ActivateL( );
}
void CGpsInfo::Draw( const TRect & aRect ) const {
CWindowGc & lGc = SystemGc( );
// Clipping auf den zu zeichnenden Bereich setzen. Das vermeidet
// Flackern der Darstellung.. laut API.. :) Und den Bereich loeschen.
lGc.SetClippingRect( aRect );
lGc.Clear( );
// Const uncasten.
CGpsInfo * self = ( CGpsInfo * ) this;
// Position fuer Label bestimmen.
const CFont * theFont = iEikonEnv->NormalFont( );
TInt vOffset = theFont->HeightInPixels( ) * 2 + theFont->BaselineOffsetInPixels( );
// Label ausgeben.
lGc.UseFont( theFont );
lGc.DrawText( *iGpsText, TPoint( 10, vOffset ) );
lGc.DiscardFont( );
// GPS Position anzeigen.
lGc.UseFont( iEikonEnv->AnnotationFont( ) );
TRealFormat gpsFormat;
gpsFormat.iPlaces = 8;
gpsFormat.iWidth = 12;
TBuf< 100 > temp;
temp.Append( _L( "Lon: " ) );
temp.AppendNum( self->iLastGpsPos.Wgs84Longitude( ), gpsFormat );
lGc.DrawText( temp, TPoint( 10, vOffset + theFont->HeightInPixels( ) * 2 ) );
temp.SetLength( 0 );
temp.Append( _L( "Lat: " ) );
temp.AppendNum( self->iLastGpsPos.Wgs84Latitude( ), gpsFormat );
lGc.DrawText( temp, TPoint( 10, vOffset + theFont->HeightInPixels( ) * 3 ) );
temp.SetLength( 0 );
temp.Append( _L( "Valid: " ) );
if ( self->iLastGpsPos.IsValid( ) )
temp.Append( _L( "Yes" ) );
else
temp.Append( _L( "No" ) );
lGc.DrawText( temp, TPoint( 10, vOffset + theFont->HeightInPixels( ) * 4 ) );
temp.SetLength( 0 );
temp.Append( _L( "Satellites: " ) );
temp.AppendNum( self->iLastGpsPos.Satellites( ) );
lGc.DrawText( temp, TPoint( 10, vOffset + theFont->HeightInPixels( ) * 5 ) );
lGc.DiscardFont( );
}
void CGpsInfo::GpsUpdate( const TGpsPosition & aNewPosition ) {
// Uebernehme die neue Position und aktualisiere die Ansicht.
iLastGpsPos.Set( aNewPosition );
DrawDeferred( );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -