Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
176 lines (122 loc) · 4.25 KB
/
Copy pathmainwindow.cpp
File metadata and controls
176 lines (122 loc) · 4.25 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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QInputDialog>
#include <QDebug>
#include <iostream>
#include <QFileDialog>
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::on_actionNew_triggered() {
QMainWindow *newWindow = new QMainWindow(this);
newWindow->show();
}
void MainWindow::on_actionSave_as_Image_triggered() {
QString filePath = QFileDialog::getSaveFileName(this, tr("Save Image"), "", tr("PNG Image (*.png);;All Files (*)"));
if (!filePath.isEmpty()) {
QSize imageSize = ui->widget->size();
QPixmap widgetPixmap = ui->widget->renderPixmap();
QPixmap backgroundPixmap(imageSize);
backgroundPixmap.fill(Qt::black);
QPainter painter(&backgroundPixmap);
painter.drawPixmap(0, 0, widgetPixmap);
backgroundPixmap.save(filePath);
qDebug() << "Image saved to: " << filePath;
} else {
qDebug() << "Image save canceled.";
}
}
void MainWindow::on_actionQuit_triggered() {
QCoreApplication::quit();
}
void MainWindow::on_actionAbout_Me_triggered() {
QMessageBox aboutMeBox;
aboutMeBox.setWindowTitle("About Painty");
aboutMeBox.setText("<h3>Painty</h3>"
"<p>Here's a little drawing tool.<br> This was a good exercise to learn more.</p><br>"
"GitHub: <a href=\"https://github.com/daninouai\">daninouai</a><br>"
"Website: <a href=\"https://danirahimi.ir\">danirahimi.ir</a>");
aboutMeBox.setStandardButtons(QMessageBox::Ok);
aboutMeBox.exec();
}
void MainWindow::on_colorWhite_clicked() {
GLWidget glWidget;
glWidget.changeColor(1.0, 1.0, 1.0);
}
void MainWindow::on_colorBlack_clicked() {
GLWidget glWidget;
glWidget.changeColor(0.0, 0.0, 0.0);
}
void MainWindow::on_colorRed_clicked() {
GLWidget glWidget;
glWidget.changeColor(1.0, 0.0, 0.0);
}
void MainWindow::on_colorGreen_clicked() {
GLWidget glWidget;
glWidget.changeColor(0.0, 1.0, 0.0);
}
void MainWindow::on_colorPurple_clicked() {
GLWidget glWidget;
glWidget.changeColor(1.0, 0.0, 1.0);
}
void MainWindow::on_colorBlue_clicked() {
GLWidget glWidget;
glWidget.changeColor(0.0, 0.0, 1.0);
}
void MainWindow::on_toolCircle_clicked() {
GLWidget glWidget;
glWidget.chanageMode(false, true, false, false, false, false, false, false);
}
void MainWindow::on_toolPen_clicked() {
GLWidget glWidget;
glWidget.chanageMode(true, false, false, false, false, false, false, false);
}
void MainWindow::on_fontSize_valueChanged(int arg1) {
GLWidget glWidget;
glWidget.changeFontSize(arg1);
}
void MainWindow::on_toolSquare_clicked() {
GLWidget glWidget;
glWidget.chanageMode(false, false, true, false, false, false, false, false);
}
void MainWindow::on_toolLine_clicked() {
GLWidget glWidget;
glWidget.chanageMode(false, false, false, true, false, false, false, false);
}
void MainWindow::on_toolEraser_clicked() {
GLWidget glWidget;
glWidget.chanageMode(false, false, false, false, true, false, false, false);
}
void MainWindow::on_toolSpray_clicked() {
GLWidget glWidget;
glWidget.chanageMode(false, false, false, false, false, true, false, false);
}
void MainWindow::on_toolText_clicked() {
GLWidget glWidget;
glWidget.chanageMode(false, false, false, false, false, false, true, false);
}
void MainWindow::on_toolSelection_clicked() {
GLWidget glWidget;
glWidget.chanageMode(false, false, false, false, false, false, false, true);
}
void MainWindow::on_actionExport_as_Json_triggered() {
GLWidget glWidget;
QString filePath = QFileDialog::getSaveFileName(this, tr("Export File"), "",
tr("Json Format (*.json);;All Files (*)"));
if (!filePath.isEmpty()) {
glWidget.SaveExportFile(filePath.toStdString());
}
}
void MainWindow::on_actionImport_triggered() {
GLWidget glWidget;
QString filePath = QFileDialog::getOpenFileName(this, tr("Import File"), "", tr("Json Format (*.json);"));
if (!filePath.isEmpty()) {
glWidget.ImportFile(filePath.toStdString());
}
}