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

📄 aknexslidercontainer.cpp

📁 symbian 中 滚动条的使用 可以用在亮度
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*  Copyright (c) 2004, Nokia. All rights reserved */

// INCLUDE FILES
#include <aknutils.h>
#include <barsread.h>
#include <e32math.h>
#include <eikappui.h>
#include <eikenv.h>
#include <eiklabel.h> // for label
#include <aknslider.h> // for slider
#include <aknform.h> // for form
#include <aknnotewrappers.h> // for note wrapper
#include <AknExSlider.rsg>
#include <e32math.h>
#include "aknexslider.hrh"
#include "AknExSliderContainer.h"
#include "aknexsliderview.h"
#include "AknExSliderSaveForm.h"


// ================= MEMBER FUNCTIONS =========================================

// ----------------------------------------------------------------------------
// CAknExSliderContainer::CAknExSliderContainer()
// Default constructor.
// ----------------------------------------------------------------------------
//
CAknExSliderContainer::CAknExSliderContainer( CAknExSliderView* aView )
:   iSlider( NULL ),
    iLabel( NULL ),
    iLabelFormat( NULL ),
    iCurrentFeature( EAknExSliderCmdEmpty ),
    iCurrentLabel( EAknExSliderChangeLabel1 ),
    iCurrentStep( KSliderInitialStepIndex ),
    iScreenStep( KSliderInitialValueOfTextScreen ),
    iView( aView )
    {
    }

// ----------------------------------------------------------------------------
// CAknExSliderContainer::ConstructL()
// Constructor.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::ConstructL( const TRect& aRect )
    {
    // Creates window.
    CreateWindowL();

    // Creates label object.
    iLabel = new( ELeave ) CEikLabel;
    iLabel->SetContainerWindowL( *this );

    // Sets rectangle of window and activates.
    SetRect( aRect );
    ActivateL();

    DisplayFeatureL(); // Displays information.
    }

// ----------------------------------------------------------------------------
// CAknExSliderContainer::~CAknExSliderContainer()
// Destructor.
// ----------------------------------------------------------------------------
//
CAknExSliderContainer::~CAknExSliderContainer()
    {
    StopDisplaySlider(); // Deletes slider control.

    // Deletes label object.
    delete iLabel;
    }

// ----------------------------------------------------------------------------
// CAknExSliderContainer::HandleCommandL()
// Handles the commands.
// ----------------------------------------------------------------------------
//
void CAknExSliderContainer::HandleCommandL( TInt aCommand )
    {
    iCurrentFeature = aCommand;
    // If the font which is used in label is <legend> font
    // sets font for displaying information to label's font.
    if ( iLabel->Font() == LatinBold19() )
        {
        SetLabelState( EAknExSliderLabelInformation );
        }

    DisplayFeatureL(); // Displays the slider control and information.
    }

// ----------------------------------------------------------------------------
// CAknExSliderContainer::OfferKeyEventL()
// Handles the key events.
// ----------------------------------------------------------------------------
//
TKeyResponse CAknExSliderContainer::OfferKeyEventL( 
    const TKeyEvent& aKeyEvent,
    TEventCode aType )
    {
    if ( aType != EEventKey ) // Is not key event?
        {
        return EKeyWasNotConsumed;
        }
    TBuf<KAknExSliderMessageBufLength> information( 0 );
    TChar charCode( aKeyEvent.iCode );

    TKeyResponse response( EKeyWasConsumed );

    switch( aKeyEvent.iCode ) // The code of key event is...
        {
        case EKeySpace: // Space key.
            DisplayNextFeature(); // Displays next screen.
            break;
        case EKeyUpArrow:
            {
            // If the screen which is displayed is value text screen
            // changes the value type of slider and information.
            if ( iCurrentFeature == EAknExSliderCmdValueText )
                {
                if ( iScreenStep > KSliderInitialValueOfTextScreen &&
                     iScreenStep <= KSliderMaxValueOfTextScreen )
                    {
                    // Sets the index of screen step in order to loop.
                    iScreenStep--; // decrements the index of screen step.
                    }
                else
                    {
                    iScreenStep = KSliderMaxValueOfTextScreen;
                    }
                ChangeScreenOfTextAppearance(); // Changes the display.
                }
            else
                {
                return EKeyWasNotConsumed;
                }
            break;
            }
        case EKeyDownArrow:
            {
            // If the screen which is displayed is value text screen
            // changes the value type of slider and information.
            if ( iCurrentFeature == EAknExSliderCmdValueText )
                {
                if ( iScreenStep >= KSliderInitialValueOfTextScreen &&
                     iScreenStep < KSliderMaxValueOfTextScreen )
                    {
                    iScreenStep++; // Increments the index of screen step.
                    }
                else
                    {
                    // Sets the index of screen step in order to loop.
                    iScreenStep = KSliderInitialValueOfTextScreen;
                    }
                ChangeScreenOfTextAppearance(); // Changes the display.
                }
            else
                {
                return EKeyWasNotConsumed;
                }
            break;
            }
        default:
            {
            response = EKeyWasNotConsumed;
            break;
            }
        }

    if ( response == EKeyWasConsumed )
        {
        return response;
        }

    
    switch ( iCurrentFeature )
        {
        case EAknExSliderCmdSetMinimum:
            {
            // If the screen which is displayed is minimum screen
            // changes the minimum text of slider control.
            if ( charCode == AKNEXSLIDER_MINIMUM_CHANGE_KEY ||
                charCode == AKNEXSLIDER_MINIMUM_CHANGE_KEY2 )
                {
                response = EKeyWasConsumed;
                
                // Makes the text which is displayed and sets this to label.
                switch ( iCurrentLabel )
                    {
                    case EAknExSliderChangeLabel1:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_MIN2 );
                        break;
                    case EAknExSliderChangeLabel2:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_LOW1 );
                        break;
                    case EAknExSliderChangeLabel3:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_LOW2 );
                        break;
                    case EAknExSliderChangeLabel4:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_MIN1 );
                        break;
                    default:
                        return EKeyWasNotConsumed;
                    }
                iSlider->SetMinimumTextL( information );
                DrawNow();
                // Increments the index of text which is displaying.
                // If number of index is more than defined maximum number,
                // sets minimum number to number of index.
                if ( ++iCurrentLabel > EAknExSliderChangeLabel4 )
                    {
                    iCurrentLabel = EAknExSliderChangeLabel1;
                    }
                }
            break;
            }
        case EAknExSliderCmdSetMaximum:
            {
            // If the screen which is displayed is maximum screen
            // changes the maximum text of slider control.
            if ( charCode == AKNEXSLIDER_MAXIMUM_CHANGE_KEY ||
                charCode == AKNEXSLIDER_MAXIMUM_CHANGE_KEY2 )
                {
                response = EKeyWasConsumed;
                
                // Makes the text which is displayed and sets this to label.
                switch ( iCurrentLabel )
                    {
                    case EAknExSliderChangeLabel1:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_MAX2 );
                        break;
                    case EAknExSliderChangeLabel2:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_HIGH1 );
                        break;
                    case EAknExSliderChangeLabel3:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_HIGH2 );
                        break;
                    case EAknExSliderChangeLabel4:
                        iCoeEnv->ReadResource( information,
                                               R_AKNEXSLIDER_LABEL_MAX1 );
                        break;
                    default:
                        return EKeyWasNotConsumed;
                    }
                iSlider->SetMaximumTextL( information );
                DrawNow();
                // Increments the index of text which is displaying.
                // If number of index is more than defined maximum number,
                // sets minimum number to number of index.
                if ( ++iCurrentLabel > EAknExSliderChangeLabel4 )
                    {
                    iCurrentLabel = EAknExSliderChangeLabel1;
                    }
                }
            break;
            }
        case EAknExSliderCmdSetRange:
            {
            if ( charCode == AKNEXSLIDER_RANGE_CHANGE_KEY ||
                charCode == AKNEXSLIDER_RANGE_CHANGE_KEY2 )
                {
                response = EKeyWasConsumed;
                
                iCurrentLabel += KSliderChangeRangeValue;
                if ( iCurrentLabel > KSliderMaxChangeRange )
                    {
                    iCurrentLabel = KSliderClearValue;
                    }
                // If current value of slider does not range from minimum value
                // to maximum value, corrects the current value.
                if ( iSlider->Value() > ( KSliderBaseMaxValue - iCurrentLabel )
                    )
                    {
                    iSlider->SetValueL( KSliderBaseMaxValue - iCurrentLabel );
                    }
                else if ( iSlider->Value() <
                          ( KSliderBaseMinValue + iCurrentLabel ) )
                    {
                    iSlider->SetValueL( KSliderBaseMinValue + iCurrentLabel );
                    }
                // Sets minimum and maximum values.
                iSlider->SetRange( KSliderBaseMinValue + iCurrentLabel,
                                   KSliderBaseMaxValue - iCurrentLabel );
                ChangeLabelL();
                }
            break;
            }
        case EAknExSliderCmdReturn:
            {
            if ( charCode == AKNEXSLIDER_VALUE_CHANGE_KEY ||
                charCode == AKNEXSLIDER_VALUE_CHANGE_KEY2 )
                {
                response = EKeyWasConsumed;
                
                ChangeLabelL();
                }
            break;
            }
        case EAknExSliderCmdSetValue:
            {
            if ( charCode == AKNEXSLIDER_VALUE_CHANGE_KEY ||
                charCode == AKNEXSLIDER_VALUE_CHANGE_KEY2 )
                {
                response = EKeyWasConsumed;
                
                TInt64 randSeed;
                TTime time;
                TInt randValue( KSliderClearValue );

                // Sets random numver to value of slider control.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -