|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbdockwidget.h" |
|
27 #include "hbdockwidget_p.h" |
|
28 |
|
29 #include <QGraphicsSceneResizeEvent> |
|
30 |
|
31 /*! |
|
32 @stable |
|
33 @hbcore |
|
34 \class HbDockWidget |
|
35 \brief HbDockWidget represents a dock widget decorator. |
|
36 |
|
37 The HbDockWidget class represents dock widget on each application. |
|
38 It provides interface for setting the widget. |
|
39 |
|
40 The dock widget can be emptied with 0. |
|
41 */ |
|
42 |
|
43 /*! |
|
44 \reimp |
|
45 \fn int HbDockWidget::type() const |
|
46 */ |
|
47 |
|
48 HbDockWidgetPrivate::HbDockWidgetPrivate() : |
|
49 HbWidgetPrivate(), |
|
50 mWidget(0) |
|
51 { |
|
52 } |
|
53 |
|
54 HbDockWidgetPrivate::~HbDockWidgetPrivate() |
|
55 { |
|
56 } |
|
57 |
|
58 // ======== MEMBER FUNCTIONS ======== |
|
59 |
|
60 /*! |
|
61 Constructs a dock widget with \a parent. |
|
62 */ |
|
63 |
|
64 HbDockWidget::HbDockWidget( QGraphicsItem *parent ) |
|
65 : HbWidget( *new HbDockWidgetPrivate, parent ) |
|
66 { |
|
67 Q_D(HbDockWidget); |
|
68 d->q_ptr = this; |
|
69 setFlag( QGraphicsItem::ItemClipsChildrenToShape, true ); |
|
70 } |
|
71 |
|
72 /*! |
|
73 Protected constructor. |
|
74 */ |
|
75 HbDockWidget::HbDockWidget( HbDockWidgetPrivate &dd, QGraphicsItem *parent ) |
|
76 : HbWidget( dd, parent ) |
|
77 { |
|
78 Q_D(HbDockWidget); |
|
79 d->q_ptr = this; |
|
80 setFlag( QGraphicsItem::ItemClipsChildrenToShape, true ); |
|
81 } |
|
82 |
|
83 /*! |
|
84 Destructor |
|
85 */ |
|
86 HbDockWidget::~HbDockWidget() |
|
87 { |
|
88 Q_D(HbDockWidget); |
|
89 if ( d->mWidget != 0 ) { |
|
90 d->mWidget->deleteLater(); |
|
91 } |
|
92 } |
|
93 |
|
94 /*! |
|
95 Returns the widget for the dock widget. This function returns zero |
|
96 if the widget has not been set. |
|
97 |
|
98 \sa setWidget() |
|
99 */ |
|
100 QGraphicsWidget *HbDockWidget::widget() const |
|
101 { |
|
102 Q_D( const HbDockWidget ); |
|
103 return d->mWidget; |
|
104 } |
|
105 |
|
106 /*! |
|
107 Sets the widget for the dock widget to \a widget. Ownership of the widget \a widget is |
|
108 transferred to dock widget. |
|
109 |
|
110 \sa widget() |
|
111 */ |
|
112 void HbDockWidget::setWidget( QGraphicsWidget *widget ) |
|
113 { |
|
114 Q_D(HbDockWidget); |
|
115 if ( d->mWidget != widget ) { |
|
116 if ( d->mWidget != 0 ) { |
|
117 d->mWidget->deleteLater(); |
|
118 } |
|
119 d->mWidget = widget; |
|
120 if ( d->mWidget != 0 ) { |
|
121 d->mWidget->setParentItem(this); |
|
122 style()->setItemName( d->mWidget, "content" ); |
|
123 QMetaObject::invokeMethod( &d->core, "visibilityChanged", Qt::QueuedConnection ); |
|
124 } |
|
125 } |
|
126 } |
|
127 |
|
128 /*! |
|
129 Emits visibilityChanged() whenever the dock widget's visibility or position changes. |
|
130 */ |
|
131 QVariant HbDockWidget::itemChange( GraphicsItemChange change, const QVariant &value ) |
|
132 { |
|
133 Q_D(HbDockWidget); |
|
134 QVariant result = HbWidget::itemChange( change, value ); |
|
135 |
|
136 switch (change) { |
|
137 case ItemVisibleHasChanged: |
|
138 // Cannot emit signals directly from "itemChange", since it might |
|
139 // lead to e.g. item deletion that's not allowed in "itemChange". |
|
140 // Using QMetaObject to emit the signal asynchronously. |
|
141 if ( d->polished ) { |
|
142 QMetaObject::invokeMethod( &d->core, "visibilityChanged", Qt::QueuedConnection ); |
|
143 } |
|
144 break; |
|
145 default: |
|
146 break; |
|
147 } |
|
148 |
|
149 return result; |
|
150 } |
|
151 |
|
152 #include "moc_hbdockwidget.cpp" |