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 bool keyHandled = false; |
|
107 |
|
108 // close the dialog if it's visible |
|
109 if (mStandbyDialogVisible && mStandbyPopup) { |
|
110 CX_DEBUG(( "closing the popup mStandbyDialogVisible = : %d", mStandbyDialogVisible )); |
|
111 mStandbyPopup->close(); |
|
112 keyHandled = true; |
|
113 } else if (mStandbyTimer && mStandbyTimer->isActive()) { |
|
114 // restart the timer only if it's running |
|
115 startTimer(); |
|
116 } |
|
117 |
|
118 return keyHandled; |
|
119 } |
|
120 |
|
121 |
|
122 /* |
|
123 * switching to standby. |
|
124 */ |
|
125 void CxuiStandby::toStandby() |
|
126 { |
|
127 CX_DEBUG_ENTER_FUNCTION(); |
|
128 |
|
129 if (proceedToStandy()) { |
|
130 |
|
131 // signal for ui classes to prepare for standby |
|
132 emit aboutToEnterStandby(); |
|
133 |
|
134 mStandbyDialogVisible = true; |
|
135 |
|
136 if (mStandbyPopup == NULL) { |
|
137 CX_DEBUG(("Loading standby DocML")); |
|
138 bool ok = false; |
|
139 // Use document loader to create popup |
|
140 mDocumentLoader->load(CxUiLayout::STANDBY_POPUP_XML, &ok); |
|
141 CX_DEBUG(("standby load ok=%d", ok)); |
|
142 mStandbyPopup = qobject_cast<HbDialog*>(mDocumentLoader->findWidget(CxUiLayout::STANDBY_POPUP)); |
|
143 CX_ASSERT_ALWAYS(mStandbyPopup); |
|
144 mStandbyPopup->setTimeout(HbDialog::NoTimeout); |
|
145 mStandbyPopup->setBackgroundFaded(false); |
|
146 mStandbyPopup->setPreferredPos(QPointF(0,0)); |
|
147 // color of standby text is set in the code. It cannot be done in docml |
|
148 HbLabel* label = qobject_cast<HbLabel*>(mDocumentLoader->findWidget(CxUiLayout::STANDBY_TEXT_WIDGET)); |
|
149 label->setTextColor(Qt::white); |
|
150 |
|
151 // connecting "abouttoclose" signal to dismissStandby |
|
152 connect(mStandbyPopup, SIGNAL(aboutToClose()), this, SLOT(dismissStandby())); |
|
153 |
|
154 // HbDialog's default background item is replaced with black rectangle |
|
155 QGraphicsRectItem *backgroundItem = new QGraphicsRectItem(); |
|
156 QBrush blackBrush = QBrush(Qt::black); |
|
157 backgroundItem->setBrush(blackBrush); |
|
158 QGraphicsItem *origBgItem = mStandbyPopup->backgroundItem(); |
|
159 backgroundItem->setRect(origBgItem->boundingRect()); |
|
160 mStandbyPopup->setBackgroundItem(backgroundItem); |
|
161 |
|
162 } |
|
163 |
|
164 CX_ASSERT_ALWAYS(mStandbyPopup); |
|
165 |
|
166 mStandbyPopup->show(); |
|
167 // connecting half press or full press key signal to dismiss standby |
|
168 connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), mStandbyPopup, SLOT(close())); |
|
169 connect(&mKeyHandler, SIGNAL(captureKeyPressed()), mStandbyPopup, SLOT(close())); |
|
170 } |
|
171 |
|
172 CX_DEBUG_EXIT_FUNCTION(); |
|
173 } |
|
174 |
|
175 |
|
176 /* |
|
177 * dismisses standby |
|
178 */ |
|
179 void CxuiStandby::dismissStandby() |
|
180 { |
|
181 CX_DEBUG_ENTER_FUNCTION(); |
|
182 |
|
183 if(mStandbyDialogVisible) { |
|
184 // stop the standby timer and close the pop-up |
|
185 mStandbyDialogVisible = false; |
|
186 //restart timer |
|
187 startTimer(); |
|
188 // signal for ui classes to prepare for standby exit |
|
189 emit aboutToExitStandby(); |
|
190 } |
|
191 |
|
192 CX_DEBUG_EXIT_FUNCTION(); |
|
193 } |
|
194 |
|
195 |
|
196 |
|
197 /* |
|
198 * checks if we can swtich to standby |
|
199 */ |
|
200 bool CxuiStandby::proceedToStandy() |
|
201 { |
|
202 CX_DEBUG_ENTER_FUNCTION(); |
|
203 CX_ASSERT_ALWAYS(mEngine); |
|
204 |
|
205 bool ok = false; |
|
206 if(!mStandbyDialogVisible && |
|
207 mEngine->isEngineReady()) { |
|
208 CX_DEBUG(("show standby dialog")); |
|
209 ok = true; |
|
210 } |
|
211 |
|
212 CX_DEBUG(( "CxuiStandby::proceedToStandy proceedToStandy: %d", ok )); |
|
213 |
|
214 return ok; |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 /* |
|
220 * Event filter which filters application wide mouse events. |
|
221 */ |
|
222 |
|
223 bool CxuiStandby::eventFilter(QObject *object, QEvent *event) |
|
224 { |
|
225 Q_UNUSED(object); |
|
226 |
|
227 bool eventWasConsumed = false; |
|
228 switch (event->type()) { |
|
229 case QEvent::GraphicsSceneMouseMove: |
|
230 case QEvent::GraphicsSceneMousePress: |
|
231 case QEvent::GraphicsSceneMouseRelease: |
|
232 eventWasConsumed = handleMouseEvent(); |
|
233 break; |
|
234 default: |
|
235 break; |
|
236 } |
|
237 return eventWasConsumed; |
|
238 } |
|
239 |
|
240 // end of file |
|