qt/LedOK/oescreenshot/oescreenshot.h

509 lines
12 KiB
C
Raw Normal View History

2022-01-04 18:11:48 +08:00
/**
* @author :
* @date : 201704
* @version: 1.0
* @note : Apache 2.0 ;
* 使
* @remarks:
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*
*
* https://git.oschina.net/Mr_ChenLuYong/screenshot
*
*
*
*
*
*
* http://blog.csdn.net/csnd_ayo
*
* http://blog.csdn.net/csnd_ayo/article/details/70197915
*
* BugIssues
*
*/
#ifndef OESCREENSHOT_H
#define OESCREENSHOT_H
#include <memory>
#include <QRect>
#include <QWidget>
class OEScreen;
class OERect;
class OEAmplifier;
class QTimer;
class QMenu;
/**
* @class : OEScreenshot
* @brief : ,
* ,.
* @remark: ( OEScreenshot::Instance(); )
*/
class OEScreenshot : public QWidget {
Q_OBJECT
signals:
/**
* @brief :
* @param : int x轴的坐标
* @param : int y轴的坐标
* @date : 20170418
*/
void cursorPosChange(int, int);
/**
* @brief :
* @date : 20170418
*/
void doubleClick(void);
/**
* @brief :
* @param : QRect
* @date : 20170418
*/
void findChildWind(QRect);
public:
/**
* @brief :
* @note :
* @date : 20170416
*/
explicit OEScreenshot(QWidget *parent = 0);
~OEScreenshot(void);
/**
* @brief :
* @note :
* @return: OEScreenshot
* @date : 20170415
*/
static OEScreenshot *Instance(void);
/**
* @brief :
* @note :
* @date : 20170430
*/
static void destroy(void);
protected:
/**
* @brief :
*/
virtual void hideEvent(QHideEvent *);
/**
* @brief :
*/
virtual void closeEvent(QCloseEvent *);
/**
* @brief :
*/
virtual void mouseDoubleClickEvent(QMouseEvent*);
/**
* @brief :
*/
virtual void mousePressEvent(QMouseEvent *);
/**
* @brief :
*/
virtual void mouseReleaseEvent(QMouseEvent *e);
/**
* @brief :
*/
virtual void mouseMoveEvent(QMouseEvent *e);
/**
* @brief :
*/
virtual void keyPressEvent(QKeyEvent *e);
/**
* @brief :
*/
virtual void paintEvent(QPaintEvent *);
/**
* @brief :
*/
void updateMouse(void);
private:
/**
* @brief : ()
* @note :
* @param : originPainting originPainting_原画
* @date : 20170415
* @remark: getGlobalScreen
*/
void initAmplifier(std::shared_ptr<QPixmap> originPainting = nullptr);
/**
* @brief : ()
* @date : 20170427
*/
void initMeasureWidget(void);
/**
* @brief :
* @return: QPixmap
* @date : 20170415
*/
std::shared_ptr<QPixmap> initGlobalScreen(void);
/**
* @brief :
* @note :
* @param : ico
* @date : 20170415
* @remark: 使Logo
*/
void initCursor(const QString& ico = "");
/**
* @brief :
* @note :
* @param : pos
* @date : 20170416
* @remark: ()
*/
std::shared_ptr<OEScreen> createScreen(const QPoint &pos);
/**
* @brief :
* @note :
* @date : 20170416
*/
void destroyScreen(void);
/**
* @brief :
* @note : QRect-1920, 0, 3840, 1080
* @return: QRect
* @date : 20170415
*/
const QRect& getScreenRect(void);
/**
* @brief :
* @note :
* @return: QPixmap*
* @date : 20170415
* @remark:
*/
std::shared_ptr<QPixmap> getGlobalScreen(void);
private:
/// 截屏窗口是否已经展示
bool isLeftPressed_;
/// 用于检测误操作
QPoint startPoint_;
/// 当前桌面屏幕的矩形数据
QRect desktopRect_;
/// 屏幕暗色背景图
std::shared_ptr<QPixmap> backgroundScreen_;
/// 屏幕原画
std::shared_ptr<QPixmap> originPainting_;
/// 截图屏幕
std::shared_ptr<OEScreen> screenTool_;
/// 截图器大小感知器
std::shared_ptr<OERect> rectTool_;
/// 放大取色器
std::shared_ptr<OEAmplifier> amplifierTool_;
/// 当前鼠标选区最小的矩形窗口
QRect windowRect_;
/// 截屏实例对象
static OEScreenshot *self_;
/// 置顶定时器
QTimer* egoisticTimer_;
/// 活动窗口
static bool isActivity_;
private slots:
/**
* @brief : Window下霸道置顶
* @date : 20170428
* @remark: 使使BUG
*/
void onEgoistic(void);
};
/**
* @class : OERect
* @brief :
* @note :
*/
class OERect : public QWidget {
Q_OBJECT
signals:
public:
explicit OERect(QWidget *parent = 0);
protected:
/**
* @brief :
*/
void paintEvent(QPaintEvent *);
public slots:
/**
* @brief :
* @note :
* @param : x
* @param : y
* @date : 20170415
*/
void onPostionChange(int x, int y);
/**
* @brief :
* @note :
* @param : w
* @param : h
* @date : 20170415
*/
void onSizeChange(int w, int h);
private:
/// 背景色
std::shared_ptr<QPixmap> backgroundPixmap_;
/// 显示的文字信息
QString info_;
};
/**
* @class : OEScreen
* @brief :
* @note :
*/
class OEScreen : public QWidget {
Q_OBJECT
signals:
/**
* @brief :
* @param : int
* @param : int
* @date : 20170417
*/
void sizeChange(int,int);
/**
* @brief :
* @param : int
* @param : int
* @date : 20170417
*/
void postionChange(int,int);
/**
* @brief :
* @date : 20170417
*/
void doubleClick(void);
protected:
/// 内边距,决定拖拽的触发。
const int PADDING_ = 6;
/// 方位枚举
enum DIRECTION {
UPPER=0,
LOWER=1,
LEFT,
RIGHT,
LEFTUPPER,
LEFTLOWER,
RIGHTLOWER,
RIGHTUPPER,
NONE
};
public:
explicit OEScreen(std::shared_ptr<QPixmap> originPainting, QPoint pos, QWidget *parent = 0);
~OEScreen() { isInit_ = false; }
/**
* @brief :
* @return: true :
* @date : 20170417
*/
static bool state(void) { return isInit_; }
protected:
/**
* @brief :
* @param : cursor
* @return: DIRECTION
* @date : 20170417
*/
DIRECTION getRegion(const QPoint &cursor);
/**
* @brief :
*/
virtual void contextMenuEvent(QContextMenuEvent *);
/**
* @brief :
*/
virtual void mouseDoubleClickEvent(QMouseEvent *e);
/**
* @brief :
*/
virtual void mousePressEvent(QMouseEvent *e);
/**
* @brief :
*/
virtual void mouseReleaseEvent(QMouseEvent *e);
/**
* @brief :
*/
virtual void mouseMoveEvent(QMouseEvent *e);
/**
* @brief :
*/
virtual void moveEvent(QMoveEvent *);
/**
* @brief :
*/
virtual void resizeEvent(QResizeEvent *);
/**
* @brief :
*/
virtual void showEvent(QShowEvent *);
/**
* @brief :
*/
virtual void hideEvent(QHideEvent *);
/**
* @brief :
*/
virtual void enterEvent(QEvent *e);
/**
* @brief :
*/
virtual void leaveEvent(QEvent *e);
/**
* @brief :
*/
virtual void closeEvent(QCloseEvent *);
/**
* @brief :
*/
virtual void paintEvent(QPaintEvent *);
private:
/**
* @brief :
* @return: QString
* @date : 20170416
*/
virtual const QString getFileName(void);
public slots:
/**
* @brief :
* @param : x
* @param : y
* @date : 20170416
*/
void onMouseChange(int x,int y);
/**
* @brief :
* @date : 20170416
*/
void onSaveScreen(void);
protected slots:
/**
* @brief :
* @note :
* @date : 20170416
*/
void onSaveScreenOther(void);
/**
* @brief : 退
* @date : 20170416
*/
void quitScreenshot(void);
private:
/// 是否已经设置初始大小
static bool isInit_;
/// 窗口大小改变时,记录改变方向
DIRECTION direction_;
/// 起点
QPoint originPoint_;
/// 鼠标是否按下
bool isPressed_;
/// 拖动的距离
QPoint movePos_;
/// 标记锚点
QPolygon listMarker_;
/// 屏幕原画
std::shared_ptr<QPixmap> originPainting_;
/// 当前窗口几何数据 用于绘制截图区域
QRect currentRect_;
/// 右键菜单对象
QMenu *menu_;
};
#endif /// OESCREENSHOT_H