|
1 /* |
|
2 * Copyright (c) 2010 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 "cxezoomcontroldesktop.h" |
|
19 #include "cxecameradevicecontrol.h" |
|
20 #include "cxutils.h" |
|
21 #include "cxenamespace.h" |
|
22 #include "cxestate.h" |
|
23 |
|
24 const int NOT_DEFINED = -1; |
|
25 |
|
26 /*! |
|
27 * Constructor |
|
28 */ |
|
29 CxeZoomControlDesktop::CxeZoomControlDesktop(CxeCameraDeviceControl &cameraDeviceControl) : |
|
30 mCameraDeviceControl(cameraDeviceControl) |
|
31 { |
|
32 CX_DEBUG_ENTER_FUNCTION(); |
|
33 |
|
34 qRegisterMetaType<CxeZoomControl::State> (); |
|
35 |
|
36 init(); |
|
37 |
|
38 CX_DEBUG_EXIT_FUNCTION(); |
|
39 } |
|
40 |
|
41 /*! |
|
42 * Destructor |
|
43 */ |
|
44 CxeZoomControlDesktop::~CxeZoomControlDesktop() |
|
45 { |
|
46 CX_DEBUG_ENTER_FUNCTION(); |
|
47 CX_DEBUG_EXIT_FUNCTION(); |
|
48 } |
|
49 |
|
50 /*! |
|
51 * Get the minimum zoom index |
|
52 */ |
|
53 int CxeZoomControlDesktop::min() const |
|
54 { |
|
55 return mMinZoomLevel; |
|
56 } |
|
57 |
|
58 /*! |
|
59 * Get the maximum zoom index |
|
60 */ |
|
61 int CxeZoomControlDesktop::max() const |
|
62 { |
|
63 return mMaxZoomLevel; |
|
64 } |
|
65 |
|
66 /*! |
|
67 * Init |
|
68 */ |
|
69 void CxeZoomControlDesktop::init() |
|
70 { |
|
71 CX_DEBUG_ENTER_FUNCTION(); |
|
72 |
|
73 // Initialize the variables |
|
74 mMinZoomLevel = 0; |
|
75 mMaxZoomLevel = 0; |
|
76 mCurrentZoomLevel = 0; |
|
77 |
|
78 mState = Idle; |
|
79 |
|
80 CX_DEBUG_EXIT_FUNCTION(); |
|
81 } |
|
82 |
|
83 /*! |
|
84 * Re-initializes the zoom control |
|
85 */ |
|
86 void CxeZoomControlDesktop::reset() |
|
87 { |
|
88 CX_DEBUG_ENTER_FUNCTION(); |
|
89 |
|
90 init(); |
|
91 emit zoomLevelChanged(mCurrentZoomLevel); |
|
92 |
|
93 CX_DEBUG_EXIT_FUNCTION(); |
|
94 } |
|
95 |
|
96 /*! |
|
97 * slot to prepare zoom control for still mode |
|
98 */ |
|
99 void CxeZoomControlDesktop::prepareZoomForStill(int ecamStillResolutionIndex) |
|
100 { |
|
101 CX_DEBUG_ENTER_FUNCTION(); |
|
102 |
|
103 Q_UNUSED(ecamStillResolutionIndex); |
|
104 |
|
105 if (mCameraDeviceControl.state() == CxeCameraDeviceControl::Ready) { |
|
106 reset(); |
|
107 int error; |
|
108 int imageQualityIndex; |
|
109 CxeError::Id cxErr; |
|
110 if (cxErr == CxeError::None && mStillMaxZoomLimits.count() > 0) { |
|
111 // fetching the zoom limit based on the image quality |
|
112 mMaxZoomLevel = mStillMaxZoomLimits[imageQualityIndex]; |
|
113 } else { |
|
114 mMaxZoomLevel = NOT_DEFINED; |
|
115 } |
|
116 |
|
117 finalizeZoomPreparation(error); |
|
118 } |
|
119 |
|
120 CX_DEBUG_EXIT_FUNCTION(); |
|
121 } |
|
122 |
|
123 /*! |
|
124 * slot to prepare zoom control for video mode |
|
125 */ |
|
126 void CxeZoomControlDesktop::prepareZoomForVideo() |
|
127 { |
|
128 CX_DEBUG_ENTER_FUNCTION(); |
|
129 |
|
130 if (mCameraDeviceControl.state() == CxeCameraDeviceControl::Ready) { |
|
131 reset(); |
|
132 int error; |
|
133 if (mVideoMaxZoomLimits.count() > 0) { |
|
134 // fetching the zoom limit based on the video quality |
|
135 mMaxZoomLevel = mVideoMaxZoomLimits[0]; |
|
136 } else { |
|
137 mMaxZoomLevel = NOT_DEFINED; |
|
138 } |
|
139 |
|
140 finalizeZoomPreparation(error); |
|
141 } |
|
142 |
|
143 |
|
144 CX_DEBUG_EXIT_FUNCTION(); |
|
145 } |
|
146 |
|
147 /*! |
|
148 * Completes zoom control preparation. |
|
149 */ |
|
150 void CxeZoomControlDesktop::finalizeZoomPreparation(int error) |
|
151 { |
|
152 CX_DEBUG_ENTER_FUNCTION(); |
|
153 |
|
154 CX_DEBUG(("Maximum zoom limit: %d", mMaxZoomLevel)); |
|
155 |
|
156 if (!error) { |
|
157 // Note that this is called only after setting the resolution. |
|
158 // emit the zoom changed signal so that clients can do any updates if necessary. |
|
159 emit zoomLevelChanged(mCurrentZoomLevel); |
|
160 |
|
161 mState = Ready; |
|
162 emit stateChanged(mState, CxeError::None); |
|
163 } |
|
164 |
|
165 CX_DEBUG_EXIT_FUNCTION(); |
|
166 } |
|
167 |
|
168 /*! |
|
169 * Zooms to the level specified in the parameter |
|
170 */ |
|
171 void CxeZoomControlDesktop::zoomTo(int value) |
|
172 { |
|
173 CX_DEBUG_ENTER_FUNCTION(); |
|
174 |
|
175 CX_DEBUG(("Zoom to: %d, current zoom: %d", value, mCurrentZoomLevel)); |
|
176 |
|
177 // If not currently zooming and value falls between min & max |
|
178 // then zoom to the passed level. Also there's no need to zoom if new zoom |
|
179 // level is same as the current. |
|
180 if (state() == CxeZoomControl::Ready && (value <= mMaxZoomLevel) |
|
181 && (value >= mMinZoomLevel) && (mCurrentZoomLevel != value)) { |
|
182 |
|
183 // Could also check the number of values in the array to avoid out of bounds indexing, |
|
184 // though this is done in alternate way by the min and max limits. |
|
185 mCurrentZoomLevel = value; |
|
186 |
|
187 // Set the appropriate zooming state |
|
188 if (value < mCurrentZoomLevel) { |
|
189 mState = ZoomingOut; |
|
190 } else { |
|
191 mState = ZoomingIn; |
|
192 } |
|
193 emit stateChanged(mState, CxeError::None); |
|
194 |
|
195 //! @todo: Wait for zoom callback: ECamEventZoomStateChanged ? |
|
196 mState = Ready; |
|
197 emit stateChanged(mState, CxeError::None); |
|
198 |
|
199 // Emit the zoom level change signal |
|
200 emit zoomLevelChanged(mCurrentZoomLevel); |
|
201 } |
|
202 |
|
203 CX_DEBUG_EXIT_FUNCTION(); |
|
204 } |
|
205 |
|
206 CxeZoomControl::State CxeZoomControlDesktop::state() const |
|
207 { |
|
208 return mState; |
|
209 } |