camerauis/cameraxui/cxui/src/cxuivideoprecaptureview.cpp
changeset 19 d9aefe59d544
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
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 <e32keys.h>
       
    19 
       
    20 #include <QApplication>
       
    21 
       
    22 #include <hbmainwindow.h>
       
    23 #include <hbaction.h>
       
    24 #include <hbtoolbar.h>
       
    25 #include <hbtoolbarextension.h>
       
    26 #include <hbtransparentwindow.h>
       
    27 #include <hblabel.h>
       
    28 #include <hbslider.h>
       
    29 #include <hbmenu.h>
       
    30 #include <hbdialog.h>
       
    31 #include <hbnotificationdialog.h>
       
    32 #include <hbfeedbackplayer.h>
       
    33 #include <hbfeedbacksettings.h>
       
    34 #include <hbfeedbacknamespace.h>
       
    35 
       
    36 #include "cxuivideoprecaptureview.h"
       
    37 #include "cxeengine.h"
       
    38 #include "cxeviewfindercontrol.h"
       
    39 #include "cxevideocapturecontrol.h"
       
    40 #include "cxecameradevicecontrol.h"
       
    41 #include "cxenamespace.h"
       
    42 #include "cxesettings.h"
       
    43 #include "cxuienums.h"
       
    44 #include "cxutils.h"
       
    45 #include "cxuicapturekeyhandler.h"
       
    46 #include "cxuidocumentloader.h"
       
    47 #include "OstTraceDefinitions.h"
       
    48 #ifdef OST_TRACE_COMPILER_IN_USE
       
    49 #include "cxuivideoprecaptureviewTraces.h"
       
    50 #endif
       
    51 #include "cxuiserviceprovider.h"
       
    52 
       
    53 
       
    54 using namespace Cxe;
       
    55 using namespace CxUiLayout;
       
    56 using namespace CxUiInternal;
       
    57 
       
    58 namespace
       
    59 {
       
    60     static const int CXUI_ELAPSED_TIME_TIMEOUT = 1000; // 1 second
       
    61     static const int CXUI_RECORD_ANIMATION_DURATION = 3000; // milliseconds
       
    62 
       
    63     //!@todo Localization?
       
    64     static const char* VIDEO_TIME_FORMAT = "%02d:%02d";
       
    65 }
       
    66 
       
    67 
       
    68 CxuiVideoPrecaptureView::CxuiVideoPrecaptureView(QGraphicsItem *parent) :
       
    69     CxuiPrecaptureView(parent),
       
    70     mElapsedTimer(this),
       
    71     mTimeElapsed(0),
       
    72     mTimeRemaining(0),
       
    73     mElapsedTimeText(NULL),
       
    74     mRemainingTimeText(NULL),
       
    75     mRecordingIcon(NULL),
       
    76     mGoToStillAction(NULL),
       
    77     mToolBarIdle(NULL),
       
    78     mToolBarRec(NULL),
       
    79     mToolBarPaused(NULL),
       
    80     mToggleLightAction(NULL),
       
    81     mVideoScenePopup(NULL),
       
    82     mVideoCaptureControl(NULL),
       
    83     mMenu(NULL),
       
    84     mCapturePending(false)
       
    85 {
       
    86     CX_DEBUG_IN_FUNCTION();
       
    87 }
       
    88 
       
    89 CxuiVideoPrecaptureView::~CxuiVideoPrecaptureView()
       
    90 {
       
    91     CX_DEBUG_IN_FUNCTION();
       
    92     mElapsedTimer.stop();
       
    93     delete mMenu;
       
    94     CX_DEBUG_EXIT_FUNCTION();
       
    95 }
       
    96 
       
    97 void CxuiVideoPrecaptureView::construct(HbMainWindow *mainwindow, CxeEngine *engine,
       
    98                                         CxuiDocumentLoader *documentLoader,
       
    99                                         CxuiCaptureKeyHandler *keyHandler)
       
   100 {
       
   101     CX_DEBUG_ENTER_FUNCTION();
       
   102 
       
   103     CxuiPrecaptureView::construct(mainwindow, engine, documentLoader, keyHandler);
       
   104     mKeyHandler = keyHandler;
       
   105 
       
   106     mVideoCaptureControl = &(engine->videoCaptureControl());
       
   107 
       
   108     connect(&mElapsedTimer, SIGNAL(timeout()), this, SLOT(updateTimeLabels()));
       
   109     connect(mVideoCaptureControl, SIGNAL(snapshotReady(CxeError::Id, const QPixmap&, const QString&)),
       
   110             this, SLOT(handleSnapshot(CxeError::Id)));
       
   111     connect(mVideoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id)),
       
   112             this, SLOT(handleVideoStateChanged(CxeVideoCaptureControl::State,CxeError::Id)));
       
   113 
       
   114     HbAction *quitAction = new HbAction(Hb::QuitNaviAction, this);
       
   115     setNavigationAction(quitAction);
       
   116     connect(quitAction, SIGNAL(triggered()), this, SLOT(handleQuitClicked()));
       
   117 
       
   118     loadDefaultWidgets();
       
   119     loadWidgets();
       
   120     hideControls();
       
   121 
       
   122     CX_DEBUG_EXIT_FUNCTION();
       
   123 
       
   124 }
       
   125 
       
   126 void CxuiVideoPrecaptureView::loadDefaultWidgets()
       
   127 {
       
   128     CX_DEBUG_ENTER_FUNCTION();
       
   129     CX_DEBUG_ASSERT(mDocumentLoader);
       
   130 
       
   131     // get pointers to ui components from the layout data
       
   132     QGraphicsWidget *widget = NULL;
       
   133     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEWFINDER);
       
   134     mViewfinder = qobject_cast<HbTransparentWindow *> (widget);
       
   135     CX_DEBUG_ASSERT(mViewfinder);
       
   136 
       
   137     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_QUALITY_ICON);
       
   138     mQualityIcon = qobject_cast<HbLabel *> (widget);
       
   139     CX_DEBUG_ASSERT(mQualityIcon);
       
   140 
       
   141     // Create background graphics for indicator containers
       
   142     HbWidget *indicatorContainer;
       
   143     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_INDICATOR_CONTAINER_TOP);
       
   144     indicatorContainer = qobject_cast<HbWidget *>(widget);
       
   145     CX_DEBUG_ASSERT(indicatorContainer);
       
   146     createWidgetBackgroundGraphic(indicatorContainer, TRANSPARENT_BACKGROUND_GRAPHIC);
       
   147     indicatorContainer->show();
       
   148 
       
   149     CX_DEBUG_EXIT_FUNCTION();
       
   150 }
       
   151 
       
   152 void CxuiVideoPrecaptureView::loadWidgets()
       
   153 {
       
   154     CX_DEBUG_ENTER_FUNCTION();
       
   155     CX_DEBUG_ASSERT(mDocumentLoader);
       
   156 
       
   157     if (mWidgetsLoaded) {
       
   158         CX_DEBUG(("Widgets already loaded"));
       
   159         CX_DEBUG_EXIT_FUNCTION();
       
   160         return;
       
   161     }
       
   162 
       
   163     // get pointers to ui components from the layout data
       
   164     QGraphicsWidget *widget = NULL;
       
   165 
       
   166     // load the "secondary" widgets
       
   167     bool ok = false;
       
   168 
       
   169     // load widgets section (creates the widgets)
       
   170     mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_WIDGETS_SECTION, &ok);
       
   171     Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing");
       
   172     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   173         mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_EMBEDDED_SECTION, &ok);
       
   174     } else {
       
   175         mDocumentLoader->load(VIDEO_1ST_XML, VIDEO_PRE_CAPTURE_STANDALONE_SECTION, &ok);
       
   176     }
       
   177     Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing");
       
   178     // get needed pointers to some of the widgets
       
   179     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_ZOOM_SLIDER);
       
   180     mSlider = qobject_cast<HbSlider *> (widget);
       
   181     CX_DEBUG_ASSERT(mSlider);
       
   182 
       
   183     //Let's add a plus and minus buttons to the slider
       
   184     addIncreaseDecreaseButtons(mSlider);
       
   185     createWidgetBackgroundGraphic(mSlider, TRANSPARENT_BACKGROUND_GRAPHIC);
       
   186 
       
   187     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_TOOLBAR);
       
   188     mToolBarIdle = qobject_cast<HbToolBar *> (widget);
       
   189     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_TOOLBAR_REC);
       
   190     mToolBarRec = qobject_cast<HbToolBar *> (widget);
       
   191     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_TOOLBAR_PAUSED);
       
   192     mToolBarPaused = qobject_cast<HbToolBar *> (widget);
       
   193 
       
   194     mToolBar = mToolBarIdle;
       
   195 
       
   196     CX_DEBUG_ASSERT(mToolBarIdle);
       
   197     CX_DEBUG_ASSERT(mToolBarRec);
       
   198     CX_DEBUG_ASSERT(mToolBarPaused);
       
   199 
       
   200     QObject* object = mDocumentLoader->findObject(VIDEO_PRE_CAPTURE_TOGGLE_LIGHT_ACTION);
       
   201     mToggleLightAction = qobject_cast<HbAction *>(object);
       
   202     CX_DEBUG_ASSERT(mToggleLightAction);
       
   203 
       
   204     hideControls();
       
   205 
       
   206     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   207         CX_DEBUG(("EMBEDDED: camera in embedded mode"));
       
   208 
       
   209         if (!CxuiServiceProvider::instance()->allowQualityChange()) {
       
   210 
       
   211             CX_DEBUG(("EMBEDDED: don't allow quality change"));
       
   212             HbAction* vq = qobject_cast<HbAction*> (mDocumentLoader->findObject(VIDEO_PRE_CAPTURE_VIDEO_QUALITY_ACTION));
       
   213             if (vq) {
       
   214                 CX_DEBUG(("EMBEDDED: setting image quality setting to disabled"));
       
   215                 vq->setEnabled(false);
       
   216             }
       
   217         }
       
   218         if (!CxuiServiceProvider::instance()->allowModeSwitching()) {
       
   219             CX_DEBUG(("EMBEDDED: don't allow mode switching"));
       
   220 
       
   221             HbAction *still = qobject_cast<HbAction*> (mDocumentLoader->findObject(VIDEO_PRE_CAPTURE_GOTO_STILL_ACTION));
       
   222             if (still) {
       
   223                 CX_DEBUG(("EMBEDDED: setting mode switch to disabled"));
       
   224                 still->setEnabled(false);
       
   225             }
       
   226         }
       
   227         if (!CxuiServiceProvider::instance()->allowCameraSwitching()) {
       
   228             CX_DEBUG(("EMBEDDED: don't allow camera switching"));
       
   229 
       
   230             HbAction *goto_2nd_cam = qobject_cast<HbAction*> (mDocumentLoader->findObject(VIDEO_PRE_CAPTURE_GOTO_2ND_CAMERA_ACTION));
       
   231             if (goto_2nd_cam) {
       
   232                 CX_DEBUG(("EMBEDDED: setting camera switch to disabled"));
       
   233                 goto_2nd_cam->setEnabled(false);
       
   234 
       
   235             }
       
   236         }
       
   237 
       
   238     }
       
   239 
       
   240 
       
   241     // Create background graphics for indicator containers
       
   242     HbWidget *indicatorContainer;
       
   243 
       
   244 
       
   245     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_INDICATOR_CONTAINER_BOTTOM);
       
   246     indicatorContainer = qobject_cast<HbWidget *>(widget);
       
   247     CX_DEBUG_ASSERT(indicatorContainer);
       
   248     createWidgetBackgroundGraphic(indicatorContainer, TRANSPARENT_BACKGROUND_GRAPHIC);
       
   249 
       
   250     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_ELAPSED_TIME_LABEL);
       
   251     mElapsedTimeText = qobject_cast<HbLabel *> (widget);
       
   252     CX_DEBUG_ASSERT(mElapsedTimeText);
       
   253 
       
   254     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_REMAINING_TIME_LABEL);
       
   255     mRemainingTimeText = qobject_cast<HbLabel *> (widget);
       
   256     CX_DEBUG_ASSERT(mRemainingTimeText);
       
   257 
       
   258     widget = mDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_RECORDING_ICON);
       
   259     mRecordingIcon = qobject_cast<HbLabel *> (widget);
       
   260     CX_DEBUG_ASSERT(mRecordingIcon);
       
   261 
       
   262     mWidgetsLoaded = true;
       
   263 
       
   264     // Initializing recording indicator animation
       
   265     mRecordingAnimation = new QPropertyAnimation(mRecordingIcon, "opacity");
       
   266     mRecordingAnimation->setStartValue(0.0);
       
   267     mRecordingAnimation->setKeyValueAt(0.5, 1.0);
       
   268     mRecordingAnimation->setEndValue(0.0);
       
   269     mRecordingAnimation->setDuration(CXUI_RECORD_ANIMATION_DURATION);
       
   270     mRecordingAnimation->setLoopCount(-1);
       
   271     mRecordingAnimation->setEasingCurve(QEasingCurve::InCubic);
       
   272 
       
   273     // Initialize the video time counters.
       
   274     updateTimeLabels();
       
   275 
       
   276     CX_DEBUG_EXIT_FUNCTION();
       
   277 }
       
   278 
       
   279 /*!
       
   280 * Initialize settings grid.
       
   281 */
       
   282 void CxuiVideoPrecaptureView::initializeSettingsGrid()
       
   283 {
       
   284     if(!mSettingsGrid) {
       
   285         HbAction* action(NULL);
       
   286 
       
   287         mSettingsGrid = new HbToolBarExtension;
       
   288 
       
   289         action = mSettingsGrid->addAction(HbIcon("qtg_mono_exposure.svg"), hbTrId("txt_cam_button_exposure_compensation"), this, SLOT(launchSliderSetting()));
       
   290         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::EV_COMPENSATION_VALUE);
       
   291         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
       
   292 
       
   293         action = mSettingsGrid->addAction(HbIcon("qtg_small_rgb.svg"), hbTrId("txt_cam_button_color_tone"), this, SLOT(launchSetting()));
       
   294         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::COLOR_TONE);
       
   295         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
       
   296 
       
   297         action = mSettingsGrid->addAction(HbIcon("qtg_mono_white_balance.svg"), hbTrId("txt_cam_button_white_balance"), this, SLOT(launchSetting()));
       
   298         action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::WHITE_BALANCE);
       
   299         action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE);
       
   300 
       
   301         connect(mKeyHandler, SIGNAL(autofocusKeyPressed()), mSettingsGrid, SLOT(close()));
       
   302     }
       
   303 }
       
   304 
       
   305 void CxuiVideoPrecaptureView::handleSnapshot(CxeError::Id /*error*/)
       
   306 {
       
   307     CX_DEBUG_ENTER_FUNCTION();
       
   308 
       
   309     CX_DEBUG_EXIT_FUNCTION();
       
   310 }
       
   311 
       
   312 void CxuiVideoPrecaptureView::record()
       
   313 {
       
   314     CX_DEBUG_ENTER_FUNCTION();
       
   315 
       
   316     mMenu = takeMenu();
       
   317     hideControls();
       
   318     mVideoCaptureControl->record();
       
   319     //mRecordingAnimation->start();
       
   320     CX_DEBUG_EXIT_FUNCTION();
       
   321 }
       
   322 
       
   323 void CxuiVideoPrecaptureView::pause()
       
   324 {
       
   325     CX_DEBUG_ENTER_FUNCTION();
       
   326 
       
   327     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   328     if (state == CxeVideoCaptureControl::Recording) {
       
   329         if (mRecordingAnimation && mRecordingIcon) {
       
   330             mVideoCaptureControl->pause();
       
   331             mRecordingAnimation->stop();
       
   332             }
       
   333 
       
   334         // force update of toolbar
       
   335         showToolbar();
       
   336     } else if (state == CxeVideoCaptureControl::Paused) {
       
   337         mVideoCaptureControl->record();
       
   338         //mRecordingAnimation->start();
       
   339     }
       
   340 
       
   341     CX_DEBUG_EXIT_FUNCTION();
       
   342 }
       
   343 
       
   344 void CxuiVideoPrecaptureView::stop()
       
   345 {
       
   346     CX_DEBUG_ENTER_FUNCTION();
       
   347     if (isPostcaptureOn()) {
       
   348         CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   349         if (state == CxeVideoCaptureControl::Recording ||
       
   350             state == CxeVideoCaptureControl::Paused) {
       
   351             mVideoCaptureControl->stop();
       
   352             // Continue in handleVideoStateChanged().
       
   353         }
       
   354     } else {
       
   355         // no postcapture
       
   356         stopAndPrepareNewVideo();
       
   357     }
       
   358 
       
   359 
       
   360     CX_DEBUG_EXIT_FUNCTION();
       
   361 }
       
   362 
       
   363 // CxuiVideoPrecaptureView::stopAndPrepareNewVideo()
       
   364 // A version of stop that doesn't go to post-capture. When
       
   365 // not going to post-capture, we need to prepare new video
       
   366 void CxuiVideoPrecaptureView::stopAndPrepareNewVideo()
       
   367 {
       
   368     CX_DEBUG_ENTER_FUNCTION();
       
   369     mVideoCaptureControl->stop();
       
   370     mElapsedTimer.stop();
       
   371     hideControls();
       
   372 
       
   373     if (mMenu) {
       
   374         setMenu(mMenu);
       
   375         mMenu = NULL;
       
   376     }
       
   377 
       
   378     // prepare new video when old one is ready
       
   379     connect(mVideoCaptureControl, SIGNAL(videoComposed(CxeError::Id, const QString&)),
       
   380             this, SLOT(prepareNewVideo(CxeError::Id)));
       
   381 
       
   382     CX_DEBUG_EXIT_FUNCTION();
       
   383 }
       
   384 
       
   385 
       
   386 // CxuiPrecaptureView::showToolbar()
       
   387 // Shows toolbar. Calls the base class implementation if not recording
       
   388 // since toolbar is not shown during recording
       
   389 void CxuiVideoPrecaptureView::showToolbar()
       
   390 {
       
   391     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   392     if (state == CxeVideoCaptureControl::Recording) {
       
   393         if (mToolBar != mToolBarRec) {
       
   394             mToolBar->hide();
       
   395             mToolBar = mToolBarRec;
       
   396         }
       
   397     } else if (state ==CxeVideoCaptureControl::Ready) {
       
   398         if (mToolBar != mToolBarIdle) {
       
   399             mToolBar->hide();
       
   400             mToolBar = mToolBarIdle;
       
   401         }
       
   402     } else if (state == CxeVideoCaptureControl::Paused) {
       
   403         if (mToolBar != mToolBarPaused) {
       
   404             mToolBar->hide();
       
   405             mToolBar = mToolBarPaused;
       
   406         }
       
   407     }
       
   408 
       
   409     CxuiPrecaptureView::showToolbar();
       
   410 }
       
   411 
       
   412 void CxuiVideoPrecaptureView::disableFeedback()
       
   413 {
       
   414     CX_DEBUG_ENTER_FUNCTION();
       
   415 
       
   416     HbFeedbackPlayer* feedback = HbFeedbackPlayer::instance();
       
   417     if (feedback) {
       
   418         feedback->settings().disableFeedback();
       
   419     }
       
   420     CX_DEBUG_EXIT_FUNCTION();
       
   421 }
       
   422 
       
   423 void CxuiVideoPrecaptureView::enableFeedback()
       
   424 {
       
   425     CX_DEBUG_ENTER_FUNCTION();
       
   426 
       
   427     HbFeedbackPlayer* feedback = HbFeedbackPlayer::instance();
       
   428     if (feedback) {
       
   429         feedback->settings().disableFeedback();
       
   430     }
       
   431 
       
   432     CX_DEBUG_EXIT_FUNCTION();
       
   433 }
       
   434 
       
   435 
       
   436 void CxuiVideoPrecaptureView::goToStill()
       
   437 {
       
   438     CX_DEBUG_ENTER_FUNCTION();
       
   439     OstTrace0( camerax_performance, DUP1_CXUIVIDEOPRECAPTUREVIEW_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 1" );
       
   440 
       
   441     hideControls();
       
   442     mEngine->initMode(ImageMode);
       
   443     emit changeToPrecaptureView();
       
   444 
       
   445     OstTrace0( camerax_performance, DUP2_CXUIVIDEOPRECAPTUREVIEW_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 0" );
       
   446     CX_DEBUG_EXIT_FUNCTION();
       
   447 }
       
   448 
       
   449 /*!
       
   450 * Update the remaining and elapsed time labels.
       
   451 */
       
   452 void CxuiVideoPrecaptureView::updateTimeLabels()
       
   453 {
       
   454     CX_DEBUG_IN_FUNCTION();
       
   455 
       
   456     if (!mRemainingTimeText || !mElapsedTimeText) {
       
   457         // Section not loaded yet. Skip update until created.
       
   458         CX_DEBUG(("CxuiVideoPrecaptureView: video time labels not loaded yet!"));
       
   459         CX_DEBUG_EXIT_FUNCTION();
       
   460         return;
       
   461     }
       
   462 
       
   463     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   464     switch (state) {
       
   465         case CxeVideoCaptureControl::Ready:
       
   466             // Update remaining time label
       
   467             getRemainingTime();
       
   468             setVideoTime(mRemainingTimeText, mTimeRemaining);
       
   469             // Update elapsed time label
       
   470             // Not recording => elapsed time is zero
       
   471             mTimeElapsed = 0;
       
   472             setVideoTime(mElapsedTimeText, mTimeElapsed);
       
   473 
       
   474             // Adjust labels' visibility
       
   475             mRemainingTimeText->show();
       
   476             mElapsedTimeText->show();
       
   477             break;
       
   478 
       
   479         case CxeVideoCaptureControl::Recording:
       
   480         case CxeVideoCaptureControl::Paused:
       
   481             // Update remaining time label
       
   482             getRemainingTime();
       
   483             setVideoTime(mRemainingTimeText, mTimeRemaining);
       
   484             // Update elapsed time label
       
   485             getElapsedTime();
       
   486             setVideoTime(mElapsedTimeText, mTimeElapsed);
       
   487 
       
   488             // Adjust labels' visibility
       
   489             mRemainingTimeText->show();
       
   490             mElapsedTimeText->show();
       
   491             break;
       
   492 
       
   493         case CxeVideoCaptureControl::Idle:
       
   494         case CxeVideoCaptureControl::Initialized:
       
   495         case CxeVideoCaptureControl::Preparing:
       
   496         default:
       
   497             // Minimize processing during initialization phase.
       
   498             // Calculating remaining time involves checking disk space,
       
   499             // which
       
   500             mTimeRemaining = 0;
       
   501             setVideoTime(mRemainingTimeText, mTimeRemaining);
       
   502             mTimeElapsed = 0;
       
   503             setVideoTime(mElapsedTimeText, mTimeElapsed);
       
   504 
       
   505             // Adjust labels' visibility
       
   506             mRemainingTimeText->hide();
       
   507             mElapsedTimeText->hide();
       
   508             break;
       
   509     }
       
   510 
       
   511     CX_DEBUG_EXIT_FUNCTION();
       
   512 }
       
   513 
       
   514 /*!
       
   515 * Helper method for formatting video time to requested label.
       
   516 * @param label Text label to show the time.
       
   517 * @param time Time in seconds to be formatted to the label text.
       
   518 */
       
   519 void CxuiVideoPrecaptureView::setVideoTime(HbLabel* label, int time)
       
   520 {
       
   521     // Convert time (seconds) into mm:ss
       
   522     // HbExtendedLocale wraps minutes at 60 so we can't use that.
       
   523     // We need to show times over 1 hour, e.g. "90:00".
       
   524     QString timeString;
       
   525     timeString.sprintf(VIDEO_TIME_FORMAT, time/60, time%60);
       
   526     label->setPlainText(timeString);
       
   527 }
       
   528 
       
   529 bool CxuiVideoPrecaptureView::getElapsedTime()
       
   530 {
       
   531     CX_DEBUG_ENTER_FUNCTION();
       
   532 
       
   533     TBool status = mVideoCaptureControl->elapsedTime(mTimeElapsed);
       
   534     CX_DEBUG(("Elapsed time: %d", mTimeElapsed));
       
   535     CX_DEBUG(("status: %d", status));
       
   536 
       
   537     CX_DEBUG_EXIT_FUNCTION();
       
   538     return status;
       
   539 }
       
   540 
       
   541 void CxuiVideoPrecaptureView::getRemainingTime()
       
   542 {
       
   543     CX_DEBUG_ENTER_FUNCTION();
       
   544 
       
   545     mVideoCaptureControl->remainingTime(mTimeRemaining);
       
   546     CX_DEBUG(("getRemainingTime time: %d", mTimeRemaining));
       
   547 
       
   548     CX_DEBUG_EXIT_FUNCTION();
       
   549 }
       
   550 
       
   551 void CxuiVideoPrecaptureView::showEvent(QShowEvent *event)
       
   552 {
       
   553     CxuiPrecaptureView::showEvent(event);
       
   554 
       
   555     updateQualityIcon();
       
   556 
       
   557     if (event->type() == QEvent::Show) {
       
   558         event->accept();
       
   559     }
       
   560 }
       
   561 
       
   562 void CxuiVideoPrecaptureView::handleVideoStateChanged(CxeVideoCaptureControl::State newState,
       
   563         CxeError::Id error)
       
   564 {
       
   565     CX_DEBUG_ENTER_FUNCTION();
       
   566     Q_UNUSED(error);
       
   567 
       
   568     updateTimeLabels();
       
   569 
       
   570     switch (newState) {
       
   571     case CxeVideoCaptureControl::Ready:
       
   572         setRecordingItemsVisibility(false);
       
   573         if (mCapturePending) {
       
   574             mCapturePending = false;
       
   575             record();
       
   576         }
       
   577         break;
       
   578     case CxeVideoCaptureControl::Recording:
       
   579         setRecordingItemsVisibility(true);
       
   580         mElapsedTimer.start(CXUI_ELAPSED_TIME_TIMEOUT);
       
   581         disableFeedback();
       
   582         break;
       
   583     case CxeVideoCaptureControl::Paused:
       
   584         mElapsedTimer.stop();
       
   585         if (mRecordingIcon) {
       
   586             mRecordingIcon->hide();
       
   587         }
       
   588         if (mElapsedTimeText) {
       
   589             mElapsedTimeText->show();
       
   590         }
       
   591         enableFeedback();
       
   592         break;
       
   593     case CxeVideoCaptureControl::Stopping:
       
   594         setRecordingItemsVisibility(false);
       
   595         enableFeedback();
       
   596 
       
   597         if (isPostcaptureOn()) {
       
   598             mElapsedTimer.stop();
       
   599             hideControls();
       
   600 
       
   601             if (mRecordingAnimation && mRecordingIcon) {
       
   602                 mRecordingAnimation->stop();
       
   603                 mRecordingIcon->setOpacity(0);
       
   604             }
       
   605             if (mMenu) {
       
   606                 setMenu(mMenu);
       
   607                 mMenu = NULL;
       
   608             }
       
   609 
       
   610             emit changeToPostcaptureView();
       
   611         }
       
   612         break;
       
   613     default:
       
   614         // in any other state, just hide the controls
       
   615         setRecordingItemsVisibility(false);
       
   616         break;
       
   617     }
       
   618 
       
   619     CX_DEBUG_EXIT_FUNCTION();
       
   620 }
       
   621 
       
   622 void CxuiVideoPrecaptureView::updateOrientation(Qt::Orientation orientation)
       
   623 {
       
   624     CX_DEBUG_ENTER_FUNCTION();
       
   625 
       
   626     hideControls();
       
   627     mMainWindow->setOrientation(orientation);
       
   628 
       
   629     if (mToolBar) {
       
   630         if (orientation == Qt::Horizontal) {
       
   631             mToolBar->setOrientation(Qt::Vertical);
       
   632         } else {
       
   633             mToolBar->setOrientation(Qt::Horizontal);
       
   634         }
       
   635     }
       
   636 
       
   637     CX_DEBUG_EXIT_FUNCTION();
       
   638 }
       
   639 
       
   640 void CxuiVideoPrecaptureView::handleCaptureKeyPressed()
       
   641 {
       
   642     CX_DEBUG_ENTER_FUNCTION();
       
   643     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   644 
       
   645     switch (state) {
       
   646         case CxeVideoCaptureControl::Ready:
       
   647         case CxeVideoCaptureControl::Paused:
       
   648             record();
       
   649             break;
       
   650         case CxeVideoCaptureControl::Recording:
       
   651             stop();
       
   652             break;
       
   653         case CxeVideoCaptureControl::Idle:
       
   654         case CxeVideoCaptureControl::Initialized:
       
   655         case CxeVideoCaptureControl::Preparing:
       
   656             mCapturePending = true;
       
   657             break;
       
   658 
       
   659     }
       
   660     CX_DEBUG_EXIT_FUNCTION();
       
   661 }
       
   662 
       
   663 void CxuiVideoPrecaptureView::prepareNewVideo(CxeError::Id error)
       
   664 {
       
   665     if (!error) {
       
   666         mEngine->initMode(Cxe::VideoMode);
       
   667         disconnect(mVideoCaptureControl, SIGNAL(videoComposed(CxeError::Id, const QString&)),
       
   668                    this, SLOT(prepareNewVideo(CxeError::Id)));
       
   669     } else {
       
   670         emit reportError(error);
       
   671     }
       
   672 
       
   673 }
       
   674 
       
   675 /**
       
   676 * Toggle video light on / off.
       
   677 */
       
   678 void CxuiVideoPrecaptureView::toggleLight()
       
   679 {
       
   680     launchNotSupportedNotification();
       
   681 }
       
   682 
       
   683 void CxuiVideoPrecaptureView::handleQuitClicked()
       
   684 {
       
   685     CX_DEBUG_ENTER_FUNCTION();
       
   686 
       
   687     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   688     if (state == CxeVideoCaptureControl::Recording){
       
   689         // Disable going to post-capture when video capture control goes to stopping state.
       
   690         disconnect(mVideoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id)),
       
   691                    this, SLOT(handleVideoStateChanged(CxeVideoCaptureControl::State,CxeError::Id)));
       
   692         mVideoCaptureControl->stop();
       
   693         mElapsedTimer.stop();
       
   694     }
       
   695 
       
   696     QCoreApplication::exit();
       
   697 
       
   698     CX_DEBUG_EXIT_FUNCTION();
       
   699 }
       
   700 
       
   701 void CxuiVideoPrecaptureView::handleFocusLost()
       
   702 {
       
   703     CX_DEBUG_IN_FUNCTION();
       
   704 
       
   705     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   706     if (state == CxeVideoCaptureControl::Recording){
       
   707         stop(); // delete recording icon
       
   708     } else {
       
   709         releaseCamera();
       
   710     }
       
   711 
       
   712 }
       
   713 
       
   714 void CxuiVideoPrecaptureView::handleBatteryEmpty()
       
   715 {
       
   716     CX_DEBUG_ENTER_FUNCTION();
       
   717 
       
   718     CxeVideoCaptureControl::State state = mVideoCaptureControl->state();
       
   719     if (state == CxeVideoCaptureControl::Recording){
       
   720         stop(); // delete recording icon
       
   721     }
       
   722     CX_DEBUG_EXIT_FUNCTION();
       
   723 }
       
   724 
       
   725 
       
   726 void CxuiVideoPrecaptureView::launchVideoScenePopup()
       
   727 {
       
   728     CX_DEBUG_ENTER_FUNCTION();
       
   729 
       
   730     if (mVideoScenePopup) {
       
   731         CX_DEBUG(("mVideoScenePopup already exists, showing..."));
       
   732         mVideoScenePopup->show();
       
   733     } else {
       
   734         CX_DEBUG(("Loading popup DocML"));
       
   735         CxuiDocumentLoader* documentLoader = new CxuiDocumentLoader(mEngine);
       
   736         bool ok = false;
       
   737 
       
   738         // Use document loader to create popup
       
   739         documentLoader->load(SCENEMODE_VIDEO_SETTING_XML, &ok);
       
   740 
       
   741         CX_DEBUG(("load ok=%d", ok));
       
   742 
       
   743         mVideoScenePopup = qobject_cast<HbDialog*>(documentLoader->findWidget("video_scenemode_popup"));
       
   744         CX_DEBUG_ASSERT(mVideoScenePopup);
       
   745         mVideoScenePopup->setTimeout(HbDialog::NoTimeout);
       
   746         mVideoScenePopup->setBackgroundFaded(false);
       
   747 
       
   748         delete documentLoader;
       
   749         documentLoader = NULL;
       
   750     }
       
   751 
       
   752     connect(mKeyHandler, SIGNAL(autofocusKeyPressed()), mVideoScenePopup, SLOT(close()));
       
   753 
       
   754     CX_DEBUG_EXIT_FUNCTION();
       
   755 }
       
   756 
       
   757 
       
   758 /*!
       
   759 * Launches show-postcapture setting pop-up
       
   760 */
       
   761 void CxuiVideoPrecaptureView::launchSetting()
       
   762 {
       
   763     CX_DEBUG_ENTER_FUNCTION();
       
   764 
       
   765     QObject *action = sender();
       
   766 
       
   767     if (action) {
       
   768         QString settingsKey = action->property(PROPERTY_KEY_SETTING_ID).toString();
       
   769         CX_DEBUG(("settingsKey=%s", settingsKey.toAscii().constData()));
       
   770         launchSettingsDialog(action);
       
   771     }
       
   772 
       
   773     CX_DEBUG_EXIT_FUNCTION();
       
   774 }
       
   775 
       
   776 /*!
       
   777 * Handle change in setting value. Update UI to reflect new value.
       
   778 */
       
   779 void CxuiVideoPrecaptureView::handleSettingValueChanged(const QString& key, QVariant newValue)
       
   780 {
       
   781     CX_DEBUG_ENTER_FUNCTION();
       
   782 
       
   783     Q_UNUSED(newValue);
       
   784     // Ignored if not in video mode.
       
   785     if (mEngine->mode() == Cxe::VideoMode) {
       
   786         if (key == CxeSettingIds::VIDEO_QUALITY) {
       
   787             // update the quality indicator on screen
       
   788             updateQualityIcon();
       
   789 
       
   790             // update video remaining time counter when video quality is changed
       
   791             updateTimeLabels();
       
   792         }
       
   793     }
       
   794 
       
   795     CX_DEBUG_EXIT_FUNCTION();
       
   796 }
       
   797 
       
   798 /*!
       
   799     Sets the visibility of recording icon and elapsed time text.
       
   800     \param visible True if widgets are to be shown, false if not.
       
   801 */
       
   802 void CxuiVideoPrecaptureView::setRecordingItemsVisibility(bool visible) {
       
   803 
       
   804     if (mRecordingIcon) {
       
   805         mRecordingIcon->setVisible(visible);
       
   806         mRecordingIcon->setOpacity(1.0f);
       
   807     }
       
   808 
       
   809     if (mElapsedTimeText) {
       
   810         mElapsedTimeText->setVisible(visible);
       
   811     }
       
   812 }
       
   813 
       
   814 
       
   815 
       
   816 //end of file