camerauis/cameraxui/cxui/src/cxuivideoprecaptureview.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 53 61bc0f252b2b
child 57 2c87b2808fd7
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
     1 /*
       
     2 * Copyright (c) 2009-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 
       
    18 
       
    19 
       
    20 #include <QApplication>
       
    21 #include <QGraphicsLayout>
       
    22 
       
    23 #include <hbmainwindow.h>
       
    24 #include <hbaction.h>
       
    25 #include <hbtoolbar.h>
       
    26 #include <hbtoolbarextension.h>
       
    27 #include <hbtransparentwindow.h>
       
    28 #include <hblabel.h>
       
    29 #include <hbslider.h>
       
    30 #include <hbmenu.h>
       
    31 #include <hbdialog.h>
       
    32 #include <hbnotificationdialog.h>
       
    33 #include <hbfeedbacksettings.h>
       
    34 #include <hbfeedbacknamespace.h>
       
    35 #include <hbactivitymanager.h>
       
    36 
       
    37 #include "cxuivideoprecaptureview.h"
       
    38 #include "cxeengine.h"
       
    39 #include "cxeviewfindercontrol.h"
       
    40 #include "cxevideocapturecontrol.h"
       
    41 #include "cxecameradevicecontrol.h"
       
    42 #include "cxenamespace.h"
       
    43 #include "cxesettings.h"
       
    44 #include "cxuienums.h"
       
    45 #include "cxutils.h"
       
    46 #include "cxuizoomslider.h"
       
    47 #include "cxuicapturekeyhandler.h"
       
    48 #include "cxuidocumentloader.h"
       
    49 #include "cxuiserviceprovider.h"
       
    50 
       
    51 #ifdef Q_OS_SYMBIAN
       
    52 #include "OstTraceDefinitions.h"
       
    53 
       
    54 #ifdef OST_TRACE_COMPILER_IN_USE
       
    55 #include "cxuivideoprecaptureviewTraces.h"
       
    56 #endif
       
    57 
       
    58 #include <e32keys.h>
       
    59 #endif  //Q_OS_SYMBIAN
       
    60 
       
    61 using namespace Cxe;
       
    62 using namespace CxUiLayout;
       
    63 using namespace CxUiInternal;
       
    64 
       
    65 namespace
       
    66 {
       
    67     static const int CXUI_ELAPSED_TIME_TIMEOUT = 1000; // 1 second
       
    68     static const int CXUI_RECORD_ANIMATION_DURATION = 3000; // milliseconds
       
    69     static const int CXUI_PAUSE_TIMEOUT = 60*1000;   // 60 seconds
       
    70 
       
    71     //!@todo Localization?
       
    72     static const char* VIDEO_TIME_FORMAT = "%02d:%02d";
       
    73     const int POSTCAPTURE_ON = -1;
       
    74 }
       
    75 
       
    76 
       
    77 CxuiVideoPrecaptureView::CxuiVideoPrecaptureView(QGraphicsItem *parent) :
       
    78     CxuiPrecaptureView(parent),
       
    79     mElapsedTimer(this),
       
    80     mTimeElapsed(0),
       
    81     mTimeRemaining(0),
       
    82     mVideoTimeText(NULL),
       
    83     mRecordingIcon(NULL),
       
    84     mGoToStillAction(NULL),
       
    85     mToolbarIdle(NULL),
       
    86     mToolbarRec(NULL),
       
    87     mToolbarPaused(NULL),
       
    88     mVideoScenePopup(NULL),
       
    89     mVideoCaptureControl(NULL),
       
    90     mMenu(NULL),
       
    91     mCapturePending(false)
       
    92 {
       
    93     CX_DEBUG_IN_FUNCTION();
       
    94 }
       
    95 
       
    96 CxuiVideoPrecaptureView::~CxuiVideoPrecaptureView()
       
    97 {
       
    98     CX_DEBUG_IN_FUNCTION();
       
    99     mElapsedTimer.stop();
       
   100     delete mMenu;
       
   101     CX_DEBUG_EXIT_FUNCTION();
       
   102 }
       
   103 
       
   104 /*!
       
   105  * Construct-method handles initialisation tasks for this class.
       
   106  * @param mainwindow
       
   107  * @param engine
       
   108  * @param documentLoader
       
   109  * @param keyHandler
       
   110  */
       
   111 void CxuiVideoPrecaptureView::construct(HbMainWindow *mainwindow, CxeEngine *engine,
       
   112                                         CxuiDocumentLoader *documentLoader,
       
   113                                         CxuiCaptureKeyHandler *keyHandler,
       
   114                                         HbActivityManager *activityManager)
       
   115 {
       
   116     CX_DEBUG_ENTER_FUNCTION();
       
   117 
       
   118     CxuiPrecaptureView::construct(mainwindow, engine, documentLoader, keyHandler, activityManager);
       
   119     mCaptureKeyHandler = keyHandler;
       
   120 
       
   121     mVideoCaptureControl = &(engine->videoCaptureControl());
       
   122 
       
   123     connect(&mElapsedTimer, SIGNAL(timeout()), this, SLOT(updateTimeLabels()));
       
   124     connect(mVideoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id)),
       
   125             this, SLOT(handleVideoStateChanged(CxeVideoCaptureControl::State,CxeError::Id)));
       
   126     connect(mVideoCaptureControl, SIGNAL(remainingTimeChanged()),
       
   127             this, SLOT(updateTimeLabels()));
       
   128 
       
   129     mEngine->settings().listenForSetting(CxeSettingIds::VIDEO_SCENE, this, SLOT(handleSceneChanged(const QVariant&)));
       
   130 
       
   131     mPauseTimer.setSingleShot(true);
       
   132     connect(&mPauseTimer, SIGNAL(timeout()), this, SLOT(stop()));
       
   133     mPauseTimer.setInterval(CXUI_PAUSE_TIMEOUT);
       
   134 
       
   135     HbAction *quitAction = new HbAction(Hb::QuitNaviAction, this);
       
   136     setNavigationAction(quitAction);
       
   137     connect(quitAction, SIGNAL(triggered()), this, SLOT(handleQuitClicked()));
       
   138 
       
   139     loadDefaultWidgets();
       
   140     loadWidgets();
       
   141     hideControls();
       
   142 
       
   143     CX_DEBUG_EXIT_FUNCTION();
       
   144 
       
   145 }
       
   146 
       
   147 /*!
       
   148  * Loads widgets that are needed right from the start.
       
   149  */
       
   150 void CxuiVideoPrecaptureView::loadDefaultWidgets()
       
   151 {
       
   152     CX_DEBUG_ENTER_FUNCTION();
       
   153     CX_ASSERT_ALWAYS(mDocumentLoader);
       
   154 
       
   155     // get pointers to ui components from the layout data
       
   156     QGraphicsWidget *widget = NULL;
       
   157     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEWFINDER);
       
   158     mViewfinder = qobject_cast<HbTransparentWindow *> (widget);
       
   159     CX_ASSERT_ALWAYS(mViewfinder);
       
   160 
       
   161     reloadIndicatorWidgets();
       
   162 
       
   163     CX_DEBUG_EXIT_FUNCTION();
       
   164 }
       
   165 
       
   166 /*!
       
   167  * Loads default indicators from docml and modifies the visibility
       
   168  * according to current settings.
       
   169  */
       
   170 void CxuiVideoPrecaptureView::reloadIndicatorWidgets()
       
   171 {
       
   172     CX_DEBUG_ENTER_FUNCTION();
       
   173     CX_ASSERT_ALWAYS(mDocumentLoader);
       
   174 
       
   175     bool ok = false;
       
   176     mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_INDICATORS_SECTION, &ok);
       
   177     CX_ASSERT_ALWAYS(ok);
       
   178 
       
   179     QGraphicsWidget *widget = NULL;
       
   180     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_QUALITY_ICON);
       
   181     mQualityIcon = qobject_cast<HbLabel *> (widget);
       
   182     CX_ASSERT_ALWAYS(mQualityIcon);
       
   183 
       
   184     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIDEOAUDIOMUTE_INDICATOR_ICON);
       
   185     HbLabel *videoaudiomuteIndicatorIcon = qobject_cast<HbLabel *>(widget);
       
   186     CX_ASSERT_ALWAYS(videoaudiomuteIndicatorIcon);
       
   187 
       
   188     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_STABILITY_INDICATOR_ICON);
       
   189     HbLabel *videoStabilityIndicatorIcon = qobject_cast<HbLabel *>(widget);
       
   190     CX_ASSERT_ALWAYS(videoStabilityIndicatorIcon);
       
   191 
       
   192     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_INDICATOR_CONTAINER_TOP);
       
   193     mIndicators = qobject_cast<HbWidget *>(widget);
       
   194     CX_ASSERT_ALWAYS(mIndicators);
       
   195 
       
   196     QGraphicsLayout *layout = mIndicators->layout();
       
   197     QGraphicsLayoutItem *graphicsLayoutItem = NULL;
       
   198     QGraphicsItem *graphicsItem = NULL;
       
   199     QString key = "";
       
   200     int currentSettingValue = -1;
       
   201     bool isSettingOff = false;
       
   202     // Go through the items in the layout to check whether they should be
       
   203     // shown or not in the indicator pane. Start from the last towards
       
   204     // the first, so that removing items from between works correctly.
       
   205     for (int i = layout->count() - 1; i >= 0; i--) {
       
   206         graphicsLayoutItem = layout->itemAt(i);
       
   207         isSettingOff = false;
       
   208         if (graphicsLayoutItem) {
       
   209             graphicsItem = graphicsLayoutItem->graphicsItem();
       
   210             currentSettingValue = -1;
       
   211             if (graphicsItem == videoaudiomuteIndicatorIcon) {
       
   212                 key = CxeSettingIds::VIDEO_MUTE_SETTING;
       
   213                 currentSettingValue = mEngine->settings().get(key, currentSettingValue);
       
   214                 // video mute implementation does not use
       
   215                 // enum for on/off values but instead
       
   216                 // 0 for off and 1 for on.
       
   217                 if (currentSettingValue == 0) {
       
   218                     isSettingOff = true;
       
   219                 }
       
   220             } else if (graphicsItem == videoStabilityIndicatorIcon) {
       
   221                 // remove video stability indicator.
       
   222                 isSettingOff = true;
       
   223             }
       
   224             if (isSettingOff) {
       
   225                 layout->removeAt(i);
       
   226             }
       
   227         }
       
   228     }
       
   229 
       
   230     // Create background graphics for indicator container
       
   231     createWidgetBackgroundGraphic(mIndicators, TRANSPARENT_BACKGROUND_GRAPHIC);
       
   232 
       
   233     mIndicators->setVisible(true);
       
   234 
       
   235     CX_DEBUG_EXIT_FUNCTION();
       
   236 }
       
   237 
       
   238 /*!
       
   239  * Loads widgets that are not part of the default section in layouts xml.
       
   240  * Widgets are created at the time they are first loaded.
       
   241  */
       
   242 void CxuiVideoPrecaptureView::loadWidgets()
       
   243 {
       
   244     CX_DEBUG_ENTER_FUNCTION();
       
   245     CX_ASSERT_ALWAYS(mDocumentLoader);
       
   246 
       
   247     if (mWidgetsLoaded) {
       
   248         CX_DEBUG(("Widgets already loaded"));
       
   249         CX_DEBUG_EXIT_FUNCTION();
       
   250         return;
       
   251     }
       
   252 
       
   253     // get pointers to ui components from the layout data
       
   254     QGraphicsWidget *widget = NULL;
       
   255 
       
   256     // load the "secondary" widgets
       
   257     bool ok = false;
       
   258 
       
   259     // load widgets section (creates the widgets)
       
   260     mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_WIDGETS_SECTION, &ok);
       
   261     CX_ASSERT_ALWAYS(ok);
       
   262     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   263         mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_EMBEDDED_SECTION, &ok);
       
   264     } else {
       
   265         mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_STANDALONE_SECTION, &ok);
       
   266     }
       
   267     CX_ASSERT_ALWAYS(ok);
       
   268     // get needed pointers to some of the widgets
       
   269     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_ZOOM_SLIDER);
       
   270     mSlider = qobject_cast<CxuiZoomSlider *> (widget);
       
   271     CX_ASSERT_ALWAYS(mSlider);
       
   272 
       
   273     //Let's add a plus and minus buttons to the slider
       
   274     mSlider->addZoomButtons();
       
   275     createWidgetBackgroundGraphic(mSlider, TRANSPARENT_BACKGROUND_GRAPHIC);
       
   276 
       
   277     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_TOOLBAR);
       
   278     mToolbarIdle = qobject_cast<HbToolBar *> (widget);
       
   279     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_TOOLBAR_REC);
       
   280     mToolbarRec = qobject_cast<HbToolBar *> (widget);
       
   281     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_TOOLBAR_PAUSED);
       
   282     mToolbarPaused = qobject_cast<HbToolBar *> (widget);
       
   283 
       
   284     mToolbar = mToolbarIdle;
       
   285 
       
   286     CX_ASSERT_ALWAYS(mToolbarIdle);
       
   287     CX_ASSERT_ALWAYS(mToolbarRec);
       
   288     CX_ASSERT_ALWAYS(mToolbarPaused);
       
   289 
       
   290     hideControls();
       
   291 
       
   292     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   293         CX_DEBUG(("EMBEDDED: camera in embedded mode"));
       
   294 
       
   295         if (!CxuiServiceProvider::instance()->allowQualityChange()) {
       
   296 
       
   297             CX_DEBUG(("EMBEDDED: don't allow quality change"));
       
   298             HbAction* vq = qobject_cast<HbAction*> (mDocumentLoader->findObject(VIDEO_PRE_CAPTURE_VIDEO_QUALITY_ACTION));
       
   299             if (vq) {
       
   300                 CX_DEBUG(("EMBEDDED: setting image quality setting to disabled"));
       
   301                 vq->setEnabled(false);
       
   302             }
       
   303         }
       
   304         if (!CxuiServiceProvider::instance()->allowModeSwitching()) {
       
   305             CX_DEBUG(("EMBEDDED: don't allow mode switching"));
       
   306 
       
   307             HbAction *still = qobject_cast<HbAction*> (mDocumentLoader->findObject(VIDEO_PRE_CAPTURE_GOTO_STILL_ACTION));
       
   308             if (still) {
       
   309                 CX_DEBUG(("EMBEDDED: setting mode switch to disabled"));
       
   310                 still->setEnabled(false);
       
   311             }
       
   312         }
       
   313         if (!CxuiServiceProvider::instance()->allowCameraSwitching()) {
       
   314             CX_DEBUG(("EMBEDDED: don't allow camera switching"));
       
   315 
       
   316         }
       
   317 
       
   318     }
       
   319 
       
   320 
       
   321     // Create background graphic for indicator container
       
   322     HbWidget *indicatorContainer;
       
   323     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_INDICATOR_CONTAINER_BOTTOM);
       
   324     indicatorContainer = qobject_cast<HbWidget *>(widget);
       
   325     CX_ASSERT_ALWAYS(indicatorContainer);
       
   326     createWidgetBackgroundGraphic(indicatorContainer, TRANSPARENT_BACKGROUND_GRAPHIC);
       
   327 
       
   328     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIDEO_TIME_LABEL);
       
   329     mVideoTimeText = qobject_cast<HbLabel *> (widget);
       
   330     CX_ASSERT_ALWAYS(mVideoTimeText);
       
   331 
       
   332     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_RECORDING_ICON);
       
   333     mRecordingIcon = qobject_cast<HbLabel *> (widget);
       
   334     CX_ASSERT_ALWAYS(mRecordingIcon);
       
   335 
       
   336     mWidgetsLoaded = true;
       
   337 
       
   338     // Initializing recording indicator animation
       
   339     mRecordingAnimation = new QPropertyAnimation(mRecordingIcon, "opacity");
       
   340     mRecordingAnimation->setStartValue(0.2);
       
   341     mRecordingAnimation->setKeyValueAt(0.5, 1.0);
       
   342     mRecordingAnimation->setEndValue(0.2);
       
   343     mRecordingAnimation->setDuration(CXUI_RECORD_ANIMATION_DURATION);
       
   344     mRecordingAnimation->setLoopCount(-1);
       
   345     mRecordingAnimation->setEasingCurve(QEasingCurve::OutInQuad);
       
   346 
       
   347 
       
   348     // Update toolbar scene mode icon.
       
   349     try {
       
   350         updateSceneIcon(mEngine->settings().get<QString>(CxeSettingIds::VIDEO_SCENE));
       
   351     } catch (CxeException &e) {
       
   352         // ignore error
       
   353     }
       
   354 
       
   355     // Initialize the video time counters.
       
   356     updateTimeLabels();
       
   357 
       
   358     // View is ready. Needed for startup performance automated testing.
       
   359     emit viewReady();
       
   360 
       
   361     CX_DEBUG_EXIT_FUNCTION();
       
   362 }
       
   363 
       
   364 /*!
       
   365  * Restore view state from activity.
       
   366  */
       
   367 void CxuiVideoPrecaptureView::restoreActivity(const QString &activityId, const QVariant &data)
       
   368 {
       
   369     Q_UNUSED(activityId);
       
   370     Q_UNUSED(data);
       
   371 
       
   372     CX_DEBUG_ENTER_FUNCTION();
       
   373     // no need to restore any state
       
   374     CX_DEBUG_EXIT_FUNCTION();
       
   375 }
       
   376 
       
   377 /*!
       
   378  * Save view state to activity.
       
   379  */
       
   380 void CxuiVideoPrecaptureView::saveActivity()
       
   381 {
       
   382     CX_DEBUG_ENTER_FUNCTION();
       
   383     QVariantMap data;
       
   384     QVariantHash params;
       
   385 
       
   386     HbIcon activityScreenshot("qtg_graf_taskswitcher_camcorder");
       
   387     QPixmap screenshot = activityScreenshot.pixmap();
       
   388     params.insert("screenshot", screenshot);
       
   389 
       
   390     mActivityManager->removeActivity(
       
   391             CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY);
       
   392     mActivityManager->addActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY,
       
   393                                   data, params);
       
   394     CX_DEBUG_EXIT_FUNCTION();
       
   395 }
       
   396 
       
   397 /*!
       
   398  * Clear activity from activity manager.
       
   399  */
       
   400 void CxuiVideoPrecaptureView::clearActivity()
       
   401 {
       
   402     CX_DEBUG_ENTER_FUNCTION();
       
   403     mActivityManager->removeActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY);
       
   404     CX_DEBUG_EXIT_FUNCTION();
       
   405 }
       
   406 
       
   407 /*!
       
   408 * Initialize settings grid.
       
   409 */
       
   410 void CxuiVideoPrecaptureView::initializeSettingsGrid()
       
   411 {
       
   412     if(!mSettingsGrid) {
       
   413         HbAction* action(NULL);
       
   414 
       
   415         mSettingsGrid = new HbToolBarExtension;
       
   416 
       
   417         action = mSettingsGrid->addAction(HbIcon("qtg_mono_exposure"), hbTrId("txt_cam_button_exposure_compensation"), this, SLOT(launchSliderSetting()));
       
   418         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::EV_COMPENSATION_VALUE);
       
   419         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
       
   420 
       
   421         action = mSettingsGrid->addAction(HbIcon("qtg_small_rgb"), hbTrId("txt_cam_button_color_tone"), this, SLOT(launchSetting()));
       
   422         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::COLOR_TONE);
       
   423         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
       
   424 
       
   425         action = mSettingsGrid->addAction(HbIcon("qtg_mono_white_balance"), hbTrId("txt_cam_button_white_balance"), this, SLOT(launchSetting()));
       
   426         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::WHITE_BALANCE);
       
   427         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
       
   428 
       
   429         connect(mCaptureKeyHandler, SIGNAL(autofocusKeyPressed()), mSettingsGrid, SLOT(close()));
       
   430     }
       
   431 }
       
   432 
       
   433 
       
   434 /**
       
   435 * Get if postcapture view should be shown or not.
       
   436 * Postcapture view may be shown for a predefined time or
       
   437 * until user dismisses it, or it may be completely disabled.
       
   438 */
       
   439 bool CxuiVideoPrecaptureView::isPostcaptureOn() const
       
   440 {
       
   441     CX_DEBUG_ENTER_FUNCTION();
       
   442     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   443         // always show post capture in embedded mode
       
   444         CX_DEBUG_EXIT_FUNCTION();
       
   445         return true;
       
   446     }
       
   447 
       
   448     // Read the value from settings. Ignoring reading error.
       
   449     // On error (missing settings) default to "postcapture on".
       
   450     int showPostcapture(POSTCAPTURE_ON);
       
   451     if(mEngine) {
       
   452         showPostcapture = mEngine->settings().get<int>(CxeSettingIds::VIDEO_SHOWCAPTURED, POSTCAPTURE_ON);
       
   453     }
       
   454 
       
   455     CX_DEBUG_EXIT_FUNCTION();
       
   456     return showPostcapture != 0; // 0 == no postcapture
       
   457 }
       
   458 
       
   459 /*!
       
   460 * Update the scene mode icon.
       
   461 * @param sceneId The new scene id.
       
   462 */
       
   463 void CxuiVideoPrecaptureView::updateSceneIcon(const QString& sceneId)
       
   464 {
       
   465     CX_DEBUG_ENTER_FUNCTION();
       
   466 
       
   467     if (mEngine->mode() == Cxe::VideoMode) {
       
   468         CX_DEBUG(("CxuiPrecaptureView - scene: %s", sceneId.toAscii().constData()));
       
   469 
       
   470         // No need to update icon, if widgets are not even loaded yet.
       
   471         // We'll update the icon once the widgets are loaded.
       
   472         if (mWidgetsLoaded) {
       
   473             QString iconObjectName = VIDEO_PRE_CAPTURE_SCENE_MODE_ACTION;
       
   474             QString icon = getSettingItemIcon(CxeSettingIds::VIDEO_SCENE, sceneId);
       
   475 
       
   476             CX_DEBUG(("CxuiVideoPrecaptureView - icon: %s", icon.toAscii().constData()));
       
   477 
       
   478             if (mDocumentLoader) {
       
   479                 QObject *obj = mDocumentLoader->findObject(iconObjectName);
       
   480                 CX_ASSERT_ALWAYS(obj);
       
   481                 qobject_cast<HbAction *>(obj)->setIcon(HbIcon(icon));
       
   482             }
       
   483         } else {
       
   484             CX_DEBUG(("CxuiVideoPrecaptureView - widgets not loaded yet, ignored!"));
       
   485         }
       
   486     }
       
   487     CX_DEBUG_EXIT_FUNCTION();
       
   488 }
       
   489 
       
   490 /*!
       
   491     Update the quality indicator
       
   492 */
       
   493 void CxuiVideoPrecaptureView::updateQualityIcon()
       
   494 {
       
   495     CX_DEBUG_ENTER_FUNCTION();
       
   496 
       
   497     if (mQualityIcon && mEngine) {
       
   498         QString icon = "";
       
   499 
       
   500         int currentValue = mEngine->settings().get<int>(CxeSettingIds::VIDEO_QUALITY, -1);
       
   501         icon = getSettingItemIcon(CxeSettingIds::VIDEO_QUALITY, currentValue);
       
   502 
       
   503         mQualityIcon->setIcon(HbIcon(icon));
       
   504     }
       
   505 
       
   506     CX_DEBUG_EXIT_FUNCTION();
       
   507 }
       
   508 
       
   509 void CxuiVideoPrecaptureView::record()
       
   510 {
       
   511     CX_DEBUG_ENTER_FUNCTION();
       
   512 
       
   513     int time(0);
       
   514     mVideoCaptureControl->remainingTime(time);
       
   515 
       
   516     if (time) {
       
   517         if (!mMenu){ // Only take out menu, if we have not already done it
       
   518             mMenu = takeMenu();
       
   519         }
       
   520         mVideoCaptureControl->record();
       
   521     } else {
       
   522         emit errorEncountered(CxeError::DiskFull);
       
   523     }
       
   524 
       
   525     CX_DEBUG_EXIT_FUNCTION();
       
   526 }
       
   527 
       
   528 void CxuiVideoPrecaptureView::pause()
       
   529 {
       
   530     CX_DEBUG_ENTER_FUNCTION();
       
   531 
       
   532     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   533     if (state == CxeVideoCaptureControl::Recording) {
       
   534         mVideoCaptureControl->pause();
       
   535     } else if (state == CxeVideoCaptureControl::Paused) {
       
   536         mVideoCaptureControl->record();
       
   537     }
       
   538 
       
   539     CX_DEBUG_EXIT_FUNCTION();
       
   540 }
       
   541 
       
   542 void CxuiVideoPrecaptureView::stop()
       
   543 {
       
   544     CX_DEBUG_ENTER_FUNCTION();
       
   545 
       
   546     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   547     if (state == CxeVideoCaptureControl::Recording ||
       
   548         state == CxeVideoCaptureControl::Paused) {
       
   549         mVideoCaptureControl->stop();
       
   550         // Continue in handleVideoStateChanged().
       
   551     }
       
   552 
       
   553     CX_DEBUG_EXIT_FUNCTION();
       
   554 }
       
   555 
       
   556 
       
   557 /*!
       
   558 * Allow showing UI controls?
       
   559 */
       
   560 bool CxuiVideoPrecaptureView::allowShowControls() const
       
   561 {
       
   562     bool show(false);
       
   563     if (mEngine) {
       
   564         CxeVideoCaptureControl::State state(mEngine->videoCaptureControl().state());
       
   565 
       
   566         show = (mEngine->isEngineReady()
       
   567              || state == CxeVideoCaptureControl::Recording
       
   568              || state == CxeVideoCaptureControl::Paused);
       
   569     }
       
   570     return show;
       
   571 }
       
   572 
       
   573 /*!
       
   574  * Play feedback when touching view outside of any widget?
       
   575  * If video is paused feedback is off.  Otherwise on.
       
   576  */
       
   577 bool CxuiVideoPrecaptureView::isFeedbackEnabled() const
       
   578 {
       
   579     CxeVideoCaptureControl::State state(mEngine->videoCaptureControl().state());
       
   580     if (state == CxeVideoCaptureControl::Paused) {
       
   581         return false;
       
   582     } else {
       
   583         return true;
       
   584     }
       
   585 }
       
   586 
       
   587 // CxuiPrecaptureView::showToolbar()
       
   588 // Shows toolbar. Calls the base class implementation if not recording
       
   589 // since toolbar is not shown during recording
       
   590 void CxuiVideoPrecaptureView::showToolbar()
       
   591 {
       
   592     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   593     if (state == CxeVideoCaptureControl::Recording) {
       
   594         if (mToolbar != mToolbarRec) {
       
   595             mToolbar->hide();
       
   596             mToolbar = mToolbarRec;
       
   597         }
       
   598     } else if (state ==CxeVideoCaptureControl::Ready) {
       
   599         if (mToolbar != mToolbarIdle) {
       
   600             mToolbar->hide();
       
   601             mToolbar = mToolbarIdle;
       
   602         }
       
   603     } else if (state == CxeVideoCaptureControl::Paused) {
       
   604         if (mToolbar != mToolbarPaused) {
       
   605             mToolbar->hide();
       
   606             mToolbar = mToolbarPaused;
       
   607         }
       
   608     }
       
   609 
       
   610     CxuiPrecaptureView::showToolbar();
       
   611 }
       
   612 
       
   613 void CxuiVideoPrecaptureView::disableFeedback()
       
   614 {
       
   615     CX_DEBUG_ENTER_FUNCTION();
       
   616 
       
   617     HbFeedbackSettings settings;
       
   618     settings.disableFeedback();
       
   619 
       
   620 
       
   621     CX_DEBUG_EXIT_FUNCTION();
       
   622 }
       
   623 
       
   624 void CxuiVideoPrecaptureView::enableFeedback()
       
   625 {
       
   626     CX_DEBUG_ENTER_FUNCTION();
       
   627 
       
   628     HbFeedbackSettings settings;
       
   629     settings.enableFeedback();
       
   630 
       
   631 
       
   632     CX_DEBUG_EXIT_FUNCTION();
       
   633 }
       
   634 
       
   635 
       
   636 void CxuiVideoPrecaptureView::goToStill()
       
   637 {
       
   638     CX_DEBUG_ENTER_FUNCTION();
       
   639     OstTrace0( camerax_performance, CXUIVIDEOPRECAPTUREVIEW_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 1" );
       
   640 
       
   641     hideControls();
       
   642     mEngine->initMode(ImageMode);
       
   643     emit changeToPrecaptureView();
       
   644 
       
   645     CX_DEBUG_EXIT_FUNCTION();
       
   646 }
       
   647 
       
   648 /*!
       
   649 * Update the remaining and elapsed time labels.
       
   650 */
       
   651 void CxuiVideoPrecaptureView::updateTimeLabels()
       
   652 {
       
   653     CX_DEBUG_IN_FUNCTION();
       
   654 
       
   655     if (!mVideoTimeText) {
       
   656         // Section not loaded yet. Skip update until created.
       
   657         CX_DEBUG(("CxuiVideoPrecaptureView: video time labels not loaded yet!"));
       
   658         CX_DEBUG_EXIT_FUNCTION();
       
   659         return;
       
   660     }
       
   661 
       
   662     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   663     switch (state) {
       
   664         case CxeVideoCaptureControl::Ready:
       
   665             getRemainingTime();
       
   666             // Not recording => elapsed time is zero
       
   667             mTimeElapsed = 0;
       
   668             break;
       
   669 
       
   670         case CxeVideoCaptureControl::Recording:
       
   671         case CxeVideoCaptureControl::Paused:
       
   672             getRemainingTime();
       
   673             getElapsedTime();
       
   674             break;
       
   675 
       
   676         case CxeVideoCaptureControl::Idle:
       
   677         case CxeVideoCaptureControl::Initialized:
       
   678         case CxeVideoCaptureControl::Preparing:
       
   679         default:
       
   680             // Minimize processing during initialization phase.
       
   681             // Calculating remaining time involves checking disk space, avoiding that.
       
   682             // which
       
   683             mTimeRemaining = 0;
       
   684             mTimeElapsed = 0;
       
   685             break;
       
   686     }
       
   687 
       
   688     setVideoTime(mVideoTimeText, mTimeElapsed, mTimeRemaining);
       
   689 
       
   690     CX_DEBUG_EXIT_FUNCTION();
       
   691 }
       
   692 
       
   693 /*!
       
   694   Overridded version of hideControls() that doesn't hide the controls when video recording
       
   695   is paused.
       
   696  */
       
   697 void CxuiVideoPrecaptureView::hideControls()
       
   698 {
       
   699     if (mVideoCaptureControl && mVideoCaptureControl->state() == CxeVideoCaptureControl::Paused) {
       
   700         // never hide controls in paused state
       
   701         return;
       
   702     }
       
   703 
       
   704     CxuiPrecaptureView::hideControls();
       
   705 
       
   706 }
       
   707 
       
   708 /*!
       
   709 * Helper method for formatting video time to requested label.
       
   710 * @param label Text label to show the time.
       
   711 * @param elapsedTime Elapsed time in seconds to be formatted to the label text.
       
   712 * @param remainingTime Remaining time in seconds to be formatted to the label text.
       
   713 */
       
   714 void CxuiVideoPrecaptureView::setVideoTime(HbLabel* label,
       
   715                                            int elapsedTime,
       
   716                                            int remainingTime)
       
   717 {
       
   718     // Convert time (seconds) into mm:ss
       
   719     // HbExtendedLocale wraps minutes at 60 so we can't use that.
       
   720     // We need to show times over 1 hour, e.g. "90:00".
       
   721     QString elapsed, remaining;
       
   722     elapsed.sprintf(VIDEO_TIME_FORMAT, elapsedTime/60, elapsedTime%60);
       
   723     remaining.sprintf(VIDEO_TIME_FORMAT, remainingTime/60, remainingTime%60);
       
   724 
       
   725     label->setPlainText(hbTrId("txt_cam_info_redorcding_time").arg(elapsed).arg(remaining));
       
   726 }
       
   727 
       
   728 bool CxuiVideoPrecaptureView::getElapsedTime()
       
   729 {
       
   730     CX_DEBUG_ENTER_FUNCTION();
       
   731 
       
   732     bool status = mVideoCaptureControl->elapsedTime(mTimeElapsed);
       
   733     CX_DEBUG(("Elapsed time: %d", mTimeElapsed));
       
   734     CX_DEBUG(("status: %d", status));
       
   735 
       
   736     CX_DEBUG_EXIT_FUNCTION();
       
   737     return status;
       
   738 }
       
   739 
       
   740 void CxuiVideoPrecaptureView::getRemainingTime()
       
   741 {
       
   742     CX_DEBUG_ENTER_FUNCTION();
       
   743 
       
   744     mVideoCaptureControl->remainingTime(mTimeRemaining);
       
   745     CX_DEBUG(("getRemainingTime time: %d", mTimeRemaining));
       
   746 
       
   747     CX_DEBUG_EXIT_FUNCTION();
       
   748 }
       
   749 
       
   750 void CxuiVideoPrecaptureView::showEvent(QShowEvent *event)
       
   751 {
       
   752     CxuiPrecaptureView::showEvent(event);
       
   753 
       
   754     updateQualityIcon();
       
   755 
       
   756     if (event->type() == QEvent::Show) {
       
   757         event->accept();
       
   758     }
       
   759 }
       
   760 
       
   761 /*!
       
   762 * Slot to handle video capture control state change.
       
   763 * Update visible items and stop / start timers.
       
   764 */
       
   765 void CxuiVideoPrecaptureView::handleVideoStateChanged(CxeVideoCaptureControl::State newState,
       
   766         CxeError::Id error)
       
   767 {
       
   768     CX_DEBUG_ENTER_FUNCTION();
       
   769     Q_UNUSED(error);
       
   770 
       
   771     updateTimeLabels();
       
   772 
       
   773     mPauseTimer.stop();
       
   774 
       
   775     switch (newState) {
       
   776     case CxeVideoCaptureControl::Ready:
       
   777         if (mDocumentLoader){
       
   778             mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_IDLE);
       
   779         }
       
   780         if (mCapturePending) {
       
   781             mCapturePending = false;
       
   782             record();
       
   783         }
       
   784         break;
       
   785     case CxeVideoCaptureControl::Recording:
       
   786         hideControls();
       
   787         emit stopStandbyTimer();
       
   788         if (mDocumentLoader){
       
   789             mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_RECORDING);
       
   790         }
       
   791 
       
   792         mElapsedTimer.start(CXUI_ELAPSED_TIME_TIMEOUT);
       
   793         disableFeedback();
       
   794 
       
   795         // commented out the activation of the recording animation because
       
   796         // it is causing issues when using SW rendering
       
   797         //if (mRecordingAnimation && mRecordingIcon) {
       
   798         //  mRecordingAnimation->start();
       
   799         //}
       
   800 
       
   801         break;
       
   802     case CxeVideoCaptureControl::Paused:
       
   803         mElapsedTimer.stop();
       
   804         if (mDocumentLoader){
       
   805             mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_PAUSED);
       
   806         }
       
   807         showControls();
       
   808         enableFeedback();
       
   809         mPauseTimer.start();
       
   810         break;
       
   811     case CxeVideoCaptureControl::Stopping:
       
   812         if (mDocumentLoader){
       
   813             mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_PAUSED);
       
   814         }
       
   815 
       
   816         // commented out the stopping of the recording animation since the activation
       
   817         // is commented out also couple lines earlier
       
   818         //if (mRecordingAnimation && mRecordingIcon) {
       
   819         //    mRecordingAnimation->stop();
       
   820         //}
       
   821 
       
   822         enableFeedback();
       
   823         emit startStandbyTimer();
       
   824         mElapsedTimer.stop();
       
   825         hideControls();
       
   826 
       
   827         if (mMenu) {
       
   828             setMenu(mMenu);
       
   829             mMenu = NULL;
       
   830         }
       
   831 
       
   832         if (isPostcaptureOn()) {
       
   833             emit changeToPostcaptureView();
       
   834         } else {
       
   835             // post capture off, we need prepare new video
       
   836             // do the prepare when the previous video is ready
       
   837             connect(mVideoCaptureControl, SIGNAL(videoComposed(CxeError::Id, const QString&)),
       
   838                     this, SLOT(prepareNewVideo(CxeError::Id)));
       
   839         }
       
   840         break;
       
   841     case CxeVideoCaptureControl::PlayingStartSound:
       
   842         // don't change anything
       
   843         break;
       
   844     default:
       
   845         // don't change anything
       
   846         break;
       
   847     }
       
   848 
       
   849     CX_DEBUG_EXIT_FUNCTION();
       
   850 }
       
   851 
       
   852 void CxuiVideoPrecaptureView::handleCaptureKeyPressed()
       
   853 {
       
   854     CX_DEBUG_ENTER_FUNCTION();
       
   855     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   856 
       
   857     switch (state) {
       
   858         case CxeVideoCaptureControl::Ready:
       
   859             record();
       
   860             break;
       
   861         case CxeVideoCaptureControl::Recording:
       
   862         case CxeVideoCaptureControl::Paused:
       
   863             stop();
       
   864             break;
       
   865         case CxeVideoCaptureControl::Idle:
       
   866         case CxeVideoCaptureControl::Initialized:
       
   867         case CxeVideoCaptureControl::Preparing:
       
   868             mCapturePending = true;
       
   869             break;
       
   870 
       
   871     }
       
   872     CX_DEBUG_EXIT_FUNCTION();
       
   873 }
       
   874 
       
   875 void CxuiVideoPrecaptureView::prepareNewVideo(CxeError::Id error)
       
   876 {
       
   877     if (!error) {
       
   878         mEngine->initMode(Cxe::VideoMode);
       
   879         disconnect(mVideoCaptureControl, SIGNAL(videoComposed(CxeError::Id, const QString&)),
       
   880                    this, SLOT(prepareNewVideo(CxeError::Id)));
       
   881     } else {
       
   882         emit errorEncountered(error);
       
   883     }
       
   884 
       
   885 }
       
   886 
       
   887 void CxuiVideoPrecaptureView::handleQuitClicked()
       
   888 {
       
   889     CX_DEBUG_ENTER_FUNCTION();
       
   890 
       
   891     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   892     if (state == CxeVideoCaptureControl::Recording ||
       
   893         state == CxeVideoCaptureControl::Paused) {
       
   894         // Disable going to post-capture when video capture control goes to stopping state.
       
   895         disconnect(mVideoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id)),
       
   896                    this, SLOT(handleVideoStateChanged(CxeVideoCaptureControl::State,CxeError::Id)));
       
   897         mVideoCaptureControl->stop();
       
   898         mElapsedTimer.stop();
       
   899     }
       
   900 
       
   901     QCoreApplication::exit();
       
   902 
       
   903     CX_DEBUG_EXIT_FUNCTION();
       
   904 }
       
   905 
       
   906 void CxuiVideoPrecaptureView::launchVideoScenePopup()
       
   907 {
       
   908     CX_DEBUG_ENTER_FUNCTION();
       
   909     hideControls();
       
   910     emit showScenesView();
       
   911     CX_DEBUG_EXIT_FUNCTION();
       
   912 }
       
   913 
       
   914 
       
   915 /*!
       
   916 * Launches show-postcapture setting pop-up
       
   917 */
       
   918 void CxuiVideoPrecaptureView::launchSetting()
       
   919 {
       
   920     CX_DEBUG_ENTER_FUNCTION();
       
   921 
       
   922     QObject *action = sender();
       
   923 
       
   924     if (action) {
       
   925         QString settingsKey = action->property(PROPERTY_KEY_SETTING_ID).toString();
       
   926         CX_DEBUG(("settingsKey=%s", settingsKey.toAscii().constData()));
       
   927         launchSettingsDialog(action);
       
   928     }
       
   929 
       
   930     CX_DEBUG_EXIT_FUNCTION();
       
   931 }
       
   932 
       
   933 /*!
       
   934 * Handle change in setting value. Update UI to reflect new value.
       
   935 */
       
   936 void CxuiVideoPrecaptureView::handleSettingValueChanged(const QString& key, QVariant newValue)
       
   937 {
       
   938     CX_DEBUG_ENTER_FUNCTION();
       
   939 
       
   940     Q_UNUSED(newValue);
       
   941     // Ignored if not in video mode.
       
   942     if (mEngine->mode() == Cxe::VideoMode) {
       
   943         if (key == CxeSettingIds::VIDEO_QUALITY) {
       
   944             // update the quality indicator on screen
       
   945             updateQualityIcon();
       
   946 
       
   947             // update video remaining time counter when video quality is changed
       
   948             updateTimeLabels();
       
   949         } else if (key == CxeSettingIds::GEOTAGGING) {
       
   950             reloadIndicatorWidgets();
       
   951         } else if (key == CxeSettingIds::VIDEO_MUTE_SETTING) {
       
   952             reloadIndicatorWidgets();
       
   953         }
       
   954     }
       
   955 
       
   956     CX_DEBUG_EXIT_FUNCTION();
       
   957 }
       
   958 
       
   959 /*!
       
   960 * Handle scene mode change.
       
   961 * @param scene The new active scene mode.
       
   962 */
       
   963 void CxuiVideoPrecaptureView::handleSceneChanged(const QVariant &scene)
       
   964 {
       
   965     CX_DEBUG_ENTER_FUNCTION();
       
   966     // Ignore if not in video mode.
       
   967     if (mEngine->mode() == Cxe::VideoMode) {
       
   968         // Update toolbar scene mode icon.
       
   969         updateSceneIcon(scene.toString());
       
   970     }
       
   971 
       
   972     CX_DEBUG_EXIT_FUNCTION();
       
   973 }
       
   974 
       
   975 /*!
       
   976  * Overridden eventFilter() to restart the pause timer.
       
   977  */
       
   978 bool CxuiVideoPrecaptureView::eventFilter(QObject *object, QEvent *event)
       
   979 {
       
   980 
       
   981     if (mVideoCaptureControl && mVideoCaptureControl->state() == CxeVideoCaptureControl::Paused) {
       
   982         // restart the timer if the screen is touched and we are in paused state
       
   983         switch (event->type())
       
   984         {
       
   985         case QEvent::GraphicsSceneMouseRelease:
       
   986             mPauseTimer.start();
       
   987             break;
       
   988         case QEvent::GraphicsSceneMousePress:
       
   989             mPauseTimer.stop();
       
   990             break;
       
   991         default:
       
   992             break;
       
   993         }
       
   994     }
       
   995     return CxuiPrecaptureView::eventFilter(object, event);
       
   996 }
       
   997 
       
   998 //end of file
       
   999