FluentUI/src/Screenshot.h

75 lines
1.9 KiB
C
Raw Normal View History

2023-08-16 18:05:49 +08:00
#ifndef SCREENSHOT_H
#define SCREENSHOT_H
#include <QQuickItem>
#include <QQuickPaintedItem>
#include <QPainter>
2023-08-17 17:14:31 +08:00
#include <QQuickItemGrabResult>
2023-08-16 18:05:49 +08:00
#include "stdafx.h"
2023-08-30 18:44:07 +08:00
#include <qmath.h>
class DrawData:public QObject{
Q_OBJECT;
public:
explicit DrawData(QObject *parent = nullptr): QObject{parent}{};
int drawType;
int lineWidth;
QPoint start;
QPoint end;
Q_INVOKABLE int getLineWidth(){
return lineWidth;
}
Q_INVOKABLE int getWidth(){
return end.x()-start.x();
}
Q_INVOKABLE int getHeight(){
return end.y()-start.y();
}
};
2023-08-16 18:05:49 +08:00
2023-08-16 23:25:52 +08:00
class ScreenshotBackground : public QQuickPaintedItem
{
Q_OBJECT;
QML_NAMED_ELEMENT(ScreenshotBackground)
2023-08-17 23:03:00 +08:00
Q_PROPERTY_AUTO(QString,saveFolder);
2023-08-17 22:06:26 +08:00
Q_PROPERTY_AUTO(int,captureMode);
2023-08-30 18:44:07 +08:00
Q_PROPERTY_AUTO(DrawData*,hitDrawData);
2023-08-16 23:25:52 +08:00
public:
ScreenshotBackground(QQuickItem* parent = nullptr);
void paint(QPainter* painter) override;
2023-08-17 17:14:31 +08:00
Q_INVOKABLE void capture(const QPoint& start,const QPoint& end);
2023-08-30 18:44:07 +08:00
Q_INVOKABLE DrawData* appendDrawData(int drawType,QPoint start,QPoint end);
Q_INVOKABLE void updateDrawData(DrawData* data,QPoint start,QPoint end);
Q_INVOKABLE void clear();
Q_INVOKABLE DrawData* hit(const QPoint& point);
2023-08-17 22:06:26 +08:00
Q_SIGNAL void captrueToPixmapCompleted(QPixmap captrue);
Q_SIGNAL void captrueToFileCompleted(QUrl captrue);
2023-08-16 23:25:52 +08:00
private:
QRect _desktopGeometry;
QPixmap _desktopPixmap;
2023-08-17 19:09:56 +08:00
QPixmap _sourcePixmap;
2023-08-17 17:14:31 +08:00
qreal _devicePixelRatio;
QSharedPointer<QQuickItemGrabResult> _grabResult;
QRect _captureRect;
2023-08-30 18:44:07 +08:00
QList<DrawData*> _drawList;
int mouseSpacing = 3;
2023-08-16 23:25:52 +08:00
};
2023-08-16 18:05:49 +08:00
class Screenshot : public QQuickPaintedItem
{
Q_OBJECT
QML_NAMED_ELEMENT(Screenshot)
Q_PROPERTY_AUTO(QPoint,start);
Q_PROPERTY_AUTO(QPoint,end);
2023-08-16 22:23:58 +08:00
Q_PROPERTY_AUTO(QColor,maskColor);
2023-08-16 18:05:49 +08:00
public:
Screenshot(QQuickItem* parent = nullptr);
void paint(QPainter* painter) override;
private:
QRect _desktopGeometry;
};
#endif // SCREENSHOT_H