-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcapturer.cpp
101 lines (83 loc) · 2.16 KB
/
capturer.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
#include "capturer.h"
#include <QPainter>
#include <QQuickItem>
saveAbleImage::saveAbleImage(QQuickItem *parent) : QQuickPaintedItem(parent),
height_(0),
smooth_(false),
width_(0)
{
}
void saveAbleImage::paint(QPainter *painter)
{
qDebug() <<"paint : " <<width_ <<", "<<height_;
if(height_ != 0 && width_ != 0){
qDebug() <<"scale paint : " << width_<<", "<<height_;
if(smooth_){
imageBuffer_ = image_.scaled(QSize(width_, height_), Qt::KeepAspectRatio, Qt::SmoothTransformation);
qDebug() <<"scale size : " <<image_.width() <<", "<<image_.height();
}else{
imageBuffer_ = image_.scaled(QSize(width_, height_), Qt::KeepAspectRatio, Qt::FastTransformation);
qDebug() <<"scale size : " <<image_.width() <<", "<<image_.height();
}
painter->drawImage((width_ - imageBuffer_.width()) / 2, (height_ - imageBuffer_.height()) / 2, imageBuffer_);
}else{
painter->drawImage(0, 0, image_);
}
}
int saveAbleImage::height() const
{
return height_;
}
void saveAbleImage::save(QString const &path) const
{
qDebug()<< "save image";
if(!imageBuffer_.isNull()){
qDebug()<<"save image : "<<imageBuffer_.save(path);
}else{
qDebug()<<"save image : "<<image_.save(path);
}
}
bool saveAbleImage::smooth() const
{
return smooth_;
}
QString saveAbleImage::source() const
{
return source_;
}
int saveAbleImage::width() const
{
return width_;
}
void saveAbleImage::setHeight(int height) {
qDebug() << "height : "<< height;
if(height_ != height){
height_ = height;
emit heightChanged();
}
}
void saveAbleImage::setSource(QString const &source)
{
qDebug() << "source = "<<source;
if(source_ != source){
source_ = source;
image_.load(source_);
update();
emit sourceChanged();
}
}
void saveAbleImage::setSmooth(bool smooth)
{
if(smooth_ != smooth){
smooth_ = smooth;
emit smoothChanged();
}
}
void saveAbleImage::setWidth(int width)
{
qDebug() <<"width : "<< width;
if(width_ != width){
width_ = width;
emit widthChanged();
}
}