37
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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: Reflection effect for Music Player Media Wall.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QPainter>
|
|
19 |
#include <QGraphicsItem>
|
|
20 |
#include <hbinstance.h>
|
|
21 |
|
|
22 |
#include "mpreflectioneffect.h"
|
|
23 |
|
|
24 |
|
|
25 |
/*!
|
|
26 |
\class MpReflectionEffect
|
|
27 |
\brief The MpReflectionEffect class provides a reflection effect.
|
|
28 |
|
|
29 |
Renders the source with a reflection.
|
|
30 |
*/
|
|
31 |
|
|
32 |
/*!
|
|
33 |
Constructs a new MpReflectionEffect instance.
|
|
34 |
The \a parent parameter is passed to QGraphicsEffect's constructor.
|
|
35 |
*/
|
|
36 |
MpReflectionEffect::MpReflectionEffect(QObject *parent)
|
|
37 |
: QGraphicsEffect( parent )
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
/*!
|
|
42 |
Destroys the effect.
|
|
43 |
*/
|
|
44 |
MpReflectionEffect::~MpReflectionEffect()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
|
48 |
/*!
|
|
49 |
\reimp
|
|
50 |
*/
|
|
51 |
QRectF MpReflectionEffect::boundingRectFor(const QRectF &rect) const
|
|
52 |
{
|
|
53 |
QRectF retRect = rect;
|
|
54 |
//this bounding rect is in device cordinates, correcting based on current transform.
|
|
55 |
if ( hbInstance->allMainWindows()[0]->orientation() == Qt::Horizontal ) {
|
|
56 |
#ifdef __WINS__
|
|
57 |
retRect.adjust(0,0,retRect.width(),0); //wincw with forced rotation is to the right.
|
|
58 |
#else
|
|
59 |
retRect.adjust(-retRect.width(),0,0,0);//currently hardware rotations is to the left.
|
|
60 |
#endif
|
|
61 |
} else {
|
|
62 |
retRect.adjust(0,0,0,retRect.height());
|
|
63 |
}
|
|
64 |
|
|
65 |
return retRect;
|
|
66 |
}
|
|
67 |
|
|
68 |
/*!
|
|
69 |
\reimp
|
|
70 |
*/
|
|
71 |
void MpReflectionEffect::draw(QPainter *painter)
|
|
72 |
{
|
|
73 |
//currently sourceBoundingRect returns somehing like boundingRectFor and
|
|
74 |
//wrong rect for widgets with scroll area. As a workaround we can get the
|
|
75 |
//original bounding rect assuming that the widget using the effect is the
|
|
76 |
//effect parent.
|
|
77 |
QGraphicsItem * sourceItem;
|
|
78 |
sourceItem = qobject_cast<QGraphicsItem *>( parent() );
|
|
79 |
QPixmap pixmap;
|
|
80 |
QPoint offset;
|
|
81 |
pixmap = sourcePixmap( Qt::LogicalCoordinates,&offset, QGraphicsEffect::NoPad );
|
|
82 |
painter->drawPixmap( offset, pixmap );
|
|
83 |
if ( sourceItem ) {
|
|
84 |
painter->save();
|
|
85 |
painter->scale( 1, -1 );
|
|
86 |
//for some reson tranlation does not work, translating cordinates by hand.
|
|
87 |
QPointF reflectionOffset( 0.0, - 2.0 * sourceItem->boundingRect().height() );
|
|
88 |
painter->drawPixmap( offset + reflectionOffset, pixmap );
|
|
89 |
QRectF reflectionRect;
|
|
90 |
reflectionRect.setTopLeft( reflectionOffset );
|
|
91 |
reflectionRect.setHeight ( sourceItem->boundingRect().height() );
|
|
92 |
reflectionRect.setWidth( pixmap.width() );
|
|
93 |
painter->fillRect( reflectionRect, QColor::fromRgbF( 0, 0, 0, 0.5f ) );
|
|
94 |
painter->restore();
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
// EOF
|