25 #include <hbcolorscheme.h> |
25 #include <hbcolorscheme.h> |
26 #include <hbdialog.h> |
26 #include <hbdialog.h> |
27 #include <hbmessagebox.h> |
27 #include <hbmessagebox.h> |
28 #include <hbframedrawer.h> |
28 #include <hbframedrawer.h> |
29 #include <hbframeitem.h> |
29 #include <hbframeitem.h> |
|
30 #include <hbtapgesture.h> |
30 #include <QPainter> |
31 #include <QPainter> |
31 #include <QPainterPath> |
32 #include <QPainterPath> |
32 #include <QBrush> |
33 #include <QBrush> |
33 #include <QGraphicsLinearLayout> |
34 #include <QGraphicsLinearLayout> |
34 #include <QApplication> |
35 #include <QApplication> |
35 #include <QLocale> |
36 #include <QLocale> |
36 #include <QTranslator> |
|
37 #include <QScopedPointer> |
37 #include <QScopedPointer> |
|
38 #include <QGesture> |
38 #include "infowidgetlogging.h" |
39 #include "infowidgetlogging.h" |
39 #include "infowidgetengine.h" |
40 #include "infowidgetengine.h" |
40 #include "infowidgetlayoutmanager.h" |
41 #include "infowidgetlayoutmanager.h" |
41 #include "infowidgetpreferences.h" |
42 #include "infowidgetpreferences.h" |
42 |
43 |
52 |
53 |
53 // Local constants |
54 // Local constants |
54 const int INFOWIDGET_DEFAULT_HEIGHT = 100; |
55 const int INFOWIDGET_DEFAULT_HEIGHT = 100; |
55 const int INFOWIDGET_DEFAULT_WIDTH = 200; |
56 const int INFOWIDGET_DEFAULT_WIDTH = 200; |
56 const int INFOWIDGET_MARQUEE_START_DELAY = 5000; |
57 const int INFOWIDGET_MARQUEE_START_DELAY = 5000; |
57 const char *TS_FILE_OPERATOR_WIDGET = "operator_widget"; |
|
58 const char *TS_FILE_COMMON = "common"; |
|
59 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; |
58 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; |
60 |
59 |
61 /*! |
60 /*! |
62 Constructor. |
61 Constructor. |
63 */ |
62 */ |
69 m_layoutManager(NULL), |
68 m_layoutManager(NULL), |
70 m_layout(NULL), |
69 m_layout(NULL), |
71 m_backgroundFrameItem(NULL), |
70 m_backgroundFrameItem(NULL), |
72 m_timerId(0), |
71 m_timerId(0), |
73 m_layoutChanging(false), |
72 m_layoutChanging(false), |
74 m_dragEvent(false), |
|
75 m_initialized(false) |
73 m_initialized(false) |
76 { |
74 { |
77 INSTALL_TRACE_MSG_HANDLER; |
75 INSTALL_TRACE_MSG_HANDLER; |
78 DPRINT; |
76 DPRINT; |
79 |
77 |
80 // Localization file loading |
|
81 installTranslator(TS_FILE_OPERATOR_WIDGET); |
|
82 |
|
83 // Create layout & child-widget manager |
78 // Create layout & child-widget manager |
84 m_layoutManager.reset(new InfoWidgetLayoutManager); |
79 m_layoutManager.reset(new InfoWidgetLayoutManager); |
85 |
80 |
86 // Create widget engine |
81 // Create widget engine |
87 m_engine.reset(new InfoWidgetEngine); |
82 m_engine.reset(new InfoWidgetEngine); |
114 // Ownership of frame drawer is |
109 // Ownership of frame drawer is |
115 // transferred for frame item |
110 // transferred for frame item |
116 m_backgroundFrameItem = new HbFrameItem( |
111 m_backgroundFrameItem = new HbFrameItem( |
117 backgroundFrameDrawer.take(), this); |
112 backgroundFrameDrawer.take(), this); |
118 |
113 |
119 setBackgroundItem(m_backgroundFrameItem); |
114 setBackgroundItem(m_backgroundFrameItem); |
|
115 |
|
116 // Listen for tap events |
|
117 grabGesture(Qt::TapGesture); |
120 } |
118 } |
121 |
119 |
122 /*! |
120 /*! |
123 Destructor. |
121 Destructor. |
124 */ |
122 */ |
126 { |
124 { |
127 DPRINT; |
125 DPRINT; |
128 // Force layout manager to delete widgets |
126 // Force layout manager to delete widgets |
129 // before InfoWidget is destroyed |
127 // before InfoWidget is destroyed |
130 m_layoutManager->destroyWidgets(); |
128 m_layoutManager->destroyWidgets(); |
131 |
|
132 // Remove and delete language translators |
|
133 removeTranslators(); |
|
134 UNINSTALL_TRACE_MSG_HANDLER; |
129 UNINSTALL_TRACE_MSG_HANDLER; |
135 } |
130 } |
136 |
131 |
137 /*! |
132 /*! |
138 Called by HS framework, saved preference data |
133 Called by HS framework, saved preference data |
143 { |
138 { |
144 DPRINT; |
139 DPRINT; |
145 m_initialized = true; |
140 m_initialized = true; |
146 // Initialize preferences from meta-object data |
141 // Initialize preferences from meta-object data |
147 if (!readPersistentPreferences()) { |
142 if (!readPersistentPreferences()) { |
148 |
|
149 // Reading failed, initialize default values |
143 // Reading failed, initialize default values |
150 m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, |
144 m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, |
151 DISPLAY_SETTING_ON); |
145 DISPLAY_SETTING_ON); |
152 m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, |
146 m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, |
153 DISPLAY_SETTING_ON); |
147 DISPLAY_SETTING_ON); |
224 m_timerId = 0; |
218 m_timerId = 0; |
225 } |
219 } |
226 } |
220 } |
227 |
221 |
228 /*! |
222 /*! |
229 Install widget translator for given translation file. |
|
230 */ |
|
231 bool InfoWidget::installTranslator(QString translationFile) |
|
232 { |
|
233 DPRINT; |
|
234 QString lang = QLocale::system().name(); |
|
235 QString path = "z:/resource/qt/translations/"; |
|
236 bool translatorLoaded(false); |
|
237 |
|
238 QScopedPointer<QTranslator> widgetTranslator; |
|
239 widgetTranslator.reset(new QTranslator); |
|
240 translatorLoaded = widgetTranslator->load( |
|
241 path + translationFile + "_" + lang); |
|
242 if (translatorLoaded) { |
|
243 qApp->installTranslator(widgetTranslator.data()); |
|
244 m_translators.append(widgetTranslator.take()); |
|
245 DPRINT << ": translator installed: " << translationFile; |
|
246 } |
|
247 return translatorLoaded; |
|
248 } |
|
249 |
|
250 /*! |
|
251 Remove translators. No need to call |
|
252 QApplication::removeTranslator, |
|
253 QTranslator object removes itself before deletion. |
|
254 */ |
|
255 void InfoWidget::removeTranslators() |
|
256 { |
|
257 DPRINT; |
|
258 qDeleteAll(m_translators); |
|
259 m_translators.clear(); |
|
260 } |
|
261 |
|
262 /*! |
|
263 Returns bounding rect. |
223 Returns bounding rect. |
264 */ |
224 */ |
265 QRectF InfoWidget::boundingRect() const |
225 QRectF InfoWidget::boundingRect() const |
266 { |
226 { |
267 return rect(); |
227 return rect(); |
268 } |
228 } |
269 |
229 |
270 /*! |
230 /*! |
271 Calculate widget size hint based on visible row count. |
231 Calculate widget size hint based on visible row count. |
272 */ |
232 */ |
273 QSizeF InfoWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const |
233 QSizeF InfoWidget::sizeHint(Qt::SizeHint which, |
|
234 const QSizeF & constraint) const |
274 { |
235 { |
275 Q_UNUSED(which); |
236 Q_UNUSED(which); |
276 Q_UNUSED(constraint); |
237 Q_UNUSED(constraint); |
277 |
238 |
278 QSizeF requiredSize( |
239 QSizeF requiredSize( |
501 DWARNING << ": operation: " << operation << |
462 DWARNING << ": operation: " << operation << |
502 " error: " << errorCode; |
463 " error: " << errorCode; |
503 } |
464 } |
504 |
465 |
505 /*! |
466 /*! |
506 Mouse press handler. |
467 Tap gesture handler. |
507 */ |
468 */ |
508 void InfoWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) |
469 void InfoWidget::gestureEvent(QGestureEvent *event) |
509 { |
470 { |
510 Q_UNUSED(event); |
471 HbTapGesture *gesture = qobject_cast<HbTapGesture *>( |
511 // Clear flag |
472 event->gesture(Qt::TapGesture)); |
512 m_dragEvent = false; |
473 |
513 } |
474 if(!gesture)return; |
514 |
475 switch (gesture->state()) { |
515 /*! |
476 case Qt::GestureFinished: |
516 Mouse release handler. |
477 if (gesture->tapStyleHint() == HbTapGesture::Tap) { |
517 */ |
478 if (m_layoutManager->currentDisplayRole() == |
518 void InfoWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
479 InfoWidgetLayoutManager::InfoDisplay) { |
519 { |
480 DPRINT << ": layout and display settings dialog"; |
520 Q_UNUSED(event); |
481 layoutSettingsDialog(); |
521 // If widget wasn't dragged |
482 } |
522 // layout and open settings dialog |
483 } |
523 if ((!m_dragEvent) && |
484 break; |
524 m_layoutManager->currentDisplayRole() == |
485 |
525 InfoWidgetLayoutManager::InfoDisplay) { |
486 default: |
526 DPRINT << ": layout and display settings dialog"; |
487 break; |
527 layoutSettingsDialog(); |
488 } |
528 } |
|
529 |
|
530 // Clear flag |
|
531 m_dragEvent = false; |
|
532 } |
|
533 |
|
534 /*! |
|
535 Mouse move handler. |
|
536 */ |
|
537 void InfoWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
538 { |
|
539 Q_UNUSED(event); |
|
540 // Mouse is moving |
|
541 // after mouse press event |
|
542 m_dragEvent = true; |
|
543 } |
489 } |
544 |
490 |
545 /*! |
491 /*! |
546 Slot for handling Spn display setting change. |
492 Slot for handling Spn display setting change. |
547 */ |
493 */ |
955 m_animatingItem = NULL; |
899 m_animatingItem = NULL; |
956 } |
900 } |
957 |
901 |
958 /*! |
902 /*! |
959 Starts marquee animation for |
903 Starts marquee animation for |
960 next item in sequence. |
904 next item in sequence. Called if there are |
|
905 multiple text items needing marquee and animation |
|
906 start/stop logic is needed. |
961 */ |
907 */ |
962 void InfoWidget::marqueeNext() |
908 void InfoWidget::marqueeNext() |
963 { |
909 { |
964 DPRINT; |
910 DPRINT; |
965 if (m_animationState == AnimationOngoing) { |
911 if (m_animationState == AnimationOngoing) { |