camerauis/cameraxui/cxui/src/cxuiprecaptureview.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 <coemain.h>
       
    19 #include <QGraphicsSceneEvent>
       
    20 #include <QProcess>
       
    21 #include <QApplication>
       
    22 #include <hbmainwindow.h>
       
    23 #include <hbslider.h>
       
    24 #include <hbtoolbar.h>
       
    25 #include <hblabel.h>
       
    26 #include <hbtoolbarextension.h>
       
    27 #include <hbtransparentwindow.h>
       
    28 #include <hbmenu.h>
       
    29 #include <hbdialog.h>
       
    30 #include <hbdeviceprofile.h>
       
    31 #include <hbnotificationdialog.h>
       
    32 #include <hbaction.h>
       
    33 #include <hbstyle.h>
       
    34 #include <hbframeitem.h>
       
    35 
       
    36 #include "cxeengine.h"
       
    37 #include "cxeviewfindercontrol.h"
       
    38 #include "cxezoomcontrol.h"
       
    39 #include "cxecameradevicecontrol.h"
       
    40 #include "cxenamespace.h"
       
    41 #include "cxefeaturemanager.h"
       
    42 #include "cxestillcapturecontrol.h"
       
    43 #include "cxevideocapturecontrol.h"
       
    44 #include "cxesettings.h"
       
    45 #include "cxutils.h"
       
    46 #include "cxuienums.h"
       
    47 #include "cxuidocumentloader.h"
       
    48 #include "cxuidisplaypropertyhandler.h"
       
    49 #include "cxuicapturekeyhandler.h"
       
    50 #include "cxuiprecaptureview.h"
       
    51 #include "cxuisettingdialog.h"
       
    52 #include "cxuisettingradiobuttonlist.h"
       
    53 #include "cxuisettingslider.h"
       
    54 #include "cxuisettingsinfo.h"
       
    55 #include "OstTraceDefinitions.h"
       
    56 #ifdef OST_TRACE_COMPILER_IN_USE
       
    57 #include "cxuiprecaptureviewTraces.h"
       
    58 #endif
       
    59 #include "cxuiserviceprovider.h"
       
    60 
       
    61 
       
    62 // CONSTANTS
       
    63 const int CXUI_HIDE_CONTROLS_TIMEOUT     = 6000; // 6 seconds
       
    64 const QString PhotosAppExe = "photos.exe";
       
    65 const QString VideosAppExe = "videoplayer.exe";
       
    66 
       
    67 using namespace CxUiLayout;
       
    68 using namespace CxUiSettings;
       
    69 using namespace CxUiInternal;
       
    70 
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CxuiPrecaptureView::CxuiPrecaptureView
       
    75 // Constructor
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CxuiPrecaptureView::CxuiPrecaptureView(QGraphicsItem *parent) :
       
    79     HbView(parent),
       
    80     mEngine(0),
       
    81     mViewfinder(0),
       
    82     mMainWindow(0),
       
    83     mDocumentLoader(0),
       
    84     mDisplayHandler(0),
       
    85     mControlsVisible(false),
       
    86     mHideControlsTimeout(this),
       
    87     mSlider(0),
       
    88     mToolBar(0),
       
    89     mSettingsGrid(0),
       
    90     mZoomVisible(false),
       
    91     mWidgetsLoaded(false),
       
    92     mSettingsDialog(NULL),
       
    93     mSettingsDialogList(NULL),
       
    94     mKeyHandler(NULL),
       
    95     mQualityIcon(NULL),
       
    96     mSettingsDialogHeading(NULL),
       
    97     mSliderSettingsDialog(NULL),
       
    98     mSliderSettingsDialogHeading(NULL),
       
    99     mSettingsSlider(NULL),
       
   100     mSettingsInfo(NULL)
       
   101 {
       
   102     CX_DEBUG_ENTER_FUNCTION();
       
   103     mDisplayHandler = new CxuiDisplayPropertyHandler();
       
   104     CX_DEBUG_EXIT_FUNCTION();
       
   105 }
       
   106 
       
   107 CxuiPrecaptureView::~CxuiPrecaptureView()
       
   108 {
       
   109     CX_DEBUG_ENTER_FUNCTION();
       
   110     QCoreApplication::instance()->removeEventFilter(this);
       
   111     delete mSettingsGrid;
       
   112     CX_DEBUG_EXIT_FUNCTION();
       
   113 }
       
   114 
       
   115 
       
   116 void CxuiPrecaptureView::construct(HbMainWindow *mainWindow, CxeEngine *engine,
       
   117                                    CxuiDocumentLoader *documentLoader,
       
   118                                    CxuiCaptureKeyHandler * keyHandler)
       
   119 {
       
   120     CX_DEBUG_ENTER_FUNCTION();
       
   121     OstTrace0( camerax_performance, CXUIPRECAPTUREVIEW_CONSTRUCT, "msg: e_CX_PRECAPVIEW_CONST 1" );
       
   122 
       
   123     CX_ASSERT_ALWAYS(mainWindow);
       
   124     CX_ASSERT_ALWAYS(engine);
       
   125     CX_ASSERT_ALWAYS(documentLoader);
       
   126 
       
   127     mMainWindow = mainWindow;
       
   128     mEngine = engine;
       
   129     mDocumentLoader = documentLoader;
       
   130     mKeyHandler = keyHandler;
       
   131 
       
   132     mSettingsInfo = new CxuiSettingsInfo(engine);
       
   133     CX_DEBUG_ASSERT(mSettingsInfo);
       
   134 
       
   135     setContentFullScreen(true);
       
   136 
       
   137     connect(&mEngine->zoomControl(), SIGNAL(stateChanged(CxeZoomControl::State, CxeError::Id)), this,
       
   138             SLOT(handleEngineZoomStateChange(CxeZoomControl::State, CxeError::Id)));
       
   139 
       
   140     connect(&mEngine->zoomControl(), SIGNAL(zoomLevelChanged(int)), this,
       
   141             SLOT(handleZoomLevelChange(int)));
       
   142 
       
   143 
       
   144     connect(&mEngine->viewfinderControl(), SIGNAL(stateChanged(CxeViewfinderControl::State, CxeError::Id)),
       
   145             this, SLOT(handleVfStateChanged(CxeViewfinderControl::State, CxeError::Id)));
       
   146 
       
   147     connect(&(mEngine->settings()), SIGNAL(settingValueChanged(const QString&,QVariant)),
       
   148             this, SLOT(handleSettingValueChanged(const QString&, QVariant)));
       
   149 
       
   150     // adjust the timer, and connect it to correct slot
       
   151     connect(&mHideControlsTimeout, SIGNAL(timeout()), this, SLOT(hideControls()));
       
   152 
       
   153     mHideControlsTimeout.setSingleShot(true);
       
   154     mHideControlsTimeout.setInterval(CXUI_HIDE_CONTROLS_TIMEOUT);
       
   155 
       
   156     hideControls();
       
   157 
       
   158     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   159         // override exit with action that completes the request before exiting
       
   160         HbAction* exitAction = new HbAction(Hb::QuitNaviAction, this);
       
   161         connect(exitAction, SIGNAL(triggered()), CxuiServiceProvider::instance(), SLOT(sendFilenameToClientAndExit()));
       
   162         setNavigationAction(exitAction);
       
   163     }
       
   164     OstTrace0( camerax_performance, DUP1_CXUIPRECAPTUREVIEW_CONSTRUCT, "msg: e_CX_PRECAPVIEW_CONST 0" );
       
   165 
       
   166     QCoreApplication::instance()->installEventFilter(this);
       
   167     CX_DEBUG_EXIT_FUNCTION();
       
   168 }
       
   169 
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CxuiPrecaptureView::prepareWindow
       
   173 //
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CxuiPrecaptureView::prepareWindow()
       
   177 {
       
   178     CX_DEBUG_ENTER_FUNCTION();
       
   179 
       
   180     if (mMainWindow) {
       
   181         mEngine->viewfinderControl().setWindow(mMainWindow->effectiveWinId());
       
   182         setFlag(QGraphicsItem::ItemIsFocusable);
       
   183         setFocusPolicy(Qt::StrongFocus);
       
   184         setFocus();
       
   185     }
       
   186 
       
   187     CX_DEBUG_EXIT_FUNCTION();
       
   188 }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CxuiPrecaptureView::handleEngineZoomStateChange
       
   192 // Slot for the initModeComplete signal from device control.
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CxuiPrecaptureView::handleEngineZoomStateChange(CxeZoomControl::State newState, CxeError::Id /*error*/ )
       
   196 {
       
   197     CX_DEBUG_ENTER_FUNCTION();
       
   198 
       
   199     if (newState == CxeZoomControl::Ready) {
       
   200         // Set the zoom range (if more than zero!)
       
   201         // NOTE: This is & should be done after ECam resolution has been set.
       
   202         int min = mEngine->zoomControl().min();
       
   203         int max = mEngine->zoomControl().max();
       
   204 
       
   205         // only change values if they are acceptable and have changed
       
   206         if (mSlider && (max - min > 0) && ((mSlider->maximum() != max)
       
   207                 || (mSlider->minimum()!= min))) {
       
   208             mSlider->setRange(min, max);
       
   209         }
       
   210     }
       
   211 
       
   212     CX_DEBUG_EXIT_FUNCTION();
       
   213 }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CxuiPrecaptureView::zoomTo
       
   217 // Responds to valueChanged notification from zoom bar UI
       
   218 // and asks the engine to set the appropriate zoom level.
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CxuiPrecaptureView::zoomTo(int value)
       
   222 {
       
   223     CX_DEBUG_ENTER_FUNCTION();
       
   224 
       
   225     CX_DEBUG(( "Slider value: %d", value ));
       
   226     mEngine->zoomControl().zoomTo(value);
       
   227 
       
   228     // restarts the timer, if ongoing
       
   229     if (mHideControlsTimeout.isActive()) {
       
   230         mHideControlsTimeout.start();
       
   231     }
       
   232 
       
   233     CX_DEBUG_EXIT_FUNCTION();
       
   234 }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CxuiPrecaptureView::hideControls
       
   238 //
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CxuiPrecaptureView::hideControls()
       
   242 {
       
   243     CX_DEBUG_ENTER_FUNCTION();
       
   244 
       
   245     hideItems(Hb::AllItems);
       
   246     hideZoom();
       
   247     mControlsVisible = false;
       
   248     if (mHideControlsTimeout.isActive()) {
       
   249         mHideControlsTimeout.stop();
       
   250     }
       
   251     hideToolbar();
       
   252     // give the keyboard focus back to the view
       
   253     // for the view to receive key events
       
   254     setFocus();
       
   255 
       
   256     CX_DEBUG_EXIT_FUNCTION();
       
   257 }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CxuiPrecaptureView::hideToolbar
       
   261 //
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CxuiPrecaptureView::hideToolbar()
       
   265 {
       
   266     CX_DEBUG_ENTER_FUNCTION();
       
   267     if (mToolBar) {
       
   268         mToolBar->hide();
       
   269     }
       
   270     CX_DEBUG_EXIT_FUNCTION();
       
   271 }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // CxuiPrecaptureView::hideZoom
       
   275 //
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CxuiPrecaptureView::hideZoom()
       
   279 {
       
   280     if (mSlider) {
       
   281         mSlider->hide();
       
   282     }
       
   283     mZoomVisible = false;
       
   284 }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CxuiPrecaptureView::showZoom
       
   288 //
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CxuiPrecaptureView::showZoom()
       
   292 {
       
   293     CX_DEBUG_ENTER_FUNCTION();
       
   294     if (mSlider) {
       
   295 
       
   296         // if maxVal has not been set yet, ask for new parameters from engine
       
   297         if (mSlider->maximum() <= 0) {
       
   298 
       
   299             // get the zoom range
       
   300             int min = mEngine->zoomControl().min();
       
   301             int max = mEngine->zoomControl().max();
       
   302 
       
   303             // only change values if they are acceptable and have changed
       
   304             if ((max - min > 0) && ((mSlider->maximum() != max) || (mSlider->minimum() != min))) {
       
   305                 mSlider->setRange(min, max);
       
   306             }
       
   307         }
       
   308 
       
   309         // show zoom only if the slider has acceptable value
       
   310         if (mSlider->maximum() > 0) {
       
   311             mSlider->show();
       
   312         }
       
   313     }
       
   314 
       
   315     mZoomVisible = true;
       
   316     CX_DEBUG_EXIT_FUNCTION();
       
   317 }
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // CxuiPrecaptureView::toggleZoom
       
   321 //
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CxuiPrecaptureView::toggleZoom()
       
   325 {
       
   326     if (mZoomVisible) {
       
   327         hideZoom();
       
   328     } else {
       
   329         showZoom();
       
   330     }
       
   331 }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CxuiPrecaptureView::showControls
       
   335 //
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CxuiPrecaptureView::showControls()
       
   339 {
       
   340     if (mEngine) {
       
   341         bool videoCases = (mEngine->videoCaptureControl().state() == CxeVideoCaptureControl::Recording ||
       
   342                            mEngine->videoCaptureControl().state() == CxeVideoCaptureControl::Paused);
       
   343 
       
   344         if (mEngine->isEngineReady() || videoCases) {
       
   345             // show toolbar
       
   346             showToolbar();
       
   347             // show zoom
       
   348             showZoom();
       
   349             // show titlepane
       
   350             showItems(Hb::AllItems);
       
   351             mHideControlsTimeout.start();
       
   352             mControlsVisible = true;
       
   353         }
       
   354     }
       
   355 }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // CxuiPrecaptureView::showToolbar
       
   359 // shows toolbar
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CxuiPrecaptureView::showToolbar()
       
   363 {
       
   364 
       
   365     CX_DEBUG_ENTER_FUNCTION();
       
   366 
       
   367     // toolbar pointer is missing if widgets for the view have not been loaded
       
   368     // from the DocML
       
   369     if (mToolBar) {
       
   370         mToolBar->show();
       
   371     }
       
   372 
       
   373     CX_DEBUG_EXIT_FUNCTION();
       
   374 }
       
   375 
       
   376 
       
   377 /*
       
   378  *  Event filter which filters tool bar mouse events and
       
   379  *  application wide mouse events.
       
   380  */
       
   381 
       
   382 bool CxuiPrecaptureView::eventFilter(QObject *object, QEvent *event)
       
   383 {
       
   384     Q_UNUSED(object)
       
   385 
       
   386     bool eventWasConsumed = false;
       
   387 
       
   388     switch (event->type())
       
   389     {
       
   390     case QEvent::GraphicsSceneMouseRelease:
       
   391         mHideControlsTimeout.start();
       
   392         break;
       
   393     case QEvent::GraphicsSceneMousePress:
       
   394         mHideControlsTimeout.stop();
       
   395         break;
       
   396     default:
       
   397         break;
       
   398     }
       
   399 
       
   400     return eventWasConsumed;
       
   401 }
       
   402 
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // CxuiPrecaptureView::toggleControls
       
   406 //
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 void CxuiPrecaptureView::toggleControls()
       
   410 {
       
   411     // This method is put here to demonstrate that widget creation can
       
   412     // be postponed using sections in layout xml
       
   413     if (!mWidgetsLoaded) {
       
   414         // call load widgets to load app DocML and get the pointers to needed widgets
       
   415         loadWidgets();
       
   416     }
       
   417 
       
   418     if (mControlsVisible) {
       
   419         hideControls();
       
   420     } else {
       
   421         showControls();
       
   422     }
       
   423 }
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CxuiPrecaptureView::mousePressEvent
       
   428 //
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CxuiPrecaptureView::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   432 {
       
   433     if (event->type() == QEvent::GraphicsSceneMousePress) {
       
   434         toggleControls();
       
   435         event->accept();
       
   436     }
       
   437 }
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // CxuiPrecaptureView::handleZoomLevelChange
       
   441 // Slot to handle zoom level change signal from zoom control.
       
   442 // -------------------------------------------------------------------------
       
   443 //
       
   444 void CxuiPrecaptureView::handleZoomLevelChange(int zoomValue)
       
   445 {
       
   446     CX_DEBUG_ENTER_FUNCTION();
       
   447 
       
   448     if (mSlider && zoomValue != mSlider->value()) {
       
   449         CX_DEBUG(( "Zoom level is: %d", zoomValue ));
       
   450         mSlider->setValue(zoomValue);
       
   451     }
       
   452 
       
   453     // reset the timer if it is ongoing
       
   454     if (mHideControlsTimeout.isActive()) {
       
   455         mHideControlsTimeout.start();
       
   456     }
       
   457 
       
   458     CX_DEBUG_EXIT_FUNCTION();
       
   459 }
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // CxuiPrecaptureView::showEvent
       
   463 //
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CxuiPrecaptureView::showEvent(QShowEvent *event)
       
   467 {
       
   468     CX_DEBUG_ENTER_FUNCTION();
       
   469 
       
   470     QGraphicsWidget::showEvent(event);
       
   471 
       
   472     if (event->type() == QEvent::Show) {
       
   473         QCoreApplication::instance()->installEventFilter(this);
       
   474         event->accept();
       
   475     }
       
   476 
       
   477     CX_DEBUG_EXIT_FUNCTION();
       
   478 }
       
   479 
       
   480 // ---------------------------------------------------------------------------
       
   481 // CxuiPrecaptureView::hideEvent
       
   482 //
       
   483 // ---------------------------------------------------------------------------
       
   484 //
       
   485 void CxuiPrecaptureView::hideEvent(QHideEvent *event)
       
   486 {
       
   487     CX_DEBUG_ENTER_FUNCTION();
       
   488 
       
   489     QGraphicsWidget::hideEvent(event);
       
   490 
       
   491     if (event->type() == QEvent::Hide) {
       
   492         QCoreApplication::instance()->removeEventFilter(this);
       
   493         hideZoom();
       
   494         event->accept();
       
   495     }
       
   496 
       
   497     CX_DEBUG_EXIT_FUNCTION();
       
   498 }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // CxuiPrecaptureView::requestCameraSwitch
       
   502 // Slot to switch camera. Needed for options menu signals (in DocML).
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CxuiPrecaptureView::requestCameraSwitch() {
       
   506     emit switchCamera();
       
   507 }
       
   508 
       
   509 /**
       
   510 * Handle pressing auto focus key.
       
   511 */
       
   512 void CxuiPrecaptureView::handleAutofocusKeyPressed()
       
   513 {
       
   514     CX_DEBUG_ENTER_FUNCTION();
       
   515 
       
   516     if (mSettingsDialog) {
       
   517         // Prevent us from trying to show grid when dialog closes.
       
   518         mSettingsDialog->setStarterAction(NULL);
       
   519         mSettingsDialog->close();
       
   520     }
       
   521     if (mSliderSettingsDialog) {
       
   522         mSliderSettingsDialog->setStarterAction(NULL);
       
   523         mSliderSettingsDialog->close();
       
   524     }
       
   525 
       
   526     menu()->close();
       
   527     hideControls();
       
   528 
       
   529     CX_DEBUG_EXIT_FUNCTION();
       
   530 }
       
   531 
       
   532 // ---------------------------------------------------------------------------
       
   533 // CxuiPrecaptureView::disableControlsTimeout
       
   534 // Slot
       
   535 // ---------------------------------------------------------------------------
       
   536 //
       
   537 void CxuiPrecaptureView::disableControlsTimeout()
       
   538 {
       
   539     CX_DEBUG_ENTER_FUNCTION();
       
   540     if (mHideControlsTimeout.isActive()) {
       
   541         mHideControlsTimeout.stop();
       
   542     }
       
   543     CX_DEBUG_EXIT_FUNCTION();
       
   544 }
       
   545 
       
   546 // ---------------------------------------------------------------------------
       
   547 // CxuiPrecaptureView::releaseCamera
       
   548 // ---------------------------------------------------------------------------
       
   549 void CxuiPrecaptureView::releaseCamera()
       
   550 {
       
   551     CX_DEBUG_ENTER_FUNCTION();
       
   552     mEngine->cameraDeviceControl().release();
       
   553     CX_DEBUG_EXIT_FUNCTION();
       
   554 }
       
   555 
       
   556 
       
   557 // ---------------------------------------------------------------------------
       
   558 // CxuiPrecaptureView::initCamera
       
   559 // ---------------------------------------------------------------------------
       
   560 void CxuiPrecaptureView::initCamera()
       
   561 {
       
   562     CX_DEBUG_ENTER_FUNCTION();
       
   563     mEngine->initMode(mEngine->mode());
       
   564     CX_DEBUG_EXIT_FUNCTION();
       
   565 }
       
   566 
       
   567 
       
   568 /*
       
   569  * viewfinder state call backs
       
   570  */
       
   571 void CxuiPrecaptureView::handleVfStateChanged(
       
   572     CxeViewfinderControl::State newState, CxeError::Id /*error*/)
       
   573 {
       
   574     CX_DEBUG_ENTER_FUNCTION();
       
   575 
       
   576     if (newState == CxeViewfinderControl::Running) {
       
   577         // switch off screen saver and turn on backlight
       
   578         if(mDisplayHandler) {
       
   579             mDisplayHandler->setDisplayAlwaysVisible(true);
       
   580         }
       
   581         // start the standby timer
       
   582         emit startStandbyTimer();
       
   583     } else {
       
   584         // switch on screen saver and turn off backlight
       
   585         if(mDisplayHandler) {
       
   586             mDisplayHandler->setDisplayAlwaysVisible(false);
       
   587         }
       
   588         // stop the standby timer when vf is not running.
       
   589         emit stopStandbyTimer();
       
   590     }
       
   591 
       
   592     CX_DEBUG_EXIT_FUNCTION();
       
   593 }
       
   594 
       
   595 
       
   596 /*
       
   597  * CxuiPrecaptureView::handleFocusGained
       
   598  */
       
   599 void CxuiPrecaptureView::handleFocusGained()
       
   600 {
       
   601     CX_DEBUG_ENTER_FUNCTION();
       
   602 
       
   603     // Set the window size and handle again.
       
   604     prepareWindow();
       
   605     initCamera();
       
   606 
       
   607     CX_DEBUG_EXIT_FUNCTION();
       
   608 }
       
   609 
       
   610 /*!
       
   611 * Handle setting dialog showing up.
       
   612 * If the setting dialog was launched from the setting grid, hide grid now.
       
   613 * @param action Action that launched the dialog.
       
   614 */
       
   615 void CxuiPrecaptureView::prepareToShowDialog(HbAction *action)
       
   616 {
       
   617     if (!action) {
       
   618         return;
       
   619     }
       
   620 
       
   621     // Check if the dialog was started from grid, and hide the grid now if needed.
       
   622     QString fromGrid = action->property(PROPERTY_KEY_SETTING_GRID).toString();
       
   623     if (fromGrid.compare(QString(PROPERTY_KEY_TRUE)) == 0 ) {
       
   624         hideSettingsGrid();
       
   625     }
       
   626 }
       
   627 
       
   628 /*!
       
   629 * Handle setting dialog closing down.
       
   630 * If the setting dialog was launched from the setting grid, show grid again now.
       
   631 * @param action Action that launched the dialog.
       
   632 */
       
   633 void CxuiPrecaptureView::prepareToCloseDialog(HbAction *action)
       
   634 {
       
   635     if (!action) {
       
   636         return;
       
   637     }
       
   638 
       
   639     // Check if the dialog was started from grid, and show the grid now if needed.
       
   640     // Autofocus key-press will clear the action to disable showing the grid.
       
   641     QString fromGrid = action->property(PROPERTY_KEY_SETTING_GRID).toString();
       
   642     if (fromGrid.compare(QString(PROPERTY_KEY_TRUE)) == 0 ) {
       
   643         showSettingsGrid();
       
   644     }
       
   645 
       
   646     // Clear the starter actions to be sure they are not reused.
       
   647     if (mSettingsDialog) {
       
   648         mSettingsDialog->setStarterAction(NULL);
       
   649     }
       
   650     if (mSliderSettingsDialog) {
       
   651         mSliderSettingsDialog->setStarterAction(NULL);
       
   652     }
       
   653 }
       
   654 
       
   655 
       
   656 
       
   657 /*!
       
   658 *Helper method to create setting dialog
       
   659 */
       
   660 CxuiSettingDialog* CxuiPrecaptureView::createSettingsDialog()
       
   661 {
       
   662     CX_DEBUG_ENTER_FUNCTION();
       
   663 
       
   664     CX_DEBUG(("Loading popup DocML"));
       
   665     CxuiDocumentLoader *documentLoader = new CxuiDocumentLoader(mEngine);
       
   666 
       
   667     // Use document loader to create popup
       
   668     bool ok = false;
       
   669     documentLoader->load(SETTINGS_DIALOG_XML, &ok);
       
   670     CX_DEBUG(("load ok=%d", ok));
       
   671 
       
   672     CxuiSettingDialog *dialog =
       
   673         qobject_cast<CxuiSettingDialog*>(documentLoader->findWidget(SETTINGS_DIALOG_WIDGET));
       
   674     CX_ASSERT_ALWAYS(dialog);
       
   675 
       
   676     dialog->setTimeout(HbDialog::NoTimeout);
       
   677     dialog->setBackgroundFaded(false);
       
   678 
       
   679     mSettingsDialogHeading = qobject_cast<HbLabel *>(
       
   680                                     documentLoader->findWidget(SETTINGS_DIALOG_HEADING_WIDGET));
       
   681     CX_ASSERT_ALWAYS(mSettingsDialogHeading);
       
   682 
       
   683     mSettingsDialogList = qobject_cast<CxuiSettingRadioButtonList *>(
       
   684                                     documentLoader->findWidget(SETTINGS_DIALOG_CONTENT_WIDGET));
       
   685     CX_ASSERT_ALWAYS(mSettingsDialogList);
       
   686 
       
   687 
       
   688     CX_DEBUG_EXIT_FUNCTION();
       
   689 
       
   690     delete documentLoader;
       
   691     documentLoader = NULL;
       
   692 
       
   693     return dialog;
       
   694 }
       
   695 
       
   696 
       
   697 
       
   698 /*!
       
   699 *Helper method to create setting dialog
       
   700 */
       
   701 void CxuiPrecaptureView::launchSettingsDialog(QObject* action)
       
   702 {
       
   703     CX_DEBUG_ENTER_FUNCTION();
       
   704 
       
   705     if (!action) {
       
   706         return;
       
   707     }
       
   708 
       
   709     QString key = action->property(PROPERTY_KEY_SETTING_ID).toString();
       
   710     CX_DEBUG(("settingsKey=%s", key.toAscii().constData()));
       
   711 
       
   712     RadioButtonListParams data;
       
   713 
       
   714     // Load data and check that the setting is supported.
       
   715     if (mSettingsInfo && mSettingsInfo->getSettingsContent(key, data)) {
       
   716 
       
   717         if (!mSettingsDialog) {
       
   718             mSettingsDialog = createSettingsDialog();
       
   719 
       
   720             connect(mSettingsDialog, SIGNAL(dialogAboutToShow(HbAction *)),
       
   721                     this, SLOT(prepareToShowDialog(HbAction *)));
       
   722             connect(mSettingsDialog, SIGNAL(dialogAboutToClose(HbAction *)),
       
   723                     this, SLOT(prepareToCloseDialog(HbAction *)));
       
   724         }
       
   725 
       
   726         if (mSettingsDialogHeading) {
       
   727             mSettingsDialogHeading->setPlainText(data.mHeading);
       
   728         }
       
   729 
       
   730         if (mSettingsDialogList) {
       
   731             mSettingsDialogList->init(&data);
       
   732         }
       
   733 
       
   734         if (mSettingsDialog) {
       
   735             // Store action that starts the dialog.
       
   736             // Dialog passes this along with it's signals,
       
   737             // so we can easily decide if we show grid again or not.
       
   738             mSettingsDialog->setStarterAction(qobject_cast<HbAction *>(action));
       
   739 
       
   740             HbAction *okAction = mSettingsDialog->primaryAction();
       
   741             if (okAction) {
       
   742                 // disconnect primary action from dialog so that dialog won't be closed
       
   743                 // automatically when action is triggered. handleSelectionAccepted
       
   744                 // is called instead
       
   745                 okAction->disconnect(mSettingsDialog);
       
   746                 connect(okAction, SIGNAL(triggered()), mSettingsDialogList, SLOT(handleSelectionAccepted()));
       
   747 
       
   748                 // Close the dialog when new setting value is committed
       
   749                 connect(mSettingsDialogList, SIGNAL(selectionCommitted()), mSettingsDialog, SLOT(close()));
       
   750 
       
   751                 connect(mSettingsDialog, SIGNAL(aboutToClose()), mSettingsDialogList, SLOT(handleClose()));
       
   752             }
       
   753 
       
   754             // Adjust position and show the dialog.
       
   755             mSettingsDialog->setPreferredPos(getDialogPosition(), HbPopup::BottomRightCorner);
       
   756             mSettingsDialog->show();
       
   757         }
       
   758     } else {
       
   759         launchNotSupportedNotification();
       
   760     }
       
   761 
       
   762     CX_DEBUG_EXIT_FUNCTION();
       
   763 }
       
   764 
       
   765 /*!
       
   766 *Helper method to create slider setting dialog
       
   767 */
       
   768 CxuiSettingDialog* CxuiPrecaptureView::createSliderSettingsDialog()
       
   769 {
       
   770     CX_DEBUG_ENTER_FUNCTION();
       
   771 
       
   772     CX_DEBUG(("Loading dialog DocML"));
       
   773     CxuiDocumentLoader *documentLoader = new CxuiDocumentLoader(mEngine);
       
   774 
       
   775     // Use document loader to create popup
       
   776     bool ok = false;
       
   777     documentLoader->load(SETTINGS_SLIDER_DIALOG_XML, &ok);
       
   778     CX_DEBUG(("load ok=%d", ok));
       
   779 
       
   780     CxuiSettingDialog *dialog =
       
   781         qobject_cast<CxuiSettingDialog *>(documentLoader->findWidget(SETTINGS_SLIDER_DIALOG_WIDGET));
       
   782     CX_ASSERT_ALWAYS(dialog);
       
   783 
       
   784     dialog->setTimeout(HbDialog::NoTimeout);
       
   785     dialog->setBackgroundFaded(false);
       
   786 
       
   787     mSliderSettingsDialogHeading = qobject_cast<HbLabel *>(
       
   788                                     documentLoader->findWidget(SETTINGS_SLIDER_DIALOG_HEADING_WIDGET));
       
   789     CX_ASSERT_ALWAYS(mSliderSettingsDialogHeading);
       
   790 
       
   791     mSettingsSlider = qobject_cast<CxuiSettingSlider *>(
       
   792                                     documentLoader->findWidget(SETTINGS_SLIDER_DIALOG_CONTENT_WIDGET));
       
   793     CX_ASSERT_ALWAYS(mSettingsSlider);
       
   794 
       
   795 
       
   796     CX_DEBUG_EXIT_FUNCTION();
       
   797 
       
   798     delete documentLoader;
       
   799     documentLoader = NULL;
       
   800 
       
   801     return dialog;
       
   802 
       
   803 }
       
   804 
       
   805 
       
   806 void CxuiPrecaptureView::launchSliderSetting()
       
   807 {
       
   808     CX_DEBUG_ENTER_FUNCTION();
       
   809 
       
   810     QObject *action = sender();
       
   811     if (!action) {
       
   812          return;
       
   813     }
       
   814 
       
   815     QString key = action->property(PROPERTY_KEY_SETTING_ID).toString();
       
   816     CX_DEBUG(("settingsKey=%s", key.toAscii().constData()));
       
   817 
       
   818     SliderParams data;
       
   819 
       
   820     // Load data and check that the setting is supported.
       
   821     if (mSettingsInfo && mSettingsInfo->getSettingsContent(key, data)) {
       
   822 
       
   823         if (!mSliderSettingsDialog) {
       
   824             mSliderSettingsDialog = createSliderSettingsDialog();
       
   825 
       
   826             connect(mSliderSettingsDialog, SIGNAL(dialogAboutToShow(HbAction *)),
       
   827                     this, SLOT(prepareToShowDialog(HbAction *)));
       
   828             connect(mSliderSettingsDialog, SIGNAL(dialogAboutToClose(HbAction *)),
       
   829                     this, SLOT(prepareToCloseDialog(HbAction *)));
       
   830         }
       
   831 
       
   832         if (mSliderSettingsDialogHeading) {
       
   833             mSliderSettingsDialogHeading->setPlainText(data.mHeading);
       
   834         }
       
   835 
       
   836         if (mSettingsSlider) {
       
   837             mSettingsSlider->init(&data);
       
   838         }
       
   839 
       
   840         if(mSliderSettingsDialog && mSettingsSlider) {
       
   841             // Store action that starts the dialog.
       
   842             // Dialog passes this along with it's signals,
       
   843             // so we can easily decide if we show grid again or not.
       
   844             mSliderSettingsDialog->setStarterAction(qobject_cast<HbAction *>(action));
       
   845 
       
   846             HbAction *okAction = mSliderSettingsDialog->primaryAction();
       
   847             if (okAction) {
       
   848                 // disconnect primary action from dialog so that dialog won't be closed
       
   849                 // automatically when action is triggered. handleSelectionAccepted
       
   850                 // is called instead
       
   851                 okAction->disconnect(mSliderSettingsDialog);
       
   852                 connect(okAction, SIGNAL(triggered()), mSettingsSlider, SLOT(handleSelectionAccepted()));
       
   853 
       
   854                 // Close the dialog when new setting value is committed
       
   855                 connect(mSettingsSlider, SIGNAL(selectionCommitted()), mSliderSettingsDialog, SLOT(close()));
       
   856 
       
   857                 connect(mSliderSettingsDialog, SIGNAL(aboutToClose()), mSettingsSlider, SLOT(handleClose()));
       
   858             }
       
   859 
       
   860             // Adjust position and show the dialog.
       
   861             mSliderSettingsDialog->setFrameType(HbPopup::Weak);
       
   862             mSliderSettingsDialog->setPreferredPos(getDialogPosition(), HbPopup::BottomRightCorner);
       
   863             mSliderSettingsDialog->show();
       
   864         }
       
   865     } else {
       
   866         launchNotSupportedNotification();
       
   867     }
       
   868 
       
   869     CX_DEBUG_EXIT_FUNCTION();
       
   870 }
       
   871 
       
   872 void CxuiPrecaptureView::launchPhotosApp()
       
   873 {
       
   874     QProcess::startDetached(PhotosAppExe);
       
   875 }
       
   876 
       
   877 /*!
       
   878  * Launching Videos application as a separate process
       
   879  */
       
   880 void CxuiPrecaptureView::launchVideosApp()
       
   881 {
       
   882     //Releasing cameda device in order to free
       
   883     //graphical memory
       
   884     releaseCamera();
       
   885     QProcess::startDetached(VideosAppExe);
       
   886 }
       
   887 
       
   888 /*!
       
   889 * Show "not supported" notification.
       
   890 */
       
   891 void CxuiPrecaptureView::launchNotSupportedNotification()
       
   892 {
       
   893     CX_DEBUG_ENTER_FUNCTION();
       
   894 
       
   895     // Instantiate a popup
       
   896     HbNotificationDialog note;
       
   897     note.setTitle("Notification");
       
   898     note.setText("Not supported yet");
       
   899     note.exec();
       
   900 
       
   901     CX_DEBUG_EXIT_FUNCTION();
       
   902 }
       
   903 
       
   904 /**
       
   905 * Show settings grid.
       
   906 */
       
   907 void CxuiPrecaptureView::showSettingsGrid()
       
   908 {
       
   909     CX_DEBUG_ENTER_FUNCTION();
       
   910 
       
   911     // Create grid if it's not shown before.
       
   912     initializeSettingsGrid();
       
   913 
       
   914     // Show grid modally.
       
   915     // This call will still not block until grid is dismissed.
       
   916     if(mSettingsGrid) {
       
   917         mSettingsGrid->setModal(true);
       
   918         mSettingsGrid->show();
       
   919     }
       
   920 
       
   921     CX_DEBUG_EXIT_FUNCTION();
       
   922 }
       
   923 
       
   924 /*!
       
   925 * Hide the settings grid dialog.
       
   926 */
       
   927 void CxuiPrecaptureView::hideSettingsGrid()
       
   928 {
       
   929     CX_DEBUG_ENTER_FUNCTION();
       
   930     if (mSettingsGrid) {
       
   931         mSettingsGrid->hide();
       
   932     }
       
   933     CX_DEBUG_EXIT_FUNCTION();
       
   934 }
       
   935 
       
   936 /**
       
   937 * Get if postcapture view should be shown or not.
       
   938 * Postcapture view may be shown for a predefined time or
       
   939 * until user dismisses it, or it may be completely disabled.
       
   940 */
       
   941 bool CxuiPrecaptureView::isPostcaptureOn() const
       
   942 {
       
   943     CX_DEBUG_ENTER_FUNCTION();
       
   944     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   945         // always show post capture in embedded mode
       
   946         return true;
       
   947     }
       
   948 
       
   949     // Read the value from settings. Ignoring reading error.
       
   950     // On error (missing settings) default to "postcapture on".
       
   951     int showPostcapture(-1);
       
   952     QString key;
       
   953     if(mEngine) {
       
   954         if (mEngine->mode() == Cxe::ImageMode) {
       
   955             key = CxeSettingIds::STILL_SHOWCAPTURED;
       
   956         } else {
       
   957             key = CxeSettingIds::VIDEO_SHOWCAPTURED;
       
   958         }
       
   959         mEngine->settings().get(key, showPostcapture);
       
   960     }
       
   961 
       
   962     CX_DEBUG_EXIT_FUNCTION();
       
   963     return showPostcapture != 0; // 0 == no postcapture
       
   964 }
       
   965 
       
   966 /*!
       
   967 * Adding zoom buttons to the slider
       
   968 * \param slider Pointer to the slider object, where the buttons will be added
       
   969 */
       
   970 void CxuiPrecaptureView::addIncreaseDecreaseButtons(HbSlider* slider)
       
   971 {
       
   972     // get current slider elements
       
   973     QList<HbSlider::SliderElement> elements = slider->elements();
       
   974     // add increase and decrease elements to the slider
       
   975     elements << HbSlider::IncreaseElement << HbSlider::DecreaseElement;
       
   976     slider->setElements(elements);
       
   977     // set icons for the increase and decrease element
       
   978     slider->setIcon(HbSlider::DecreaseElement , HbIcon("qtg_mono_minus"));
       
   979     slider->setIcon(HbSlider::IncreaseElement , HbIcon("qtg_mono_plus"));
       
   980 }
       
   981 
       
   982 
       
   983 /*!
       
   984 * Function can be used to create a graphics item and setting it as a background
       
   985 * item for HbWidget. graphicName refers to system wide graphic name. Given graphic
       
   986 * can consist of one, three or nine pieces. Nine piece graphics are used by default.
       
   987 * See HbFrameDrawer documentation for graphic naming.
       
   988 */
       
   989 void CxuiPrecaptureView::createWidgetBackgroundGraphic(HbWidget *widget,
       
   990                                                        const QString &graphicName,
       
   991                                                        HbFrameDrawer::FrameType frameType)
       
   992 {
       
   993     HbFrameDrawer *drawer = new HbFrameDrawer(graphicName, frameType);
       
   994 
       
   995     if (drawer && widget) {
       
   996         HbFrameItem *backgroundItem = new HbFrameItem(drawer, widget);
       
   997         if (backgroundItem) {
       
   998             // set item to fill the whole widget
       
   999             backgroundItem->setGeometry(QRectF(QPointF(0, 0), widget->size()));
       
  1000             backgroundItem->setZValue(0);
       
  1001             widget->setBackgroundItem(backgroundItem);
       
  1002         }
       
  1003     }
       
  1004 }
       
  1005 
       
  1006 /*!
       
  1007 * Returns dialogs bottom right corner
       
  1008 */
       
  1009 QPointF CxuiPrecaptureView::getDialogPosition()
       
  1010 {
       
  1011     HbStyle *style = new HbStyle();
       
  1012     qreal bottomMargin;
       
  1013     qreal rightMargin;
       
  1014     bool ok = style->parameter("hb-param-margin-gene-bottom", bottomMargin);
       
  1015     CX_ASSERT_ALWAYS(ok);
       
  1016     ok = style->parameter("hb-param-margin-gene-right", rightMargin);
       
  1017     CX_ASSERT_ALWAYS(ok);
       
  1018 
       
  1019     // calculate dialog's bottom right position
       
  1020     QSize deviceRes = mEngine->viewfinderControl().deviceDisplayResolution();
       
  1021     QPointF point(deviceRes.width() - rightMargin, deviceRes.height() - bottomMargin);
       
  1022 
       
  1023     delete style;
       
  1024 
       
  1025     return point;
       
  1026 }
       
  1027 
       
  1028 
       
  1029 /*!
       
  1030     Get setting item icon for given value.
       
  1031     \param key Setting key (CxeSettingIds)
       
  1032     \param value Setting value
       
  1033     \return Returns string containing icon locigal name
       
  1034 */
       
  1035 QString CxuiPrecaptureView::getSettingItemIcon(const QString &key, QVariant value)
       
  1036 {
       
  1037     CxUiSettings::RadioButtonListParams data;
       
  1038     QString icon = "";
       
  1039     if (mSettingsInfo && mSettingsInfo->getSettingsContent(key, data)) {
       
  1040         CxUiSettings::SettingItem setting;
       
  1041         foreach (setting, data.mSettingPairList) {
       
  1042             if (setting.mValue == value) {
       
  1043                 icon = setting.mIcon;
       
  1044                 break;
       
  1045             }
       
  1046         }
       
  1047     }
       
  1048     return icon;
       
  1049 }
       
  1050 
       
  1051 /*!
       
  1052     Update the quality indicator
       
  1053 */
       
  1054 void CxuiPrecaptureView::updateQualityIcon()
       
  1055 {
       
  1056     CX_DEBUG_ENTER_FUNCTION();
       
  1057 
       
  1058     if (mQualityIcon && mEngine) {
       
  1059         QString key = "";
       
  1060         QString icon = "";
       
  1061         int currentValue = -1;
       
  1062 
       
  1063         if (mEngine->mode() == Cxe::VideoMode) {
       
  1064             key = CxeSettingIds::VIDEO_QUALITY;
       
  1065         } else {
       
  1066             key = CxeSettingIds::IMAGE_QUALITY;
       
  1067         }
       
  1068 
       
  1069         mEngine->settings().get(key, currentValue);
       
  1070         icon = getSettingItemIcon(key, currentValue);
       
  1071 
       
  1072         mQualityIcon->setIcon(HbIcon(icon));
       
  1073     }
       
  1074 
       
  1075     CX_DEBUG_EXIT_FUNCTION();
       
  1076 }
       
  1077 
       
  1078 void CxuiPrecaptureView::handleSettingValueChanged(const QString& key, QVariant newValue)
       
  1079 {
       
  1080     CX_DEBUG_ENTER_FUNCTION();
       
  1081     Q_UNUSED(key);
       
  1082     Q_UNUSED(newValue);
       
  1083     CX_DEBUG_EXIT_FUNCTION();
       
  1084 }
       
  1085 
       
  1086 // end of file