-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
85 lines (72 loc) · 2.52 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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->item_0_0->setScene(new QGraphicsScene());
auto zoom = new Graphics_view_zoom(ui->item_0_0);
zoom->set_modifiers(Qt::NoModifier);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::SetWindow() {
int number = QInputDialog::getInt(ui->centralwidget, "Select numbers",
"Select number of pictures to compare (square num)");
number = static_cast<int>(sqrt(number));
/* Now edit the grid layout and create the new window */
this->removeAll();
auto original = this->ui->item_0_0;
loop(x, number) {
loop(y, number) {
if(x == 0 && y == 0) {
this->elements.emplace(std::pair<int, int>(x, y), original);
continue;
}
auto elem = new QGraphicsView(new QGraphicsScene(), original->parentWidget());
auto zoom = new Graphics_view_zoom(elem);
zoom->set_modifiers(Qt::NoModifier);
zoomers.push_back(zoom);
this->ui->mainLayout->addWidget(elem, y, x);
this->elements.emplace(std::pair<int, int>(x, y), elem);
}
}
}
auto MainWindow::removeAll() -> void {
for(auto elem : this->elements) {
if (elem.first != std::pair<int, int>(0, 0)) {
delete dynamic_cast<QGraphicsView*>(elem.second)->scene();
this->ui->mainLayout->removeWidget(elem.second);
delete elem.second;
}
}
this->zoomers.clear();
this->elements.clear();
}
void MainWindow::LoadImages() {
QFileDialog dialog(this);
dialog.setDirectory(QDir::homePath());
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter(trUtf8("Splits (*.png *.jpg)"));
QStringList files;
if (dialog.exec()) {
files = dialog.selectedFiles();
for(auto elem : this->elements) {
auto widget = dynamic_cast<QGraphicsView*>(elem.second);
if (files.isEmpty()) {
break;
}
auto img = QImage(files.front());
auto item = new QGraphicsPixmapItem(QPixmap::fromImage(img));
widget->scene()->addItem(item);
widget->show();
files.pop_front();
}
} else {
QMessageBox messageBox;
messageBox.critical(this,"Error","Please select files!");
messageBox.setFixedSize(500,200);
return;
}
}