-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadaptink.cpp
More file actions
124 lines (100 loc) · 3.2 KB
/
adaptink.cpp
File metadata and controls
124 lines (100 loc) · 3.2 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
#include <QColorDialog>
#include <QFileDialog>
#include <QMessageBox>
#include <QSpinBox>
#include <QAction>
#include <adaptink.hpp>
#include <ui_adaptink.h>
#include <dcanvas.hpp>
Adaptink::Adaptink(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::Adaptink),
m_current_file_name()
{
m_ui->setupUi(this);
QSpinBox* tool_size_spin_box = new QSpinBox();
tool_size_spin_box->setValue(5);
m_ui->dcanvas->front->setToolSize(5);
m_ui->toolBarContextual->insertWidget(new QAction, tool_size_spin_box);
connect(tool_size_spin_box, SIGNAL(valueChanged(int)), m_ui->dcanvas->front, SLOT(setToolSize(int)));
}
Adaptink::~Adaptink() {
delete m_ui;
}
void Adaptink::on_actionQuit_triggered() {
QCoreApplication::quit();
}
void Adaptink::on_actionNew_triggered() {
QApplication::instance()->exit(RESTART_EXIT_STATUS);
}
void Adaptink::on_actionOpen_triggered() {
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open file"),
QString(),
tr("All files (*);;JPEG image (*.jpg *.jpeg *.jpe);;PNG image (*.png);;Windows BMP image (*.bmp)"));
if (!fileName.isEmpty()) {
QPixmap pixmap;
if (!pixmap.load(fileName)) {
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;
}
m_ui->dcanvas->front->setPixmap(pixmap);
m_ui->dcanvas->front->repaint();
m_current_file_name = fileName;
}
}
void Adaptink::on_actionExport_triggered() {
if (m_current_file_name.isEmpty()) {
on_actionExportAs_triggered();
} else {
exportCanvas();
}
}
void Adaptink::on_actionExportAs_triggered() {
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save file as"),
QString(),
tr("All files (*);;JPEG image (*.jpg *.jpeg *.jpe);;PNG image (*.png);;Windows BMP image (*.bmp)"));
if (!fileName.isEmpty()) {
m_current_file_name = fileName;
exportCanvas();
}
}
void Adaptink::on_actionChangeColor_triggered() {
QColor color = QColorDialog::getColor(Qt::white, nullptr, tr("Pick a color"), QColorDialog::ShowAlphaChannel);
if (color != QColor::Invalid) {
m_ui->dcanvas->front->setPaintColor(color);
}
}
void Adaptink::on_actionToolPencil_triggered() {
m_ui->dcanvas->front->setTool(Pencil);
}
void Adaptink::on_actionToolBrush_triggered() {
m_ui->dcanvas->front->setTool(Paintbrush);
}
void Adaptink::on_actionToolLabel_triggered() {
m_ui->dcanvas->front->setTool(Label);
}
void Adaptink::on_actionRubber_triggered() {
m_ui->dcanvas->front->setTool(Rubber);
}
void Adaptink::on_actionSet_Background_color_triggered() {
QColor color = QColorDialog::getColor(Qt::white, nullptr, tr("Pick a color"), QColorDialog::ShowAlphaChannel);
if (color != QColor::Invalid) {
m_ui->dcanvas->background->setPalette(QPalette(color));
}
}
// === private ===
void Adaptink::exportCanvas() {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("Save with background?"), tr("Save with background?"), QMessageBox::Yes | QMessageBox::No);
bool success;
if (reply == QMessageBox::Yes) {
success = m_ui->dcanvas->grab().save(m_current_file_name);
} else {
success = m_ui->dcanvas->front->grab().save(m_current_file_name);
}
if (!success) {
QMessageBox::critical(this, tr("Error"), tr("Could not save file"));
}
}