diff --git a/example/src/component/CircularReveal.cpp b/example/src/component/CircularReveal.cpp index 48aef669..d845cfc5 100644 --- a/example/src/component/CircularReveal.cpp +++ b/example/src/component/CircularReveal.cpp @@ -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(width()), static_cast(height())), _source); QPainterPath path; path.moveTo(_center.x(),_center.y()); diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index 25e06cd3..abe4b7d0 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -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(); +} diff --git a/src/Screenshot.h b/src/Screenshot.h index afacd4ea..856883a0 100644 --- a/src/Screenshot.h +++ b/src/Screenshot.h @@ -6,6 +6,20 @@ #include #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 diff --git a/src/imports/FluentUI/Controls/FluScreenshot.qml b/src/imports/FluentUI/Controls/FluScreenshot.qml index 76015896..a3c77d64 100644 --- a/src/imports/FluentUI/Controls/FluScreenshot.qml +++ b/src/imports/FluentUI/Controls/FluScreenshot.qml @@ -35,6 +35,9 @@ Loader { Component.onCompleted: { setGeometry(0,0,Screen.desktopAvailableWidth,Screen.height) } + ScreenshotBackground{ + anchors.fill: parent + } Screenshot{ id:screenshot anchors.fill: parent