23 #include <HbFrameDrawer> |
23 #include <HbFrameDrawer> |
24 #include <HbIconItem> |
24 #include <HbIconItem> |
25 #include <HbTextItem> |
25 #include <HbTextItem> |
26 #include <HbTouchArea> |
26 #include <HbTouchArea> |
27 #include <HbInstantFeedback> |
27 #include <HbInstantFeedback> |
28 #include "dialerwidgetengine.h" |
28 #include <HbTapGesture> |
|
29 |
29 #include "dialerwidget.h" |
30 #include "dialerwidget.h" |
30 #include "qtphonelog.h" |
|
31 |
31 |
32 #ifdef Q_OS_SYMBIAN |
32 #ifdef Q_OS_SYMBIAN |
33 #include "qtphonelog.h" |
33 #include "dialerwidgetengine.h" |
34 #include <xqappmgr.h> |
34 #include "qtphonelog.h" |
35 #include <xqservicerequest.h> |
35 #include <xqappmgr.h> |
36 #include <xqpublishandsubscribeutils.h> |
36 #include <xqservicerequest.h> |
37 #include <xqrequestinfo.h> |
37 #include <xqpublishandsubscribeutils.h> |
38 #include <xqaiwdecl.h> |
38 #include <xqrequestinfo.h> |
|
39 #include <xqaiwdecl.h> |
|
40 #else |
|
41 #define PHONE_TRACE |
39 #endif |
42 #endif |
40 |
43 |
41 namespace |
44 const QLatin1String KDialerWidgetIconNormal("qtg_graf_hs_dialer_normal"); |
42 { |
45 const QLatin1String KDialerWidgetIconPressed("qtg_graf_hs_dialer_pressed"); |
43 const char KDialerWidgetIconNormal[] = "qtg_graf_hs_dialer_normal"; |
46 const QLatin1String KDialerWidgetMissedCallBadge("qtg_fr_shortcut_badge_bg"); |
44 const char KDialerWidgetIconPressed[] = "qtg_graf_hs_dialer_pressed"; |
47 const QLatin1String KDialerWidgetWidgetml(":/resource/dialerwidget.widgetml"); |
45 const char KMissedCallShortcutBadge[] = "qtg_fr_shortcut_badge_bg"; |
48 const QLatin1String KDialerWidgetCss(":/resource/dialerwidget.css"); |
46 const char KDialerWidgetWidgetml[] = ":/data/resource/dialerwidget.widgetml"; |
49 const QLatin1String KDialerWidgetNormalLayout("normal"); |
47 const char KDialerWidgetCss[] = ":/data/resource/dialerwidget.css"; |
50 const QLatin1String KDialerWidgetMissedCallLayout("missed_call"); |
48 } |
51 const int KDialerWidgetMaxBadgeTextLenght = 2; // displayable |
|
52 // update corresponding values also in css side |
|
53 const qreal KDialerWidgetNormalSize = 12.0; // unit |
|
54 const qreal KDialerWidgetMissedCallSize = 12.75; // unit |
49 |
55 |
50 /*! |
56 /*! |
51 \class DialerWidget |
57 \class DialerWidget |
52 |
58 |
53 \ingroup group_dialerwidgetplugin |
59 \ingroup group_dialerwidgetplugin |
104 if (request == NULL) { |
135 if (request == NULL) { |
105 PHONE_TRACE1("service not found"); |
136 PHONE_TRACE1("service not found"); |
106 return; |
137 return; |
107 } |
138 } |
108 request->setArguments(args); |
139 request->setArguments(args); |
|
140 request->setSynchronous(false); |
109 bool ret = request->send(); |
141 bool ret = request->send(); |
110 PHONE_TRACE2("request sent successfully:", ret); |
142 PHONE_TRACE2("request sent successfully:", ret); |
111 #endif |
143 #endif |
112 |
144 |
113 } |
145 } |
114 |
146 |
115 void DialerWidget::onInitialize() |
147 void DialerWidget::onInitialize() |
116 { |
148 { |
117 PHONE_TRACE |
149 PHONE_TRACE |
|
150 #ifdef Q_OS_SYMBIAN |
118 QT_TRY{ |
151 QT_TRY{ |
119 // basic ui |
|
120 createPrimitives(); |
|
121 Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetWidgetml)); |
|
122 Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetCss)); |
|
123 // Engine construction is 2 phased |
152 // Engine construction is 2 phased |
124 m_engine = new DialerWidgetEngine(); |
153 m_engine = new DialerWidgetEngine(); |
125 connect(m_engine, SIGNAL( exceptionOccured(const int&) ) |
154 connect(m_engine, SIGNAL( exceptionOccured(const int&) ) |
126 ,this, SLOT( onEngineException(const int&) ) ); |
155 ,this, SLOT( onEngineException(const int&) ) ); |
|
156 |
|
157 connect( m_engine, SIGNAL(missedCallsCountChanged(const int&)), |
|
158 this, SLOT(onMissedCallsCountChange(const int&))); |
127 |
159 |
128 if(!m_engine->initialize()){ |
160 if(!m_engine->initialize()){ |
129 //engine construction failed. Give up. |
161 //engine construction failed. Give up. |
130 emit error(); |
162 emit error(); |
131 return; |
163 return; |
132 } |
164 } |
133 connect( m_engine, SIGNAL(missedCallsCountChanged(const int&)), |
165 } |
134 this, SLOT(onMissedCallsCountChange(const int&))); |
|
135 } |
|
136 QT_CATCH(...){ |
166 QT_CATCH(...){ |
137 emit error(); |
167 emit error(); |
138 } |
168 } |
|
169 #endif |
139 } |
170 } |
140 |
171 |
141 /*! |
172 /*! |
142 \fn void DialerWidget::onShow() |
173 \fn void DialerWidget::onShow() |
143 |
174 |
144 Shows the widget |
175 Shows the widget |
145 */ |
176 */ |
146 void DialerWidget::onShow() |
177 void DialerWidget::onShow() |
147 { |
178 { |
148 PHONE_TRACE |
179 PHONE_TRACE |
149 updatePrimitives(); |
|
150 } |
180 } |
151 |
181 |
152 /*! |
182 /*! |
153 \fn void DialerWidget::onHide() |
183 \fn void DialerWidget::onHide() |
154 |
184 |
157 void DialerWidget::onHide() |
187 void DialerWidget::onHide() |
158 { |
188 { |
159 PHONE_TRACE |
189 PHONE_TRACE |
160 } |
190 } |
161 |
191 |
|
192 /*! |
|
193 \fn void DialerWidget::onUninitialize() |
|
194 |
|
195 Uninitializes the widget |
|
196 */ |
162 void DialerWidget::onUninitialize() |
197 void DialerWidget::onUninitialize() |
163 { |
198 { |
164 PHONE_TRACE |
199 PHONE_TRACE |
165 HbStyleLoader::unregisterFilePath(KDialerWidgetWidgetml); |
|
166 HbStyleLoader::unregisterFilePath(KDialerWidgetCss); |
|
167 } |
200 } |
168 |
201 |
169 void DialerWidget::onEngineException(const int& exc) |
202 void DialerWidget::onEngineException(const int& exc) |
170 { |
203 { |
171 Q_UNUSED(exc); |
204 Q_UNUSED(exc); |
172 emit error(); |
205 emit error(); |
173 } |
206 } |
174 |
207 |
175 void DialerWidget::onMissedCallsCountChange(const int& count) |
208 void DialerWidget::onMissedCallsCountChange(const int& count) |
176 { |
209 { |
177 m_text->setText( QLocale::system().toString(count)); |
210 if (count){ |
178 if ( count ){ |
211 QString newText = QLocale::system().toString(count); |
|
212 |
|
213 if (newText.length()>KDialerWidgetMaxBadgeTextLenght) { |
|
214 newText = QLatin1String("*"); |
|
215 } |
|
216 |
|
217 bool doRepolish = (m_text->text().length() != newText.length()); |
|
218 |
|
219 m_badgeBackground->setVisible(true); |
|
220 |
|
221 m_text->setText(newText); |
|
222 |
179 m_text->setVisible(true); |
223 m_text->setVisible(true); |
180 m_badgeBackground->setVisible(true); |
224 |
|
225 if (doRepolish) { |
|
226 repolish(); |
|
227 } |
|
228 |
|
229 setLayout(KDialerWidgetMissedCallLayout); |
181 } else { |
230 } else { |
|
231 m_badgeBackground->setVisible(false); |
|
232 |
182 m_text->setVisible(false); |
233 m_text->setVisible(false); |
183 m_badgeBackground->setVisible(false); |
234 |
184 } |
235 setLayout(KDialerWidgetNormalLayout); |
185 } |
236 } |
186 |
237 } |
187 void DialerWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) |
238 |
188 { |
239 void DialerWidget::gestureEvent(QGestureEvent *event) |
189 PHONE_TRACE; |
240 { |
190 Q_UNUSED(event) |
241 HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
191 setBackgroundToPressed(); |
242 if (gesture) { |
192 } |
243 switch (gesture->state()) { |
193 |
244 case Qt::GestureStarted: |
194 void DialerWidget::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) |
245 setBackgroundToPressed(); |
195 { |
246 break; |
196 if (contains(event->pos())) { |
247 case Qt::GestureCanceled: |
197 setBackgroundToPressed(); |
248 setBackgroundToNormal(); |
198 } else { |
249 break; |
199 setBackgroundToNormal(); |
250 case Qt::GestureFinished: |
200 } |
251 setBackgroundToNormal(); |
201 } |
252 if (gesture->tapStyleHint() == HbTapGesture::Tap) { |
202 |
253 HbInstantFeedback::play(HbFeedback::Basic); |
203 void DialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
254 startDialer(); |
204 { |
255 } |
205 PHONE_TRACE; |
256 break; |
206 Q_UNUSED(event); |
257 default: |
207 HbInstantFeedback::play(HbFeedback::Basic); |
258 break; |
208 setBackgroundToNormal(); |
259 } |
209 startDialer(); |
260 } |
210 } |
261 } |
211 |
262 |
212 bool DialerWidget::sceneEvent(QEvent *event) |
263 QRectF DialerWidget::boundingRect() const |
213 { |
264 { |
214 if (event->type() == QEvent::UngrabMouse) { |
265 return childrenBoundingRect(); |
215 setBackgroundToNormal(); |
266 } |
216 } |
267 |
217 |
268 QPainterPath DialerWidget::shape() const |
218 return HsWidget::sceneEvent(event);; |
269 { |
219 } |
270 QPainterPath path; |
220 |
271 path.addRect(boundingRect()); |
221 HsWidget::StartResult DialerWidget::onStart() |
272 return path; |
222 { |
|
223 return StartResultRunning; |
|
224 } |
|
225 HsWidget::StopResult DialerWidget::onStop() |
|
226 { |
|
227 return StopResultFinished; |
|
228 } |
|
229 HsWidget::SuspendResult DialerWidget::onSuspend() |
|
230 { |
|
231 return SuspendResultSuspended; |
|
232 } |
|
233 HsWidget::ResumeResult DialerWidget::onResume() |
|
234 { |
|
235 return ResumeResultRunning; |
|
236 } |
273 } |
237 |
274 |
238 void DialerWidget::createPrimitives() |
275 void DialerWidget::createPrimitives() |
239 { |
276 { |
240 setPreferredSize(100,100); |
|
241 // Background |
277 // Background |
242 if (!m_background) { |
278 if (!m_background) { |
243 HbFrameDrawer *drawer = new HbFrameDrawer( |
279 HbFrameDrawer *drawer = new HbFrameDrawer( |
244 KDialerWidgetIconNormal, HbFrameDrawer::OnePiece); |
280 KDialerWidgetIconNormal, HbFrameDrawer::OnePiece); |
245 m_background = new HbFrameItem(drawer, this); |
281 m_background = new HbFrameItem(drawer, this); |
246 style()->setItemName(m_background, QLatin1String("background")); |
282 style()->setItemName(m_background, QLatin1String("background")); |
247 m_background->moveBy(0,10); |
|
248 m_background->resize(81,81); |
|
249 } |
283 } |
250 |
284 |
251 // Badge background |
285 // Badge background |
252 if (!m_badgeBackground) { |
286 if (!m_badgeBackground) { |
253 HbFrameDrawer *badgedrawer = new HbFrameDrawer( |
287 HbFrameDrawer *badgedrawer = new HbFrameDrawer( |
254 KMissedCallShortcutBadge, HbFrameDrawer::ThreePiecesHorizontal); |
288 KDialerWidgetMissedCallBadge, HbFrameDrawer::ThreePiecesHorizontal); |
255 m_badgeBackground = new HbFrameItem(badgedrawer, this); |
289 m_badgeBackground = new HbFrameItem(badgedrawer, this); |
256 style()->setItemName(m_background, QLatin1String("badgeBackground")); |
290 style()->setItemName(m_badgeBackground, QLatin1String("badgeBackground")); |
257 m_badgeBackground->resize(20,20); |
|
258 m_badgeBackground->moveBy(70,0); |
|
259 m_badgeBackground->setVisible(true); |
|
260 m_badgeBackground->setVisible( false ); |
291 m_badgeBackground->setVisible( false ); |
261 } |
292 } |
262 |
293 |
263 // Text |
294 // Text |
264 if (!m_text) { |
295 if (!m_text) { |
265 m_text = new HbTextItem(this); |
296 m_text = new HbTextItem(this); |
266 style()->setItemName(m_text, QLatin1String("text")); |
297 style()->setItemName(m_text, QLatin1String("badgeText")); |
267 m_text->resize(20,20); |
298 m_text->setVisible(false); |
268 m_text->moveBy(76,0); |
299 } |
269 m_text->setVisible(true); |
300 |
270 HbFontSpec *textFont = new HbFontSpec(HbFontSpec::Primary); |
301 // Touch area |
271 textFont->setTextHeight(3*HbDeviceProfile::current().unitValue()); |
|
272 m_text->setFontSpec(*textFont); |
|
273 m_text->setText("0"); |
|
274 m_text->setVisible( false); |
|
275 } |
|
276 |
|
277 // Touch Area |
|
278 if (!m_touchArea) { |
302 if (!m_touchArea) { |
279 m_touchArea = new HbTouchArea(this); |
303 m_touchArea = new HbTouchArea(this); |
280 m_touchArea->installEventFilter(this); |
304 m_touchArea->setFlag(QGraphicsItem::ItemIsFocusable); |
281 style()->setItemName(m_touchArea, QLatin1String("touch_area")); |
305 style()->setItemName(m_touchArea, QLatin1String("touchArea")); |
282 m_touchArea->moveBy(0,10); |
306 setFiltersChildEvents(true); |
283 m_touchArea->resize(81,81); |
307 m_touchArea->grabGesture(Qt::TapGesture); |
284 } |
308 } |
285 } |
309 } |
286 |
310 |
287 void DialerWidget::setBackgroundToNormal() |
311 void DialerWidget::setBackgroundToNormal() |
288 { |
312 { |