-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathblurreditem.cpp
64 lines (54 loc) · 1.57 KB
/
blurreditem.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "blurreditem.h"
#include <QPainter>
#include <QDebug>
BlurredItem::BlurredItem(QDeclarativeItem *parent) :
QDeclarativeItem(parent), mSource(0)
{
setFlag(ItemHasNoContents, false);
}
QDeclarativeItem* BlurredItem::source() const
{
return mSource;
}
void BlurredItem::setSource(QDeclarativeItem *source)
{
if (mSource != source) {
mSource = source;
emit sourceChanged();
if (isComponentComplete())
refresh();
}
}
QT_BEGIN_NAMESPACE
extern Q_GUI_EXPORT void qt_blurImage( QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0 );
QT_END_NAMESPACE
void BlurredItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
if (mPixmap.isNull() && mSource && mSource->width() >= 1 && mSource->height() >= 1) {
QImage image = QImage((int)mSource->width(), (int)mSource->height(), QImage::Format_ARGB32);
QImage srcImg = image;
{
QPainter p(&srcImg);
mSource->paint(&p, option, 0);
}
QPainter p(&image);
qt_blurImage(&p, srcImg, 50, true, false);
p.fillRect(image.rect(), QColor(0, 0, 0, 160));
mPixmap = QPixmap::fromImage(image);
}
if (mPixmap.isNull())
painter->fillRect(boundingRect(), Qt::transparent);
else
painter->drawPixmap(boundingRect().toRect(), mPixmap);
}
void BlurredItem::refresh()
{
mPixmap = QPixmap();
update();
}
void BlurredItem::componentComplete()
{
QDeclarativeItem::componentComplete();
if (mSource)
refresh();
}