From 2d492ceb95d0f233383c628420cafa4a149101fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Wed, 16 Aug 2023 23:25:52 +0800 Subject: [PATCH] update --- example/src/component/CircularReveal.cpp | 1 - src/Screenshot.cpp | 17 ++++++++++++++--- src/Screenshot.h | 16 ++++++++++++++-- src/imports/FluentUI/Controls/FluScreenshot.qml | 3 +++ 4 files changed, 31 insertions(+), 6 deletions(-) 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