-
Notifications
You must be signed in to change notification settings - Fork 5
/
importimage.cpp
executable file
·94 lines (77 loc) · 2.41 KB
/
importimage.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
#include "importimage.h"
#include "ui_importimage.h"
#include <QMessageBox>
#include <QFile>
#include <QFileDialog>
#include "base/dialogs.h"
#include "layer/imagelayer.h"
ImportImage::ImportImage(AppContext *context, QWidget *parent) :
QWidget(parent),
ui(new Ui::ImportImage)
{
this->context = context;
ui->setupUi(this);
}
ImportImage::~ImportImage()
{
delete ui;
}
void ImportImage::on_pushButton_import_clicked()
{
if(this->context == NULL) {
qDebug() << "NewProject: app context is NULL";
return;
}
// nacteni a overeni cesty projektu
QString path = this->ui->lineEdit_path->text();
if(path.length() == 0) {
QMessageBox::warning(
this,
tr("Import Image"),
tr("Path to image is not set"));
return;
}
// nacteni velikosti obrazku
int width = this->ui->spinBox_width->value();
int height = this->ui->spinBox_height->value();
// nacteni a kontrola projektu
Project *project = this->context->getProject();
if(project == NULL) {
QMessageBox::warning(
this,
tr("Import Image"),
DIALOG_PROJECT_NOT_EXISTS);
return;
}
// vytvori vrstvu z obrakem
ImageLayer *layer = new ImageLayer(project,
"Image ",
this->ui->lineEdit_path->text(),
QSize(width, height)
);
project->insertLayerAbove(layer);
project->requestRepaint();
QMessageBox::information(this, tr("Import Image"), tr("Image successfully imported"));
this->close();
}
void ImportImage::on_pushButton_path_clicked()
{
// nacteni a kontrola projektu
Project *project = this->context->getProject();
if(project == NULL) {
QMessageBox::warning(
this,
tr("Import Image"),
DIALOG_PROJECT_NOT_EXISTS);
return;
}
// zobrazeni file dialogu pro import obrazku
QString path = QFileDialog::getOpenFileName(
this,
"Open File",
QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)"));
// relativni cesta k projektovemu
QDir dir(project->getDirPath());
QString rel = dir.relativeFilePath(path);
this->ui->lineEdit_path->setText(rel);
}