|
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: Bubble container. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtGui> |
|
19 #include <hbstyle.h> |
|
20 #include <hbframeitem.h> |
|
21 #include <hbframedrawer.h> |
|
22 #include "bubblecontainerwidget.h" |
|
23 #include "bubbleprimitives.h" |
|
24 #include "bubblestyleoption.h" |
|
25 |
|
26 BubbleContainerWidget::BubbleContainerWidget( |
|
27 const QString& stylePluginName, QGraphicsItem* item) |
|
28 : HbWidget(item), mStylePluginName(stylePluginName), |
|
29 mBackground(0) |
|
30 { |
|
31 setPluginBaseId(style()->registerPlugin(mStylePluginName)); |
|
32 Q_ASSERT(pluginBaseId()!=-1); |
|
33 |
|
34 createPrimitives(); |
|
35 updatePrimitives(); |
|
36 } |
|
37 |
|
38 BubbleContainerWidget::~BubbleContainerWidget() |
|
39 { |
|
40 style()->unregisterPlugin(mStylePluginName); |
|
41 } |
|
42 |
|
43 void BubbleContainerWidget::createPrimitives() |
|
44 { |
|
45 QGraphicsItem *background = style()->createPrimitive( |
|
46 (HbStyle::Primitive)(pluginBaseId()+BP_Bubble_frame), this); |
|
47 style()->setItemName(mBackground, "background"); |
|
48 |
|
49 delete mBackground; |
|
50 mBackground = |
|
51 qgraphicsitem_cast<HbFrameItem*>(background); |
|
52 } |
|
53 |
|
54 void BubbleContainerWidget::updatePrimitives() |
|
55 { |
|
56 if (mBackground) { |
|
57 BubbleStyleOption option; |
|
58 style()->updatePrimitive( |
|
59 mBackground, (HbStyle::Primitive)(pluginBaseId()+BP_Bubble_frame), |
|
60 &option); |
|
61 mBackground->setVisible(false); // background in drawn in paint() |
|
62 } |
|
63 } |
|
64 |
|
65 void BubbleContainerWidget::mousePressEvent( |
|
66 QGraphicsSceneMouseEvent * event) |
|
67 { |
|
68 if (event->button() != Qt::LeftButton) { |
|
69 event->ignore(); |
|
70 return; |
|
71 } |
|
72 |
|
73 mPressed = true; |
|
74 event->accept(); |
|
75 } |
|
76 |
|
77 void BubbleContainerWidget::mouseMoveEvent( |
|
78 QGraphicsSceneMouseEvent *event) |
|
79 { |
|
80 if (!(event->buttons() & Qt::LeftButton)) { |
|
81 event->ignore(); |
|
82 return; |
|
83 } |
|
84 |
|
85 if ( !rect().contains(event->pos()) && mPressed ) { |
|
86 ungrabMouse(); |
|
87 mPressed = false; |
|
88 } |
|
89 } |
|
90 |
|
91 void BubbleContainerWidget::mouseReleaseEvent( |
|
92 QGraphicsSceneMouseEvent * event) |
|
93 { |
|
94 if (event->button() != Qt::LeftButton) { |
|
95 event->ignore(); |
|
96 return; |
|
97 } |
|
98 |
|
99 if (mPressed) { |
|
100 emit clicked(); |
|
101 mPressed = false; |
|
102 event->accept(); |
|
103 } |
|
104 } |
|
105 |
|
106 void BubbleContainerWidget::paint( |
|
107 QPainter *painter, |
|
108 const QStyleOptionGraphicsItem *option, |
|
109 QWidget *widget) |
|
110 { |
|
111 Q_UNUSED(widget) |
|
112 Q_UNUSED(option) |
|
113 |
|
114 if (mBackground) { |
|
115 mBackground->frameDrawer().paint(painter,boundingRect()); |
|
116 } |
|
117 } |
|
118 |