/
mainwindow.cpp
211 lines (185 loc) · 6.43 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
#include <QtGui>
#include <QAction>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QScrollArea>
#include <QScrollBar>
#include <QWidget>
#include "dialogaboutdot.h"
#include "dialogabouttestmatrix.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "image.h"
#include "point.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
centralW = new QWidget;
orignW = new QWidget;
transW = new QWidget;
qDebug("original");
original = new Image(orignW, this);
qDebug("transformed");
transformed = new Image(transW, this);
imageLayout = new QHBoxLayout;
imageLayout->addWidget(orignW);
imageLayout->addWidget(transW);
centralW->setLayout(imageLayout);
setCentralWidget(centralW);
createActions();
createMenus();
setWindowTitle(tr("Transformation"));
resize(1350, 700);
connect(this, SIGNAL(saveImages(QString)), transformed, SLOT(saveImage(QString)));
}
MainWindow::~MainWindow()
{
delete ui;
delete original;
delete transformed;
delete orignW;
delete transW;
delete imageLayout;
delete centralW;
delete enterRefPointAct;
delete exitAct;
delete showMatrixAct;
delete transformAct;
delete fileMenu;
delete transformMenu;
}
void MainWindow::enterRefPoint()
{
DialogAboutDot *dialog = new DialogAboutDot();
connect(dialog, SIGNAL(acceptEnterRefPoint(DialogAboutDot*)), original, SLOT(setNewMatrix(DialogAboutDot*)));
dialog->show();
}
void MainWindow::createActions()
{
enterRefPointAct = new QAction(tr("Enter Reference Point"), this);
enterRefPointAct->setShortcut(tr("Ctrl+P"));
connect(enterRefPointAct, SIGNAL(triggered()), this, SLOT(enterRefPoint()));
exitAct = new QAction(tr("Exit"), this);
exitAct->setShortcut(tr("Esc, Alt+F12"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
normalSizeAct = new QAction(tr("&Normal Size"), this);
normalSizeAct->setShortcut(tr("Ctrl+S"));
normalSizeAct->setEnabled(false);
connect(normalSizeAct, SIGNAL(triggered()), this, SLOT(normalSize()));
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcut(tr("Ctrl+O"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
saveTransfImgAct = new QAction(tr("Save Transformed Image"), this);
saveTransfImgAct->setShortcut(tr("Ctrl+S"));
saveTransfImgAct->setEnabled(false);
connect(saveTransfImgAct, SIGNAL(triggered()), this, SLOT(saveTransfImg()));
showMatrixAct = new QAction(tr("Show Matrix"), this);
showMatrixAct->setShortcut(tr("Ctrl+M"));
connect(showMatrixAct, SIGNAL(triggered()), this, SLOT(showMatrix()));
transformAct = new QAction(tr("&Tranform"), this);
transformAct->setShortcut(tr("Ctrl+T"));
connect(transformAct, SIGNAL(triggered()), this, SLOT(transform()));
testMatrixAct = new QAction(tr("Set Test Matrix"), this);
testMatrixAct->setShortcut(tr("Ctrl+E"));
connect(testMatrixAct, SIGNAL(triggered()), this, SLOT(setTestMatrix()));
zoomInAct = new QAction(tr("Zoom &In (25%)"), this);
zoomInAct->setShortcut(tr("Ctrl++"));
zoomInAct->setEnabled(false);
connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn()));
zoomOutAct = new QAction(tr("Zoom &Out (25%)"), this);
zoomOutAct->setShortcut(tr("Ctrl+-"));
zoomOutAct->setEnabled(false);
connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut()));
}
void MainWindow::createMenus()
{
fileMenu = new QMenu(tr("File"), this);
fileMenu->addAction(openAct);
fileMenu->addSeparator();
fileMenu->addAction(saveTransfImgAct);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
transformMenu = new QMenu(tr("Transformation"), this);
transformMenu->addAction(transformAct);
transformMenu->addSeparator();
transformMenu->addAction(enterRefPointAct);
transformMenu->addAction(testMatrixAct);
transformMenu->addAction(showMatrixAct);
viewMenu = new QMenu(tr("&View"), this);
viewMenu->addAction(zoomInAct);
viewMenu->addAction(zoomOutAct);
viewMenu->addAction(normalSizeAct);
menuBar()->addMenu(fileMenu);
menuBar()->addMenu(viewMenu);
menuBar()->addMenu(transformMenu);
}
void MainWindow::normalSize()
{
original->normalSize();
original->adjustSize();
transformed->normalSize();
transformed->adjustSize();
scaleFactor = 1.0;
}
void MainWindow::open()
{
imgfilename = QFileDialog::getOpenFileName(
this, tr("Open Document"), QDir::currentPath(),
tr("Image files (*.jpg *.jpeg *.bmp);;Exotic Image (*.bmp *.png *.gif);;All files (*.*)"),
0, QFileDialog::DontUseNativeDialog
);
if (!imgfilename.isEmpty()) {
QImage image(imgfilename);
if (image.isNull()) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load %1.").arg(imgfilename));
return;
}
original->setImage(image);
scaleFactor = 1.0;
normalSizeAct->setEnabled(true);
zoomOutAct->setEnabled(true);
zoomOutAct->setEnabled(true);
}
}
void MainWindow::saveTransfImg()
{
QString str_matrix = original->showMatrix();
str_matrix.replace(QRegExp("[^\\w]+"), "_");
emit saveImages(imgfilename+str_matrix);
}
void MainWindow::setTestMatrix()
{
DialogAboutTestMatrix *dialog = new DialogAboutTestMatrix();
connect(dialog, SIGNAL(readyTestMatrix(double *)), original, SLOT(setTestMatrix(double *)));
dialog->show();
}
void MainWindow::showMatrix()
{
QString info_about_matrix1 = original->showMatrix();
QString info_about_matrix2 = transformed->showMatrix();
QMessageBox::about(0, tr("Info About Matrix Of Transformation"),
tr("First matrix: \n").append(info_about_matrix1).append(tr("\nSecond matrix:\n")).append(info_about_matrix2));
}
void MainWindow::transform()
{
original->getNewImage(transformed);
saveTransfImgAct->setEnabled(true);
}
void MainWindow::zoomIn()
{
original->zoomIn();
transformed->zoomIn();
}
void MainWindow::zoomOut()
{
original->zoomOut();
transformed->zoomOut();
}