camerauis/cameraxui/cxui/src/cxuistillprecaptureview.cpp
changeset 21 fa6d9f75d6a6
parent 19 d9aefe59d544
child 24 2094593137f5
--- a/camerauis/cameraxui/cxui/src/cxuistillprecaptureview.cpp	Fri Apr 16 14:51:30 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/cxuistillprecaptureview.cpp	Mon May 03 12:22:55 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -30,6 +30,7 @@
 #include <hbtoolbutton.h>
 #include <hbdeviceprofile.h> // HbDeviceProfile
 #include <hbmenu.h>
+#include <hbicon.h>
 
 #include "cxuiselftimer.h"
 #include "cxeengine.h"
@@ -52,6 +53,7 @@
 #include "cxuiserviceprovider.h"
 #include "cxuisettingdialog.h"
 #include "cxuisettingradiobuttonlist.h"
+#include "cxuizoomslider.h"
 
 using namespace Cxe;
 using namespace CxUiLayout;
@@ -100,6 +102,8 @@
             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()));
 
     loadDefaultWidgets();
     hideControls();
@@ -126,13 +130,11 @@
     mQualityIcon = qobject_cast<HbLabel *>(widget);
     CX_DEBUG_ASSERT(mQualityIcon);
 
+    widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_INDICATOR_CONTAINER);
+    mIndicators = qobject_cast<HbWidget *>(widget);
+    CX_DEBUG_ASSERT(mIndicators);
     // create background for indicator container
-    HbWidget *container = NULL;
-    widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_INDICATOR_CONTAINER);
-    container = qobject_cast<HbWidget *>(widget);
-    CX_DEBUG_ASSERT(container);
-    createWidgetBackgroundGraphic(container, TRANSPARENT_BACKGROUND_GRAPHIC);
-    container->show();
+    createWidgetBackgroundGraphic(mIndicators, TRANSPARENT_BACKGROUND_GRAPHIC);
 
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -169,7 +171,7 @@
     QObject *object = NULL;
 
     widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_ZOOM_SLIDER);
-    mSlider = qobject_cast<HbSlider *>(widget);
+    mSlider = qobject_cast<CxuiZoomSlider *>(widget);
     CX_DEBUG_ASSERT(mSlider);
     addIncreaseDecreaseButtons(mSlider);
     createWidgetBackgroundGraphic(mSlider, TRANSPARENT_BACKGROUND_GRAPHIC);
@@ -187,12 +189,6 @@
     CX_DEBUG_ASSERT(container);
     createWidgetBackgroundGraphic(container, TRANSPARENT_BACKGROUND_GRAPHIC);
 
-    widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_SELFTIMER_BUTTON_CONTAINER);
-    container = qobject_cast<HbWidget *>(widget);
-    CX_DEBUG_ASSERT(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);
@@ -239,19 +235,23 @@
             }
         }
         if (!CxuiServiceProvider::instance()->allowCameraSwitching()) {
-
             CX_DEBUG(("EMBEDDED: don't allow camera switching"));
-
-            HbAction *goto_2nd_cam = qobject_cast<HbAction*> (mDocumentLoader->findObject(STILL_PRE_CAPTURE_GOTO_2ND_CAMERA_ACTION));
-            if (goto_2nd_cam) {
-                CX_DEBUG(("EMBEDDED: setting camera switch to disabled"));
-                goto_2nd_cam->setEnabled(false);
-
-            }
         }
 
     }
 
+    // update toolbar flash icon
+    int flash;
+    if (mEngine->settings().get(CxeSettingIds::FLASH_MODE, flash) == CxeError::None) {
+        handleSettingValueChanged(CxeSettingIds::FLASH_MODE, flash);
+    }
+
+    // update toolbar scene mode
+    QString scene;
+    if (mEngine->settings().get(CxeSettingIds::IMAGE_SCENE, scene) == CxeError::None) {
+        handleSettingValueChanged(CxeSettingIds::IMAGE_SCENE, scene);
+    }
+
     hideControls();
 
     mWidgetsLoaded = true;
@@ -305,31 +305,8 @@
 void CxuiStillPrecaptureView::launchSceneModesPopup()
 {
     CX_DEBUG_ENTER_FUNCTION();
-
-    if(mSceneModePopup) {
-        CX_DEBUG(("mSceneModePopup exists, showing.."));
-        mSceneModePopup->show();
-    } else {
-        CX_DEBUG(("Loading scene mode popup DocML"));
-        CxuiDocumentLoader* documentLoader = new CxuiDocumentLoader(mEngine);
-        bool ok = false;
-
-        // Use document loader to create popup
-        documentLoader->load(SCENEMODE_SETTING_XML, &ok);
-
-        CX_DEBUG(("load ok=%d", ok));
-
-        mSceneModePopup = qobject_cast<HbDialog*>(documentLoader->findWidget("still_scenemode_popup"));
-        CX_DEBUG_ASSERT(mSceneModePopup);
-        mSceneModePopup->setTimeout(HbDialog::NoTimeout);
-        mSceneModePopup->setBackgroundFaded(false);
-
-        delete documentLoader;
-        documentLoader = NULL;
-    }
-
-    connect(mKeyHandler, SIGNAL(autofocusKeyPressed()), mSceneModePopup, SLOT(close()));
-
+    hideControls();
+    emit showScenesView();
     CX_DEBUG_EXIT_FUNCTION();
 }
 
@@ -401,8 +378,14 @@
                 mEngine->autoFocusControl().cancel();
                 setCapturePending();
             } else {
-                mEngine->stillCaptureControl().reset();  //! @todo: Do not delete snapshots before images are really saved
-                mEngine->stillCaptureControl().capture();
+                // Engine uses disk space *estimate* for imagesLeft() so it
+                // should not cause significant delay / additional shutter lag.
+                if (mEngine->stillCaptureControl().imagesLeft()) {
+                    mEngine->stillCaptureControl().reset();  //! @todo: Do not delete snapshots before images are really saved
+                    mEngine->stillCaptureControl().capture();
+                } else {
+                    launchDiskFullNotification();
+                }
             }
         } else {
             setCapturePending();
@@ -544,6 +527,13 @@
         return;
     }
 
+    // in case of selftimer being enabled, autofocuskey does not start focusing
+    if (mSelfTimer && mSelfTimer->isEnabled()){
+        CX_DEBUG(("Selftimer enabled, ignoring autofocus key press"));
+        CX_DEBUG_EXIT_FUNCTION();
+        return;
+    }
+
     // Auto-focus can only work if viewfinder is running
     if (mEngine->viewfinderControl().state() == CxeViewfinderControl::Running) {
 
@@ -557,6 +547,13 @@
 {
     CX_DEBUG_ENTER_FUNCTION();
 
+    // in case of selftimer being enabled, autofocuskey should not do anything
+    if (mSelfTimer && mSelfTimer->isEnabled()){
+        CX_DEBUG(("Selftimer enabled, ignoring autofocus key release"));
+        CX_DEBUG_EXIT_FUNCTION();
+        return;
+    }
+
     if (mEngine->autoFocusControl().supported()) {
         // Check that capture is not in progress, or pending.
         // Otherwise wouldn't want to cancel the focus.
@@ -638,7 +635,7 @@
     CxeStillCaptureControl::State newState, CxeError::Id /*error*/)
 {
     if (newState == CxeStillCaptureControl::Ready) {
-        OstTrace0(camerax_performance, CXUISTILLPRECAPTUREVIEW_SHOT_TO_SHOT_DUP2, "msg: e_CX_SHOT_TO_SHOT 0");
+        OstTrace0(camerax_performance, DUP1_CXUISTILLPRECAPTUREVIEW_SHOT_TO_SHOT, "msg: e_CX_SHOT_TO_SHOT 0");
 
         if (mCapturePending) {
             CX_DEBUG(("mCapturePending is true, starting capture now"));
@@ -665,19 +662,23 @@
 
 }
 
+/*!
+* Slot to handle application being sent to background.
+*/
 void CxuiStillPrecaptureView::handleFocusLost()
 {
-    CX_DEBUG_IN_FUNCTION();
-    bool captureInProgress = mEngine->stillCaptureControl().state() == CxeStillCaptureControl::Capturing;
-    if (!captureInProgress) {
-        if (mSelfTimer && mSelfTimer->isOngoing()) {
-            // If self-timer is running, stop and reset the delay now.
-            mSelfTimer->reset();
-        }
+    CX_DEBUG_ENTER_FUNCTION();
 
-        // Release camera as we are going to background.
-        releaseCamera();
+    if (mSelfTimer && mSelfTimer->isOngoing()) {
+        // If self-timer is running, stop and reset the delay now.
+        mSelfTimer->reset();
     }
+
+    // Release camera as we are going to background.
+    // If taking image is just ongoing, it will be cancelled by engine.
+    releaseCamera();
+
+    CX_DEBUG_EXIT_FUNCTION();
 }
 
 void CxuiStillPrecaptureView::handleFocusGained()
@@ -687,10 +688,24 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*
+    Slot for handling scene mode change
+    \param scene QVariantMap containing settings related to the new scene mode
+ */
 void CxuiStillPrecaptureView::handleSceneChanged(CxeScene &scene)
 {
     CX_DEBUG_ENTER_FUNCTION();
     if (mEngine->mode() == Cxe::ImageMode) {
+
+        // update toolbar scene mode icon
+        QString icon = getSettingItemIcon(CxeSettingIds::IMAGE_SCENE, scene[CxeSettingIds::SCENE_ID]);
+        CX_DEBUG((("New scene mode icon: %s"), icon.toAscii().constData()));
+        if (mDocumentLoader) {
+            QObject *obj = mDocumentLoader->findObject(STILL_PRE_CAPTURE_SCENE_MODE_ACTION);
+            CX_DEBUG_ASSERT(obj);
+            qobject_cast<HbAction *>(obj)->setIcon(HbIcon(icon));
+        }
+
         // for now, we are only interested in flashmode change
         if (scene.contains(CxeSettingIds::FLASH_MODE)) {
             CX_DEBUG(("updating flash to: %d", scene[CxeSettingIds::FLASH_MODE].value<int>()));
@@ -707,25 +722,36 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*
+    Slot for handling setting value changes. Notice that changing the scene mode
+    does not emit settingValueChanged signal.
+    \param key      CxSettingIds key defining the changed setting
+    \param newValue QVariant containing the new setting value
+
+    \sa CxuiStillPrecaptureView::handleSceneChanged(CxeScene &scene)
+ */
 void CxuiStillPrecaptureView::handleSettingValueChanged(const QString& key, QVariant newValue)
 {
     CX_DEBUG_ENTER_FUNCTION();
 
     if (mEngine->mode() == Cxe::ImageMode) {
+
+        // update images left and image quality icons
         if (key == CxeSettingIds::IMAGE_QUALITY) {
-
             // update the quality indicator on screen
             updateQualityIcon();
-
             // update images left when quality values are changed
             updateImagesLeftLabel();
         }
 
+        // update toolbar flash icon
         if (mFlashSetting && key == CxeSettingIds::FLASH_MODE) {
-            CX_DEBUG((("flash mode: %d"),newValue.toInt()))
+            CX_DEBUG((("flash mode: %d"), newValue.toInt()));
             QString icon = getSettingItemIcon(key, newValue);
+            CX_DEBUG((("flash mode icon: %s"), icon.toAscii().constData()))
             mFlashSetting->setIcon(HbIcon(icon));
         }
+
     }
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -794,7 +820,7 @@
         }
 
         CX_DEBUG(("Images left %d", images));
-        mImagesLeft->setPlainText(hbTrId("%L1").arg(images));
+        mImagesLeft->setPlainText(hbTrId("txt_cam_fullscreen_imagesleft").arg(images));
     }
 
     CX_DEBUG_EXIT_FUNCTION();