-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cpp
108 lines (87 loc) · 2.9 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <MainWindow.h>
#include <QAction>
#include <QActionGroup>
#include <QMenu>
#include <QToolBar>
#include <QMenuBar>
#include <QDialog>
#include <QColorDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowIcon(QIcon(":/images/paint.png"));
CreateActions();
m_paintwidget = new PaintWidget(this);
setCentralWidget(m_paintwidget);
}
MainWindow::~MainWindow()
{
}
void MainWindow::CreateActions()
{
paintmodeGroup = new QActionGroup(this);
paintmodeGroup->setExclusive(true);
FreehandAct = new QAction(paintmodeGroup);
FreehandAct->setIcon(QIcon(":/images/freehand.png"));
connect(FreehandAct, SIGNAL(triggered()), this, SLOT(on_freehandtriggered()));
LineAct = new QAction(paintmodeGroup);
LineAct->setIcon(QIcon(":/images/line2.png"));
connect(LineAct,SIGNAL(triggered()),this,SLOT(on_linetriggered()));
RectAct = new QAction(paintmodeGroup);
RectAct->setIcon(QIcon(":/images/rect1.png"));
connect(RectAct, SIGNAL(triggered()), this, SLOT(on_recttriggered()));
EllipseAct = new QAction(paintmodeGroup);
EllipseAct->setIcon(QIcon(":/images/ellipse1.png"));
connect(EllipseAct, SIGNAL(triggered()), this, SLOT(on_ellipsetriggered()));
PolygonAct = new QAction(paintmodeGroup);
PolygonAct->setIcon(QIcon(":/images/polygon1.png"));
connect(PolygonAct, SIGNAL(triggered()), this, SLOT(on_polygontriggered()));
LineAct->setChecked(true);
selectcolorAct = new QAction(this);
selectcolorAct->setIcon(QIcon(":/images/color2.png"));
connect(selectcolorAct, SIGNAL(triggered()), this, SLOT(on_selectcolorAct()));
/*paintmodeGroup->addAction(LineAct);
paintmodeGroup->addAction(RectAct);
paintmodeGroup->addAction(EllipseAct);*/
paintmodeMenu = new QMenu(QStringLiteral("ÐÎ×´"),this);
paintmodeMenu->addAction(FreehandAct);
paintmodeMenu->addAction(LineAct);
paintmodeMenu->addAction(RectAct);
paintmodeMenu->addAction(EllipseAct);
paintmodeMenu->addAction(PolygonAct);
menuBar()->addMenu(paintmodeMenu);
paintmodeBar = addToolBar(QStringLiteral("ÐÎ×´"));
paintmodeBar->addAction(FreehandAct);
paintmodeBar->addAction(LineAct);
paintmodeBar->addAction(RectAct);
paintmodeBar->addAction(EllipseAct);
paintmodeBar->addAction(PolygonAct);
colorBar = addToolBar(QStringLiteral("ÑÕÉ«"));
colorBar->addAction(selectcolorAct);
}
void MainWindow::on_freehandtriggered()
{
m_paintwidget->setPaintMode(CFREEHAND);
}
void MainWindow::on_linetriggered()
{
m_paintwidget->setPaintMode(CLINE);
}
void MainWindow::on_recttriggered()
{
m_paintwidget->setPaintMode(CRECT);
}
void MainWindow::on_ellipsetriggered()
{
m_paintwidget->setPaintMode(CELLIPSE);
}
void MainWindow::on_polygontriggered()
{
m_paintwidget->setPaintMode(CPOLYGON);
}
void MainWindow::on_selectcolorAct()
{
QColor color = QColorDialog::getColor(Qt::red, this, QStringLiteral("Ñ¡ÔñÑÕÉ«"));
m_paintstyle = paintstyle(color.red(), color.green(), color.blue(), m_paintstyle.w());
m_paintwidget->setPaintStyle(m_paintstyle);
}