-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
221 lines (195 loc) · 5.86 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "scene.h"
#include "QFileDialog"
#include "QLabel"
#include "QMouseEvent"
#include "QToolBar"
#include "settingsdialog.h"
#include "view.h"
#include "QDebug"
#include "QActionGroup"
#include "opencv2/highgui/highgui.hpp"
int currenttool=-1;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
initGui();
loaded=0;
loadSettings();
flag=0;
}
void MainWindow::initGui()
{
ui->setupUi(this);
this->setWindowTitle("Image");
tabs=new QTabWidget(ui->centralWidget);
tabs->setTabsClosable(1);
connect(tabs,SIGNAL(tabCloseRequested(int)),this,SLOT(onTabClose(int)));
setActionsDisabled();
tabs->setStyleSheet("border:0px solid black;");
QAction *settings=ui->menuBar->addAction("Настройки");
dialog=new settingsDialog;
dialog->setSettings(curentSettings);
connect(settings,SIGNAL(triggered()),this,SLOT(openSettingsDialog()));
createToolBar();
addToolBar(Qt::LeftToolBarArea, lefttoolbar);
}
void MainWindow::createToolBar()
{
lefttoolbar = new QToolBar("lefttoolbar");
lefttoolbar->setMovable(0);
actiongroup = new QActionGroup(lefttoolbar);
actiongroup->addAction(QIcon(":/circ.png"),"Line");
actiongroup->addAction(QIcon(":/line.png"),"Circle");
actiongroup->addAction(QIcon(":/rect.png"),"Rectangle");
actiongroup->addAction(QIcon(":/marker.png"),"Marker");
lefttoolbar->addActions(actiongroup->actions());
foreach(QAction *action, actiongroup->actions())
{
action->setCheckable(true);
}
connect(actiongroup,SIGNAL(triggered(QAction*)),this,SLOT(actionGroupChecked(QAction*)));
}
void MainWindow::actionGroupChecked(QAction * activeAction)
{
currenttool=actiongroup->actions().indexOf(activeAction);
}
void MainWindow::loadSettings()
{
curentSettings=new QSettings;
}
void MainWindow::saveSettings()
{
}
void MainWindow::exportSelected()
{
QString filename=QFileDialog::getSaveFileName(this,"Export to matrix","","YAML Files(*.yaml);;XML Files(*.xml);;All Files(*)");
QFile checkfile(filename);
if(!checkfile.open(QIODevice::WriteOnly | QIODevice::Text))
return;
checkfile.close();
cv::FileStorage file(filename.toUtf8().data(), cv::FileStorage::WRITE);
file<<"Image"<<scenelist.at(tabs->currentIndex())->getSelected();
file.release();
}
void MainWindow::buildProfile()
{
scenelist.at(tabs->currentIndex())->getProfile();
}
void MainWindow::openSettingsDialog()
{
connect(dialog,SIGNAL(accepted()),this,SLOT(saveSettings()));
dialog->show();
}
void MainWindow::setActionsDisabled()
{
ui->actionSave->setDisabled(1);
ui->actionSaveAs->setDisabled(1);
ui->actionExport->setDisabled(1);
ui->actionClose->setDisabled(1);
}
void MainWindow::setActionsEnabled()
{
ui->actionSave->setEnabled(1);
ui->actionSaveAs->setEnabled(1);
ui->actionExport->setEnabled(1);
ui->actionClose->setEnabled(1);
}
void MainWindow::resizeEvent(QResizeEvent *)
{
tabs->resize(this->size().width()-this->lefttoolbar->width(),this->size().height()-ui->menuBar->height()+1);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onTabClose(int index)
{
delete scenelist[tabs->currentIndex()];
scenelist.removeAt(index);
tabs->removeTab(index);
if(scenelist.size()==0)
setActionsDisabled();
}
void MainWindow::on_actionClose_triggered()
{
onTabClose(tabs->currentIndex());
}
void MainWindow::on_actionOpen_triggered()
{
QString filename=QFileDialog::getOpenFileName(this,"Open File","","TIFF Images(*.tiff *.tif);;PNG Images(*.png)");
QFile checkfile(filename);
if(!checkfile.exists())
return;
cv::Mat image=cv::imread(filename.toUtf8().data(),CV_LOAD_IMAGE_GRAYSCALE);
if(!image.data)
{
return;
}
displayLoaded(image, filename);
}
void MainWindow::on_actionImport_triggered()
{
QString filename=QFileDialog::getOpenFileName(this,"Import File","","OpenCV Filestorages(*.yaml *.xml);;All Files(*)");
QFile checkfile(filename);
if(!checkfile.exists())
return;
cv::FileStorage file(filename.toUtf8().data(), cv::FileStorage::READ);
cv::Mat image;
file["Image"]>>image;
file.release();
if(!image.data)
{
return;
}
displayLoaded(image,filename);
}
void MainWindow::displayLoaded(cv::Mat image,QString filename)
{
setActionsEnabled();
images *newimage=new images(image);
scene *pixmap=new scene;
scenelist<<pixmap;
pixmap->setMainImage(newimage);
view *newview=new view;
connect(newview,SIGNAL(scaleChanged(double)),pixmap,SLOT(setScale(double)));
newview->setScene(pixmap);
newview->show();
connect(newview,SIGNAL(export_triggered()),this,SLOT(exportSelected()));
connect(newview,SIGNAL(profile_triggered()),this,SLOT(buildProfile()));
tabs->addTab(newview,filename);
}
void MainWindow::on_actionSave_triggered()
{
QString filename=tabs->tabText(tabs->currentIndex());
QFile checkfile(filename);
if((filename.endsWith("tiff",Qt::CaseInsensitive) or filename.endsWith("tif",Qt::CaseInsensitive)) and checkfile.open(QIODevice::WriteOnly | QIODevice::Text))
{
checkfile.close();
cv::imwrite(filename.toUtf8().data(),scenelist.at(tabs->currentIndex())->getMainImage()->getCvMat());
}
else
on_actionSaveAs_triggered();
}
void MainWindow::on_actionSaveAs_triggered()
{
QString filename=QFileDialog::getSaveFileName(this,"Save Image as","","TIFF Files(*.tiff *.tif);;PNG Files(*.png);;All Files(*)");
QFile checkfile(filename);
if(!checkfile.open(QIODevice::WriteOnly | QIODevice::Text))
return;
checkfile.close();
cv::imwrite(filename.toUtf8().data(),scenelist.at(tabs->currentIndex())->getMainImage()->getCvMat());
}
void MainWindow::on_actionExport_triggered()
{
QString filename=QFileDialog::getSaveFileName(this,"Export to matrix","","YAML Files(*.yaml);;XML Files(*.xml);;All Files(*)");
QFile checkfile(filename);
if(!checkfile.open(QIODevice::WriteOnly | QIODevice::Text))
return;
checkfile.close();
cv::FileStorage file(filename.toUtf8().data(), cv::FileStorage::WRITE);
file<<"Image"<<scenelist.at(tabs->currentIndex())->getMainImage()->getCvMat();
file.release();
}