This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
canvas.h
151 lines (113 loc) · 3.34 KB
/
canvas.h
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
#ifndef CANVAS_H
#define CANVAS_H
/*
* Author:qiuzhiqian
* Email:[email protected]
* Github:https://github.com/qiuzhiqian
* Date:2017.07.23
**/
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QMouseEvent>
#include <QPainter>
#include <QPaintEvent>
#include <QDesktopWidget>
#include <QScreen>
#include <QPixmap>
#include <QGuiApplication>
#include <QPen>
#include <QApplication>
#include <QPushButton>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QClipboard>
#include <QComboBox>
#include <QColorDialog>
#include <QFontDialog>
#include "linepaint.h"
#include "rectpaint.h"
#include "textpaint.h"
enum DrawStatus {
waitDraw=0,
drawing,
drawed,
};
class Canvas : public QWidget
{
Q_OBJECT
public:
explicit Canvas(QWidget *parent = 0);
void setbgPixmap(QPixmap &px);
void shootScreen(QRectF &rect);
void canvasInit();
void initToolBar();
void showToolBar();
void hideToolBar();
void refrashToolBar();
//void initShapeToolBar();
//void showShapeToolBar();
//void hideShapeToolBar();
//void initShapeToolBar();
//void showShapeToolBar();
//void hideShapeToolBar();
quint8 caputerRect(QRectF t_rect,qreal t_x,qreal t_y);
RectPaint getRectF(QPointF p1,QPointF p2); //通过两个坐标点生成矩形
void changeLanguage(QString lan);
signals:
public slots:
void slt_drawLine();
void slt_drawRect();
void slt_drawEllipse();
void slt_drawText();
void slt_saveFile(); //保存到文件
void slt_saveClipboard(); //保存到剪切板
void slt_cancel();
void slt_changePenWidth(QString s);
void slt_changePenColor();
void slt_changePenStyle(int index);
void slt_changeTextColor();
void slt_changeTextFont();
private:
int screen_width=0,screen_height=0;
quint8 okFlag=0;
QPointF pointS; //鼠标绘制起点
QPointF pointE; //鼠标绘制终点
RectPaint shotArea; //截图区域
QList<LinePaint> lineList; //直线列表
QList<RectPaint> rectList; //矩形列表
QList<RectPaint> ellipseList; //椭圆列表
QList<TextPaint *> textList; //文本列表
QPointF pointDrag; //拖拽点
DrawStatus rectFlag=DrawStatus::waitDraw;
quint8 drawEditFlag=0; //绘图修改
QPixmap fullPixmap; //原始全屏图片
QPixmap originalPixmap;
QWidget *toolbar; //工具条
QPushButton *btn_saveFile;
QPushButton *btn_saveClipboard;
QPushButton *btn_cancel;
QPushButton *btn_drawLine; //画直线
QPushButton *btn_drawRect; //画矩形
QPushButton *btn_drawEllipse; //画椭圆
QPushButton *btn_drawText; //添加文本
QPen drawPen; //线宽颜色风格
QWidget *shapeToolBar;
QWidget *textToolBar;
int toolBarWidth;
int toolBarHeight;
QComboBox *cbx_lineSize;
QPushButton *btn_colorSelect;
QComboBox *cbx_lineStyle;
QPushButton *btn_colorText;
QPushButton *btn_FontText;
QColor textcolor;
QFont textfont;
QClipboard *clipboard;
quint8 cursorCaptureFlag=0;
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *e);
};
#endif // CANVAS_H