-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcropdialog.cpp
53 lines (46 loc) · 1.35 KB
/
cropdialog.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
#include "cropdialog.h"
#include "ui_cropdialog.h"
CropDialog::CropDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CropDialog)
{
ui->setupUi(this);
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setParent(this);
}
void CropDialog::setImage(QImage img)
{
image = img ;
QPixmap pix(QPixmap::fromImage(image));
imageLabel->resize(pix.size());
imageLabel->setPixmap(pix);
QList<QPushButton *> buttons = this->findChildren<QPushButton *>();
foreach (QPushButton * b, buttons) {
b->setParent(imageLabel);
}
}
CropDialog::~CropDialog()
{
delete ui;
}
void CropDialog::on_saveButton_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
"/home/jana/untitled.png",
tr("Images (*.png *.bmp *.jpg)"));
while ( fileName.isEmpty() )
{
fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
"/home/jana/untitled.png",
tr("Images (*.png *.bmp *.jpg)"));
}
QImageWriter writer(fileName);
writer.write(image );
this->close();
}
void CropDialog::on_CancelButton_clicked()
{
this->close();
}