|
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 "hbfadeitem_p.h" |
|
27 #include "hbwidget_p.h" |
|
28 #include "hbgraphicsscene.h" |
|
29 #include <QEvent> |
|
30 #include <QApplication> |
|
31 |
|
32 /*! |
|
33 \class HbFadeItem |
|
34 |
|
35 \brief Item that blocks all scene events. |
|
36 |
|
37 \internal |
|
38 */ |
|
39 |
|
40 class HbFadeItemPrivate : public HbWidgetPrivate |
|
41 { |
|
42 Q_DECLARE_PUBLIC(HbFadeItem) |
|
43 |
|
44 public: |
|
45 HbFadeItemPrivate( ); |
|
46 virtual ~HbFadeItemPrivate(); |
|
47 void init(); |
|
48 |
|
49 mutable QRectF mRect; |
|
50 |
|
51 private: |
|
52 static HbFadeItemPrivate *d_ptr(HbFadeItem *fadeItem) { |
|
53 Q_ASSERT(fadeItem); |
|
54 return fadeItem->d_func(); |
|
55 } |
|
56 }; |
|
57 |
|
58 HbFadeItemPrivate::HbFadeItemPrivate() |
|
59 { |
|
60 } |
|
61 |
|
62 HbFadeItemPrivate::~HbFadeItemPrivate() |
|
63 { |
|
64 } |
|
65 |
|
66 void HbFadeItemPrivate::init() |
|
67 { |
|
68 Q_Q(HbFadeItem); |
|
69 |
|
70 q->setBackgroundItem(HbStyle::P_Fade_background); |
|
71 |
|
72 q->setAcceptHoverEvents(true); |
|
73 // This is needed to be able to block moving the focus to items behind background item by |
|
74 // clicking on them. |
|
75 q->setFlag(QGraphicsItem::ItemIsFocusable); |
|
76 } |
|
77 |
|
78 HbFadeItem::HbFadeItem( QGraphicsItem *parent ) : HbWidget(*new HbFadeItemPrivate, parent) |
|
79 { |
|
80 Q_D(HbFadeItem); |
|
81 d->q_ptr = this; |
|
82 d->init(); |
|
83 } |
|
84 |
|
85 HbFadeItem::HbFadeItem(HbFadeItemPrivate &dd, QGraphicsItem *parent) : HbWidget(dd, parent) |
|
86 { |
|
87 Q_D(HbFadeItem); |
|
88 d->q_ptr = this; |
|
89 d->init(); |
|
90 } |
|
91 |
|
92 QRectF HbFadeItem::boundingRect() const |
|
93 { |
|
94 Q_D(const HbFadeItem); |
|
95 if(!d->mRect.isValid()){ |
|
96 // set size so that it is big enough |
|
97 // to cover the screen both landscape and portrait mode |
|
98 const QSizeF screenSize = HbDeviceProfile::profile(this).logicalSize(); |
|
99 qreal dim = qMax(screenSize.width(), screenSize.height()); |
|
100 d->mRect.adjust(0,0,dim,dim); |
|
101 } |
|
102 return d->mRect; |
|
103 } |
|
104 |
|
105 bool HbFadeItem::sceneEvent(QEvent *event) |
|
106 { |
|
107 if (event->type() == QEvent::FocusIn) { |
|
108 // Prevents last focus item losing its focus |
|
109 // This event is received only when popup is modal |
|
110 QFocusEvent restoreLastFocus(QEvent::FocusIn, Qt::OtherFocusReason); |
|
111 QApplication::sendEvent(window()->scene(), &restoreLastFocus); |
|
112 } |
|
113 event->accept(); |
|
114 return true; |
|
115 } |
|
116 |
|
117 bool HbFadeItem::event(QEvent *event) |
|
118 { |
|
119 if (event->type() == QEvent::Polish) { |
|
120 // No need for any real polishing. |
|
121 Q_D(HbFadeItem); |
|
122 d->polished = true; |
|
123 return true; |
|
124 } |
|
125 return HbWidget::event(event); |
|
126 } |