This commit is contained in:
朱子楚\zhuzi 2023-08-16 23:25:52 +08:00
parent 736c19c41e
commit 2d492ceb95
4 changed files with 31 additions and 6 deletions

View File

@ -21,7 +21,6 @@ CircularReveal::CircularReveal(QQuickItem* parent) : QQuickPaintedItem(parent)
void CircularReveal::paint(QPainter* painter)
{
painter->save();
painter->eraseRect(boundingRect());
painter->drawImage(QRect(0, 0, static_cast<int>(width()), static_cast<int>(height())), _source);
QPainterPath path;
path.moveTo(_center.x(),_center.y());

View File

@ -9,7 +9,6 @@ Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent)
start(QPoint(0,0));
end(QPoint(0,0));
_desktopGeometry = qApp->primaryScreen()->virtualGeometry();
_desktopPixmap = qApp->primaryScreen()->grabWindow(0, _desktopGeometry.x(), _desktopGeometry.y(), _desktopGeometry.width(), _desktopGeometry.height());
connect(this,&Screenshot::startChanged,this,[=]{update();});
connect(this,&Screenshot::endChanged,this,[=]{update();});
}
@ -17,10 +16,22 @@ Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent)
void Screenshot::paint(QPainter* painter)
{
painter->save();
painter->eraseRect(boundingRect());
painter->drawPixmap(_desktopGeometry,_desktopPixmap);
painter->fillRect(_desktopGeometry,_maskColor);
painter->setCompositionMode(QPainter::CompositionMode_Clear);
painter->fillRect(QRect(_start.x(),_start.y(),_end.x()-_start.x(),_end.y()-_start.y()), Qt::black);
painter->restore();
}
ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedItem(parent)
{
_desktopGeometry = qApp->primaryScreen()->virtualGeometry();
_desktopPixmap = qApp->primaryScreen()->grabWindow(0, _desktopGeometry.x(), _desktopGeometry.y(), _desktopGeometry.width(), _desktopGeometry.height());
}
void ScreenshotBackground::paint(QPainter* painter)
{
painter->save();
painter->drawPixmap(_desktopGeometry,_desktopPixmap);
painter->restore();
}

View File

@ -6,6 +6,20 @@
#include <QPainter>
#include "stdafx.h"
class ScreenshotBackground : public QQuickPaintedItem
{
Q_OBJECT;
QML_NAMED_ELEMENT(ScreenshotBackground)
public:
ScreenshotBackground(QQuickItem* parent = nullptr);
void paint(QPainter* painter) override;
private:
QRect _desktopGeometry;
QPixmap _desktopPixmap;
};
class Screenshot : public QQuickPaintedItem
{
Q_OBJECT
@ -19,8 +33,6 @@ public:
private:
QRect _desktopGeometry;
QPixmap _desktopPixmap;
bool _isFirst = true;
};
#endif // SCREENSHOT_H

View File

@ -35,6 +35,9 @@ Loader {
Component.onCompleted: {
setGeometry(0,0,Screen.desktopAvailableWidth,Screen.height)
}
ScreenshotBackground{
anchors.fill: parent
}
Screenshot{
id:screenshot
anchors.fill: parent