-
Notifications
You must be signed in to change notification settings - Fork 0
/
vemainwindow.cpp
124 lines (112 loc) · 4.9 KB
/
vemainwindow.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
#include "vemainwindow.h"
#include "ui_vemainwindow.h"
VEMainWindow::VEMainWindow(QWidget *parent)
: QWidget(parent)
, ui(new Ui::VEMainWindow)
{
ui->setupUi(this);
toolsGroup_ = new QButtonGroup;
toolsGroup_->addButton(ui->toolBtnSelect);
toolsGroup_->setId(ui->toolBtnSelect, VeCanvas::TOOL_SEL_MOVE_TRANS);
toolsGroup_->addButton(ui->toolBtnPLine);
toolsGroup_->setId(ui->toolBtnPLine, VeCanvas::TOOL_DRAW_POLY_LINE);
toolsGroup_->addButton(ui->toolBtnRect);
toolsGroup_->setId(ui->toolBtnRect, VeCanvas::TOOL_DRAW_RECTANGLE);
toolsGroup_->exclusive();
ui->toolBtnSelect->setChecked(true);
foreach (QAbstractButton *tool_btn, toolsGroup_->buttons()) {
connect(tool_btn, SIGNAL(clicked()), this, SLOT(slotForToolBtn_clicked()));
}
ui->pushBtnBrushColor->setStyleSheet("border: 2px solid black;"
"border-radius: 0px;"
"background-color: transparent;");
ui->pushBtnPenColor->setStyleSheet("border: 1px solid black;"
"border-radius: 0px;"
"background-color: black;");
scene_ = new VeCanvas(this);
scene_->setSceneRect(ui->graphicsView->rect());
connect(scene_, SIGNAL(itemSelected(const VeShapeItem *)), this, SLOT(slotForVEShapeItem_selected(const VeShapeItem *)));
ui->graphicsView->setScene(scene_);
}
VEMainWindow::~VEMainWindow()
{
delete ui;
}
void VEMainWindow::slotForToolBtn_clicked()
{
scene_->setCurrentTool(toolsGroup_->checkedId());
switch (toolsGroup_->checkedId()) {
case VeCanvas::TOOL_SEL_MOVE_TRANS: {
ui->graphicsView->setCursor(Qt::ArrowCursor);
break;
}
case VeCanvas::TOOL_DRAW_RECTANGLE:
case VeCanvas::TOOL_DRAW_POLY_LINE: {
ui->graphicsView->setCursor(Qt::CrossCursor);
break;
}
default: {
ui->graphicsView->setCursor(Qt::ArrowCursor);
break;
}
}
}
void VEMainWindow::slotForVEShapeItem_selected(const VeShapeItem *p_item)
{
if (p_item) {
ui->pushBtnBrushColor->setStyleSheet("border: 2px solid " + p_item->pen().color().name(QColor::HexArgb) + ";"
"border-radius: 0px;"
"background-color: " + p_item->brush().color().name(QColor::HexArgb) + ";");
ui->pushBtnPenColor->setStyleSheet("border: 1px solid #000000;"
"border-radius: 0px;"
"background-color: " + p_item->pen().color().name(QColor::HexArgb) + ";");
ui->spinBoxPenWidth->setValue(p_item->pen().width());
}
}
void VEMainWindow::on_pushBtnBrushColor_clicked()
{
QBrush new_brush = scene_->getCurrentBrush();
QColor selected_color = QColorDialog::getColor(new_brush.color(), this, tr("Select Color"), QColorDialog::ShowAlphaChannel);
if (selected_color.isValid()) {
new_brush.setColor(selected_color);
scene_->setCurrentBrush(new_brush);
ui->pushBtnBrushColor->setStyleSheet("border: 2px solid " + scene_->getCurrentPen().color().name(QColor::HexArgb) + ";"
"border-radius: 0px;"
"background-color: " + selected_color.name(QColor::HexArgb) + ";");
}
}
void VEMainWindow::on_spinBoxPenWidth_valueChanged(int arg1)
{
QPen new_pen = scene_->getCurrentPen();
new_pen.setWidth(arg1);
scene_->setCurrentPen(new_pen);
}
void VEMainWindow::on_pushBtnSave_clicked()
{
QString file_path = QFileDialog::getSaveFileName(this, tr("Save SVG"), "", tr("SVG files (*.svg)"));
if (!file_path.isEmpty()){
scene_->saveToSVG(file_path);
}
}
void VEMainWindow::on_pushBtnLoad_clicked()
{
QString file_path = QFileDialog::getOpenFileName(this, tr("Open SVG"), "", tr("SVG files (*.svg)"));
if (!file_path.isEmpty()){
scene_->loadFromSVG(file_path);
}
}
void VEMainWindow::on_pushBtnPenColor_clicked()
{
QPen new_pen = scene_->getCurrentPen();
QColor selected_color = QColorDialog::getColor(new_pen.color(), this, tr("Select Color"), QColorDialog::ShowAlphaChannel);
if (selected_color.isValid()) {
new_pen.setColor(selected_color);
scene_->setCurrentPen(new_pen);
ui->pushBtnPenColor->setStyleSheet("border: 1px solid #000000;"
"border-radius: 0px;"
"background-color: " + selected_color.name(QColor::HexArgb) + ";");
ui->pushBtnBrushColor->setStyleSheet("border: 2px solid " + selected_color.name(QColor::HexArgb) + ";"
"border-radius: 0px;"
"background-color: " + scene_->getCurrentBrush().color().name(QColor::HexArgb) + ";");
}
}