-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlighteffect.cpp
34 lines (28 loc) · 992 Bytes
/
highlighteffect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "highlighteffect.h"
HighlightEffect::HighlightEffect( qreal offset ) :
QGraphicsEffect(),
mColor( 255, 255, 0, 128 ), // yellow, semi-transparent
mOffset( offset, offset ) {}
QRectF HighlightEffect::boundingRectFor( const QRectF& sourceRect) const
{
return sourceRect.adjusted( -mOffset.x(), -mOffset.y(), mOffset.x(), mOffset.y() );
}
void HighlightEffect::draw( QPainter* painter )
{
QPoint offset;
QPixmap pixmap;
// if ( sourceIsPixmap() ) // doesn't seems to work, return false
// {
// No point in drawing in device coordinates (pixmap will be scaled anyways).
pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset);
//}
QRectF bound = boundingRectFor( pixmap.rect() );
painter->save();
painter->setPen( Qt::NoPen );
painter->setBrush( mColor );
QPointF p( offset.x()-mOffset.x(), offset.y()-mOffset.y() );
bound.moveTopLeft( p );
painter->drawRoundedRect( bound, 5, 5, Qt::RelativeSize );
painter->drawPixmap( offset, pixmap );
painter->restore();
}