-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateformdialog.cpp
More file actions
159 lines (131 loc) · 4.52 KB
/
Copy pathupdateformdialog.cpp
File metadata and controls
159 lines (131 loc) · 4.52 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "updateformdialog.h"
#include "ui_updateformdialog.h"
#include <QFileDialog>
#include <QRegularExpressionValidator>
#include <QMessageBox>
#include <QPainter>
#include <QPainterPath>
UpdateFormDialog::UpdateFormDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UpdateFormDialog)
{
ui->setupUi(this);
lineName= new QLineEdit(this);
lineSurname= new QLineEdit(this);
lineName->hide();
lineSurname->hide();
QRegularExpression rxString("^(?!\\s*$).+.",QRegularExpression::CaseInsensitiveOption);
lineName->setValidator(new QRegularExpressionValidator(rxString, this));
lineSurname->setValidator(new QRegularExpressionValidator(rxString, this));
connect(lineName,&QLineEdit::returnPressed,this,&UpdateFormDialog::changeName);
connect(lineSurname,&QLineEdit::returnPressed,this,&UpdateFormDialog::changeCognome);
}
UpdateFormDialog::~UpdateFormDialog()
{
delete ui;
}
void UpdateFormDialog::updateOK(const User &user)
{
User userChange=user;
ui->error->clear();
}
void UpdateFormDialog::updateKO(const QString &str)
{
ui->error->setText(str);
ui->name->setText(user.getName());
ui->surmane->setText(user.getSurname());
}
void UpdateFormDialog::userLogged(const User &userL)
{
user=userL;
QImage image;
image.loadFromData(user.getImage());
image = image.scaledToWidth(ui->image->width(), Qt::SmoothTransformation);
image = image.scaledToHeight(ui->image->height(),Qt::SmoothTransformation);
QPixmap qImage = QPixmap::fromImage(image);
QPixmap pixmap(ui->image->width(), ui->image->height());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QPainterPath path;
path.addEllipse(0, 0, ui->image->width(), ui->image->height());
painter.setClipPath(path);
painter.drawPixmap(0, 0, ui->image->width(), ui->image->height(), qImage);
ui->image->setPixmap(pixmap);
ui->surmane->setText(user.getSurname());
ui->name->setText(user.getName());
ui->nickname->setText(user.getNickname());
ui->email->setText(user.getEmail());
}
void UpdateFormDialog::on_imageChange_clicked()
{
QString filename = QFileDialog::getOpenFileName(this,tr("Choose"),"",tr("Images (*.png *.jpg *.jpeg)"));
if(QString::compare(filename,QString())!=0){
QImage image;
bool check = image.load(filename);
const char* typeImage = std::move(filename.split(".")[1].toUpper().toStdString().c_str());
if(check){
image = image.scaledToWidth(ui->image->width(), Qt::SmoothTransformation);
image = image.scaledToHeight(ui->image->height(),Qt::SmoothTransformation);
QPixmap qImage = QPixmap::fromImage(image);
QPixmap pixmap(ui->image->width(), ui->image->height());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QPainterPath path;
path.addEllipse(0, 0, ui->image->width(), ui->image->height());
painter.setClipPath(path);
painter.drawPixmap(0, 0, ui->image->width(), ui->image->height(), qImage);
ui->image->setPixmap(pixmap);
QByteArray byteArray;
QBuffer buffer(&byteArray);
image.save(&buffer, typeImage);
emit imageChange(byteArray);
ui->error->clear();
}else{
ui->error->setText("Choose an other image");
}
}
}
void UpdateFormDialog::on_passwordChange_clicked()
{
emit showCP();
}
void UpdateFormDialog::on_nameChange_clicked()
{
QRect pos = ui->name->geometry();
ui->name->hide();
lineName->setGeometry(pos);
lineName->setText(ui->name->text());
lineName->show();
}
void UpdateFormDialog::on_surnameChange_clicked()
{
QRect pos =ui->surmane->geometry();
ui->surmane->hide();
lineSurname->setGeometry(pos);
lineSurname->setText(ui->surmane->text());
lineSurname->show();
}
void UpdateFormDialog::changeName()
{
if(lineName->hasAcceptableInput()){
emit nameChange(lineName->text());
ui->name->setText(lineName->text());
lineName->hide();
ui->name->show();
}
}
void UpdateFormDialog::changeCognome()
{
if(lineSurname->hasAcceptableInput()){
emit surnameChange(lineSurname->text());
ui->surmane->setText(lineSurname->text());
lineSurname->hide();
ui->surmane->show();
}
}
void UpdateFormDialog::on_logout_clicked()
{
emit logout();
}