-
Notifications
You must be signed in to change notification settings - Fork 11
/
screenshots.h
95 lines (82 loc) · 3.69 KB
/
screenshots.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
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2020-2024 XMuli
// SPDX-GitHub: https://github.com/XMuli/shotx
// SPDX-Author: XMuli <xmulitech@gmail.com>
#ifndef SCREENSHOTS_H
#define SCREENSHOTS_H
#include "systeminfo.h"
#include <QPoint>
#include <QWidget>
static const int g_width = 4; // 灵敏度调节 [且便于测试]
enum ScreenType {
Select = 0x0001, // 选择截图矩形
Move = 0x0002, // 移动矩形区域
SetSize = 0x0004 // 设置矩形大小
};
Q_DECLARE_FLAGS(ScreenTypes, ScreenType) // 枚举 ScreenType 生成宏 ScreenTypes
Q_DECLARE_OPERATORS_FOR_FLAGS(ScreenTypes) // 重载宏 ScreenTypes 的 |() 函数
enum PosType {
Contains, // 点在矩形内部
Cross, // 点在矩形线上
External, // 点在矩形外部
Other // 未知
};
enum PosArrow { // 鼠标在线框时候的方向枚举
Top,
Bottom,
Left,
Right,
TopLeft,
TopRight,
BottomLeft,
BottomRight,
UnKnown
};
class ToolBoxWindow;
class ScreenShots : public QWidget
{
Q_OBJECT
public:
~ScreenShots();
static ScreenShots *instances();
void init();
QRect setCurrRect(); // 判断当前矩形的大小
PosType isInArea(QPoint pos, int width = g_width); // 判断鼠标是否在截图矩形之中
bool DectionAndSetMouseTracking(bool b = false); // 检测并且开启鼠标跟踪
QRect rootRect();
QRect baseRect();
QPixmap savePixmap();
private:
ScreenShots(); // 构造函数为私有
QPoint offset(); // 偏移量(m_moveEndPos - m_moveStaPos)
void updateCursor(QPoint pos, int width = 0); // 依据光标和矩形所处的位置,刷新鼠标形状
const QPixmap *pixmap();
const QPixmap *basePixmap(); // 背景图
void drawScreenRect(QRect &rect, QPainter &pa); // 绘画截图黑白线框
void drawAnchor(QPainter &pa, bool b = true, int r = g_width); // 绘画线框的八个锚点
PosArrow posArrow(QPoint pos, int width = g_width);
protected:
void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
private:
bool m_mouseTracking; // 鼠标跟踪是否开启标志
bool m_cursor; // 鼠标样式是否修改标志
QRect m_rect; // 截图矩形框大小(前台)
QPoint m_staPos;
QPoint m_endPos;
QPoint m_moveStaPos;
QPoint m_moveEndPos;
QPoint m_sizeStaPos;
QPoint m_sizeEndPos;
QPoint m_translate; // 快捷键移动矩形位置
QMargins m_sizeMargins; // 快捷键调整矩形大小
ScreenTypes m_screenType;
QPixmap *m_pixmap; // 原图
QPixmap *m_basePixmap; // 背景图(= 原图 + 灰色)
SystemInfo *m_sysInfo; // 物理屏幕基础信息
ToolBoxWindow *m_toolBox; // 修改截图的工具箱
};
#endif // SCREENSHOTS_H