📄 aknexslidercontainer.cpp
字号:
// Displays slider control and information.
DisplaySliderL( R_AKNEXSLIDER_SLIDER_LAYOUT_VALUE_DECIMAL,
KSliderInitialValueOfValueTypeScreen );
DisplayInformationL( R_AKNEXSLIDER_INFO_VALUETYPE_DECIMAL );
break;
case EAknExSliderCmdValueText: // Value text screen.
// Displays slider control and information.
iScreenStep = KSliderInitialValueOfTextScreen;
DisplaySliderL( R_AKNEXSLIDER_SLIDER_LAYOUT_TEXT_VALUE_BARE );
DisplayInformationL( R_AKNEXSLIDER_INFO_VALUETEXT_BARE );
break;
default:
// Ecepstion : Layout1 screen.
DisplaySliderL( R_AKNEXSLIDER_SLIDER_LAYOUT1 );
DisplayInformationL( R_AKNEXSLIDER_INFO_LAYOUT1 );
break;
}
DrawNow();
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::DisplaySliderL()
// Creates slider control.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::DisplaySliderL( TInt aResourceId, TInt aValue )
{
StopDisplaySlider(); // Deletes slider control object.
if ( !iSlider )
{
// Creates slider control object.
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
iSlider = new( ELeave ) CAknSlider;
// Sets edit-mode or view-mode.
if ( iCurrentFeature == EAknExSliderCmdViewMode )
{
iSlider->HandleResourceChange(
KEikMessageCaptionedControlNotEditableStateChange );
}
else
{
iSlider->HandleResourceChange(
KEikMessageCaptionedControlEditableStateChange );
}
iSlider->ConstructFromResourceL( this, aValue, reader );
CleanupStack::PopAndDestroy(); // reader
iSlider->SetObserver( this );
// Adds slider control to control stack. Slider control can get offered
// key event.
iEikonEnv->EikAppUi()->AddToStackL( iSlider );
}
}
// ----------------------------------------------------------------------------
// void CAknExSliderContainer::DisplayFormL()
// Creates and displays form.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::DisplayFormL( TInt aResourceId )
{
CAknExSliderSaveForm* form = CAknExSliderSaveForm::NewL();
form->ExecuteLD( aResourceId );
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::DisplayInformationL()
// Displays the information.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::DisplayInformationL( TInt aResourceId )
{
// Makes text which is displayed from resource.
TBuf<KAknExSliderMessageBufLength> information( 0 );
iCoeEnv->ReadResource( information, aResourceId );
switch ( iCurrentFeature ) // Screen which is displayed is...
{
case EAknExSliderCmdReturn: // Return screen.
case EAknExSliderCmdSetRange: // Range screen.
case EAknExSliderCmdSetValue: // Current value screen.
case EAknExSliderCmdSetStep: // Step size screen.
case EAknExSliderCmdValueChanged: // Value changed screen.
case EAknExSliderCmdTypeNotShown: // Value type( not shown ) screen.
case EAknExSliderCmdTypeBare: // Value type( bare ) screen.
case EAknExSliderCmdTypePercent: // Value type( percent ) screen.
case EAknExSliderCmdTypeFraction: // Value type( fraction ) screen.
case EAknExSliderCmdTypeDecimal: // Value type( decimal ) screen.
// Sets the value of slider object to text.
iLabelFormat.SetLength( KSliderClearValue );
iLabelFormat = information;
information.SetLength( KSliderClearValue );
static_cast<void> ( SetValueTextL( information ) );
break;
default:
break;
}
SetLabelL( information ); // Sets text to label.
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::SetLabelL()
// Sets string in the label.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::SetLabelL( TDesC& aInformation )
{
if ( iLabel ) // Is label object created?
{
TPoint labelPosition( KSliderClearValue, KSliderInformationOffset );
TSize labelSize( Size() );
if ( iSlider ) // Is slider control object created?
{
// Vertical position of label is bottom position of slider control.
labelPosition += iSlider->Position();
labelPosition.iY += iSlider->Size().iHeight;
labelSize.iHeight -= iSlider->Size().iHeight;
}
// Sets rectangle of label and text.
iLabel->SetExtent( labelPosition, labelSize );
iLabel->SetTextL( aInformation );
}
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::SetValueTextL()
// Makes the string which is displayed.
// ----------------------------------------------------------------------------
//
TDesC* CAknExSliderContainer::SetValueTextL( TDes& aTextBuf ) const
{
switch ( iCurrentFeature ) // Current screen is...
{
case EAknExSliderCmdReturn: // Return value screen.
case EAknExSliderCmdSetValue: // Current value screen.
case EAknExSliderCmdValueChanged: // Value changed screen.
case EAknExSliderCmdTypeNotShown: // Value type( not shown ) screen.
case EAknExSliderCmdTypeBare: // Value type( bare ) screen.
case EAknExSliderCmdTypePercent: // Value type( percent ) screen.
case EAknExSliderCmdTypeFraction: // Value type( fraction ) screen.
// Sets the current value of slider control to text.
aTextBuf.Format( iLabelFormat, iSlider->Value() );
break;
case EAknExSliderCmdSetRange: // Range screen.
// Sets the range values of slider control to text.
aTextBuf.Format( iLabelFormat,
KSliderBaseMinValue + iCurrentLabel,
KSliderBaseMaxValue - iCurrentLabel );
break;
case EAknExSliderCmdSetStep: // Step size screen.
// Sets the step size to control.
aTextBuf.Format( iLabelFormat,
KSliderStepChangeSize[iCurrentStep] );
break;
case EAknExSliderCmdTypeDecimal: // Value type( decimal ) screen.
{
// Sets the current value of slider control to text.
TInt sliderValue( iSlider->Value() );
TInt decimalPlaces( iSlider->DecimalPlaces() );
TReal64 showValue( sliderValue );
TReal r;
Math::Pow10( r, decimalPlaces );
showValue = showValue / r;
aTextBuf.Format( iLabelFormat, showValue );
break;
}
default:
break;
}
return &aTextBuf;
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::ChangeLabelL()
// Changes the display of the label.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::ChangeLabelL()
{
// Updates text which is displayed.
TBuf<KAknExSliderMessageBufLength> information( 0 );
TDesC* labelString = SetValueTextL( information );
SetLabelL( *labelString );
DrawNow(); // Redraws all components in container.
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::ChangeScreenOfTextAppearance()
// Changes the display of the value text in slider of each value type.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::ChangeScreenOfTextAppearance()
{
if ( iSlider )
{
// Displays slider control and information according to iScreenStep.
switch ( iScreenStep )
{
// Value text screen.
case EAknExSliderChangeText1: // Value type is bare figure.
DisplaySliderL( R_AKNEXSLIDER_SLIDER_LAYOUT_TEXT_VALUE_BARE );
DisplayInformationL( R_AKNEXSLIDER_INFO_VALUETEXT_BARE );
DrawNow();
break;
case EAknExSliderChangeText2: // Value is not shown.
DisplaySliderL(
R_AKNEXSLIDER_SLIDER_LAYOUT_TEXT_VALUE_NOTSHOWN );
DisplayInformationL( R_AKNEXSLIDER_INFO_VALUETEXT_NOTSHOWN );
DrawNow();
break;
case EAknExSliderChangeText3: // Value type is percentage.
DisplaySliderL(
R_AKNEXSLIDER_SLIDER_LAYOUT_TEXT_VALUE_PERCENT );
DisplayInformationL( R_AKNEXSLIDER_INFO_VALUETEXT_PERCENT );
DrawNow();
break;
case EAknExSliderChangeText4: // Value type is fraction.
DisplaySliderL(
R_AKNEXSLIDER_SLIDER_LAYOUT_TEXT_VALUE_FRACTION );
DisplayInformationL( R_AKNEXSLIDER_INFO_VALUETEXT_FRACTION );
DrawNow();
break;
case EAknExSliderChangeText5: // Value type is decimal.
DisplaySliderL(
R_AKNEXSLIDER_SLIDER_LAYOUT_TEXT_VALUE_DECIMAL );
DisplayInformationL( R_AKNEXSLIDER_INFO_VALUETEXT_DECIMAL );
DrawNow();
break;
default:
break;
}
}
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::CountComponentControls()
// Returns number of component.
// ----------------------------------------------------------------------------
//
TInt CAknExSliderContainer::CountComponentControls() const
{
TInt count( KSliderCountComponentControls );
// return the number of slider control
if ( iSlider )
{
count++;
}
return count;
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::ComponentControl()
// Returns pointer to particular component.
// ----------------------------------------------------------------------------
//
CCoeControl* CAknExSliderContainer::ComponentControl( TInt aIndex ) const
{
switch ( aIndex )
{
case EAknExSliderComponentLabel:
return iLabel; // Return pointer to label object.
case EAknExSliderComponentSlider:
return iSlider; // Return pointer to slider object.
default:
return NULL; // Exception : Returns NULL.
}
}
// ----------------------------------------------------------------------------
// CAknExSliderContainer::Draw()
// Clears the window's rectangle.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::Draw( const TRect& aRect ) const
{
// ( Re )draw the rectangle of frame.
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( AKNEXSLIDER_WHITE );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ----------------------------------------------------------------------------
// void CAknExSliderContainer::HandleControlEventL()
// Handles the event when state change.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::HandleControlEventL(
CCoeControl* aControl,
TCoeEvent aEventType )
{
if ( aControl == iSlider && aEventType == EEventStateChanged )
{
switch ( iCurrentFeature )
{
// Changes label of current value.
case EAknExSliderCmdValueChanged: // Value changed screen.
case EAknExSliderCmdTypeNotShown: // Value type( not shown ) screen.
case EAknExSliderCmdTypeBare: // Value type( bare ) screen.
case EAknExSliderCmdTypePercent: // Value type( percent ) screen.
case EAknExSliderCmdTypeFraction: // Value type( fraction ) screen.
case EAknExSliderCmdTypeDecimal: // Value type( decimal ) screen.
ChangeLabelL();
break;
default:
break;
}
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -