-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstyleintensitydialog.cpp
102 lines (82 loc) · 2.65 KB
/
styleintensitydialog.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
102
#include "styleintensitydialog.h"
#include "ui_styleintensitydialog.h"
StyleIntensityDialog::StyleIntensityDialog(QWidget *parent,QString srcPath,QString stylePath,QString destPath) :
QDialog(parent),
ui(new Ui::StyleIntensityDialog)
{
ui->setupUi(this);
// ui->sliderStyleIntensity->setValue(100);
strSourcePath=srcPath;
strStylePath=stylePath;
strSavePath=destPath;
QImage top(strStylePath);
QImage bot(strSourcePath);
// both images are opaque because JPEG has no alpha channel
QPixmap combined(bot.size());
QPainter p(&combined);
p.drawImage(QPoint(0, 0), bot); // drawn as-is
p.setOpacity(1.0);
p.drawImage(QPoint(0, 0), top);
p.end();
ui->labelCanvas->setPixmap(combined);
changeStyleStrength(50);
ui->sliderStyleIntensity->setValue(50);
if (QFile::exists(strSavePath))
QFile::remove(strSavePath);
ui->labelCanvas->pixmap()->save(strSavePath);
}
StyleIntensityDialog::~StyleIntensityDialog()
{
delete ui;
}
void StyleIntensityDialog::on_sliderStyleIntensity_valueChanged(int value)
{
ui->label->setText("Style strength :"+QString::number(value)+"%");
changeStyleStrength(value);
}
void StyleIntensityDialog::on_pushButtonSave_clicked()
{
if (QFile::exists(strSavePath))
QFile::remove(strSavePath);
ui->labelCanvas->pixmap()->save(strSavePath);
}
void StyleIntensityDialog::changeStyleStrength(int styleStrength)
{
QImage top(strStylePath);
QImage bot(strSourcePath);
QImage wm(":/images/wm.png");
QPixmap combined(bot.size());
QPainter p(&combined);
p.drawImage(QPoint(0, 0), bot); // drawn as-is
p.setOpacity(styleStrength/100.0);
p.drawImage(QPoint(0, 0), top);
p.end();
//Draw water mark
QPainter p2(&combined);
/*
+---------------------------+
| 5 |
|<----5------>wm<----5----->|
| 5 |
+---------------------------+
Rect width = wm.width+10
Rect height =wm.height+10
Rect x =imgwidth-width
Rect y =img height-height
*/
int pad=8;
int rectWidth = wm.width()+(pad*2);
int rectHeight = wm.height()+(pad*2);
int rectLeft = bot.width()-rectWidth;
int rectTop = bot.height()-rectHeight;
/*
Water mark image
Point x =rectLeft+pad
Point y =rectTop+pad */
int wmLeft = rectLeft+pad;
int wmTop = rectTop+pad;
p2.fillRect(QRect(rectLeft,rectTop,rectWidth,rectHeight), QBrush(QColor(0, 0, 0, 128)));
p2.drawImage(QPoint(wmLeft, wmTop), wm);
p2.end();
ui->labelCanvas->setPixmap(combined);
}