-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
150 lines (116 loc) · 3.98 KB
/
mainwindow.cpp
File metadata and controls
150 lines (116 loc) · 3.98 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
/*To do
* 1) Fix position after changing n x n
* 2) Add toolbar (rotate, reset, zoom) by buttons
* 3) UI/UX
* 4) Check at UNIX +
* 5) Download support
* 6) PSD opening
* 7) Add slider fixed positions 3x3 5x5 7x7 9x9 12x12 15x15 17x17 19x19 21x21
* 8) Fix sliders after opening new file at default positions
*/
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//startup functions
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::set_picture(QString picture_location, int size_nxn){
QPixmap texture(picture_location);
static_picture = texture;
create_picture(size_nxn);
scene->addPixmap(current_picture);
ui->texture_viewer->setScene(&*scene);
//ui->texture_viewer->viewport()->repaint();
ui->texture_viewer->fitInView(ui->texture_viewer->sceneRect(), Qt::KeepAspectRatio);
}
void MainWindow::create_picture(int size_nxn){
int width = static_picture.width();
int height = static_picture.height();
QPixmap cache_for_picture(width*size_nxn, height*size_nxn);
for (int i{0}; i<width*size_nxn; i+=width){
for (int j{0}; j<height*size_nxn; j+=height) {
QPainter painter(&cache_for_picture);
painter.drawPixmap(QPoint(i,j),static_picture);
//painter.save();
}
}
current_picture = cache_for_picture;
}
void MainWindow::reset_parametrs_to_default(){
//reset sliders
ui->texture_viewer->resetMatrix();
ui->zoom_slider->setValue(100);
int current_angel = ui->angle_slider->value();
if(current_angel > 0){
if(current_angel < 180){
}
}
else{
}
ui->angle_slider->setValue(0);
}
void MainWindow::on_open_file_clicked()
{
// seting filter data in explorer
QString filter = "All Files (*.*) ;; Image Files (*.png; *.jpg; *.jpeg) ;; PSD Files (*.psd)";
// creating string with file adress
QString opened_file = QFileDialog::getOpenFileName(this,"Open a file", QDir::homePath(), filter);
if(opened_file == ""){ // do nothing when path is empty "nothing selected"
return;
}
ui->file_name->setText(opened_file);
//reset_parametrs_to_default();
set_picture(opened_file, sizes_of_images.at(ui->multiplication_slider->value()));
}
void MainWindow::on_zoom_slider_valueChanged(int value)
{
if(value > slider_postion_zoom){
ui->texture_viewer->scale(zoom_ratio,zoom_ratio);
}
else {
ui->texture_viewer->scale(1/zoom_ratio,1/zoom_ratio);
}
slider_postion_zoom = value;
QString info = QString::number(value)+ "%";
ui->zoom_status->setText(info);
}
void MainWindow::on_angle_slider_valueChanged(int value)
{
if(value > slider_postion_angle){
ui->texture_viewer->rotate(5);
slider_postion_angle+=1;
}
else if(value < slider_postion_angle) {
ui->texture_viewer->rotate(-5);
slider_postion_angle-=1;
}
QString info = QString::number(value*5)+ "°";
ui->angle_status->setText(info);
}
void MainWindow::on_multiplication_slider_valueChanged(int value)
{
scene->clear();
/*
QPixmap cache_for_picture(0, 0);
scene->addPixmap(cache_for_picture);
ui->texture_viewer->setScene(scene);
ui->texture_viewer->fitInView(ui->texture_viewer->sceneRect(), Qt::KeepAspectRatio);
*/
create_picture(sizes_of_images.at(value));
//reset_parametrs_to_default();
scene->addPixmap(current_picture);
ui->texture_viewer->setScene(&*scene);
ui->texture_viewer->viewport()->repaint();
ui->texture_viewer->fitInView(ui->texture_viewer->sceneRect(), Qt::KeepAspectRatio);
//scene->setSceneRect(0,0,ui->texture_viewer->frameSize().width(),ui->texture_viewer->frameSize().height());
QString info = QString::number(sizes_of_images.at(value)) + "x" + QString::number(sizes_of_images.at(value));
ui->multiplication_status->setText(info);
//ui->texture_viewer->setTransform(QTransform());
}