multiview4.cpp
来自「《UIQ 3 The Complete Guide》书的源代码」· C++ 代码 · 共 627 行 · 第 1/2 页
CPP
627 行
//
// MultiView4.cpp - Multi-views example
//
// Copyright (C) UIQ Technology AB, 2007
//
// This material is provided "as is" without any warranty to its performance or functionality.
// In no event shall UIQ Technology be liable for any damages whatsoever arising out of the
// use or inabilty to use this material.
//
#include "MultiView4.h"
#include "MultiView4.hrh"
#include <MultiView4.rsg>
#include <QikViewBase.h>
#include <QikCommand.h>
#include <QikListBoxModel.h>
#include <QikListBox.h>
#include <MQikListBoxData.h>
#include <QikSlider.h>
#include <QikNumberEditor.h>
#include <QikSaveChangesDlg.h>
#include <QikViewDialog.h>
#include <eikstart.h>
#include <eikchlst.h>
#include <eikchkbx.h>
#include <eikedwin.h>
//////////////////////////////////////////////////////////////////////////////
// The application Uid here MUST match UID3 defined in the MMP file
// This is a development UID and must NOT be used in production type software
const TUid KAppSpecificUid={0xEDEAD00B};
// internal secondary view id, must be unique amongst this applications views
const TUid KUidListView={0x00000001};
const TUid KUidDetailsView={0x00000002};
// views within applications are fully identified by the app Uid and secondary view id
#define KViewIdListView TVwsViewId(KAppSpecificUid,KUidListView)
#define KViewIdDetailsView TVwsViewId(KAppSpecificUid,KUidDetailsView)
//////////////////////////////////////////////////////////////////////////////////
const TInt KMaxListItemText=32; // we support a max of 32 chars for each text item to be displayed
enum TAppEntityState
{
EAppStateWinners, // these match the text found in the choice list
EAppStateRunnersUp, // resource r_detailspage_choicelist_array
EAppStateKnockedOut,
EAppStateStillInTournament,
};
class TAppSpecificEntity
{
public:
TAppEntityState iState; // one of the available enum values
TInt iPoints; // in range 0-6
TInt iOddsOfWinning; // in range 0->100
TBuf<KMaxListItemText> iName;
};
//////////////////////////////////////////////////////////////////////////////////
const TInt KMultiView4Items=7;
class CAppEngine : public CBase
{
protected:
public:
CAppEngine(const TInt aZoomLevel);
void ConstructL(CEikonEnv* aEnv);
TInt ListViewZoomState() const;
TInt ListViewIndex() const;
void SetListViewIndex(const TInt aIndex);
TInt ListItemCount() const;
const TAppSpecificEntity& ListItemAt(const TInt aIndex) const;
const TAppSpecificEntity& CurrentListItem() const;
void UpdateCurrentListItem(const TAppSpecificEntity& aEntity);
protected:
// The 'engine' stores 'UI' information since UI components come and go, yet we want to preserve
// UI configuration information between invocations of the view.
TInt iZoomLevel;
// the engine stores which item from the list view was selected
TInt iListViewIndex;
// the list of items we can display and manipulate
// we have chosen to have a simple flat array of items to reduce complexity in this app
TAppSpecificEntity iListViewContent[KMultiView4Items];
};
CAppEngine::CAppEngine(const TInt aZoomLevel) :
iZoomLevel(aZoomLevel)
{}
void CAppEngine::ConstructL(CEikonEnv* aEnv)
//
// We are a single line list box. Add each of the items to the listbox for display
//
{
// setup some initial data for each of our entries
for (TInt i=0;i<KMultiView4Items;i++)
{
iListViewContent[i].iState=EAppStateStillInTournament;
iListViewContent[i].iPoints=0; // in range 0-6
iListViewContent[i].iOddsOfWinning=50; // in range 0->100
aEnv->ReadResourceL(iListViewContent[i].iName,R_STR_LIST_CONTENT_1+i);
}
}
TInt CAppEngine::ListViewZoomState() const
// Report the currently stored zoom state
{
return(iZoomLevel);
}
TInt CAppEngine::ListViewIndex() const
// Report the currently indicated list view item index
{
return(iListViewIndex);
}
void CAppEngine::SetListViewIndex(const TInt aIndex)
// Store the currently indicated list view item index
{
iListViewIndex=aIndex;
}
TInt CAppEngine::ListItemCount() const
// Report the number of items within the list
{
return(KMultiView4Items);
}
const TAppSpecificEntity& CAppEngine::ListItemAt(const TInt aIndex) const
// Return a reference to the 'n'th item in the list
{
return(iListViewContent[aIndex]);
}
const TAppSpecificEntity& CAppEngine::CurrentListItem() const
// Return a reference to the current item
{
return(ListItemAt(iListViewIndex));
}
void CAppEngine::UpdateCurrentListItem(const TAppSpecificEntity& aEntity)
// Update the current entity to contain the new values
{
iListViewContent[iListViewIndex]=aEntity;
}
//////////////////////////////////////////////////////////////////////////////////
class CAppSpecificDetailsView : public CQikViewBase
{
protected:
// from CQikViewBase
TVwsViewId ViewId() const;
void HandleCommandL(CQikCommand& aCommand);
void ViewConstructL();
void ViewDeactivated();
void ViewActivatedL(const TVwsViewId& aPrevViewId,const TUid aCustomMessageId,const TDesC8& aCustomMessage);
void SaveL();
// new methods
TBool DetailsHaveChanged();
public:
// new methods
CAppSpecificDetailsView(CAppSpecificUi& aAppUi,CAppEngine* aEngine);
protected:
CAppEngine* iEngine;
};
CAppSpecificDetailsView::CAppSpecificDetailsView(CAppSpecificUi& aAppUi,CAppEngine* aEngine) :
CQikViewBase(aAppUi,KViewIdListView),iEngine(aEngine)
{}
TVwsViewId CAppSpecificDetailsView::ViewId() const
{
return(KViewIdDetailsView);
}
TBool CAppSpecificDetailsView::DetailsHaveChanged()
// Return ETrue if any of the current details have changed, EFalse otherwise
{
const TAppSpecificEntity& entry=iEngine->CurrentListItem();
CEikChoiceList* cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList1);
if (entry.iState!=(TAppEntityState)cl->CurrentItem())
return(ETrue);
CQikNumberEditor* numEd=LocateControlByUniqueHandle<CQikNumberEditor>(EAppEdwin1);
if (entry.iPoints!=numEd->Value())
return(ETrue);
CQikSlider* sl=LocateControlByUniqueHandle<CQikSlider>(EAppSlider1);
if (entry.iOddsOfWinning!=sl->CurrentValue())
return(ETrue);
return(EFalse);
}
void CAppSpecificDetailsView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
{
switch (aCommand.Id())
{
case EAppCmdAbout:
break;
case EAppCmdSave:
ActivatePreviousViewL(ESave);
break;
case EQikCmdGoBack:
if (DetailsHaveChanged())
{
CQikSaveChangesDialog::TExitOption ret=CQikSaveChangesDialog::RunDlgLD();
if (ret==CQikSaveChangesDialog::EShut)
break; // user no longer wants to go back, remain here
if (ret==CQikSaveChangesDialog::ESave)
{ // user wants to save changes and go back
ActivatePreviousViewL(ESave);
break;
}
// user wants to abandon changes and go back
}
// FALL through to default:
default: // e.g. the back button...
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
void CAppSpecificDetailsView::ViewConstructL()
{
ViewConstructFromResourceL(R_DETAILS_VIEW_CONFIGURATIONS);
TBuf<64>bb;
iEikonEnv->ReadResourceL(bb,R_STR_DETAILS_TITLE);
ViewContext()->AddTextL(1,bb); // without this ChangeTextL() will panic !!
}
void CAppSpecificDetailsView::SaveL()
//
// We are being asked to save the changes made withing the UI components before this view is
// deactivated
//
{
// seed any update with the full content, incl those field we dont edit in this view
TAppSpecificEntity entry(iEngine->CurrentListItem());
// update the state, points and oddsOfWinning values
CEikChoiceList* cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList1);
entry.iState=(TAppEntityState)cl->CurrentItem();
CQikNumberEditor* numEd=LocateControlByUniqueHandle<CQikNumberEditor>(EAppEdwin1);
entry.iPoints=numEd->Value();
CQikSlider* sl=LocateControlByUniqueHandle<CQikSlider>(EAppSlider1);
entry.iOddsOfWinning=sl->CurrentValue();
// finally update the current item within engine with new content
iEngine->UpdateCurrentListItem(entry);
}
void CAppSpecificDetailsView::ViewDeactivated()
{
}
void CAppSpecificDetailsView::ViewActivatedL(
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
const TAppSpecificEntity& entry=iEngine->CurrentListItem();
// now set up the UI components as defined by our current settings
CEikChoiceList* cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList1);
cl->SetCurrentItem(entry.iState);
CQikNumberEditor* numEd=LocateControlByUniqueHandle<CQikNumberEditor>(EAppEdwin1);
numEd->SetValueL(entry.iPoints);
CQikSlider* sl=LocateControlByUniqueHandle<CQikSlider>(EAppSlider1);
sl->SetValue(entry.iOddsOfWinning);
// display some context information for the details...
ViewContext()->ChangeTextL(1,entry.iName);
}
//////////////////////////////////////////////////////////////////////////////
// A view being used more like a dialog
class CDetailsAsAViewDialog : public CQikViewDialog
{
protected:
// from CQikViewBase
void HandleCommandL(CQikCommand& aCommand);
void ViewActivatedL(const TVwsViewId& aPrevViewId,const TUid aCustomMessageId,const TDesC8& aCustomMessage);
void ViewConstructL();
void SaveL();
public:
TInt RunDialogLD(CAppEngine* aEngine);
protected:
CAppEngine* iEngine;
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?