camerauis/cameraxui/cxui/src/cxuistillprecaptureview.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 56 01e205c615b9
--- a/camerauis/cameraxui/cxui/src/cxuistillprecaptureview.cpp	Tue Jul 06 14:04:02 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/cxuistillprecaptureview.cpp	Wed Aug 18 09:37:18 2010 +0300
@@ -14,14 +14,16 @@
 * Description:
 *
 */
+#include <QVariant>
+#include <QMetaType>
+#include <QGraphicsLayout>
+
 #include <hbpushbutton.h>
 #include <hblabel.h>
 #include <hbtoolbar.h>
 #include <hbaction.h>
 #include <hbmainwindow.h>
 #include <hbtransparentwindow.h>
-#include <QVariant>
-#include <QMetaType>
 #include <hbslider.h>
 #include <hblistwidget.h>
 #include <hbdialog.h>
@@ -46,10 +48,16 @@
 #include "cxesettings.h"
 #include "cxefeaturemanager.h" // mEngine->featureManager()
 #include "cxuidocumentloader.h"
+
+#ifdef Q_OS_SYMBIAN
 #include "OstTraceDefinitions.h"
+
 #ifdef OST_TRACE_COMPILER_IN_USE
 #include "cxuistillprecaptureviewTraces.h"
 #endif
+
+#endif //Q_OS_SYMBIAN
+
 #include "cxuistillprecaptureview.h"
 #include "cxuiserviceprovider.h"
 #include "cxuisettingdialog.h"
@@ -110,23 +118,14 @@
             this, SLOT(handleStillCaptureStateChanged(CxeStillCaptureControl::State, CxeError::Id)));
     connect(&mEngine->viewfinderControl(), SIGNAL(stateChanged(CxeViewfinderControl::State, CxeError::Id)),
             this, SLOT(handleViewfinderStateChanged(CxeViewfinderControl::State, CxeError::Id)));
-    connect(&(mEngine->settings()), SIGNAL(sceneChanged(CxeScene&)),
-            this, SLOT(handleSceneChanged(CxeScene&)));
     connect(&mEngine->stillCaptureControl(), SIGNAL(availableImagesChanged()),
             this, SLOT(updateImagesLeftLabel()));
 
+    mEngine->settings().listenForSetting(CxeSettingIds::IMAGE_SCENE_DATA, this, SLOT(handleSceneChanged(const QVariant&)));
+
     loadDefaultWidgets();
     hideControls();
 
-    mSelfTimer = new CxuiSelfTimer(mEngine->settings());
-    connect(mSelfTimer, SIGNAL(timerFinished()), this, SLOT(focusAndCapture()));
-
-    int value = Cxe::GeoTaggingDisclaimerDisabled;
-    mEngine->settings().get(CxeSettingIds::GEOTAGGING_DISCLAIMER, value);
-    if(value == Cxe::GeoTaggingDisclaimerEnabled) {
-        launchGeoTaggingDisclaimerDialog();
-    }
-
     OstTrace0( camerax_performance, DUP1_CXUISTILLPRECAPTUREVIEW_CONSTRUCT, "msg: e_CX_STILLPRECAPVIEW_CONSTRUCT 0" );
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -137,32 +136,97 @@
 void CxuiStillPrecaptureView::loadDefaultWidgets()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    CX_DEBUG_ASSERT(mDocumentLoader);
+    CX_ASSERT_ALWAYS(mDocumentLoader);
 
     // get pointer to the viewfinder
     QGraphicsWidget *widget = NULL;
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEWFINDER);
     mViewfinder = qobject_cast<HbTransparentWindow *>(widget);
-    CX_DEBUG_ASSERT(mViewfinder);
+    CX_ASSERT_ALWAYS(mViewfinder);
+
+    reloadIndicatorWidgets();
+    CX_DEBUG_EXIT_FUNCTION();
+}
 
+/*!
+ * Loads default indicators from docml and modifies the visibility
+ * according to current settings.
+ */
+void CxuiStillPrecaptureView::reloadIndicatorWidgets()
+{
+    CX_DEBUG_ENTER_FUNCTION();
+    CX_ASSERT_ALWAYS(mDocumentLoader);
+
+    bool ok = false;
+    mDocumentLoader->load(STILL_1ST_XML, STILL_PRE_CAPTURE_INDICATORS_SECTION, &ok);
+    CX_ASSERT_ALWAYS(ok);
+
+    QGraphicsWidget *widget = NULL;
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_QUALITY_ICON);
     mQualityIcon = qobject_cast<HbLabel *>(widget);
-    CX_DEBUG_ASSERT(mQualityIcon);
+    CX_ASSERT_ALWAYS(mQualityIcon);
+
+    widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_FLASHBLINK_INDICATOR_ICON);
+    HbLabel *flashBlinkingIcon = qobject_cast<HbLabel *>(widget);
+    CX_ASSERT_ALWAYS(flashBlinkingIcon);
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_GEOTAGGING_INDICATOR_ICON);
     mGeoTaggingIndicatorIcon = qobject_cast<HbLabel *>(widget);
-    CX_DEBUG_ASSERT(mGeoTaggingIndicatorIcon);
+    CX_ASSERT_ALWAYS(mGeoTaggingIndicatorIcon);
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_FACE_TRACKING_ICON);
     mFaceTrackingIcon = qobject_cast<HbLabel *>(widget);
-    CX_DEBUG_ASSERT(mFaceTrackingIcon);
+    CX_ASSERT_ALWAYS(mFaceTrackingIcon);
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_INDICATOR_CONTAINER);
     mIndicators = qobject_cast<HbWidget *>(widget);
-    CX_DEBUG_ASSERT(mIndicators);
+    CX_ASSERT_ALWAYS(mIndicators);
+
+    QGraphicsLayout *layout = mIndicators->layout();
+    QGraphicsLayoutItem *graphicsLayoutItem = NULL;
+    QGraphicsItem *graphicsItem = NULL;
+    QString key = "";
+    int currentSettingValue = -1;
+    bool isSettingOff = false;
+    // Go through the items in the layout to check whether they should be
+    // shown or not in the indicator pane. Start from the last towards
+    // the first, so that removing items from between works correctly.
+    for (int i = layout->count() - 1; i >= 0; i--) {
+        graphicsLayoutItem = layout->itemAt(i);
+        isSettingOff = false;
+        if (graphicsLayoutItem) {
+            graphicsItem = graphicsLayoutItem->graphicsItem();
+            currentSettingValue = -1;
+            if (graphicsItem == mGeoTaggingIndicatorIcon) {
+                key = CxeSettingIds::GEOTAGGING;
+                currentSettingValue = mEngine->settings().get(key, currentSettingValue);
+                if (currentSettingValue == Cxe::GeoTaggingOff) {
+                    isSettingOff = true;
+                }
+            } else if (graphicsItem == mFaceTrackingIcon) {
+                key = CxeSettingIds::FACE_TRACKING;
+                currentSettingValue = mEngine->settings().get(key, currentSettingValue);
+                // facetracking implementation does not use
+                // enum for on/off values but instead
+                // 0 for off and 1 for on.
+                if (currentSettingValue == 0) {
+                    isSettingOff = true;
+                }
+            } else if (graphicsItem == flashBlinkingIcon) {
+                //remove flash indicator
+                isSettingOff = true;
+            }
+            if (isSettingOff) {
+                layout->removeAt(i);
+            }
+        }
+    }
+
     // create background for indicator container
     createWidgetBackgroundGraphic(mIndicators, TRANSPARENT_BACKGROUND_GRAPHIC);
 
+    mIndicators->setVisible(true);
+
     CX_DEBUG_EXIT_FUNCTION();
 }
 
@@ -173,9 +237,9 @@
 void CxuiStillPrecaptureView::loadWidgets()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    CX_DEBUG_ASSERT(mDocumentLoader);
+    CX_ASSERT_ALWAYS(mDocumentLoader);
 
-    if( mWidgetsLoaded ) {
+    if (mWidgetsLoaded) {
         CX_DEBUG(("Widgets already loaded"));
         CX_DEBUG_EXIT_FUNCTION();
         return;
@@ -187,14 +251,14 @@
 
     OstTrace0( camerax_performance, DUP4_CXUISTILLPRECAPTUREVIEW_LOADWIDGETS, "msg: e_CX_DOCUMENTLOADER_LOAD 1" );
     mDocumentLoader->load(STILL_1ST_XML, STILL_PRE_CAPTURE_WIDGETS_SECTION, &ok);
-    Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing");
+    CX_ASSERT_ALWAYS(ok);
     if (CxuiServiceProvider::isCameraEmbedded()) {
         mDocumentLoader->load(STILL_1ST_XML, STILL_PRE_CAPTURE_EMBEDDED_SECTION, &ok);
     } else {
         mDocumentLoader->load(STILL_1ST_XML, STILL_PRE_CAPTURE_STANDALONE_SECTION, &ok);
     }
     OstTrace0( camerax_performance, DUP5_CXUISTILLPRECAPTUREVIEW_LOADWIDGETS, "msg: e_CX_DOCUMENTLOADER_LOAD 0" );
-    Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing");
+    CX_ASSERT_ALWAYS(ok);
 
     // get pointers to ui components from the layout data
     QGraphicsWidget *widget = NULL;
@@ -202,47 +266,48 @@
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_ZOOM_SLIDER);
     mSlider = qobject_cast<CxuiZoomSlider *>(widget);
-    CX_DEBUG_ASSERT(mSlider);
+    CX_ASSERT_ALWAYS(mSlider);
     mSlider->addZoomButtons();
     createWidgetBackgroundGraphic(mSlider, TRANSPARENT_BACKGROUND_GRAPHIC);
 
-    if (mSelfTimer) {
-        // let selftimer class get needed selftimer related widgets
-        // from the documentloader
-        mSelfTimer->loadSelftimerWidgets(mDocumentLoader);
-    }
-
     // create background for selftimer containers
     HbWidget *container = NULL;
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_SELFTIMER_CONTAINER);
     container = qobject_cast<HbWidget *>(widget);
-    CX_DEBUG_ASSERT(container);
+    CX_ASSERT_ALWAYS(container);
     createWidgetBackgroundGraphic(container, TRANSPARENT_BACKGROUND_GRAPHIC);
 
     // connect selftimer start button to hide controls
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_SELFTIMER_START_BUTTON);
     HbPushButton *startButton = qobject_cast<HbPushButton *>(widget);
-    CX_DEBUG_ASSERT(startButton);
+    CX_ASSERT_ALWAYS(startButton);
     connect(startButton, SIGNAL(released()), this, SLOT(hideControls()));
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_TOOLBAR);
     mToolbar = qobject_cast<HbToolBar *>(widget);
-    CX_DEBUG_ASSERT(mToolbar);
+    CX_ASSERT_ALWAYS(mToolbar);
 
     object = mDocumentLoader->findObject(STILL_PRE_CAPTURE_FLASH_ACTION);
     mFlashSetting = qobject_cast<HbAction *>(object);
-    CX_DEBUG_ASSERT(mFlashSetting);
+    CX_ASSERT_ALWAYS(mFlashSetting);
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_IMAGES_LEFT_LABEL);
     mImagesLeft = qobject_cast<HbLabel *>(widget);
-    CX_DEBUG_ASSERT(mImagesLeft);
+    CX_ASSERT_ALWAYS(mImagesLeft);
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_IMAGES_LEFT_CONTAINER);
     mImagesLeftContainer = qobject_cast<HbWidget *>(widget);
-    CX_DEBUG_ASSERT(mImagesLeftContainer);
+    CX_ASSERT_ALWAYS(mImagesLeftContainer);
     createWidgetBackgroundGraphic(mImagesLeftContainer, TRANSPARENT_BACKGROUND_GRAPHIC);
     updateImagesLeftLabel();
 
+    // Create self timer.
+    // Let selftimer class get needed selftimer related widgets from the documentloader
+    mSelfTimer = new CxuiSelfTimer(mEngine->settings());
+    CX_ASSERT_ALWAYS(mSelfTimer);
+    connect(mSelfTimer, SIGNAL(timerFinished()), this, SLOT(focusAndCapture()));
+    mSelfTimer->loadSelftimerWidgets(mDocumentLoader);
+
     if (CxuiServiceProvider::isCameraEmbedded()) {
         CX_DEBUG(("EMBEDDED: camera in embedded mode"));
 
@@ -274,19 +339,20 @@
     mWidgetsLoaded = true;
 
     // Update toolbar flash mode icon
-    int flash;
-    if (mEngine->settings().get(CxeSettingIds::FLASH_MODE, flash) == CxeError::None) {
-        handleSettingValueChanged(CxeSettingIds::FLASH_MODE, flash);
-    }
+    int flash = mEngine->settings().get<int>(CxeSettingIds::FLASH_MODE);
+    handleSettingValueChanged(CxeSettingIds::FLASH_MODE, flash);
 
     // Update toolbar scene mode icon
-    QString sceneId;
-    if (mEngine->settings().get(CxeSettingIds::SCENE_ID, sceneId) == CxeError::None) {
-        updateSceneIcon(sceneId);
-    }
+    updateSceneIcon(mEngine->settings().get<QString>(CxeSettingIds::IMAGE_SCENE));
 
     hideControls();
 
+    // Check if we need to show the geotagging disclaimer for first time use.
+    Cxe::GeoTaggingDisclaimer value = mEngine->settings().get<Cxe::GeoTaggingDisclaimer>(CxeSettingIds::GEOTAGGING_DISCLAIMER, Cxe::GeoTaggingDisclaimerDisabled);
+    if (value == Cxe::GeoTaggingDisclaimerEnabled) {
+        launchGeoTaggingDisclaimerDialog();
+    }
+
     // View is ready. Needed for startup performance automated testing.
     emit viewReady();
 
@@ -392,7 +458,7 @@
     // On error (missing settings) default to "postcapture on".
     int showPostcapture(-1);
     if(mEngine) {
-        mEngine->settings().get(CxeSettingIds::STILL_SHOWCAPTURED, showPostcapture);
+        showPostcapture = mEngine->settings().get<int>(CxeSettingIds::STILL_SHOWCAPTURED, -1);
     }
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -421,7 +487,7 @@
 
             if (mDocumentLoader) {
                 QObject *obj = mDocumentLoader->findObject(iconObjectName);
-                CX_DEBUG_ASSERT(obj);
+                CX_ASSERT_ALWAYS(obj);
                 qobject_cast<HbAction *>(obj)->setIcon(HbIcon(icon));
             }
         } else {
@@ -440,9 +506,7 @@
 
     if (mQualityIcon && mEngine) {
         QString icon = "";
-        int currentValue = -1;
-
-        mEngine->settings().get(CxeSettingIds::IMAGE_QUALITY, currentValue);
+        int currentValue = mEngine->settings().get<int>(CxeSettingIds::IMAGE_QUALITY, -1);
         icon = getSettingItemIcon(CxeSettingIds::IMAGE_QUALITY, currentValue);
 
         mQualityIcon->setIcon(HbIcon(icon));
@@ -491,16 +555,17 @@
 {
     CX_DEBUG_ENTER_FUNCTION();
 
-    if (!mEngine->autoFocusControl().supported()) {
+    if (!mEngine->autoFocusControl().supported() ||
+         mEngine->autoFocusControl().isFixedFocusMode(mEngine->autoFocusControl().mode())) {
         // autofocus is not supported, so start capturing straight away
         capture();
     } else {
+        setCapturePending();
         // start focusing
         // Auto-focus can only work if viewfinder is running
         if (mEngine->viewfinderControl().state() == CxeViewfinderControl::Running) {
             mEngine->autoFocusControl().start(false);
         }
-        setCapturePending();
     }
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -797,11 +862,12 @@
     Slot for handling scene mode change
     \param scene QVariantMap containing settings related to the new scene mode
  */
-void CxuiStillPrecaptureView::handleSceneChanged(CxeScene &scene)
+void CxuiStillPrecaptureView::handleSceneChanged(const QVariant &newSceneData)
 {
     CX_DEBUG_ENTER_FUNCTION();
     if (mEngine->mode() == Cxe::ImageMode) {
 
+        CxeScene scene = newSceneData.toMap();
         // update toolbar scene mode icon
         updateSceneIcon(scene[CxeSettingIds::SCENE_ID].toString());
 
@@ -812,10 +878,10 @@
         } else {
             // No flash mode specified within the scene.
             // Check from setting model what is it currently.
-            int flashMode(Cxe::FlashAuto);
-            mEngine->settings().get(CxeSettingIds::FLASH_MODE, flashMode);
+            Cxe::FlashMode flashMode = mEngine->settings().get<Cxe::FlashMode>(CxeSettingIds::FLASH_MODE, Cxe::FlashAuto);
             handleSettingValueChanged(CxeSettingIds::FLASH_MODE, QVariant(flashMode));
         }
+
     }
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -860,7 +926,10 @@
             // update images left when quality values are changed
             updateImagesLeftLabel();
         } else if (key == CxeSettingIds::FACE_TRACKING) {
+            reloadIndicatorWidgets();
             updateFaceTrackingIcon();
+        } else if (key == CxeSettingIds::GEOTAGGING) {
+            reloadIndicatorWidgets();
         }
 
         // update toolbar flash icon
@@ -914,10 +983,8 @@
         launchSettingsDialog(action);
         // special case to get value changed event to the selftimer class
         if (settingsKey == CxeSettingIds::SELF_TIMER) {
-            // if selftimer is active remember the previously selected value
-            if (mSelfTimer->isEnabled()) {
-                mSettingsDialogList->setOriginalSelectedItemByValue(mSelfTimer->getTimeout());
-            }
+            // selftimer is not found in settings so set the value now
+            mSettingsDialogList->setOriginalSelectedItemByValue(mSelfTimer->getTimeout());
             connect(mSettingsDialogList, SIGNAL(valueSelected(int)),
                     mSelfTimer, SLOT(changeTimeOut(int)));
         }
@@ -958,11 +1025,10 @@
     if (mFaceTrackingIcon && mEngine) {
         QString key = "";
         QString icon = "";
-        int currentValue = -1;
 
         key = CxeSettingIds::FACE_TRACKING;
 
-        mEngine->settings().get(key, currentValue);
+        int currentValue = mEngine->settings().get<int>(key, -1);
         icon = getSettingItemIcon(key, currentValue);
 
         mFaceTrackingIcon->setIcon(HbIcon(icon));