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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "VisualFlowLite.h" |
|
21 |
|
22 #include <QTimer> |
|
23 #include <QPainter> |
|
24 #include <QKeyEvent> |
|
25 #include <QMouseEvent> |
|
26 |
|
27 #include <QDebug> |
|
28 |
|
29 |
|
30 // CONSTANTS |
|
31 const int KVisualFlowViewOffsetX = 2; |
|
32 |
|
33 //Animation related factors |
|
34 const int KResizeFactorIncr = 20; |
|
35 const int KAnimFactorInc = 25; |
|
36 const int KFastScrollAnimFactorInc = 40; |
|
37 const int KMaxAnimFactor = 100; |
|
38 const int KMinAnimFactor = 0; |
|
39 |
|
40 const int KRepaintTimerCb = 20; |
|
41 const int KCenterThumbnailWidthPercent = 50; |
|
42 const int KCenterThumbnailHeightPercent = 90; |
|
43 const int KSideThumbnailWidthPercent = 25; |
|
44 const int KSideThumbnailHeightPercent = 70; |
|
45 |
|
46 #define KCenterImageBorderColor Qt::red |
|
47 #define KSideImageBorderColor Qt::black |
|
48 |
|
49 |
|
50 namespace WRT { |
|
51 const int KScrollTimeout = 200; |
|
52 |
|
53 |
|
54 VisualFlowLite::VisualFlowLite(QWidget* parent) : FlowInterface(parent), |
|
55 m_resizeFactor (KMinAnimFactor), |
|
56 m_placeHolderResizeFactor(KMinAnimFactor), |
|
57 m_centerPageIndex(-1), |
|
58 m_scalingAllowed(false) |
|
59 { |
|
60 m_paintState = paintStateNormal; |
|
61 m_scrollTimer = NULL; |
|
62 } |
|
63 |
|
64 void VisualFlowLite::init() |
|
65 { |
|
66 m_repaintTimer = new QTimer; |
|
67 connect(m_repaintTimer, SIGNAL(timeout()), this, SLOT(calcRepaintRect())); |
|
68 resize(parentWidget()->rect().size()); |
|
69 |
|
70 m_repaintTimer->start(KRepaintTimerCb); |
|
71 // FIXME: Cursor undef for symbian? |
|
72 #if !defined(Q_OS_SYMBIAN) |
|
73 setCursor(Qt::ArrowCursor); |
|
74 #endif |
|
75 setFocusPolicy(Qt::WheelFocus); |
|
76 setFocus(Qt::OtherFocusReason); |
|
77 } |
|
78 |
|
79 void VisualFlowLite::addSlide(const QImage& image) |
|
80 { |
|
81 m_imageList.append(new QImage(image)); |
|
82 } |
|
83 |
|
84 void VisualFlowLite::clear() |
|
85 { |
|
86 if (m_repaintTimer->isActive()) { |
|
87 m_repaintTimer->stop(); |
|
88 } |
|
89 while (!m_imageList.isEmpty()) |
|
90 delete m_imageList.takeFirst(); |
|
91 if (m_scrollTimer) { |
|
92 m_scrollTimer->stop(); |
|
93 } |
|
94 |
|
95 m_paintState = paintStateNormal; |
|
96 m_direction = 0; |
|
97 m_repaintTimer->start(KRepaintTimerCb); |
|
98 } |
|
99 |
|
100 int VisualFlowLite::slideCount() const |
|
101 { |
|
102 return m_imageList.count(); |
|
103 } |
|
104 |
|
105 QImage VisualFlowLite::slide(int index) const |
|
106 { |
|
107 const QImage* i = 0; |
|
108 if((index >= 0) && (index < m_imageList.count())) |
|
109 i = m_imageList.at(index); |
|
110 return i ? QImage(*i) : QImage(); |
|
111 } |
|
112 |
|
113 void VisualFlowLite::setCenterIndex(int i) |
|
114 { |
|
115 setCurrentIndex(i); |
|
116 } |
|
117 |
|
118 int VisualFlowLite::centerIndex() const |
|
119 { |
|
120 return m_centerPageIndex; |
|
121 } |
|
122 |
|
123 bool VisualFlowLite::slideAnimationOngoing() const |
|
124 { |
|
125 return m_repaintTimer->isActive(); |
|
126 } |
|
127 |
|
128 void VisualFlowLite::setCenterThumbnail(int i) |
|
129 { |
|
130 if(m_centerPageIndex + 1 == i) { |
|
131 showNext(); |
|
132 } |
|
133 else if(m_centerPageIndex - 1 == i) { |
|
134 showPrevious(); |
|
135 } |
|
136 else { |
|
137 setCurrentIndex(i); |
|
138 calculateLayout(); |
|
139 update(); |
|
140 } |
|
141 |
|
142 } |
|
143 |
|
144 void VisualFlowLite::setCurrentIndex(int i) |
|
145 { |
|
146 m_currentIndex = i; |
|
147 m_centerPageIndex = i; |
|
148 } |
|
149 |
|
150 VisualFlowLite::~VisualFlowLite() |
|
151 { |
|
152 if (m_repaintTimer->isActive()) { |
|
153 m_repaintTimer->stop(); |
|
154 } |
|
155 delete m_repaintTimer; |
|
156 while (!m_imageList.isEmpty()) |
|
157 delete m_imageList.takeFirst(); |
|
158 if (m_scrollTimer) { |
|
159 m_scrollTimer->stop(); |
|
160 delete m_scrollTimer; |
|
161 } |
|
162 } |
|
163 |
|
164 bool VisualFlowLite::calcRepaintRect() |
|
165 { |
|
166 m_repaintTimer->stop(); |
|
167 disconnect(m_repaintTimer, SIGNAL(timeout()), this, SLOT(calcRepaintRect())); |
|
168 connect(m_repaintTimer, SIGNAL(timeout()), this, SLOT(animatePlaceHolderPosition())); |
|
169 if (m_resizeFactor == KMaxAnimFactor) { |
|
170 m_repaintRect.setRect(rect().x(), rect().y(), rect().width(), rect().height()); |
|
171 update(); |
|
172 return false; |
|
173 } |
|
174 m_repaintRect.setRect(rect().x(), rect().y(), rect().width() * m_resizeFactor/100, rect().height() * m_resizeFactor/100); |
|
175 m_resizeFactor += KResizeFactorIncr; |
|
176 update(); |
|
177 return true; |
|
178 } |
|
179 |
|
180 void VisualFlowLite::keyPressEvent(QKeyEvent* event) |
|
181 { |
|
182 switch (event->key()) { |
|
183 case Qt::Key_Left: |
|
184 showPrevious(); |
|
185 break; |
|
186 case Qt::Key_Right: |
|
187 showNext(); |
|
188 break; |
|
189 case Qt::Key_Escape: |
|
190 emit cancel(); |
|
191 break; |
|
192 case Qt::Key_Enter: |
|
193 case Qt::Key_Return: |
|
194 case Qt::Key_Select: |
|
195 emit ok(m_currentIndex); |
|
196 break; |
|
197 } |
|
198 } |
|
199 |
|
200 void VisualFlowLite::mousePressEvent(QMouseEvent* event) |
|
201 { |
|
202 m_lastMoveEventPos = event->pos(); |
|
203 m_scrollTimer = new QTimer; |
|
204 connect(m_scrollTimer, SIGNAL(timeout()), this, SLOT(scroll())); |
|
205 m_scrollTimer->start(KScrollTimeout); |
|
206 scroll(); |
|
207 } |
|
208 |
|
209 void VisualFlowLite::mouseMoveEvent(QMouseEvent* event) |
|
210 { |
|
211 m_lastMoveEventPos = event->pos(); |
|
212 } |
|
213 |
|
214 void VisualFlowLite::mouseReleaseEvent(QMouseEvent* event) |
|
215 { |
|
216 m_scrollTimer->stop(); |
|
217 delete m_scrollTimer; |
|
218 m_scrollTimer = NULL; |
|
219 if (slideAnimationOngoing()) { |
|
220 // qDebug() << "vfl:mouseReleaseEvent slideanimation running, ignoring click"; |
|
221 return; |
|
222 } |
|
223 if (event->x() > m_centerPlaceHolderRect.left() && event->x() < m_centerPlaceHolderRect.right()) { |
|
224 emit ok(centerIndex()); |
|
225 } |
|
226 } |
|
227 |
|
228 void VisualFlowLite::scroll() |
|
229 { |
|
230 if (m_lastMoveEventPos.x() < m_leftPlaceHolderRect.right()) |
|
231 showPrevious(); |
|
232 else if (m_lastMoveEventPos.x() > m_rightPlaceHolderRect.left()) |
|
233 showNext(); |
|
234 } |
|
235 |
|
236 void VisualFlowLite::paintEvent(QPaintEvent* event) |
|
237 { |
|
238 if (m_paintState == paintStateNormal) { |
|
239 paintNormalState(event); |
|
240 } |
|
241 else if (m_paintState == paintStateInTransition) { |
|
242 paintInTransition(event); |
|
243 } |
|
244 } |
|
245 |
|
246 void VisualFlowLite::paintNormalState(QPaintEvent* event) |
|
247 { |
|
248 int imageCount = m_imageList.count(); |
|
249 const QImage* centerEntry = (m_centerPageIndex >= 0)&&(imageCount>0) ? (m_imageList.at(m_centerPageIndex)) : NULL; |
|
250 const QImage* leftEntry = (m_centerPageIndex - 1 >= 0)&&(imageCount>0) ? (m_imageList.at(m_centerPageIndex - 1)) : NULL; |
|
251 const QImage* rightEntry = (m_centerPageIndex + 1 < imageCount) ? (m_imageList.at(m_centerPageIndex + 1)) : NULL; |
|
252 |
|
253 QPainter painter(this); |
|
254 painter.save(); |
|
255 painter.setBrush(Qt::white); |
|
256 painter.drawRect(rect()); |
|
257 painter.setBrush(Qt::NoBrush); |
|
258 if (leftEntry) { |
|
259 //painter.drawImage(m_leftPlaceHolderRect.topLeft(), *leftEntry, QRect(QPoint(0, 0), m_leftPlaceHolderRect.size())); |
|
260 paintImage(&painter, m_leftPlaceHolderRect, *leftEntry); |
|
261 |
|
262 painter.setPen(KSideImageBorderColor); |
|
263 painter.drawRect(m_leftPlaceHolderRect); |
|
264 } |
|
265 if (rightEntry) { |
|
266 //painter.drawImage(m_rightPlaceHolderRect.topLeft(), *rightEntry, QRect(QPoint(0, 0), m_rightPlaceHolderRect.size())); |
|
267 paintImage(&painter, m_rightPlaceHolderRect, *rightEntry); |
|
268 |
|
269 painter.setPen(KSideImageBorderColor); |
|
270 painter.drawRect(m_rightPlaceHolderRect); |
|
271 } |
|
272 if (centerEntry ) { |
|
273 //painter.drawImage(m_centerPlaceHolderRect.topLeft(), *centerEntry, QRect(QPoint(0, 0), m_centerPlaceHolderRect.size())); |
|
274 paintImage(&painter, m_centerPlaceHolderRect, *centerEntry); |
|
275 } |
|
276 painter.setPen(KCenterImageBorderColor); |
|
277 painter.drawRect(m_centerPlaceHolderRect); |
|
278 painter.restore(); |
|
279 } |
|
280 |
|
281 void VisualFlowLite::resizeEvent(QResizeEvent* event) |
|
282 { |
|
283 calculateLayout(); |
|
284 update(); |
|
285 } |
|
286 |
|
287 void VisualFlowLite::calculateLayout() |
|
288 { |
|
289 QSize screenSize = rect().size(); |
|
290 //QSize screenSize = sizeHint(); |
|
291 |
|
292 QSize viewSize((screenSize.width() - 2 * KVisualFlowViewOffsetX), screenSize.height()); |
|
293 int centerImageWidth(viewSize.width() * KCenterThumbnailWidthPercent / 100); |
|
294 int centerImageHeight(viewSize.height() * KCenterThumbnailHeightPercent/100); |
|
295 QSize centerImageSize(centerImageWidth, centerImageHeight); |
|
296 |
|
297 int sideImageWidth(viewSize.width() * KSideThumbnailWidthPercent/100); |
|
298 int sideImageHeight(viewSize.height() * KSideThumbnailHeightPercent/100); |
|
299 QSize sideImageSize(sideImageWidth, sideImageHeight); |
|
300 |
|
301 int centerImageX(KVisualFlowViewOffsetX + sideImageWidth); |
|
302 int centerImageY(viewSize.height() * (100 - KCenterThumbnailHeightPercent) / (2 * 100)); |
|
303 QPoint centerImageOrigin(centerImageX, centerImageY); |
|
304 |
|
305 m_centerPlaceHolderRect.setRect(centerImageOrigin.x(), centerImageOrigin.y(), centerImageSize.width(), centerImageSize.height()); |
|
306 int sideImageY(viewSize.height() * (100 - KSideThumbnailHeightPercent) / (2 * 100)); |
|
307 QPoint leftThumbnailOrigin(KVisualFlowViewOffsetX, sideImageY ); |
|
308 QPoint rightThumbnailOrigin((int)(KVisualFlowViewOffsetX + sideImageWidth + centerImageWidth), sideImageY ); |
|
309 |
|
310 m_leftPlaceHolderRect.setRect(leftThumbnailOrigin.x(), leftThumbnailOrigin.y(), sideImageSize.width(), sideImageSize.height()); |
|
311 m_rightPlaceHolderRect.setRect(rightThumbnailOrigin.x(), rightThumbnailOrigin.y(), sideImageSize.width(), sideImageSize.height()); |
|
312 } |
|
313 |
|
314 bool VisualFlowLite::animatePlaceHolderPosition() |
|
315 { |
|
316 m_repaintTimer->stop(); |
|
317 if (m_placeHolderResizeFactor >= KMaxAnimFactor) { |
|
318 //Restore old values and end AO |
|
319 if (m_direction == 1) { |
|
320 m_centerPageIndex++; |
|
321 } |
|
322 if (m_direction == -1) { |
|
323 m_centerPageIndex--; |
|
324 } |
|
325 m_placeHolderResizeFactor = 0; |
|
326 m_direction = 0; |
|
327 m_paintState = paintStateNormal; |
|
328 update(); |
|
329 emit centerIndexChanged(m_centerPageIndex); |
|
330 return false; |
|
331 } |
|
332 update(); |
|
333 return true; |
|
334 } |
|
335 |
|
336 void VisualFlowLite::paintInTransition(QPaintEvent* event) |
|
337 { |
|
338 QRect rects[4]; |
|
339 int dw = 0; |
|
340 int dh = 0; |
|
341 int dx = 0; |
|
342 //left movement |
|
343 if (m_direction == -1) { |
|
344 QPoint pt(m_leftPlaceHolderRect.x(), m_leftPlaceHolderRect.y() + m_leftPlaceHolderRect.height() / 2); |
|
345 dw = m_leftPlaceHolderRect.width() * m_placeHolderResizeFactor / 200; |
|
346 dh = m_leftPlaceHolderRect.height() * m_placeHolderResizeFactor / 200; |
|
347 rects[0].setRect(pt.x(), pt.y() - dh, 2 * dw, 2 * dh); |
|
348 |
|
349 dx = (m_centerPlaceHolderRect.x() - m_leftPlaceHolderRect.x()) * m_placeHolderResizeFactor / 100; |
|
350 dw = (m_centerPlaceHolderRect.width() - m_leftPlaceHolderRect.width()) * m_placeHolderResizeFactor / 200; |
|
351 dh = (m_centerPlaceHolderRect.height() - m_leftPlaceHolderRect.height()) * m_placeHolderResizeFactor / 200; |
|
352 rects[1].setRect(m_leftPlaceHolderRect.x() + dx, m_leftPlaceHolderRect.y() - dh, m_leftPlaceHolderRect.width() + 2 * dw, m_leftPlaceHolderRect.height() + 2 * dh); |
|
353 |
|
354 dx = (m_rightPlaceHolderRect.x() - m_centerPlaceHolderRect.x()) * m_placeHolderResizeFactor / 100; |
|
355 dw = (m_centerPlaceHolderRect.width() - m_rightPlaceHolderRect.width()) * m_placeHolderResizeFactor / 200; |
|
356 dh = (m_centerPlaceHolderRect.height() - m_rightPlaceHolderRect.height()) * m_placeHolderResizeFactor / 200; |
|
357 rects[2].setRect(m_centerPlaceHolderRect.x() + dx, m_centerPlaceHolderRect.y() + dh, m_centerPlaceHolderRect.width() - 2 * dw, m_centerPlaceHolderRect.height() - 2 * dh); |
|
358 |
|
359 dw = (m_rightPlaceHolderRect.width()) * m_placeHolderResizeFactor / 200; |
|
360 dh = (m_rightPlaceHolderRect.height()) * m_placeHolderResizeFactor / 200; |
|
361 rects[3].setRect(m_rightPlaceHolderRect.x() + 3 * dw, m_rightPlaceHolderRect.y() + dh, m_rightPlaceHolderRect.width() - 2 * dw, m_rightPlaceHolderRect.height() - 2 * dh); |
|
362 |
|
363 const QImage* item = 0; |
|
364 QPainter painter(this); |
|
365 painter.setPen(Qt::NoPen); |
|
366 QBrush whiteBrush(Qt::white, Qt::SolidPattern); |
|
367 painter.setBrush(whiteBrush); |
|
368 painter.drawRect(rect()); |
|
369 |
|
370 for (int i = 0; i < 4; i++) { |
|
371 item = (m_centerPageIndex - 2 + i >= 0 && m_centerPageIndex - 2 + i < m_imageList.count()) ? |
|
372 m_imageList.at(m_centerPageIndex - 2 + i) : NULL; |
|
373 if (item) { |
|
374 QRect intersectRect(rect()); |
|
375 intersectRect = intersectRect.intersected(rects[i]); |
|
376 if (!intersectRect.isEmpty()) { |
|
377 //painter.drawImage(intersectRect.topLeft(), *item, QRect(0, 0, rects[i].width(), rects[i].height())); |
|
378 paintImage(&painter, intersectRect, *item); |
|
379 |
|
380 QPen sideImagePen(KSideImageBorderColor); |
|
381 sideImagePen.setStyle(Qt::SolidLine); |
|
382 painter.setPen(sideImagePen); |
|
383 painter.setBrush(Qt::NoBrush); |
|
384 painter.drawRect(intersectRect); |
|
385 } |
|
386 } |
|
387 } |
|
388 } |
|
389 |
|
390 if (m_direction == 1) { |
|
391 dw = m_leftPlaceHolderRect.width() * m_placeHolderResizeFactor / 200; |
|
392 dh = m_leftPlaceHolderRect.height() * m_placeHolderResizeFactor / 200; |
|
393 rects[0].setRect(m_leftPlaceHolderRect.x() + 3 * dw, m_leftPlaceHolderRect.y() + dh, m_leftPlaceHolderRect.width() - 2 * dw, m_leftPlaceHolderRect.height() - 2 * dh); |
|
394 |
|
395 dx = (m_centerPlaceHolderRect.x() - m_leftPlaceHolderRect.x()) * m_placeHolderResizeFactor / 100; |
|
396 dw = (m_centerPlaceHolderRect.width() - m_leftPlaceHolderRect.width()) * m_placeHolderResizeFactor / 200; |
|
397 dh = (m_centerPlaceHolderRect.height() - m_leftPlaceHolderRect.height()) * m_placeHolderResizeFactor / 200; |
|
398 rects[1].setRect(m_centerPlaceHolderRect.x() - dx, m_centerPlaceHolderRect.y() + dh, m_centerPlaceHolderRect.width() - 2 * dw, m_centerPlaceHolderRect.height() - 2 * dh); |
|
399 |
|
400 dx = (m_rightPlaceHolderRect.x() - m_centerPlaceHolderRect.x()) * m_placeHolderResizeFactor / 100; |
|
401 dw = (m_centerPlaceHolderRect.width() - m_rightPlaceHolderRect.width()) * m_placeHolderResizeFactor / 200; |
|
402 dh = (m_centerPlaceHolderRect.height() - m_rightPlaceHolderRect.height()) * m_placeHolderResizeFactor / 200; |
|
403 rects[2].setRect(m_rightPlaceHolderRect.x() - dx, m_rightPlaceHolderRect.y() -dh, m_rightPlaceHolderRect.width() + 2 * dw, m_rightPlaceHolderRect.height() + 2 * dh); |
|
404 |
|
405 QPoint pt(m_rightPlaceHolderRect.x() + m_rightPlaceHolderRect.width(), m_rightPlaceHolderRect.y() + m_rightPlaceHolderRect.height() / 2); |
|
406 dw = (m_rightPlaceHolderRect.width()) * m_placeHolderResizeFactor / 200; |
|
407 dh = (m_rightPlaceHolderRect.height()) * m_placeHolderResizeFactor / 200; |
|
408 rects[3].setRect(pt.x() - 2 * dw, pt.y() - dh, pt.x(), pt.y() + 2 * dh); |
|
409 |
|
410 const QImage* item = 0; |
|
411 QPainter painter(this); |
|
412 painter.setPen(Qt::NoPen); |
|
413 QBrush whiteBrush(Qt::white, Qt::SolidPattern); |
|
414 painter.setBrush(whiteBrush); |
|
415 painter.drawRect(rect()); |
|
416 |
|
417 for (int i = 0; i < 4; i++) { |
|
418 item = (m_centerPageIndex - 1 + i >= 0 && m_centerPageIndex - 1 + i < m_imageList.count()) ? |
|
419 m_imageList.at(m_centerPageIndex - 1 + i) : NULL; |
|
420 if (item) { |
|
421 QRect intersectRect(rect()); |
|
422 intersectRect = intersectRect.intersected(rects[i]); |
|
423 if (!intersectRect.isEmpty()) { |
|
424 //painter.drawImage(intersectRect.topLeft(), *item, QRect(0, 0, rects[i].width(), rects[i].height())); |
|
425 paintImage(&painter, intersectRect, *item); |
|
426 |
|
427 QPen sideImagePen(KSideImageBorderColor); |
|
428 sideImagePen.setStyle(Qt::SolidLine); |
|
429 painter.setPen(sideImagePen); |
|
430 painter.setBrush(Qt::NoBrush); |
|
431 painter.drawRect(intersectRect); |
|
432 } |
|
433 } |
|
434 } |
|
435 } |
|
436 if (!m_fastScroll) { |
|
437 m_placeHolderResizeFactor += KAnimFactorInc; |
|
438 } |
|
439 else { |
|
440 m_placeHolderResizeFactor += KFastScrollAnimFactorInc; |
|
441 } |
|
442 m_repaintTimer->start(KRepaintTimerCb); |
|
443 } |
|
444 |
|
445 void VisualFlowLite::showPrevious() |
|
446 { |
|
447 if (m_centerPageIndex > 0) { |
|
448 if (m_repaintTimer->isActive()) { |
|
449 m_repaintTimer->stop(); |
|
450 m_resizeFactor = KMaxAnimFactor; |
|
451 } |
|
452 m_paintState = paintStateInTransition; |
|
453 m_direction = -1; |
|
454 m_repaintTimer->start(KRepaintTimerCb); |
|
455 } |
|
456 } |
|
457 |
|
458 void VisualFlowLite::showNext() |
|
459 { |
|
460 int count = m_imageList.count(); |
|
461 if (m_centerPageIndex < ( count -1 )) { |
|
462 if (m_repaintTimer->isActive()) { |
|
463 m_repaintTimer->stop(); |
|
464 m_resizeFactor = KMaxAnimFactor; |
|
465 } |
|
466 m_paintState = paintStateInTransition; |
|
467 m_direction = 1; |
|
468 m_repaintTimer->start(KRepaintTimerCb); |
|
469 } |
|
470 } |
|
471 |
|
472 void VisualFlowLite::paintImage(QPainter* painter, QRect rect, QImage image) |
|
473 { |
|
474 // scaling images up does not look good so we only scale down if image is too big |
|
475 bool shouldScale(false); |
|
476 if (m_scalingAllowed) |
|
477 shouldScale = (image.height() > rect.height() || image.width() > rect.width()); // scale down needed |
|
478 |
|
479 |
|
480 QImage img = (shouldScale) ? image.scaled(rect.width(), rect.height(), Qt::KeepAspectRatio) : image; |
|
481 |
|
482 int originX = rect.topLeft().x(); |
|
483 int originY = rect.topLeft().y(); |
|
484 // center the image if needed |
|
485 if (rect.width() > img.width()) |
|
486 originX += (rect.width() - img.width()) / 2; |
|
487 if (rect.height() > img.height()) |
|
488 originY += (rect.height() - img.height()) / 2; |
|
489 |
|
490 painter->drawImage(QPoint(originX, originY), img, QRect(QPoint(0, 0), rect.size())); |
|
491 } |
|
492 |
|
493 QRect VisualFlowLite::centralRect() const |
|
494 { |
|
495 return QRect(); |
|
496 } |
|
497 |
|
498 } |
|