-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
91 lines (70 loc) · 2.08 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap butPixmap(":/img/button");
QIcon butIcon(butPixmap);
ui->pushButton_2->setIcon(butIcon);
qApp->setStyleSheet("#pushButton_2{border:5px;}");
this->setWindowFlags(Qt::FramelessWindowHint);
if(!QDir("pics").exists()) QDir().mkdir("pics");
}
MainWindow::~MainWindow()
{
delete ui;
}
QPixmap MainWindow::makeImg(QString inText){
QPixmap pixmap(300,150);
pixmap.fill(Qt::blue);
QPainter painter(&pixmap);
painter.setPen(Qt::green);
painter.setFont(QFont("Arial",45));
painter.drawText(15,90,inText);
//ui->label->setPixmap(pixmap);
return pixmap;
}
QPixmap MainWindow::distortImg(QPixmap pixmap)
{
QImage pixmapImg = pixmap.toImage();
QPixmap pixmap2(pixmap.width(),pixmap.height());
QPainter painter2(&pixmap2);
// Distort text
for(int x = 0; x < pixmap.width(); x++){
for(int y = 0; y < pixmap.height(); y++){
qsrand(x);
float rand1 = qrand()%5;
qsrand(y);
float rand2 = qrand()%5;
float sinx = sin(x/10+1)*5;
float siny = qSin(y/10)*5;
int newx = x+rand1+sinx;
int newy = y+rand2+siny;
if(newx < pixmap.width() && newy < pixmap.height()){
if(rand1+rand2 > 1) {
painter2.setPen(pixmapImg.pixel(newx,newy));
} else {
painter2.setPen(Qt::green);
painter2.drawRect(x,y,10,10);
}
painter2.drawRect(x,y,1,1);
}
}
}
ui->label->setPixmap(pixmap2);
return pixmap2;
}
void MainWindow::on_pushButton_clicked()
{
QString inText = ui->lineEdit->text();
QFile newpic("pics/"+inText+".png");
newpic.open(QIODevice::WriteOnly);
qDebug() << "pics/"+inText+".png";
distortImg(makeImg(inText)).save(&newpic,"PNG");
}
void MainWindow::on_pushButton_2_clicked()
{
qApp->exit();
}