13 * |
13 * |
14 * Description: Bubble container. |
14 * Description: Bubble container. |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <QtGui> |
18 #include <QGraphicsSceneMouseEvent> |
|
19 #include <QPainter> |
19 #include <hbstyle.h> |
20 #include <hbstyle.h> |
20 #include <hbframeitem.h> |
21 #include <hbframeitem.h> |
21 #include <hbframedrawer.h> |
22 #include <hbframedrawer.h> |
22 #include "bubblecontainerwidget.h" |
23 #include "bubblecontainerwidget.h" |
23 |
24 |
24 BubbleContainerWidget::BubbleContainerWidget(QGraphicsItem* item) |
25 BubbleContainerWidget::BubbleContainerWidget(QGraphicsItem* item) |
25 : HbWidget(item), mBackground(0) |
26 : HbWidget(item), mBackground(0) |
26 { |
27 { |
|
28 setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
29 |
27 createPrimitives(); |
30 createPrimitives(); |
28 updatePrimitives(); |
31 updatePrimitives(); |
29 Q_ASSERT(mBackground); |
|
30 } |
32 } |
31 |
33 |
32 BubbleContainerWidget::~BubbleContainerWidget() |
34 BubbleContainerWidget::~BubbleContainerWidget() |
33 { |
35 { |
34 } |
36 } |
35 |
37 |
36 void BubbleContainerWidget::createPrimitives() |
38 void BubbleContainerWidget::createPrimitives() |
37 { |
39 { |
38 delete mBackground; |
40 delete mBackground; |
39 mBackground = new HbFrameItem(this); |
41 mBackground = new HbFrameItem(this); |
40 style()->setItemName(mBackground, "background"); |
42 style()->setItemName(mBackground, QLatin1String("background")); |
41 mBackground->setZValue(-1.0); |
43 mBackground->setZValue(-1.0); |
42 mBackground->setVisible(false); // background in drawn in paint() |
44 mBackground->setVisible(false); // background in drawn in paint() |
43 } |
45 } |
44 |
46 |
45 void BubbleContainerWidget::updatePrimitives() |
47 void BubbleContainerWidget::updatePrimitives() |
46 { |
48 { |
47 mBackground->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
49 mBackground->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
48 mBackground->frameDrawer().setFrameGraphicsName("qtg_fr_list_normal"); |
50 mBackground->frameDrawer().setFrameGraphicsName( |
|
51 QLatin1String("qtg_fr_list_normal")); |
49 } |
52 } |
50 |
53 |
51 void BubbleContainerWidget::mousePressEvent( |
54 void BubbleContainerWidget::mousePressEvent( |
52 QGraphicsSceneMouseEvent * event) |
55 QGraphicsSceneMouseEvent * event) |
53 { |
56 { |
54 if (event->button() != Qt::LeftButton) { |
57 if (event->button() != Qt::LeftButton) { |
55 event->ignore(); |
|
56 return; |
58 return; |
57 } |
59 } |
58 |
60 |
59 mPressed = true; |
61 mPressed = true; |
60 event->accept(); |
|
61 } |
62 } |
62 |
63 |
63 void BubbleContainerWidget::mouseMoveEvent( |
64 void BubbleContainerWidget::mouseMoveEvent( |
64 QGraphicsSceneMouseEvent *event) |
65 QGraphicsSceneMouseEvent *event) |
65 { |
66 { |
66 if (!(event->buttons() & Qt::LeftButton)) { |
|
67 event->ignore(); |
|
68 return; |
|
69 } |
|
70 |
|
71 if ( !rect().contains(event->pos()) && mPressed ) { |
67 if ( !rect().contains(event->pos()) && mPressed ) { |
72 ungrabMouse(); |
68 ungrabMouse(); |
73 mPressed = false; |
69 mPressed = false; |
74 } |
70 } |
75 } |
71 } |
76 |
72 |
77 void BubbleContainerWidget::mouseReleaseEvent( |
73 void BubbleContainerWidget::mouseReleaseEvent( |
78 QGraphicsSceneMouseEvent *event) |
74 QGraphicsSceneMouseEvent *event) |
79 { |
75 { |
80 if (event->button() != Qt::LeftButton) { |
76 Q_UNUSED(event) |
81 event->ignore(); |
|
82 return; |
|
83 } |
|
84 |
77 |
85 if (mPressed) { |
78 if (mPressed) { |
86 emit clicked(); |
79 emit clicked(); |
87 mPressed = false; |
80 mPressed = false; |
88 event->accept(); |
|
89 } |
81 } |
90 } |
82 } |
91 |
83 |
92 void BubbleContainerWidget::paint( |
84 void BubbleContainerWidget::paint( |
93 QPainter *painter, |
85 QPainter *painter, |