camerauis/cameraxui/cxengine/src/cxezoomcontrolsymbian.cpp
changeset 19 d9aefe59d544
child 21 fa6d9f75d6a6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cxezoomcontrolsymbian.h"
       
    19 #include "cxecameradevicecontrol.h"
       
    20 #include "cxefeaturemanager.h"
       
    21 #include "cxesettings.h"
       
    22 #include "cxutils.h"
       
    23 #include "cxenamespace.h"
       
    24 #include "cxestate.h"
       
    25 
       
    26 const int NOT_DEFINED = -1;
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CxeZoomControlSymbian::CxeZoomControlSymbian
       
    30 //
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CxeZoomControlSymbian::CxeZoomControlSymbian(CxeCameraDevice &cameraDevice,
       
    34                                              CxeCameraDeviceControl &cameraDeviceControl,
       
    35                                              CxeSettings &settings,
       
    36                                              CxeFeatureManager &featureManager) :
       
    37     CxeStateMachine("CxeZoomControlSymbian"),
       
    38     mCameraDevice(cameraDevice),
       
    39     mCameraDeviceControl(cameraDeviceControl),
       
    40     mSettings(settings)
       
    41 {
       
    42     CX_DEBUG_ENTER_FUNCTION();
       
    43 
       
    44     qRegisterMetaType<CxeZoomControl::State> ();
       
    45 
       
    46     // Initialize states and member variables
       
    47     initializeStates();
       
    48 
       
    49     // getting still max zoom limits from feature manager
       
    50     featureManager.configuredValues(CxeRuntimeKeys::STILL_MAX_ZOOM_LIMITS, mStillMaxZoomLimits);
       
    51     featureManager.configuredValues(CxeRuntimeKeys::VIDEO_MAX_ZOOM_LIMITS, mVideoMaxZoomLimits);
       
    52 
       
    53     connect(&mCameraDevice,
       
    54             SIGNAL(prepareForCameraDelete()),
       
    55             this,
       
    56             SLOT(reset()));
       
    57 
       
    58     // enabling setting value change call backs
       
    59     connect(&mSettings,
       
    60             SIGNAL(settingValueChanged(const QString&,QVariant)),
       
    61             this,
       
    62             SLOT(handleSettingValueChanged(const QString&,QVariant)));
       
    63 
       
    64     init();
       
    65 
       
    66     CX_DEBUG_EXIT_FUNCTION();
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CxeZoomControlSymbian::~CxeZoomControlSymbian
       
    71 //
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CxeZoomControlSymbian::~CxeZoomControlSymbian()
       
    75 {
       
    76     CX_DEBUG_ENTER_FUNCTION();
       
    77 
       
    78     // clean up
       
    79     mDigitalZoomValues.Close();
       
    80 
       
    81     CX_DEBUG_EXIT_FUNCTION();
       
    82 }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CxeZoomControlSymbian::min
       
    86 // Get the minimum zoom index
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 int CxeZoomControlSymbian::min() const
       
    90 {
       
    91     return mMinZoomLevel;
       
    92 }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CxeZoomControlSymbian::max
       
    96 // Get the maximum zoom index
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 int CxeZoomControlSymbian::max() const
       
   100 {
       
   101     return mMaxZoomLevel;
       
   102 }
       
   103 
       
   104 void CxeZoomControlSymbian::init()
       
   105 {
       
   106     CX_DEBUG_ENTER_FUNCTION();
       
   107 
       
   108     // Initialize the variables
       
   109     mMinZoomLevel = 0;
       
   110     mMaxZoomLevel = 0;
       
   111     mCurrentZoomLevel = 0;
       
   112     mDigitalZoomValues.Close();
       
   113 
       
   114     setState(Idle);
       
   115 
       
   116     CX_DEBUG_EXIT_FUNCTION();
       
   117 }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CxeZoomControlSymbian::reset
       
   121 // Re-initializes the zoom control
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CxeZoomControlSymbian::reset()
       
   125 {
       
   126     CX_DEBUG_ENTER_FUNCTION();
       
   127 
       
   128     init();
       
   129     emit zoomLevelChanged(mCurrentZoomLevel);
       
   130 
       
   131     CX_DEBUG_EXIT_FUNCTION();
       
   132 }
       
   133 
       
   134 
       
   135 
       
   136 /**
       
   137  * Settings changed, needs updated
       
   138  */
       
   139 void CxeZoomControlSymbian::handleSettingValueChanged(const QString& settingId, QVariant /*newValue*/)
       
   140 {
       
   141     CX_DEBUG_ENTER_FUNCTION();
       
   142 
       
   143     if (settingId == CxeSettingIds::IMAGE_QUALITY ||
       
   144         settingId == CxeSettingIds::VIDEO_QUALITY) {
       
   145         reset();
       
   146     } else {
       
   147         // do nothing
       
   148     }
       
   149     CX_DEBUG_EXIT_FUNCTION();
       
   150 }
       
   151 
       
   152 
       
   153 /*!
       
   154 * slot to prepare zoom control for still mode
       
   155 */
       
   156 void CxeZoomControlSymbian::prepareZoomForStill(int ecamStillResolutionIndex)
       
   157 {
       
   158     CX_DEBUG_ENTER_FUNCTION();
       
   159 
       
   160     if (mCameraDeviceControl.state() == CxeCameraDeviceControl::Ready) {
       
   161         init();
       
   162         // For image mode
       
   163         CCamera::TFormat format = CCamera::EFormatExif;
       
   164         TBool isInfluencePossible = EFalse;
       
   165         int error = KErrNone;
       
   166 
       
   167         // Get the zoom steps for image mode
       
   168         TRAP(error, mCameraDevice.advancedSettings()->GetDigitalZoomStepsForStillL (
       
   169                             mDigitalZoomValues,
       
   170                             mDigitalZoomValueInfo,
       
   171                             ecamStillResolutionIndex,
       
   172                             format,
       
   173                             isInfluencePossible));
       
   174 
       
   175         int imageQualityIndex;
       
   176         CxeError::Id cxErr = mSettings.get(CxeSettingIds::IMAGE_QUALITY, imageQualityIndex);
       
   177         if (cxErr == CxeError::None && mStillMaxZoomLimits.count() > 0) {
       
   178             // fetching the zoom limit based on the image quality
       
   179             mMaxZoomLevel = mStillMaxZoomLimits[imageQualityIndex];
       
   180         } else {
       
   181             mMaxZoomLevel = NOT_DEFINED;
       
   182         }
       
   183 
       
   184         finalizeZoomPreparation(error);
       
   185     }
       
   186 
       
   187     CX_DEBUG_EXIT_FUNCTION();
       
   188 }
       
   189 
       
   190 
       
   191 /*!
       
   192 * slot to prepare zoom control for video mode
       
   193 */
       
   194 void CxeZoomControlSymbian::prepareZoomForVideo()
       
   195 {
       
   196     CX_DEBUG_ENTER_FUNCTION();
       
   197 
       
   198     if (mCameraDeviceControl.state() == CxeCameraDeviceControl::Ready) {
       
   199         init();
       
   200         // if CxeCameraDeviceControl is ready, this pointer is valid
       
   201         CX_ASSERT_ALWAYS(mCameraDevice.advancedSettings())
       
   202         int error = KErrNone;
       
   203         TRAP(error,
       
   204                 mCameraDevice.advancedSettings()->GetDigitalZoomStepsL(mDigitalZoomValues, mDigitalZoomValueInfo);
       
   205             );
       
   206 
       
   207         if (mVideoMaxZoomLimits.count() > 0) {
       
   208             // fetching the zoom limit based on the video quality
       
   209             mMaxZoomLevel = mVideoMaxZoomLimits[0];
       
   210         } else {
       
   211             mMaxZoomLevel = NOT_DEFINED;
       
   212         }
       
   213 
       
   214         finalizeZoomPreparation(error);
       
   215     }
       
   216 
       
   217 
       
   218     CX_DEBUG_EXIT_FUNCTION();
       
   219 }
       
   220 
       
   221 
       
   222 
       
   223 /**
       
   224 * Completes zoom control preparation.
       
   225 */
       
   226 void CxeZoomControlSymbian::finalizeZoomPreparation(int error)
       
   227 {
       
   228     CX_DEBUG_ENTER_FUNCTION();
       
   229 
       
   230     CX_DEBUG(("Num digital zoom steps: %d", mDigitalZoomValues.Count()));
       
   231     CX_DEBUG(("Maximum zoom limit: %d", mMaxZoomLevel));
       
   232 
       
   233     if (!error) {
       
   234         // Note that this is called only after setting the resolution.
       
   235         TCameraInfo cameraInfo;
       
   236         mCameraDevice.camera()->CameraInfo(cameraInfo);
       
   237         CX_DEBUG(("cameraInfo.iMinZoom: %d, cameraInfo.iMaxDigitalZoom: %d, cameraInfo.iMaxZoom: %d",
       
   238                             cameraInfo.iMinZoom, cameraInfo.iMaxDigitalZoom, cameraInfo.iMaxZoom ));
       
   239 
       
   240         CX_DEBUG(("cameraInfo.iMaxDigitalZoomFactor: %d", cameraInfo.iMaxDigitalZoomFactor));
       
   241 
       
   242         mMinZoomLevel = cameraInfo.iMinZoom;
       
   243         if ( (mMaxZoomLevel == NOT_DEFINED) || mMaxZoomLevel > cameraInfo.iMaxDigitalZoom) {
       
   244             CX_DEBUG(("Fetching maximum zoom limit value from ecam"));
       
   245             mMaxZoomLevel = cameraInfo.iMaxDigitalZoom;
       
   246         }
       
   247         // change the state, since zoom is now ready
       
   248         setState(Ready, KErrNone);
       
   249 
       
   250         mCameraDevice.advancedSettings()->SetDigitalZoom(mDigitalZoomValues[mCurrentZoomLevel]);
       
   251 
       
   252         // emit the zoom changed signal so that clients can do any updates if necessary.
       
   253         emit zoomLevelChanged(mCurrentZoomLevel);
       
   254     }
       
   255 
       
   256     CX_DEBUG_EXIT_FUNCTION();
       
   257 }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CxeZoomControlSymbian::zoomTo
       
   261 // Zooms to the level specified in the parameter.
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CxeZoomControlSymbian::zoomTo(int value)
       
   265 {
       
   266     CX_DEBUG_ENTER_FUNCTION();
       
   267 
       
   268     CX_DEBUG(("Zoom to: %d, current zoom: %d", value, mCurrentZoomLevel));
       
   269 
       
   270     // If not currently zooming and value falls between min & max
       
   271     // then zoom to the passed level. Also there's no need to zoom if new zoom
       
   272     // level is same as the current.
       
   273     if (state() == CxeZoomControl::Ready && (value <= mMaxZoomLevel)
       
   274             && (value >= mMinZoomLevel) && (mCurrentZoomLevel != value)) {
       
   275 
       
   276         // Set the appropriate zooming state
       
   277         if (value < mCurrentZoomLevel) {
       
   278             setState(CxeZoomControl::ZoomingOut);
       
   279         } else {
       
   280             setState(CxeZoomControl::ZoomingIn);
       
   281         }
       
   282 
       
   283         // Could also check the number of values in the array to avoid out of bounds indexing,
       
   284         // though this is done in alternate way by the min and max limits.
       
   285         mCameraDevice.advancedSettings()->SetDigitalZoom(mDigitalZoomValues[value]);
       
   286         mCurrentZoomLevel = value;
       
   287 
       
   288         //! @todo: Wait for zoom callback: ECamEventZoomStateChanged ?
       
   289         // set the state to idle.
       
   290         setState(CxeZoomControl::Ready);
       
   291 
       
   292         // Emit the zoom level change signal
       
   293         emit zoomLevelChanged(mCurrentZoomLevel);
       
   294     }
       
   295 
       
   296     CX_DEBUG_EXIT_FUNCTION();
       
   297 }
       
   298 
       
   299 CxeZoomControl::State CxeZoomControlSymbian::state() const
       
   300 {
       
   301     return static_cast<State> (stateId());
       
   302 }
       
   303 
       
   304 void CxeZoomControlSymbian::handleStateChanged(int newStateId,
       
   305                                                CxeError::Id error)
       
   306 {
       
   307     emit stateChanged(static_cast<State> (newStateId), error);
       
   308 }
       
   309 
       
   310 void CxeZoomControlSymbian::initializeStates()
       
   311 {
       
   312     // addState( id, name, allowed next states )
       
   313     addState(new CxeState(Idle, "Idle", Ready));
       
   314     addState(new CxeState(ZoomingIn, "ZoomingIn", Ready | ZoomingOut | Idle));
       
   315     addState(new CxeState(ZoomingOut, "ZoomingOut", Ready | ZoomingIn | Idle));
       
   316     addState(new CxeState(Ready, "Ready", Idle | ZoomingOut | ZoomingIn));
       
   317 
       
   318     setInitialState(Idle);
       
   319 }