forked from Kalebros/qt-bqrencode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbqrdecoratedcolorfactory.cpp
102 lines (76 loc) · 3.11 KB
/
bqrdecoratedcolorfactory.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// This file is part of BQREncode
// BQREncode, a library wrapper of libqrencode for Qt 5*
// Copyright (C) 2015, Antonio Ramírez Marti ([email protected])
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "bqrdecoratedcolorfactory.h"
namespace BQREncode {
BQRDecoratedColorFactory::BQRDecoratedColorFactory(QObject *parent,QColor color,QSize size) :
BQRColorFactory(parent,color),
_imageSize(size)
{
_pathDecorationImage=QString();
}
QImage *BQRDecoratedColorFactory::buildImageFromCode(const BQRCode &code)
{
QImage *image =BQRColorFactory::buildImageFromCode(code);
if(_pathDecorationImage.isEmpty())
return image;
return buildDecoratedImage(image);
}
QImage *BQRDecoratedColorFactory::buildImageFromCode(const BQRCode *code)
{
QImage *image=BQRColorFactory::buildImageFromCode(code);
if(_pathDecorationImage.isEmpty())
return image;
return buildDecoratedImage(image);
}
void BQRDecoratedColorFactory::setSize(QSize size)
{
_imageSize=size;
_decorationSize=QSize((size.width()/10)+10,(size.height()/10)+10);
}
void BQRDecoratedColorFactory::setPathDecoration(QString path)
{
_pathDecorationImage=path;
}
void BQRDecoratedColorFactory::setBackgroundDecorationSize(QSize decorationSize)
{
_decorationSize=decorationSize;
}
QImage *BQRDecoratedColorFactory::buildDecoratedImage(QImage *originalImage)
{
QImage *scaledImage=new QImage(originalImage->scaled(_imageSize));
delete originalImage;
QImage decorativeImage(_pathDecorationImage);
QPainter painter(scaledImage);
painter.setRenderHint(QPainter::Antialiasing, true);
QPen pPen=painter.pen();
pPen.setColor(_color);
pPen.setWidth(5);
painter.setPen(pPen);
painter.setBrush(Qt::white);
QPoint center=scaledImage->rect().center();
QRect rect_dibujo(QPoint(center.x()-_decorationSize.width(),center.y()-_decorationSize.height()),QPoint(center.x()+_decorationSize.width(),center.y()+_decorationSize.height())); // Tamaño arbitrario
painter.begin(scaledImage);
painter.drawEllipse(rect_dibujo);
painter.setBackgroundMode(Qt::TransparentMode);
painter.setRenderHint(QPainter::Antialiasing);
int rectWidth=(_imageSize.width()/10)+10;
int rectHeight=(_imageSize.height()/10)+10;
QRect rect_imagen(QPoint(center.x()-rectWidth,center.y()-rectHeight),QPoint(center.x()+rectWidth,center.y()+rectHeight));
painter.drawImage(rect_imagen,decorativeImage);
painter.end();
return scaledImage;
}
}