-
Notifications
You must be signed in to change notification settings - Fork 1
/
capturescreen.h
87 lines (75 loc) · 2.33 KB
/
capturescreen.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
#ifndef CAPTURESCREEN_H
#define CAPTURESCREEN_H
#include <QWidget>
#include <QPainter>
enum CaptureState{
InitCapture = 0,
BeginCaptureImage,
FinishCaptureImage,
BeginMoveCaptureArea,
FinishMoveCaptureArea,
BeginMoveStretchRect,
FinishMoveStretchRect
}; //进行截屏的状态;
enum StretchRectState{
NotSelect = 0,
TopLeftRect,
TopRightRect,
BottomLeftRect,
BottomRightRect,
LeftCenterRect,
TopCenterRect,
RightCenterRect,
BottomCenterRect
};// 当前鼠标所在顶点状态;
class CaptureScreen : public QWidget
{
Q_OBJECT
public:
explicit CaptureScreen(QWidget *parent = nullptr);
~CaptureScreen();
signals:
// 通知截图完毕,并将截取图片传递给调用类;
void signalCompleteCature(QPixmap catureImage);
private:
void initWindow();
void initStretchRect();
void loadBackgroundPixmap();
QRect getRect(const QPoint &beginPoint, const QPoint &endPoint);
QRect getMoveRect();
QRect getStretchRect();
bool isPressPointInSelectRect(QPoint mousePressPoint);
QRect getSelectRect();
QPoint getMovePoint();
StretchRectState getStrethRectState(QPoint point);
void setStretchCursorStyle(StretchRectState stretchRectState);
void drawCaptureImage();
void drawStretchRect();
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void paintEvent(QPaintEvent *event);
private slots:
void onSaveScreen(); //保存至剪切板
void onCompleteShot();
private:
QPixmap m_loadPixmap, m_capturePixmap;
int m_screenwidth;
int m_screenheight;
// 保存确定选区的坐标点;
QPoint m_beginPoint, m_endPoint, m_beginMovePoint, m_endMovePoint;
QPainter m_painter;
// 保存当前截图状态;
CaptureState m_currentCaptureState;
// 当前选择区域矩形;
QRect m_currentSelectRect;
// 选中矩形8个顶点小矩形;
QRect m_topLeftRect, m_topRightRect, m_bottomLeftRect, m_bottomRightRect;
QRect m_leftCenterRect, m_topCenterRect, m_rightCenterRect, m_bottomCenterRect;
// 当前鼠标所在顶点状态;
StretchRectState m_stretchRectState;
protected:
virtual void contextMenuEvent(QContextMenuEvent *event);
};
#endif // CAPTURESCREEN_H