|
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 HbFeedback 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 "hbabstractfeedback.h" |
|
27 |
|
28 #include <QGraphicsItem> |
|
29 #include <QGraphicsView> |
|
30 |
|
31 class HbAbstractFeedbackPrivate |
|
32 { |
|
33 public: |
|
34 HbAbstractFeedbackPrivate() : cWindow(0) {}; |
|
35 ~HbAbstractFeedbackPrivate() {}; |
|
36 QRect mapWidgetToWindow(const QGraphicsItem* graphicsItem, const QGraphicsView* graphicsView); |
|
37 QRect mapWidgetToWindow(const QWidget* widget); |
|
38 |
|
39 public: |
|
40 QPointer<QWidget> cWindow; |
|
41 QRect cRect; |
|
42 }; |
|
43 |
|
44 /*! |
|
45 \internal |
|
46 @{ |
|
47 Maps the widget rectangle to the parent window |
|
48 co-ordinate system. |
|
49 @} |
|
50 */ |
|
51 QRect HbAbstractFeedbackPrivate::mapWidgetToWindow(const QWidget* widget) |
|
52 { |
|
53 // null rectangle |
|
54 QRect mappedRect = QRect(); |
|
55 |
|
56 if (widget && widget->window()) { |
|
57 QRect widgetRect = widget->rect(); |
|
58 // from widget to parent window coordinates |
|
59 QPoint topLeft = widget->mapTo(widget->window(), |
|
60 widgetRect.topLeft()); |
|
61 QPoint bottomRight = widget->mapTo(widget->window(), |
|
62 widgetRect.bottomRight()); |
|
63 mappedRect = QRect(topLeft, bottomRight); |
|
64 } |
|
65 |
|
66 return mappedRect; |
|
67 } |
|
68 |
|
69 /*! |
|
70 \internal |
|
71 @{ |
|
72 Maps the graphics widget bounding rectangle trough a |
|
73 given graphics view view port to the parent window |
|
74 co-ordinate system. |
|
75 @} |
|
76 */ |
|
77 QRect HbAbstractFeedbackPrivate::mapWidgetToWindow(const QGraphicsItem* graphicsWidget, |
|
78 const QGraphicsView* graphicsView) |
|
79 { |
|
80 // null rectangle |
|
81 QRect mappedRect = QRect(); |
|
82 |
|
83 if (graphicsWidget && graphicsView && graphicsView->window()) { |
|
84 // belong to same scene |
|
85 if (graphicsView->scene() |
|
86 && graphicsView->scene() == graphicsWidget->scene()) { |
|
87 // from scene to graphics view coordinates |
|
88 mappedRect = graphicsView->mapFromScene( |
|
89 graphicsWidget->mapToScene( |
|
90 graphicsWidget->boundingRect() |
|
91 ).boundingRect() |
|
92 ).boundingRect(); |
|
93 |
|
94 // from graphics view to window coordinates |
|
95 QPoint topLeft = graphicsView->mapTo( |
|
96 graphicsView->window(), mappedRect.topLeft()); |
|
97 QPoint bottomRight = graphicsView->mapTo( |
|
98 graphicsView->window(), mappedRect.bottomRight()); |
|
99 mappedRect = QRect(topLeft, bottomRight); |
|
100 } |
|
101 } |
|
102 |
|
103 return mappedRect; |
|
104 } |
|
105 |
|
106 /*! |
|
107 @beta |
|
108 @hbfeedback |
|
109 \class HbAbstractFeedback |
|
110 |
|
111 \brief Abstract base class for different haptic feedback effects. |
|
112 |
|
113 Concrete feedback objects have to define their type HbFeedback::Type by overriding the method type(). |
|
114 |
|
115 Provides common methods for assigning the parent window and the feedback area for the feedback effect. |
|
116 |
|
117 \sa HbInstantFeedback, HbContinuousFeedback, HbTacticonFeedback |
|
118 */ |
|
119 |
|
120 /*! |
|
121 \fn HbFeedback::Type HbAbstractFeedback::type() const |
|
122 |
|
123 Returns the haptic type of the feedback object. Every derived class has to define their a type. |
|
124 */ |
|
125 |
|
126 /*! |
|
127 \fn QWidget* HbAbstractFeedback::window() const |
|
128 |
|
129 Returns the owning widget, null if not defined. |
|
130 */ |
|
131 |
|
132 QWidget* HbAbstractFeedback::window() const |
|
133 { |
|
134 return d->cWindow; |
|
135 } |
|
136 |
|
137 /*! |
|
138 \fn bool HbAbstractFeedback::isLocated() const |
|
139 |
|
140 Returns true if both the parent window and the feedback area rectange (in relation to the parent window) has been defined. Not all feedback objects have to be located. |
|
141 |
|
142 */ |
|
143 |
|
144 bool HbAbstractFeedback::isLocated() const |
|
145 { |
|
146 return d->cWindow && d->cRect.isValid(); |
|
147 } |
|
148 |
|
149 /*! |
|
150 \fn bool HbAbstractFeedback::isValid() const |
|
151 |
|
152 Whether or not all the necessary parameters have been defined for the feedback object. What constitutes as valid differs between different types of feedback. |
|
153 */ |
|
154 |
|
155 /*! |
|
156 \fn QRect HbAbstractFeedback::rect() const |
|
157 |
|
158 Returns the feedback area rect in relation of it's parent widget. |
|
159 */ |
|
160 |
|
161 QRect HbAbstractFeedback::rect() const |
|
162 { |
|
163 return d->cRect; |
|
164 } |
|
165 |
|
166 /*! |
|
167 \fn void HbAbstractFeedback::setRect(QRect rect) |
|
168 |
|
169 Sets the feedback area rect in relation of it's parent widget. |
|
170 */ |
|
171 |
|
172 void HbAbstractFeedback::setRect(QRect rect) |
|
173 { |
|
174 d->cRect = rect; |
|
175 } |
|
176 |
|
177 /*! |
|
178 Constructor. |
|
179 */ |
|
180 HbAbstractFeedback::HbAbstractFeedback() : d(new HbAbstractFeedbackPrivate) |
|
181 { |
|
182 } |
|
183 |
|
184 /*! |
|
185 Destructor. |
|
186 */ |
|
187 HbAbstractFeedback::~HbAbstractFeedback() |
|
188 { |
|
189 delete d; |
|
190 } |
|
191 |
|
192 /*! |
|
193 Inherits feedback area rect from the given widget. Position is calculated relative to the parent window. |
|
194 |
|
195 */ |
|
196 void HbAbstractFeedback::setRect(const QWidget* widget) |
|
197 { |
|
198 if (widget) { |
|
199 d->cRect = d->mapWidgetToWindow(widget); |
|
200 } |
|
201 } |
|
202 |
|
203 /*! |
|
204 Inherits feedback area rect from the graphics item in relation to the parent graphics view. Position is calculated relative to the window. |
|
205 */ |
|
206 void HbAbstractFeedback::setRect(const QGraphicsItem* graphicsItem, const QGraphicsView* graphicsView) |
|
207 { |
|
208 if (graphicsItem && graphicsView && graphicsView->window()) { |
|
209 d->cRect = d->mapWidgetToWindow(graphicsItem, graphicsView); |
|
210 } |
|
211 } |
|
212 |
|
213 /*! |
|
214 Sets window that initiates the feedback. If given QWidget is not a window, |
|
215 uses the parent window instead. |
|
216 */ |
|
217 void HbAbstractFeedback::setOwningWindow(const QWidget* widget) |
|
218 { |
|
219 d->cWindow = 0; |
|
220 if (widget && widget->window()) { |
|
221 d->cWindow = widget->window(); |
|
222 } |
|
223 } |
|
224 |
|
225 /*! |
|
226 Assigns a copy of the feedback \a feedback to this feedback, and returns a |
|
227 reference to it. |
|
228 */ |
|
229 HbAbstractFeedback &HbAbstractFeedback::operator=(const HbAbstractFeedback & feedback) |
|
230 { |
|
231 setRect(feedback.rect()); |
|
232 setOwningWindow(feedback.window()); |
|
233 return *this; |
|
234 } |
|
235 |
|
236 /*! |
|
237 Returns true if this feedback has the same configuration as the feedback \a |
|
238 feedback; otherwise returns false. |
|
239 */ |
|
240 bool HbAbstractFeedback::operator==(const HbAbstractFeedback &feedback) const |
|
241 { |
|
242 return (d->cRect == feedback.rect() |
|
243 && d->cWindow == feedback.window() |
|
244 && type() == feedback.type()); |
|
245 } |
|
246 |
|
247 /*! |
|
248 Returns true if this feedback has different configuration than the feedback \a |
|
249 feedback; otherwise returns false. |
|
250 */ |
|
251 bool HbAbstractFeedback::operator!=(const HbAbstractFeedback &feedback) const |
|
252 { |
|
253 return !(*this == feedback); |
|
254 } |