|
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 <QTimer> |
|
19 #include <QApplication> |
|
20 #include <QGraphicsSceneEvent> |
|
21 #include <hblabel.h> |
|
22 #include <hbdialog.h> |
|
23 #include <QGraphicsRectItem> |
|
24 #include <QColor> |
|
25 |
|
26 #include "cxutils.h" |
|
27 #include "cxeengine.h" |
|
28 #include "cxuienums.h" |
|
29 #include "cxuistandby.h" |
|
30 #include "cxuidocumentloader.h" |
|
31 #include "cxeviewfindercontrol.h" |
|
32 #include "cxuicapturekeyhandler.h" |
|
33 #include "cxestillcapturecontrol.h" |
|
34 #include "cxevideocapturecontrol.h" |
|
35 |
|
36 |
|
37 |
|
38 /* |
|
39 * CxuiStandby::CxuiStandby |
|
40 */ |
|
41 CxuiStandby::CxuiStandby(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader, CxeEngine *engine) |
|
42 : mKeyHandler(keyHandler), |
|
43 mDocumentLoader(documentLoader), |
|
44 mEngine(engine), |
|
45 mStandbyPopup(NULL), |
|
46 mStandbyDialogVisible(false) |
|
47 { |
|
48 CX_DEBUG_ENTER_FUNCTION(); |
|
49 CX_ASSERT_ALWAYS(engine); |
|
50 |
|
51 // initialize standby timer |
|
52 mStandbyTimer = new QTimer(this); |
|
53 |
|
54 // install event filter for application wide events |
|
55 QCoreApplication::instance()->installEventFilter(this); |
|
56 |
|
57 CX_ASSERT_ALWAYS(mStandbyTimer); |
|
58 connect(mStandbyTimer, SIGNAL(timeout()), this, SLOT(toStandby())); |
|
59 mStandbyTimer->setSingleShot(true); |
|
60 |
|
61 CX_DEBUG_EXIT_FUNCTION(); |
|
62 } |
|
63 |
|
64 |
|
65 |
|
66 /* |
|
67 * CxuiStandby::~CxuiStandby() |
|
68 */ |
|
69 CxuiStandby::~CxuiStandby() |
|
70 { |
|
71 CX_DEBUG_IN_FUNCTION(); |
|
72 // remove the event filter |
|
73 QCoreApplication::instance()->removeEventFilter(this); |
|
74 // stop standby timer |
|
75 stopTimer(); |
|
76 } |
|
77 |
|
78 |
|
79 /* |
|
80 * stops standby timer |
|
81 */ |
|
82 void CxuiStandby::stopTimer() |
|
83 { |
|
84 if(mStandbyTimer) { |
|
85 mStandbyTimer->stop(); |
|
86 } |
|
87 } |
|
88 |
|
89 /* |
|
90 * starts standby timer |
|
91 */ |
|
92 void CxuiStandby::startTimer() |
|
93 { |
|
94 if(mStandbyTimer) { |
|
95 mStandbyTimer->start(CXUI_STANDBY_CAMERA_TIMEOUT); |
|
96 } |
|
97 } |
|
98 |
|
99 |
|
100 /* |
|
101 * handles mouse press events |
|
102 * returns if mouse key press is consumed. |
|
103 */ |
|
104 bool CxuiStandby::handleMouseEvent() |
|
105 { |
|
106 CX_DEBUG_ENTER_FUNCTION(); |
|
107 |
|
108 bool keyHandled = false; |
|
109 |
|
110 // close the dialog if it's visible |
|
111 if(mStandbyDialogVisible && mStandbyPopup) { |
|
112 CX_DEBUG(( "closing the popup mStandbyDialogVisible = : %d", mStandbyDialogVisible )); |
|
113 mStandbyPopup->close(); |
|
114 keyHandled = true; |
|
115 } else if (mStandbyTimer && mStandbyTimer->isActive()) { |
|
116 // restart the timer only if it's running |
|
117 startTimer(); |
|
118 } |
|
119 |
|
120 CX_DEBUG_EXIT_FUNCTION(); |
|
121 |
|
122 return keyHandled; |
|
123 } |
|
124 |
|
125 |
|
126 /* |
|
127 * switching to standby. |
|
128 */ |
|
129 void CxuiStandby::toStandby() |
|
130 { |
|
131 CX_DEBUG_ENTER_FUNCTION(); |
|
132 |
|
133 if (proceedToStandy()) { |
|
134 |
|
135 // signal for ui classes to prepare for standby |
|
136 emit aboutToEnterStandby(); |
|
137 |
|
138 mStandbyDialogVisible = true; |
|
139 |
|
140 if (mStandbyPopup == NULL) { |
|
141 CX_DEBUG(("Loading standby DocML")); |
|
142 bool ok = false; |
|
143 // Use document loader to create popup |
|
144 mDocumentLoader->load(CxUiLayout::STANDBY_POPUP_XML, &ok); |
|
145 CX_DEBUG(("standby load ok=%d", ok)); |
|
146 mStandbyPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::STANDBY_POPUP)); |
|
147 CX_ASSERT_ALWAYS(mStandbyPopup); |
|
148 mStandbyPopup->setTimeout(HbDialog::NoTimeout); |
|
149 mStandbyPopup->setBackgroundFaded(false); |
|
150 mStandbyPopup->setPreferredPos(QPointF(0,0)); |
|
151 // color of standby text is set in the code. It cannot be done in docml |
|
152 HbLabel* label = qobject_cast<HbLabel*>(mDocumentLoader->findWidget(CxUiLayout::STANDBY_TEXT_WIDGET)); |
|
153 label->setTextColor(Qt::white); |
|
154 |
|
155 // connecting "abouttoclose" signal to dismissStandby |
|
156 connect(mStandbyPopup, SIGNAL(aboutToClose()), this, SLOT(dismissStandby())); |
|
157 |
|
158 // HbDialog's default background item is replaced with black rectangle |
|
159 QGraphicsRectItem *backgroundItem = new QGraphicsRectItem(); |
|
160 QBrush blackBrush = QBrush(Qt::black); |
|
161 backgroundItem->setBrush(blackBrush); |
|
162 QGraphicsItem *origBgItem = mStandbyPopup->backgroundItem(); |
|
163 backgroundItem->setRect(origBgItem->boundingRect()); |
|
164 mStandbyPopup->setBackgroundItem(backgroundItem); |
|
165 |
|
166 } |
|
167 |
|
168 CX_ASSERT_ALWAYS(mStandbyPopup); |
|
169 |
|
170 mStandbyPopup->show(); |
|
171 // connecting half press or full press key signal to dismiss standby |
|
172 connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), mStandbyPopup, SLOT(close())); |
|
173 connect(&mKeyHandler, SIGNAL(captureKeyPressed()), mStandbyPopup, SLOT(close())); |
|
174 } |
|
175 |
|
176 CX_DEBUG_EXIT_FUNCTION(); |
|
177 } |
|
178 |
|
179 |
|
180 /* |
|
181 * dismisses standby |
|
182 */ |
|
183 void CxuiStandby::dismissStandby() |
|
184 { |
|
185 CX_DEBUG_ENTER_FUNCTION(); |
|
186 |
|
187 if(mStandbyDialogVisible) { |
|
188 // stop the standby timer and close the pop-up |
|
189 mStandbyDialogVisible = false; |
|
190 //restart timer |
|
191 startTimer(); |
|
192 // signal for ui classes to prepare for standby exit |
|
193 emit aboutToExitStandby(); |
|
194 } |
|
195 |
|
196 CX_DEBUG_EXIT_FUNCTION(); |
|
197 } |
|
198 |
|
199 |
|
200 |
|
201 /* |
|
202 * checks if we can swtich to standby |
|
203 */ |
|
204 bool CxuiStandby::proceedToStandy() |
|
205 { |
|
206 CX_DEBUG_ENTER_FUNCTION(); |
|
207 CX_ASSERT_ALWAYS(mEngine); |
|
208 |
|
209 bool ok = false; |
|
210 if(!mStandbyDialogVisible && |
|
211 mEngine->isEngineReady()) { |
|
212 CX_DEBUG(("show standby dialog")); |
|
213 ok = true; |
|
214 } |
|
215 |
|
216 CX_DEBUG(( "CxuiStandby::proceedToStandy proceedToStandy: %d", ok )); |
|
217 |
|
218 return ok; |
|
219 } |
|
220 |
|
221 |
|
222 |
|
223 /* |
|
224 * Event filter which filters application wide mouse events. |
|
225 */ |
|
226 |
|
227 bool CxuiStandby::eventFilter(QObject *object, QEvent *event) |
|
228 { |
|
229 Q_UNUSED(object); |
|
230 |
|
231 bool eventWasConsumed = false; |
|
232 switch (event->type()) { |
|
233 case QEvent::GraphicsSceneMouseMove: |
|
234 case QEvent::GraphicsSceneMousePress: |
|
235 case QEvent::GraphicsSceneMouseRelease: |
|
236 CX_DEBUG(("CxuiStandby::eventFilter -> mouse event")); |
|
237 eventWasConsumed = handleMouseEvent(); |
|
238 break; |
|
239 default: |
|
240 break; |
|
241 } |
|
242 return eventWasConsumed; |
|
243 } |
|
244 |
|
245 // end of file |