-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprojectfromimage.cpp
executable file
·121 lines (102 loc) · 3.39 KB
/
projectfromimage.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "projectfromimage.h"
#include "ui_projectfromimage.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QImageReader>
#include "base/project.h"
#include "layer/bitmaplayer.h"
ProjectFromImage::ProjectFromImage(AppContext *context, QWidget *parent) :
QWidget(parent),
ui(new Ui::ProjectFromImage)
{
this->context = context;
ui->setupUi(this);
this->setWindowTitle("New Project");
}
ProjectFromImage::~ProjectFromImage()
{
delete ui;
}
void ProjectFromImage::on_pushButton_clicked()
{
if(this->context == NULL) {
qDebug() << "Open Project: app context is NULL";
return;
}
// nacteni a overeni nazvu projektu
QString name = this->ui->lineEdit_name->text();
if(name.length() < PROJECT_MIN_NAME_LENGTH) {
QMessageBox::warning(
this,
tr("Project From Image"),
tr("Name of the project is too short. The name must have at least 3 characters."));
return;
}
// nacteni a overeni cesty projektu
QString path = this->ui->lineEdit_path->text();
if(path.length() == 0) {
QMessageBox::warning(
this,
tr("Project From Image"),
tr("Path of project is not set"));
return;
}
QFile file(path);
if (file.exists())
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(
this,
tr("Project From Image"),
tr("Name of the project is same as the name of existing file. Do you want to create a project?"),
QMessageBox::Yes|QMessageBox::No);
if(reply == QMessageBox::No) {
return;
}
}
// nacteni a overeni cesty obrazku
QString pathImg = this->ui->lineEdit_path_img->text();
if(path.length() == 0) {
QMessageBox::warning(
this,
tr("Project From Image"),
tr("Path of image is not set"));
return;
}
// velikost obrazku
QImageReader imgReader(pathImg);
// vytvori novy projekt a priradi ho do workspacu
Project *p = new Project(NULL, name, path, imgReader.size());
BitmapLayer *l = new BitmapLayer(p, "Background", pathImg);
p->addLayerAtTop(l);
p->setSelectedLayer(l);
this->context->setProject(p);
// info + zavreni okna
QMessageBox::information(this, tr("Open Project"), tr("Project successfully opened"));
this->close();
// singnal -> project vytvoren
emit this->projectCreated();
}
void ProjectFromImage::on_pushButton_path_clicked()
{
// zobrazeni file dialogu pro umisteni projektoveho souboru
QString filter = QString("QT-BE Project (*%1)").arg(PROJECT_FILE_EXTENSION);
QString path = QFileDialog::getSaveFileName(
this,
"Save Project",
QDir::homePath(), filter);
if(path.endsWith(PROJECT_FILE_EXTENSION)) {
this->ui->lineEdit_path->setText(path);
} else {
this->ui->lineEdit_path->setText(path + PROJECT_FILE_EXTENSION);
}
}
void ProjectFromImage::on_pushButton_path_2_clicked()
{
// zobrazeni file dialogu pro otevreni obrazku
QString path = QFileDialog::getOpenFileName(
this,
"Open Image",
QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)"));
this->ui->lineEdit_path_img->setText(path);
}