camerauis/cameraxui/cxui/src/cxuiscenemodeview.cpp
changeset 21 fa6d9f75d6a6
child 24 2094593137f5
equal deleted inserted replaced
19:d9aefe59d544 21:fa6d9f75d6a6
       
     1 /*
       
     2 * Copyright (c) 2010 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 #include <hbframeitem.h>
       
    18 
       
    19 #include "cxenamespace.h"
       
    20 #include "cxesettings.h"
       
    21 #include "cxuiscenemodeview.h"
       
    22 #include "cxuienums.h"
       
    23 #include "cxutils.h"
       
    24 #include "cxuicapturekeyhandler.h"
       
    25 #include "cxuisettingsinfo.h"
       
    26 #include "cxeviewfindercontrol.h"
       
    27 #include "cxecameradevicecontrol.h"
       
    28 #include "cxuidocumentloader.h"
       
    29 
       
    30 using namespace Cxe;
       
    31 using namespace CxUi;
       
    32 using namespace CxUiLayout;
       
    33 using namespace CxUiSettings;
       
    34 using namespace CxeSettingIds;
       
    35 
       
    36 const int CXUI_SCENES_TRANSITION_TIME = 350; // 350 milliseconds
       
    37 const int CXUI_SCENES_CAMERA_TIMEOUT = 60000; // 60 seconds for the camera hw release timeout
       
    38 const QString CXUI_SCENES_AUTOMATIC_IMAGE=":/camerax/scene_automatic.png";
       
    39 const QString CXUI_SCENES_LANDSCAPE_IMAGE=":/camerax/scene_landscape.png";
       
    40 const QString CXUI_SCENES_CLOSEUP_IMAGE=":/camerax/scene_close-up.png";
       
    41 const QString CXUI_SCENES_PORTRAIT_IMAGE=":/camerax/scene_portrait.png";
       
    42 const QString CXUI_SCENES_SPORT_IMAGE=":/camerax/scene_sport.png";
       
    43 const QString CXUI_SCENES_NIGHT_IMAGE=":/camerax/scene_night.png";
       
    44 const QString CXUI_SCENES_NIGHT_PORTRAIT_IMAGE=":/camerax/scene_nightportrait.png";
       
    45 const QString CXUI_SCENES_LOW_LIGHT_IMAGE=":/camerax/scene_lowlight.png";
       
    46 
       
    47 
       
    48 /*!
       
    49 * Constructor
       
    50 */
       
    51 CxuiSceneModeView::CxuiSceneModeView(QGraphicsItem *parent) :
       
    52     HbView(parent),
       
    53     mMainWindow(NULL),
       
    54     mSettingsInfo(NULL),
       
    55     mEngine(NULL),
       
    56     mDocumentLoader(NULL),
       
    57     mCaptureKeyHandler(NULL),
       
    58 	mScenesBackground(NULL)
       
    59 {
       
    60     CX_DEBUG_IN_FUNCTION();
       
    61 }
       
    62 
       
    63 /*!
       
    64 * Destructor
       
    65 */
       
    66 CxuiSceneModeView::~CxuiSceneModeView()
       
    67 {
       
    68     CX_DEBUG_ENTER_FUNCTION();
       
    69     CX_DEBUG_EXIT_FUNCTION();
       
    70 }
       
    71 
       
    72 /*!
       
    73 * Construct-method handles initialisation tasks for this class. Needs to be called
       
    74 * before the instance of this class is used.
       
    75 * @param mainwindow
       
    76 * @param engine
       
    77 * @param documentLoader
       
    78 * @param keyHandler
       
    79 */
       
    80 void CxuiSceneModeView::construct(HbMainWindow *mainwindow,
       
    81                                CxeEngine *engine,
       
    82                                CxuiDocumentLoader *documentLoader,
       
    83                                CxuiCaptureKeyHandler *keyHandler)
       
    84 {
       
    85     CX_DEBUG_ENTER_FUNCTION();
       
    86 
       
    87     mMainWindow = mainwindow;
       
    88     mDocumentLoader = documentLoader;
       
    89     mCaptureKeyHandler = keyHandler;
       
    90     mEngine = engine;
       
    91     mSettingsInfo = new CxuiSettingsInfo(mEngine);
       
    92     setContentFullScreen(true);
       
    93     loadDefaultWidgets();
       
    94 
       
    95     mCameraReleaseTimer.setInterval(CXUI_SCENES_CAMERA_TIMEOUT);    
       
    96     connect(&mCameraReleaseTimer, SIGNAL(timeout()), this, SLOT(releaseCameraHw()), Qt::UniqueConnection);
       
    97 
       
    98     CX_DEBUG_EXIT_FUNCTION();
       
    99 }
       
   100 
       
   101 /*!
       
   102 * Load widgets from DocML.
       
   103 */
       
   104 void CxuiSceneModeView::loadDefaultWidgets()
       
   105 {
       
   106     CX_DEBUG_ENTER_FUNCTION();
       
   107     CX_DEBUG_ASSERT(mDocumentLoader);
       
   108 
       
   109     QGraphicsWidget *widget = NULL;
       
   110 
       
   111     widget = mDocumentLoader->findWidget(SCENE_VIEW_CONTAINER);
       
   112     mScenesContainer = qobject_cast<HbWidget *> (widget);
       
   113 
       
   114     //Now let's retreive the pointer to icon widget
       
   115     widget = mDocumentLoader->findWidget(SCENE_VIEW_BG_IMAGE);
       
   116     mScenesBackground = qobject_cast<HbLabel *> (widget);
       
   117 
       
   118     widget = mDocumentLoader->findWidget(SCENE_VIEW_BG_IMAGE2);
       
   119     mScenesBackground2 = qobject_cast<HbLabel *> (widget);
       
   120 
       
   121     //Assuming that the automatic scene mode is always the default one
       
   122     CX_DEBUG(("CxuiSceneModeView::loadDefaultWidgets -> Now setting default image"));
       
   123     mScenesBackground->setIcon(HbIcon(CXUI_SCENES_AUTOMATIC_IMAGE));
       
   124 
       
   125     widget = mDocumentLoader->findWidget(SCENE_VIEW_RADIOBUTTONS);
       
   126     mScenesList = qobject_cast<CxuiSettingRadioButtonList *> (widget);
       
   127 
       
   128     mTransitionAnimation = new QPropertyAnimation(mScenesBackground2, "opacity");
       
   129     mTransitionAnimation->setDuration(CXUI_SCENES_TRANSITION_TIME);
       
   130 
       
   131     createWidgetBackgroundGraphic(mScenesContainer, TRANSPARENT_BACKGROUND_GRAPHIC);
       
   132 
       
   133     connectSignals();
       
   134 
       
   135     CX_DEBUG_EXIT_FUNCTION();
       
   136 }
       
   137 
       
   138 /*!
       
   139 * Helper function to connect signals needed in this class.
       
   140 */
       
   141 void CxuiSceneModeView::connectSignals()
       
   142 {
       
   143     connect(mScenesList, SIGNAL(itemSelected(int)), this, SLOT(handleSceneRadiobuttonPress(int)));
       
   144     connect(mTransitionAnimation, SIGNAL(finished()), this, SLOT(finishScenesTransition()));
       
   145 }
       
   146 
       
   147 /*!
       
   148 * Function can be used to create a graphics item and setting it as a background
       
   149 * item for HbWidget. graphicName refers to system wide graphic name. Given graphic
       
   150 * can consist of one, three or nine pieces. Nine piece graphics are used by default.
       
   151 * See HbFrameDrawer documentation for graphic naming.
       
   152 */
       
   153 void CxuiSceneModeView::createWidgetBackgroundGraphic(HbWidget *widget,
       
   154                                                        const QString &graphicName,
       
   155                                                        HbFrameDrawer::FrameType frameType)
       
   156 {
       
   157     if (widget) {
       
   158         HbFrameDrawer *drawer = new HbFrameDrawer(graphicName, frameType);
       
   159 
       
   160         if (drawer) {
       
   161             HbFrameItem *backgroundItem = new HbFrameItem(drawer, widget);
       
   162             if (backgroundItem) {
       
   163                 // set item to fill the whole widget
       
   164                 backgroundItem->setGeometry(QRectF(QPointF(0, 0), widget->size()));
       
   165                 backgroundItem->setZValue(0);
       
   166                 widget->setBackgroundItem(backgroundItem);
       
   167             }
       
   168         }
       
   169     }
       
   170 }
       
   171 
       
   172 /*!
       
   173 * This public method assumes that the view is already properly constructed
       
   174 */
       
   175 void CxuiSceneModeView::loadBackgroundImages()
       
   176 {
       
   177      CX_DEBUG_ENTER_FUNCTION();
       
   178     RadioButtonListParams data;
       
   179     if (mEngine->mode() == Cxe::ImageMode) {
       
   180         mSettingsInfo->getSettingsContent(CxeSettingIds::IMAGE_SCENE, data);
       
   181     } else {
       
   182         mSettingsInfo->getSettingsContent(CxeSettingIds::VIDEO_SCENE, data);
       
   183     }
       
   184     mSettingPairList = data.mSettingPairList;
       
   185     mScenesList->init(&data);
       
   186 
       
   187     if (mScenesBackground) {
       
   188         QString sceneId;
       
   189         mEngine->settings().get(data.mSettingId, sceneId);
       
   190         mScenesBackground->setIcon(HbIcon(backgroundForScene(sceneId)));
       
   191     } else {
       
   192         //First time displaying a list
       
   193         //Assuming that the automatic scene mode is always the default one and is on top of the list
       
   194         mScenesList->setSelected(0);
       
   195     }
       
   196     CX_DEBUG_EXIT_FUNCTION();
       
   197 }
       
   198 
       
   199 /*!
       
   200 * Handle selecting value in scene list.
       
   201 */
       
   202 void CxuiSceneModeView::handleSceneRadiobuttonPress(int index)
       
   203 {
       
   204     CX_DEBUG_ENTER_FUNCTION();
       
   205 
       
   206     CxUiSettings::SettingItem item = mSettingPairList.at(index);
       
   207     QString sceneId = item.mValue.toString();
       
   208     mScenesBackground2->setIcon(HbIcon(backgroundForScene(sceneId)));
       
   209     startBackgroundTransition();
       
   210     CX_DEBUG_EXIT_FUNCTION();
       
   211 }
       
   212 
       
   213 
       
   214 /*!
       
   215 * Helper method for getting the background graphic name
       
   216 * for each of the scenes.
       
   217 */
       
   218 QString CxuiSceneModeView::backgroundForScene(const QString& sceneId)
       
   219 {
       
   220     //!@todo: This mapping should be added to the setting xml.
       
   221     if (sceneId == CxeSettingIds::IMAGE_SCENE_AUTO) {
       
   222         return CXUI_SCENES_AUTOMATIC_IMAGE;
       
   223     } else if (sceneId == CxeSettingIds::IMAGE_SCENE_PORTRAIT) {
       
   224         return CXUI_SCENES_PORTRAIT_IMAGE;
       
   225     } else if (sceneId == CxeSettingIds::IMAGE_SCENE_SCENERY) {
       
   226         return CXUI_SCENES_LANDSCAPE_IMAGE;
       
   227     } else if (sceneId == CxeSettingIds::IMAGE_SCENE_MACRO) {
       
   228         return CXUI_SCENES_CLOSEUP_IMAGE;
       
   229     } else if (sceneId == CxeSettingIds::IMAGE_SCENE_SPORTS) {
       
   230         return CXUI_SCENES_SPORT_IMAGE;
       
   231     } else if (sceneId == CxeSettingIds::IMAGE_SCENE_NIGHT) {
       
   232         return CXUI_SCENES_NIGHT_IMAGE;
       
   233     } else if (sceneId == CxeSettingIds::IMAGE_SCENE_NIGHTPORTRAIT) {
       
   234         return CXUI_SCENES_NIGHT_PORTRAIT_IMAGE;
       
   235     } else if (sceneId == CxeSettingIds::VIDEO_SCENE_AUTO) {
       
   236         return CXUI_SCENES_AUTOMATIC_IMAGE;
       
   237     } else if (sceneId == CxeSettingIds::VIDEO_SCENE_LOWLIGHT) {
       
   238         return CXUI_SCENES_LOW_LIGHT_IMAGE;
       
   239     } else if (sceneId == CxeSettingIds::VIDEO_SCENE_NIGHT) {
       
   240         return CXUI_SCENES_NIGHT_IMAGE;
       
   241     } else {
       
   242         return "";
       
   243     }
       
   244 
       
   245 }
       
   246 
       
   247 /*!
       
   248 * Start animation for changing the scene background graphic.
       
   249 */
       
   250 void CxuiSceneModeView::startBackgroundTransition()
       
   251 {
       
   252     mTransitionAnimation->setStartValue(0.0);
       
   253     mTransitionAnimation->setEndValue(1.0);
       
   254     mTransitionAnimation->start();
       
   255 
       
   256 }
       
   257 
       
   258 /*!
       
   259 * Handle scene background graphic animation finishing.
       
   260 */
       
   261 void CxuiSceneModeView::finishScenesTransition()
       
   262 {
       
   263     mScenesBackground->setIcon(mScenesBackground2->icon());
       
   264     mScenesBackground2->setOpacity(0);
       
   265     mScenesBackground2->setIcon(HbIcon());
       
   266 }
       
   267 
       
   268 /*!
       
   269 * Handle press of ok button.
       
   270 */
       
   271 void CxuiSceneModeView::handleOkButtonPress()
       
   272 {
       
   273     CX_DEBUG_ENTER_FUNCTION();
       
   274     closeView();
       
   275     CX_DEBUG_EXIT_FUNCTION();
       
   276 }
       
   277 
       
   278 /*!
       
   279 * Handle press of cancel button.
       
   280 */
       
   281 void CxuiSceneModeView::handleCancelButtonPress()
       
   282 {
       
   283     CX_DEBUG_ENTER_FUNCTION();
       
   284     closeView();
       
   285     CX_DEBUG_EXIT_FUNCTION();
       
   286 }
       
   287 
       
   288 /*!
       
   289 * This view is about to be shown.
       
   290 * Update the view to match currently selected scene.
       
   291 */
       
   292 void CxuiSceneModeView::showEvent(QShowEvent *event)
       
   293 {
       
   294     CX_DEBUG_ENTER_FUNCTION();
       
   295     mScenesList->scrollTo(mScenesList->currentIndex(), HbAbstractItemView::PositionAtTop);
       
   296 
       
   297     mEngine->viewfinderControl().stop();
       
   298     mCameraReleaseTimer.start();
       
   299     QGraphicsWidget::showEvent(event);
       
   300     CX_DEBUG_EXIT_FUNCTION();
       
   301 }
       
   302 
       
   303 /*!
       
   304 * Slot to handle capture key full press.
       
   305 */
       
   306 void CxuiSceneModeView::handleCaptureKeyPressed()
       
   307 {
       
   308     CX_DEBUG_ENTER_FUNCTION();
       
   309     closeView();
       
   310     CX_DEBUG_EXIT_FUNCTION();
       
   311 }
       
   312 
       
   313 /*!
       
   314 * Slot to handle capture key half press / autofocus key press.
       
   315 */
       
   316 void CxuiSceneModeView::handleAutofocusKeyPressed()
       
   317 {
       
   318     CX_DEBUG_ENTER_FUNCTION();
       
   319     closeView();
       
   320     CX_DEBUG_EXIT_FUNCTION();
       
   321 }
       
   322 
       
   323 /*!
       
   324 * Closing the view and reactivating camera hw if needed
       
   325 */
       
   326 void CxuiSceneModeView::closeView()
       
   327 {
       
   328     CX_DEBUG_ENTER_FUNCTION();
       
   329     mScenesList->handleSelectionAccepted();
       
   330     mScenesList->handleClose();
       
   331     mScenesBackground->setIcon(HbIcon());
       
   332     // Make sure engine prepares for new image/video if necessary
       
   333     mEngine->initMode(mEngine->mode());
       
   334     emit viewCloseEvent();
       
   335     CX_DEBUG_EXIT_FUNCTION();
       
   336 }
       
   337 
       
   338 /*!
       
   339 * Slot to handle camera hw release timeout
       
   340 */
       
   341 void CxuiSceneModeView::releaseCameraHw()
       
   342 {
       
   343     CX_DEBUG_ENTER_FUNCTION();
       
   344     mCameraReleaseTimer.stop();
       
   345     mEngine->cameraDeviceControl().release();
       
   346     CX_DEBUG_EXIT_FUNCTION();
       
   347 }
       
   348 
       
   349 // end of file
       
   350