47 //Local constants |
47 //Local constants |
48 const char DOCML[] = ":/CalendarWidget"; |
48 const char DOCML[] = ":/CalendarWidget"; |
49 |
49 |
50 #define CALWIDGET_HIGHLIGHT_ACTIVE |
50 #define CALWIDGET_HIGHLIGHT_ACTIVE |
51 |
51 |
|
52 namespace { |
|
53 const char *WIDGET_BACKGROUND = "widgetBackground"; |
|
54 const char *ICON_LABEL = "iconLabel"; |
|
55 } |
|
56 |
52 // ======== MEMBER FUNCTIONS ======== |
57 // ======== MEMBER FUNCTIONS ======== |
53 |
58 |
54 /* |
59 /* |
55 * CalendarWidget::CalendarWidget() |
60 * CalendarWidget::CalendarWidget() |
56 */ |
61 */ |
60 LOGS("CalendarWidget::CalendarWidget"); |
65 LOGS("CalendarWidget::CalendarWidget"); |
61 grabGesture(Qt::TapGesture); |
66 grabGesture(Qt::TapGesture); |
62 grabGesture(Qt::PanGesture); |
67 grabGesture(Qt::PanGesture); |
63 grabGesture(Qt::PinchGesture); |
68 grabGesture(Qt::PinchGesture); |
64 grabGesture(Qt::SwipeGesture); |
69 grabGesture(Qt::SwipeGesture); |
|
70 mWidgetLoaded = false; |
65 } |
71 } |
66 |
72 |
67 /* |
73 /* |
68 * CalendarWidget::~CalendarWidget() |
74 * CalendarWidget::~CalendarWidget() |
69 */ |
75 */ |
75 /* |
81 /* |
76 * CalendarWidget::boundingRect() |
82 * CalendarWidget::boundingRect() |
77 */ |
83 */ |
78 QRectF CalendarWidget::boundingRect() const |
84 QRectF CalendarWidget::boundingRect() const |
79 { |
85 { |
80 LOGS("CalendarWidget::boundingRect"); |
|
81 return childrenBoundingRect(); |
86 return childrenBoundingRect(); |
82 } |
87 } |
83 |
88 |
84 /* |
89 /* |
85 * CalendarWidget::shape() |
90 * CalendarWidget::shape() |
86 */ |
91 */ |
87 QPainterPath CalendarWidget::shape() const |
92 QPainterPath CalendarWidget::shape() const |
88 { |
93 { |
89 LOGS("CalendarWidget::shape"); |
|
90 |
|
91 QPainterPath path; |
94 QPainterPath path; |
92 path.addRect(boundingRect()); |
95 if( !mWidgetLoaded ) { |
|
96 path.addRect(boundingRect()); |
|
97 } |
|
98 else { |
|
99 QRectF layoutRect( QPointF( mWidgetBackground->rect().topLeft().x() + mWidgetBackground->pos().x(), mWidgetBackground->rect().topLeft().y() + mWidgetBackground->pos().y() ), |
|
100 QPointF( mWidgetBackground->rect().bottomRight().x() + mWidgetBackground->pos().x(), mWidgetBackground->rect().bottomRight().y() + mWidgetBackground->pos().y() )); |
|
101 path.addRoundRect( layoutRect, 15 ); |
|
102 //the icon path is adjusted because the icon is slightly smaller than the container |
|
103 path.moveTo( QPointF( mIconLabel->pos().x() + 3, mWidgetBackground->pos().y() ) ); |
|
104 path.lineTo( QPointF( mIconLabel->pos().x() + 3, mIconLabel->pos().y() + 8 ) ); |
|
105 path.lineTo( QPointF( mIconLabel->rect().topRight().x() + mIconLabel->pos().x() - 3, mIconLabel->pos().y() + 8 ) ); |
|
106 path.lineTo( QPointF( mIconLabel->rect().bottomRight().x() + mIconLabel->pos().x() - 3, mWidgetBackground->pos().y() ) ); |
|
107 } |
|
108 |
93 return path; |
109 return path; |
94 } |
110 } |
95 |
111 |
96 /* |
112 /* |
97 * CalendarWidget::loadWidget() |
113 * CalendarWidget::loadWidget() |
100 { |
116 { |
101 LOGS("CalendarWidget::loadWidget"); |
117 LOGS("CalendarWidget::loadWidget"); |
102 |
118 |
103 // Use document loader to load the contents |
119 // Use document loader to load the contents |
104 HbDocumentLoader loader; |
120 HbDocumentLoader loader; |
105 bool loaded = true; |
121 mWidgetLoaded = true; |
106 bool ok = false; |
122 bool ok = false; |
107 loader.load(DOCML, &ok); |
123 loader.load(DOCML, &ok); |
108 |
124 |
109 if (ok) { |
125 if (ok) { |
|
126 //load the containers that are necessary to get the shape |
|
127 mWidgetBackground = qobject_cast<HbLabel*>( loader.findWidget( WIDGET_BACKGROUND ) ); |
|
128 mIconLabel = qobject_cast<HbLabel*>( loader.findWidget( ICON_LABEL ) ); |
|
129 |
110 QObject* contentLayoutHandler = new ContentLayoutHandler(); |
130 QObject* contentLayoutHandler = new ContentLayoutHandler(); |
111 connectLayoutHandler(this, contentLayoutHandler, loader); |
131 connectLayoutHandler(this, contentLayoutHandler, loader); |
112 |
132 |
113 QString fileName( "C:/private/20022F35/gestures.xml" ); |
133 QString fileName( "C:/private/20022F35/gestures.xml" ); |
114 QFile xmlConfiguration(fileName); |
134 QFile xmlConfiguration(fileName); |
134 dynamic_cast<QGraphicsLinearLayout*>(contentLayoutHandler)->preferredSize()); |
154 dynamic_cast<QGraphicsLinearLayout*>(contentLayoutHandler)->preferredSize()); |
135 parentWidget()->resize(preferredSize()); // workaround for layouting |
155 parentWidget()->resize(preferredSize()); // workaround for layouting |
136 setLayout(dynamic_cast<QGraphicsLinearLayout*>(contentLayoutHandler)); |
156 setLayout(dynamic_cast<QGraphicsLinearLayout*>(contentLayoutHandler)); |
137 } |
157 } |
138 else { |
158 else { |
139 loaded = false; |
159 mWidgetLoaded = false; |
140 } |
160 } |
141 } |
161 } |
142 else { |
162 else { |
143 loaded = false; |
163 mWidgetLoaded = false; |
144 } |
164 } |
145 |
165 |
146 return loaded; |
166 return mWidgetLoaded; |
147 } |
167 } |
148 |
168 |
149 /* |
169 /* |
150 * CalendarWidget::connectLayoutHandler() |
170 * CalendarWidget::connectLayoutHandler() |
151 */ |
171 */ |
297 QGraphicsSceneMouseEvent* mouseEvent = (QGraphicsSceneMouseEvent*)event; |
317 QGraphicsSceneMouseEvent* mouseEvent = (QGraphicsSceneMouseEvent*)event; |
298 QPointF pos = mouseEvent->scenePos(); |
318 QPointF pos = mouseEvent->scenePos(); |
299 // emit mousePressed(pos); |
319 // emit mousePressed(pos); |
300 } |
320 } |
301 else if (event->type() == QEvent::GraphicsSceneMouseRelease) { |
321 else if (event->type() == QEvent::GraphicsSceneMouseRelease) { |
302 // emit mouseReleased(); |
322 emit mouseReleased(); |
303 } |
323 } |
304 return false; |
324 return false; |
305 } |
325 } |
306 |
326 |
307 /* |
327 /* |
309 */ |
329 */ |
310 void CalendarWidget::gestureEvent(QGestureEvent *event) |
330 void CalendarWidget::gestureEvent(QGestureEvent *event) |
311 { |
331 { |
312 LOGS("CalendarWidget::gestureEvent"); |
332 LOGS("CalendarWidget::gestureEvent"); |
313 if (QTapGesture *tap = (QTapGesture*)event->gesture(Qt::TapGesture)) { |
333 if (QTapGesture *tap = (QTapGesture*)event->gesture(Qt::TapGesture)) { |
314 //QPointF pos = mapFromScene(event->mapToGraphicsScene(tap->position())); |
334 QPointF posFromScene = mapFromScene(event->mapToGraphicsScene(tap->position())); |
315 QPointF pos = tap->position(); |
|
316 switch(tap->state()) { |
335 switch(tap->state()) { |
317 case Qt::GestureStarted: |
336 case Qt::GestureStarted: |
318 emit mousePressed(pos); |
337 emit mousePressed(posFromScene); |
319 LOGS("CalendarWidget::gestureEvent => gestureStarted"); |
338 LOGS("CalendarWidget::gestureEvent => gestureStarted"); |
320 break; |
339 break; |
321 case Qt::GestureUpdated: |
340 case Qt::GestureUpdated: |
322 LOGS("CalendarWidget::gestureEvent => gestureUpdated"); |
341 LOGS("CalendarWidget::gestureEvent => gestureUpdated"); |
323 break; |
342 break; |
324 case Qt::GestureFinished: |
343 case Qt::GestureFinished: |
325 emit tapGesture(pos); |
344 emit tapGesture(posFromScene); |
326 emit mouseReleased(); |
345 emit mouseReleased(); |
327 LOGS("CalendarWidget::gestureEvent => gestureFinished"); |
346 LOGS("CalendarWidget::gestureEvent => gestureFinished"); |
328 break; |
347 break; |
329 case Qt::GestureCanceled: |
348 case Qt::GestureCanceled: |
330 LOGS("CalendarWidget::gestureEvent => gestureCanceled"); |
349 LOGS("CalendarWidget::gestureEvent => gestureCanceled"); |
342 default: |
361 default: |
343 break; |
362 break; |
344 } |
363 } |
345 } |
364 } |
346 |
365 |
347 if (QSwipeGesture *pan = (QSwipeGesture*)event->gesture(Qt::SwipeGesture)) { |
366 if (QSwipeGesture *swipe = (QSwipeGesture*)event->gesture(Qt::SwipeGesture)) { |
348 switch (pan->state()) { |
367 switch (swipe->state()) { |
349 case Qt::GestureFinished: |
368 case Qt::GestureFinished: |
350 emit mouseReleased(); |
369 emit mouseReleased(); |
351 break; |
370 break; |
352 default: |
371 default: |
353 break; |
372 break; |
354 } |
373 } |
355 } |
374 } |
356 |
375 |
357 if (QPinchGesture *pan = (QPinchGesture*)event->gesture(Qt::PinchGesture)) { |
376 if (QPinchGesture *pinch = (QPinchGesture*)event->gesture(Qt::PinchGesture)) { |
358 switch (pan->state()) { |
377 switch (pinch->state()) { |
359 case Qt::GestureFinished: |
378 case Qt::GestureFinished: |
360 emit mouseReleased(); |
379 emit mouseReleased(); |
361 break; |
380 break; |
362 default: |
381 default: |
363 break; |
382 break; |