|
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 #include <hbpushbutton.h> |
|
18 #include <hblabel.h> |
|
19 #include <hbtoolbar.h> |
|
20 #include <hbaction.h> |
|
21 #include <hbmainwindow.h> |
|
22 #include <hbtransparentwindow.h> |
|
23 #include <QVariant> |
|
24 #include <QMetaType> |
|
25 #include <hbslider.h> |
|
26 #include <hblistwidget.h> |
|
27 #include <hbdialog.h> |
|
28 #include <hblistwidgetitem.h> |
|
29 #include <hbtoolbarextension.h> |
|
30 #include <hbtoolbutton.h> |
|
31 #include <hbdeviceprofile.h> // HbDeviceProfile |
|
32 #include <hbmenu.h> |
|
33 |
|
34 #include "cxuiselftimer.h" |
|
35 #include "cxeengine.h" |
|
36 #include "cxeviewfindercontrol.h" |
|
37 #include "cxecameradevicecontrol.h" |
|
38 #include "cxestillcapturecontrol.h" |
|
39 #include "cxeautofocuscontrol.h" |
|
40 #include "cxuicapturekeyhandler.h" |
|
41 #include "cxutils.h" |
|
42 #include "cxenamespace.h" // CxeSettingIds |
|
43 #include "cxuienums.h" |
|
44 #include "cxesettings.h" |
|
45 #include "cxefeaturemanager.h" // mEngine->featureManager() |
|
46 #include "cxuidocumentloader.h" |
|
47 #include "OstTraceDefinitions.h" |
|
48 #ifdef OST_TRACE_COMPILER_IN_USE |
|
49 #include "cxuistillprecaptureviewTraces.h" |
|
50 #endif |
|
51 #include "cxuistillprecaptureview.h" |
|
52 #include "cxuiserviceprovider.h" |
|
53 #include "cxuisettingdialog.h" |
|
54 #include "cxuisettingradiobuttonlist.h" |
|
55 |
|
56 using namespace Cxe; |
|
57 using namespace CxUiLayout; |
|
58 using namespace CxUiInternal; |
|
59 |
|
60 const int CXUI_CAPTURE_PENDING_TIMEOUT = 5000; // 5 seconds |
|
61 const int CXUI_IMAGES_LEFT_LIMIT = 99; // images left is shown only if below this limit |
|
62 |
|
63 CxuiStillPrecaptureView::CxuiStillPrecaptureView( QGraphicsItem *parent) : |
|
64 CxuiPrecaptureView(parent), |
|
65 mSelfTimer(NULL), |
|
66 mFlashSetting(NULL), |
|
67 mStillSettingsPopup(NULL), |
|
68 mSceneModePopup(NULL), |
|
69 mCapturePending(false), |
|
70 mImagesLeft(NULL), |
|
71 mImagesLeftContainer(NULL), |
|
72 mPendingAfCanceling(false) |
|
73 { |
|
74 CX_DEBUG_IN_FUNCTION(); |
|
75 } |
|
76 |
|
77 CxuiStillPrecaptureView::~CxuiStillPrecaptureView() |
|
78 { |
|
79 CX_DEBUG_IN_FUNCTION(); |
|
80 delete mSelfTimer; |
|
81 } |
|
82 |
|
83 void CxuiStillPrecaptureView::construct(HbMainWindow *mainwindow, CxeEngine *engine, |
|
84 CxuiDocumentLoader *documentLoader, |
|
85 CxuiCaptureKeyHandler *keyHandler) |
|
86 { |
|
87 CX_DEBUG_ENTER_FUNCTION(); |
|
88 OstTrace0( camerax_performance, CXUISTILLPRECAPTUREVIEW_CONSTRUCT, "msg: e_CX_STILLPRECAPVIEW_CONSTRUCT 1" ); |
|
89 |
|
90 // constuct base class |
|
91 CxuiPrecaptureView::construct(mainwindow, engine, documentLoader, keyHandler); |
|
92 |
|
93 connect(&mEngine->autoFocusControl(), SIGNAL(stateChanged(CxeAutoFocusControl::State,CxeError::Id)), |
|
94 this, SLOT(handleAutoFocusStateChanged(CxeAutoFocusControl::State,CxeError::Id))); |
|
95 connect(&mEngine->stillCaptureControl(), SIGNAL(snapshotReady(CxeError::Id, const QPixmap&, int)), |
|
96 this, SLOT(handleSnapshot(CxeError::Id))); |
|
97 connect(&mEngine->stillCaptureControl(), SIGNAL(stateChanged(CxeStillCaptureControl::State, CxeError::Id)), |
|
98 this, SLOT(handleStillCaptureStateChanged(CxeStillCaptureControl::State, CxeError::Id))); |
|
99 connect(&mEngine->viewfinderControl(), SIGNAL(stateChanged(CxeViewfinderControl::State, CxeError::Id)), |
|
100 this, SLOT(handleViewfinderStateChanged(CxeViewfinderControl::State, CxeError::Id))); |
|
101 connect(&(mEngine->settings()), SIGNAL(sceneChanged(CxeScene&)), |
|
102 this, SLOT(handleSceneChanged(CxeScene&))); |
|
103 |
|
104 loadDefaultWidgets(); |
|
105 hideControls(); |
|
106 |
|
107 mSelfTimer = new CxuiSelfTimer(mEngine->settings()); |
|
108 connect(mSelfTimer, SIGNAL(timerFinished()), this, SLOT(focusAndCapture())); |
|
109 |
|
110 OstTrace0( camerax_performance, DUP1_CXUISTILLPRECAPTUREVIEW_CONSTRUCT, "msg: e_CX_STILLPRECAPVIEW_CONSTRUCT 0" ); |
|
111 CX_DEBUG_EXIT_FUNCTION(); |
|
112 } |
|
113 |
|
114 void CxuiStillPrecaptureView::loadDefaultWidgets() |
|
115 { |
|
116 CX_DEBUG_ENTER_FUNCTION(); |
|
117 CX_DEBUG_ASSERT(mDocumentLoader); |
|
118 |
|
119 // get pointer to the viewfinder |
|
120 QGraphicsWidget *widget = NULL; |
|
121 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEWFINDER); |
|
122 mViewfinder = qobject_cast<HbTransparentWindow *>(widget); |
|
123 CX_DEBUG_ASSERT(mViewfinder); |
|
124 |
|
125 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_QUALITY_ICON); |
|
126 mQualityIcon = qobject_cast<HbLabel *>(widget); |
|
127 CX_DEBUG_ASSERT(mQualityIcon); |
|
128 |
|
129 // create background for indicator container |
|
130 HbWidget *container = NULL; |
|
131 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_INDICATOR_CONTAINER); |
|
132 container = qobject_cast<HbWidget *>(widget); |
|
133 CX_DEBUG_ASSERT(container); |
|
134 createWidgetBackgroundGraphic(container, TRANSPARENT_BACKGROUND_GRAPHIC); |
|
135 container->show(); |
|
136 |
|
137 CX_DEBUG_EXIT_FUNCTION(); |
|
138 } |
|
139 |
|
140 |
|
141 void CxuiStillPrecaptureView::loadWidgets() |
|
142 { |
|
143 CX_DEBUG_ENTER_FUNCTION(); |
|
144 CX_DEBUG_ASSERT(mDocumentLoader); |
|
145 |
|
146 if( mWidgetsLoaded ) { |
|
147 CX_DEBUG(("Widgets already loaded")); |
|
148 CX_DEBUG_EXIT_FUNCTION(); |
|
149 return; |
|
150 } |
|
151 |
|
152 OstTrace0( camerax_performance, CXUISTILLPRECAPTUREVIEW_LOADWIDGETS, "msg: e_CX_STILLPRECAPTUREVIEW_LOADWIDGETS 1" ); |
|
153 |
|
154 bool ok = false; |
|
155 |
|
156 OstTrace0( camerax_performance, DUP4_CXUISTILLPRECAPTUREVIEW_LOADWIDGETS, "msg: e_CX_DOCUMENTLOADER_LOAD 1" ); |
|
157 mDocumentLoader->load(STILL_1ST_XML, STILL_PRE_CAPTURE_WIDGETS_SECTION, &ok); |
|
158 Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing"); |
|
159 if (CxuiServiceProvider::isCameraEmbedded()) { |
|
160 mDocumentLoader->load(STILL_1ST_XML, STILL_PRE_CAPTURE_EMBEDDED_SECTION, &ok); |
|
161 } else { |
|
162 mDocumentLoader->load(STILL_1ST_XML, STILL_PRE_CAPTURE_STANDALONE_SECTION, &ok); |
|
163 } |
|
164 OstTrace0( camerax_performance, DUP5_CXUISTILLPRECAPTUREVIEW_LOADWIDGETS, "msg: e_CX_DOCUMENTLOADER_LOAD 0" ); |
|
165 Q_ASSERT_X(ok, "camerax ui", "error in xml file parsing"); |
|
166 |
|
167 // get pointers to ui components from the layout data |
|
168 QGraphicsWidget *widget = NULL; |
|
169 QObject *object = NULL; |
|
170 |
|
171 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_ZOOM_SLIDER); |
|
172 mSlider = qobject_cast<HbSlider *>(widget); |
|
173 CX_DEBUG_ASSERT(mSlider); |
|
174 addIncreaseDecreaseButtons(mSlider); |
|
175 createWidgetBackgroundGraphic(mSlider, TRANSPARENT_BACKGROUND_GRAPHIC); |
|
176 |
|
177 if (mSelfTimer) { |
|
178 // let selftimer class get needed selftimer related widgets |
|
179 // from the documentloader |
|
180 mSelfTimer->loadSelftimerWidgets(mDocumentLoader); |
|
181 } |
|
182 |
|
183 // create background for selftimer containers |
|
184 HbWidget *container = NULL; |
|
185 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_SELFTIMER_CONTAINER); |
|
186 container = qobject_cast<HbWidget *>(widget); |
|
187 CX_DEBUG_ASSERT(container); |
|
188 createWidgetBackgroundGraphic(container, TRANSPARENT_BACKGROUND_GRAPHIC); |
|
189 |
|
190 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_SELFTIMER_BUTTON_CONTAINER); |
|
191 container = qobject_cast<HbWidget *>(widget); |
|
192 CX_DEBUG_ASSERT(container); |
|
193 createWidgetBackgroundGraphic(container, TRANSPARENT_BACKGROUND_GRAPHIC); |
|
194 |
|
195 |
|
196 // connect selftimer start button to hide controls |
|
197 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_SELFTIMER_START_BUTTON); |
|
198 HbPushButton *startButton = qobject_cast<HbPushButton *>(widget); |
|
199 CX_DEBUG_ASSERT(startButton); |
|
200 connect(startButton, SIGNAL(released()), this, SLOT(hideControls())); |
|
201 |
|
202 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_TOOLBAR); |
|
203 mToolBar = qobject_cast<HbToolBar *>(widget); |
|
204 CX_DEBUG_ASSERT(mToolBar); |
|
205 |
|
206 object = mDocumentLoader->findObject(STILL_PRE_CAPTURE_FLASH_ACTION); |
|
207 mFlashSetting = qobject_cast<HbAction *>(object); |
|
208 CX_DEBUG_ASSERT(mFlashSetting); |
|
209 |
|
210 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_IMAGES_LEFT_LABEL); |
|
211 mImagesLeft = qobject_cast<HbLabel *>(widget); |
|
212 CX_DEBUG_ASSERT(mImagesLeft); |
|
213 |
|
214 widget = mDocumentLoader->findWidget(STILL_PRE_CAPTURE_IMAGES_LEFT_CONTAINER); |
|
215 mImagesLeftContainer = qobject_cast<HbWidget *>(widget); |
|
216 CX_DEBUG_ASSERT(mImagesLeftContainer); |
|
217 createWidgetBackgroundGraphic(mImagesLeftContainer, TRANSPARENT_BACKGROUND_GRAPHIC); |
|
218 updateImagesLeftLabel(); |
|
219 |
|
220 if (CxuiServiceProvider::isCameraEmbedded()) { |
|
221 CX_DEBUG(("EMBEDDED: camera in embedded mode")); |
|
222 |
|
223 if (!CxuiServiceProvider::instance()->allowQualityChange()) { |
|
224 |
|
225 CX_DEBUG(("EMBEDDED: don't allow quality change")); |
|
226 HbAction* iq = qobject_cast<HbAction*>(mDocumentLoader->findObject(STILL_PRE_CAPTURE_IMAGE_QUALITY_ACTION)); |
|
227 if (iq) { |
|
228 CX_DEBUG(("EMBEDDED: setting image quality setting to disabled")); |
|
229 iq->setEnabled(false); |
|
230 } |
|
231 } |
|
232 if (!CxuiServiceProvider::instance()->allowModeSwitching()) { |
|
233 CX_DEBUG(("EMBEDDED: don't allow mode switching")); |
|
234 |
|
235 HbAction *video = qobject_cast<HbAction*>(mDocumentLoader->findObject(STILL_PRE_CAPTURE_GOTO_VIDEO_ACTION)); |
|
236 if (video) { |
|
237 CX_DEBUG(("EMBEDDED: setting mode switch to disabled")); |
|
238 video->setEnabled(false); |
|
239 } |
|
240 } |
|
241 if (!CxuiServiceProvider::instance()->allowCameraSwitching()) { |
|
242 |
|
243 CX_DEBUG(("EMBEDDED: don't allow camera switching")); |
|
244 |
|
245 HbAction *goto_2nd_cam = qobject_cast<HbAction*> (mDocumentLoader->findObject(STILL_PRE_CAPTURE_GOTO_2ND_CAMERA_ACTION)); |
|
246 if (goto_2nd_cam) { |
|
247 CX_DEBUG(("EMBEDDED: setting camera switch to disabled")); |
|
248 goto_2nd_cam->setEnabled(false); |
|
249 |
|
250 } |
|
251 } |
|
252 |
|
253 } |
|
254 |
|
255 hideControls(); |
|
256 |
|
257 mWidgetsLoaded = true; |
|
258 |
|
259 OstTrace0( camerax_performance, DUP1_CXUISTILLPRECAPTUREVIEW_LOADWIDGETS, "msg: e_CX_STILLPRECAPTUREVIEW_LOADWIDGETS 0" ); |
|
260 CX_DEBUG_EXIT_FUNCTION(); |
|
261 } |
|
262 |
|
263 /*! |
|
264 * Initializing settings grid |
|
265 */ |
|
266 void CxuiStillPrecaptureView::initializeSettingsGrid() |
|
267 { |
|
268 if(!mSettingsGrid) { |
|
269 HbAction* action(NULL); |
|
270 |
|
271 // Initialize settings grid |
|
272 mSettingsGrid = new HbToolBarExtension; |
|
273 |
|
274 action = mSettingsGrid->addAction(HbIcon("qtg_mono_exposure.svg"), hbTrId("txt_cam_button_exposure_compensation"), this, SLOT(launchSliderSetting())); |
|
275 action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::EV_COMPENSATION_VALUE); |
|
276 action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE); |
|
277 |
|
278 action = mSettingsGrid->addAction(HbIcon("qtg_mono_iso.svg"), hbTrId("txt_cam_button_iso"), this, SLOT(launchSetting())); |
|
279 action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::LIGHT_SENSITIVITY); |
|
280 action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE); |
|
281 |
|
282 action = mSettingsGrid->addAction(HbIcon("qtg_small_rgb.svg"), hbTrId("txt_cam_button_color_tone"), this, SLOT(launchSetting())); |
|
283 action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::COLOR_TONE); |
|
284 action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE); |
|
285 |
|
286 action = mSettingsGrid->addAction(HbIcon("qtg_mono_white_balance.svg"), hbTrId("txt_cam_button_white_balance"), this, SLOT(launchSetting())); |
|
287 action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::WHITE_BALANCE); |
|
288 action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE); |
|
289 |
|
290 action = mSettingsGrid->addAction(HbIcon("qtg_mono_sharpness.svg"), hbTrId("txt_cam_grid_sharpness"), this, SLOT(launchSliderSetting())); |
|
291 action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::SHARPNESS); |
|
292 action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE); |
|
293 |
|
294 action = mSettingsGrid->addAction(HbIcon("qtg_mono_contrast.svg"), hbTrId("txt_cam_button_contrast"), this, SLOT(launchSliderSetting())); |
|
295 action->setProperty(PROPERTY_KEY_SETTING_ID, CxeSettingIds::CONTRAST); |
|
296 action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE); |
|
297 |
|
298 mSettingsGrid->addAction(HbIcon("qtg_mono_face_tracking.svg"), hbTrId("txt_cam_button_face_tracking"), this, SLOT(launchNotSupportedNotification())); |
|
299 action->setProperty(PROPERTY_KEY_SETTING_GRID, PROPERTY_KEY_TRUE); |
|
300 |
|
301 connect(mKeyHandler, SIGNAL(autofocusKeyPressed()), mSettingsGrid, SLOT(close())); |
|
302 } |
|
303 } |
|
304 |
|
305 void CxuiStillPrecaptureView::launchSceneModesPopup() |
|
306 { |
|
307 CX_DEBUG_ENTER_FUNCTION(); |
|
308 |
|
309 if(mSceneModePopup) { |
|
310 CX_DEBUG(("mSceneModePopup exists, showing..")); |
|
311 mSceneModePopup->show(); |
|
312 } else { |
|
313 CX_DEBUG(("Loading scene mode popup DocML")); |
|
314 CxuiDocumentLoader* documentLoader = new CxuiDocumentLoader(mEngine); |
|
315 bool ok = false; |
|
316 |
|
317 // Use document loader to create popup |
|
318 documentLoader->load(SCENEMODE_SETTING_XML, &ok); |
|
319 |
|
320 CX_DEBUG(("load ok=%d", ok)); |
|
321 |
|
322 mSceneModePopup = qobject_cast<HbDialog*>(documentLoader->findWidget("still_scenemode_popup")); |
|
323 CX_DEBUG_ASSERT(mSceneModePopup); |
|
324 mSceneModePopup->setTimeout(HbDialog::NoTimeout); |
|
325 mSceneModePopup->setBackgroundFaded(false); |
|
326 |
|
327 delete documentLoader; |
|
328 documentLoader = NULL; |
|
329 } |
|
330 |
|
331 connect(mKeyHandler, SIGNAL(autofocusKeyPressed()), mSceneModePopup, SLOT(close())); |
|
332 |
|
333 CX_DEBUG_EXIT_FUNCTION(); |
|
334 } |
|
335 |
|
336 |
|
337 void CxuiStillPrecaptureView::handleSnapshot(CxeError::Id error) |
|
338 { |
|
339 CX_DEBUG_ENTER_FUNCTION(); |
|
340 |
|
341 if (mPendingAfCanceling) { |
|
342 mPendingAfCanceling = false; |
|
343 mEngine->autoFocusControl().cancel(); |
|
344 } |
|
345 |
|
346 if (error == CxeError::None) { |
|
347 // Enging may emit snapshot events even if we don't need the snapshot. |
|
348 // Check if postcapture is actually wanted and change view now if so. |
|
349 if(isPostcaptureOn()) { |
|
350 emit changeToPostcaptureView(); |
|
351 if (mSlider) { |
|
352 mSlider->hide(); |
|
353 } |
|
354 } |
|
355 } else { |
|
356 emit reportError(error); |
|
357 } |
|
358 |
|
359 CX_DEBUG_EXIT_FUNCTION(); |
|
360 } |
|
361 |
|
362 |
|
363 /*! |
|
364 Method for starting focusing which will be followed by capture. |
|
365 Meant for selftimer purposes. If autofocusing is not supported, capture |
|
366 will start without focusing. |
|
367 |
|
368 \sa capture() |
|
369 \sa handleAutofocusKeyPressed() |
|
370 \sa handleCaptureKeyPressed() |
|
371 \sa setCapturePending() |
|
372 */ |
|
373 void CxuiStillPrecaptureView::focusAndCapture() |
|
374 { |
|
375 CX_DEBUG_ENTER_FUNCTION(); |
|
376 |
|
377 if (!mEngine->autoFocusControl().supported()) { |
|
378 // autofocus is not supported, so start capturing straight away |
|
379 capture(); |
|
380 } else { |
|
381 // start focusing |
|
382 handleAutofocusKeyPressed(); |
|
383 setCapturePending(); |
|
384 } |
|
385 |
|
386 CX_DEBUG_EXIT_FUNCTION(); |
|
387 } |
|
388 |
|
389 void CxuiStillPrecaptureView::capture() |
|
390 { |
|
391 CX_DEBUG_ENTER_FUNCTION(); |
|
392 mCapturePending = false; |
|
393 |
|
394 if (mEngine->mode() == Cxe::ImageMode) { |
|
395 // do not start capturing, if it is already ongoing |
|
396 // the user might be repeatly triggering capture key |
|
397 if (mEngine->stillCaptureControl().state() == CxeStillCaptureControl::Ready) { |
|
398 // If focusing in progress, cancel it now. |
|
399 // Set capture pending and continue once focusing is cancelled. |
|
400 if(mEngine->autoFocusControl().state() == CxeAutoFocusControl::InProgress) { |
|
401 mEngine->autoFocusControl().cancel(); |
|
402 setCapturePending(); |
|
403 } else { |
|
404 mEngine->stillCaptureControl().reset(); //! @todo: Do not delete snapshots before images are really saved |
|
405 mEngine->stillCaptureControl().capture(); |
|
406 } |
|
407 } else { |
|
408 setCapturePending(); |
|
409 } |
|
410 } |
|
411 |
|
412 // after capturing check what is the new amount for images left |
|
413 updateImagesLeftLabel(); |
|
414 |
|
415 CX_DEBUG_EXIT_FUNCTION(); |
|
416 } |
|
417 |
|
418 void CxuiStillPrecaptureView::setCapturePending() |
|
419 { |
|
420 CX_DEBUG_ENTER_FUNCTION(); |
|
421 mCapturePending = true; |
|
422 QTimer::singleShot(CXUI_CAPTURE_PENDING_TIMEOUT, this, SLOT(resetCapturePendingFlag())); |
|
423 CX_DEBUG_EXIT_FUNCTION(); |
|
424 } |
|
425 |
|
426 |
|
427 void CxuiStillPrecaptureView::goToVideo() |
|
428 { |
|
429 CX_DEBUG_ENTER_FUNCTION(); |
|
430 OstTrace0( camerax_performance, DUP1_CXUISTILLPRECAPTUREVIEW_GOTOVIDEO, "msg: e_CX_GO_TO_VIDEO_MODE 1" ); |
|
431 |
|
432 hideControls(); |
|
433 mEngine->initMode(VideoMode); |
|
434 emit changeToPrecaptureView(); |
|
435 |
|
436 CX_DEBUG_EXIT_FUNCTION(); |
|
437 } |
|
438 |
|
439 /*! |
|
440 CxuiStillPrecaptureView::handleAutoFocusStateChanged |
|
441 |
|
442 \sa focusAndCapture() |
|
443 \sa capture() |
|
444 \sa handleAutofocusKeyPressed() |
|
445 */ |
|
446 void CxuiStillPrecaptureView::handleAutoFocusStateChanged(CxeAutoFocusControl::State newstate, CxeError::Id error) |
|
447 { |
|
448 CX_DEBUG_ENTER_FUNCTION(); |
|
449 CxeAutoFocusControl::Mode mode = mEngine->autoFocusControl().mode(); |
|
450 CX_DEBUG( ("CxuiStillPrecaptureView::handleAutoFocusStateChanged <> error: %d mode: %d state %d", error, mode, |
|
451 newstate ) ); |
|
452 |
|
453 |
|
454 switch (newstate) { |
|
455 case CxeAutoFocusControl::Failed: |
|
456 case CxeAutoFocusControl::Ready: |
|
457 if (mCapturePending) { |
|
458 // focus and capture were grouped together, capture straight away |
|
459 capture(); |
|
460 } |
|
461 break; |
|
462 case CxeAutoFocusControl::Unknown: |
|
463 // Capture key was pressed, focus has been cancelled, |
|
464 // continue with capturing. |
|
465 if(mCapturePending) { |
|
466 CX_DEBUG(("mCapturePending is true, starting capture now")); |
|
467 capture(); |
|
468 } |
|
469 break; |
|
470 default: |
|
471 break; |
|
472 } |
|
473 //} |
|
474 |
|
475 CX_DEBUG_EXIT_FUNCTION(); |
|
476 } |
|
477 |
|
478 |
|
479 void CxuiStillPrecaptureView::updateOrientation(Qt::Orientation orientation) |
|
480 { |
|
481 CX_DEBUG_ENTER_FUNCTION(); |
|
482 |
|
483 hideControls(); |
|
484 mMainWindow->setOrientation(orientation); |
|
485 |
|
486 if (orientation == Qt::Horizontal) { |
|
487 CX_DEBUG(("New screen orientation is horizontal")); |
|
488 mToolBar->setOrientation(Qt::Vertical); |
|
489 } else { |
|
490 CX_DEBUG(("New screen orientation is vertical")); |
|
491 mToolBar->setOrientation(Qt::Horizontal); |
|
492 } |
|
493 |
|
494 CX_DEBUG_EXIT_FUNCTION(); |
|
495 } |
|
496 |
|
497 /*! |
|
498 * Handle capture key full press. |
|
499 */ |
|
500 void CxuiStillPrecaptureView::handleCaptureKeyPressed() |
|
501 { |
|
502 CX_DEBUG_ENTER_FUNCTION(); |
|
503 if (mEngine->mode() == Cxe::ImageMode) { |
|
504 OstTrace0(camerax_performance, CXUISTILLPRECAPTUREVIEW_SHOT_TO_SHOT, "msg: e_CX_SHOT_TO_SHOT 1"); |
|
505 OstTrace0(camerax_performance, CXUISTILLPRECAPTUREVIEW_SHOT_TO_SNAP, "msg: e_CX_SHOT_TO_SNAPSHOT 1"); |
|
506 OstTrace0(camerax_performance, CXUISTILLPRECAPTUREVIEW_SHOT_TO_SAVE, "msg: e_CX_SHOT_TO_SAVE 1"); |
|
507 |
|
508 menu()->close(); |
|
509 |
|
510 // close open dialogs |
|
511 closeDialogs(); |
|
512 |
|
513 if (mSelfTimer && mSelfTimer->isEnabled() ) { |
|
514 if (mSelfTimer->isOngoing()) { |
|
515 // dismiss selftimer and capture image |
|
516 mSelfTimer->cancel(); |
|
517 capture(); |
|
518 } else { |
|
519 // start selftimer if it is enabled and not yet started |
|
520 mSelfTimer->startTimer(); |
|
521 } |
|
522 } else { |
|
523 // normal capture |
|
524 capture(); |
|
525 } |
|
526 } |
|
527 CX_DEBUG_EXIT_FUNCTION(); |
|
528 } |
|
529 |
|
530 /*! |
|
531 * Handle capture key half pressed (aka "autofocus key press"). |
|
532 */ |
|
533 void CxuiStillPrecaptureView::handleAutofocusKeyPressed() |
|
534 { |
|
535 CX_DEBUG_ENTER_FUNCTION(); |
|
536 OstTrace0( camerax_performance, CXUISTILLPRECAPTUREVIEW_AUTOFOCUS, "msg: e_CX_AUTOFOCUS_LOCK 1" ); |
|
537 |
|
538 // Base class handling needs to happen first to keep e.g. settings dialogs handling sane. |
|
539 CxuiPrecaptureView::handleAutofocusKeyPressed(); |
|
540 |
|
541 if (!mEngine->autoFocusControl().supported()) { |
|
542 CX_DEBUG(("Autofocus not supported, ignoring key press")); |
|
543 CX_DEBUG_EXIT_FUNCTION(); |
|
544 return; |
|
545 } |
|
546 |
|
547 // Auto-focus can only work if viewfinder is running |
|
548 if (mEngine->viewfinderControl().state() == CxeViewfinderControl::Running) { |
|
549 |
|
550 mEngine->autoFocusControl().start(); |
|
551 } |
|
552 |
|
553 CX_DEBUG_EXIT_FUNCTION(); |
|
554 } |
|
555 |
|
556 void CxuiStillPrecaptureView::handleAutofocusKeyReleased() |
|
557 { |
|
558 CX_DEBUG_ENTER_FUNCTION(); |
|
559 |
|
560 if (mEngine->autoFocusControl().supported()) { |
|
561 // Check that capture is not in progress, or pending. |
|
562 // Otherwise wouldn't want to cancel the focus. |
|
563 CxeStillCaptureControl::State state(mEngine->stillCaptureControl().state()); |
|
564 if (state != CxeStillCaptureControl::Capturing && !mCapturePending) { |
|
565 mEngine->autoFocusControl().cancel(); |
|
566 } else { |
|
567 // set pending AF release |
|
568 mPendingAfCanceling = true; |
|
569 } |
|
570 |
|
571 } else { |
|
572 CX_DEBUG(("Autofocus not supported, ignoring key release")); |
|
573 } |
|
574 |
|
575 CX_DEBUG_EXIT_FUNCTION(); |
|
576 } |
|
577 |
|
578 void CxuiStillPrecaptureView::showEvent(QShowEvent *event) |
|
579 { |
|
580 CxuiPrecaptureView::showEvent(event); |
|
581 |
|
582 updateImagesLeftLabel(); |
|
583 updateQualityIcon(); |
|
584 |
|
585 // cancel selftimer when returning to precapture |
|
586 // since selftimer needs to be turned off after capturing an image |
|
587 // (with selftimer postcapture is always shown) |
|
588 if (mSelfTimer && mSelfTimer->isEnabled()) { |
|
589 mSelfTimer->cancel(); |
|
590 } |
|
591 |
|
592 // In case the user presses and holds the auto-focus key (ie. half-press) |
|
593 // in post-capture view, we need to start auto-focusing when entering |
|
594 // the still precapture view. |
|
595 if (event->type() == QEvent::Show && |
|
596 mKeyHandler && mKeyHandler->isAutofocusKeyPressed()) { |
|
597 |
|
598 CX_DEBUG(("Still pre-capture coming visible and auto-focus key pressed -> starting AF")); |
|
599 handleAutofocusKeyPressed(); |
|
600 } |
|
601 } |
|
602 |
|
603 void CxuiStillPrecaptureView::showToolbar() |
|
604 { |
|
605 if (mEngine && mEngine->isEngineReady()) { |
|
606 CxuiPrecaptureView::showToolbar(); |
|
607 } |
|
608 } |
|
609 |
|
610 |
|
611 void CxuiStillPrecaptureView::handleViewfinderStateChanged( |
|
612 CxeViewfinderControl::State newState, CxeError::Id /*error*/) |
|
613 { |
|
614 CX_DEBUG_ENTER_FUNCTION(); |
|
615 |
|
616 if (newState == CxeViewfinderControl::Running) { |
|
617 |
|
618 // the toolbar is created when the viewfinder is started the first time |
|
619 // in order to hide the delay caused by the creation |
|
620 if(!mWidgetsLoaded) { |
|
621 loadWidgets(); |
|
622 } |
|
623 |
|
624 if(mMainWindow->currentView() == this && |
|
625 mKeyHandler->isAutofocusKeyPressed()) { |
|
626 // Viewfinder just started and the user is pressing the auto-focus key. |
|
627 // Start focusing. |
|
628 |
|
629 CX_DEBUG(("Viewfinder starting and auto-focus key pressed -> starting AF")); |
|
630 handleAutofocusKeyPressed(); |
|
631 } |
|
632 } |
|
633 |
|
634 CX_DEBUG_EXIT_FUNCTION(); |
|
635 } |
|
636 |
|
637 void CxuiStillPrecaptureView::handleStillCaptureStateChanged( |
|
638 CxeStillCaptureControl::State newState, CxeError::Id /*error*/) |
|
639 { |
|
640 if (newState == CxeStillCaptureControl::Ready) { |
|
641 OstTrace0(camerax_performance, CXUISTILLPRECAPTUREVIEW_SHOT_TO_SHOT_DUP2, "msg: e_CX_SHOT_TO_SHOT 0"); |
|
642 |
|
643 if (mCapturePending) { |
|
644 CX_DEBUG(("mCapturePending is true, starting capture now")); |
|
645 capture(); |
|
646 } |
|
647 } |
|
648 } |
|
649 |
|
650 void CxuiStillPrecaptureView::resetCapturePendingFlag() |
|
651 { |
|
652 CX_DEBUG_IN_FUNCTION(); |
|
653 |
|
654 mCapturePending = false; |
|
655 } |
|
656 |
|
657 void CxuiStillPrecaptureView::showControls() |
|
658 { |
|
659 // show controls when selftimer counter is not active |
|
660 // and when autofocus key is not being pressed |
|
661 if ( !(mSelfTimer && mSelfTimer->isOngoing()) && |
|
662 (!mKeyHandler || !mKeyHandler->isAutofocusKeyPressed()) ) { |
|
663 CxuiPrecaptureView::showControls(); |
|
664 } |
|
665 |
|
666 } |
|
667 |
|
668 void CxuiStillPrecaptureView::handleFocusLost() |
|
669 { |
|
670 CX_DEBUG_IN_FUNCTION(); |
|
671 bool captureInProgress = mEngine->stillCaptureControl().state() == CxeStillCaptureControl::Capturing; |
|
672 if (!captureInProgress) { |
|
673 if (mSelfTimer && mSelfTimer->isOngoing()) { |
|
674 // If self-timer is running, stop and reset the delay now. |
|
675 mSelfTimer->reset(); |
|
676 } |
|
677 |
|
678 // Release camera as we are going to background. |
|
679 releaseCamera(); |
|
680 } |
|
681 } |
|
682 |
|
683 void CxuiStillPrecaptureView::handleFocusGained() |
|
684 { |
|
685 CX_DEBUG_ENTER_FUNCTION(); |
|
686 CxuiPrecaptureView::handleFocusGained(); |
|
687 CX_DEBUG_EXIT_FUNCTION(); |
|
688 } |
|
689 |
|
690 void CxuiStillPrecaptureView::handleSceneChanged(CxeScene &scene) |
|
691 { |
|
692 CX_DEBUG_ENTER_FUNCTION(); |
|
693 if (mEngine->mode() == Cxe::ImageMode) { |
|
694 // for now, we are only interested in flashmode change |
|
695 if (scene.contains(CxeSettingIds::FLASH_MODE)) { |
|
696 CX_DEBUG(("updating flash to: %d", scene[CxeSettingIds::FLASH_MODE].value<int>())); |
|
697 handleSettingValueChanged(CxeSettingIds::FLASH_MODE, scene[CxeSettingIds::FLASH_MODE]); |
|
698 } else { |
|
699 // No flash mode specified within the scene. |
|
700 // Check from setting model what is it currently. |
|
701 int flashMode(Cxe::FlashAuto); |
|
702 mEngine->settings().get(CxeSettingIds::FLASH_MODE, flashMode); |
|
703 handleSettingValueChanged(CxeSettingIds::FLASH_MODE, QVariant(flashMode)); |
|
704 } |
|
705 } |
|
706 |
|
707 CX_DEBUG_EXIT_FUNCTION(); |
|
708 } |
|
709 |
|
710 void CxuiStillPrecaptureView::handleSettingValueChanged(const QString& key, QVariant newValue) |
|
711 { |
|
712 CX_DEBUG_ENTER_FUNCTION(); |
|
713 |
|
714 if (mEngine->mode() == Cxe::ImageMode) { |
|
715 if (key == CxeSettingIds::IMAGE_QUALITY) { |
|
716 |
|
717 // update the quality indicator on screen |
|
718 updateQualityIcon(); |
|
719 |
|
720 // update images left when quality values are changed |
|
721 updateImagesLeftLabel(); |
|
722 } |
|
723 |
|
724 if (mFlashSetting && key == CxeSettingIds::FLASH_MODE) { |
|
725 CX_DEBUG((("flash mode: %d"),newValue.toInt())) |
|
726 QString icon = getSettingItemIcon(key, newValue); |
|
727 mFlashSetting->setIcon(HbIcon(icon)); |
|
728 } |
|
729 } |
|
730 |
|
731 CX_DEBUG_EXIT_FUNCTION(); |
|
732 } |
|
733 |
|
734 |
|
735 /*! |
|
736 Close open dialogs. |
|
737 */ |
|
738 void CxuiStillPrecaptureView::closeDialogs() |
|
739 { |
|
740 |
|
741 if (mSettingsDialog && mSettingsDialog->isVisible()) { |
|
742 mSettingsDialog->close(); |
|
743 } |
|
744 |
|
745 if (mSceneModePopup && mSceneModePopup->isVisible()) { |
|
746 mSceneModePopup->close(); |
|
747 } |
|
748 |
|
749 if (mStillSettingsPopup && mStillSettingsPopup->isVisible()) { |
|
750 mStillSettingsPopup->close(); |
|
751 } |
|
752 |
|
753 hideSettingsGrid(); |
|
754 } |
|
755 |
|
756 |
|
757 /*! |
|
758 *Helper method to create setting dialog |
|
759 */ |
|
760 void CxuiStillPrecaptureView::launchSetting() |
|
761 { |
|
762 CX_DEBUG_ENTER_FUNCTION(); |
|
763 |
|
764 QObject *action = sender(); |
|
765 |
|
766 if (action) { |
|
767 QString settingsKey = action->property(PROPERTY_KEY_SETTING_ID).toString(); |
|
768 CX_DEBUG(("settingsKey=%s", settingsKey.toAscii().constData())); |
|
769 launchSettingsDialog(action); |
|
770 // special case to get value changed event to the selftimer class |
|
771 if (settingsKey == CxeSettingIds::SELF_TIMER) { |
|
772 connect(mSettingsDialogList, SIGNAL(valueSelected(int)), |
|
773 mSelfTimer, SLOT(changeTimeOut(int))); |
|
774 } |
|
775 } |
|
776 |
|
777 CX_DEBUG_EXIT_FUNCTION(); |
|
778 } |
|
779 |
|
780 /*! |
|
781 Update the images left counter |
|
782 */ |
|
783 void CxuiStillPrecaptureView::updateImagesLeftLabel() |
|
784 { |
|
785 CX_DEBUG_ENTER_FUNCTION(); |
|
786 |
|
787 if (mImagesLeft && mImagesLeftContainer) { |
|
788 int images = mEngine->stillCaptureControl().imagesLeft(); |
|
789 |
|
790 if (images > CXUI_IMAGES_LEFT_LIMIT) { |
|
791 mImagesLeftContainer->hide(); |
|
792 } else { |
|
793 mImagesLeftContainer->show(); |
|
794 } |
|
795 |
|
796 CX_DEBUG(("Images left %d", images)); |
|
797 mImagesLeft->setPlainText(hbTrId("%L1").arg(images)); |
|
798 } |
|
799 |
|
800 CX_DEBUG_EXIT_FUNCTION(); |
|
801 } |
|
802 |
|
803 // end of file |