diff --git a/src/FluTools.cpp b/src/FluTools.cpp index 3656e877..b622236c 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -110,3 +111,7 @@ QString FluTools::html2PlantText(const QString& html){ textDocument.setHtml(html); return textDocument.toPlainText(); } + +QRect FluTools::getVirtualGeometry(){ + return qApp->primaryScreen()->virtualGeometry(); +} diff --git a/src/FluTools.h b/src/FluTools.h index c4782180..ba3c5f3b 100644 --- a/src/FluTools.h +++ b/src/FluTools.h @@ -103,14 +103,25 @@ public: */ Q_INVOKABLE QString toLocalPath(const QUrl& url); - Q_INVOKABLE QString getFileNameByUrl(const QUrl& url); - /** * @brief deleteItem 销毁Item对象 * @param p */ Q_INVOKABLE void deleteItem(QObject *p); + /** + * @brief getFileNameByUrl + * @param url + * @return + */ + Q_INVOKABLE QString getFileNameByUrl(const QUrl& url); + + /** + * @brief getVirtualGeometry + * @return + */ + Q_INVOKABLE QRect getVirtualGeometry(); + }; diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index abe4b7d0..e5936780 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -2,13 +2,14 @@ #include #include #include +#include Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent) { + _desktopGeometry = qApp->primaryScreen()->virtualGeometry(); maskColor(QColor(0,0,0,80)); start(QPoint(0,0)); end(QPoint(0,0)); - _desktopGeometry = qApp->primaryScreen()->virtualGeometry(); connect(this,&Screenshot::startChanged,this,[=]{update();}); connect(this,&Screenshot::endChanged,this,[=]{update();}); } @@ -24,14 +25,45 @@ void Screenshot::paint(QPainter* painter) ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedItem(parent) { - + _devicePixelRatio = qApp->primaryScreen()->devicePixelRatio(); _desktopGeometry = qApp->primaryScreen()->virtualGeometry(); _desktopPixmap = qApp->primaryScreen()->grabWindow(0, _desktopGeometry.x(), _desktopGeometry.y(), _desktopGeometry.width(), _desktopGeometry.height()); + int w = qApp->primaryScreen()->geometry().width(); + int h = qApp->primaryScreen()->geometry().height(); + foreach (auto item, qApp->screens()) { + if(item != qApp->primaryScreen()){ + w = w + item->geometry().width()/qApp->primaryScreen()->devicePixelRatio(); + } + } + setWidth(w); + setHeight(h); } void ScreenshotBackground::paint(QPainter* painter) { painter->save(); - painter->drawPixmap(_desktopGeometry,_desktopPixmap); + QPixmap sourcePixmap; + QPainter p(&sourcePixmap); + p.drawPixmap(_desktopGeometry,_desktopPixmap); + painter->drawPixmap(_desktopGeometry,sourcePixmap); painter->restore(); } + +void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){ + qDebug()<image().copy(_captureRect).save("aaa.png"); + +} + diff --git a/src/Screenshot.h b/src/Screenshot.h index 856883a0..17487d84 100644 --- a/src/Screenshot.h +++ b/src/Screenshot.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "stdafx.h" class ScreenshotBackground : public QQuickPaintedItem @@ -13,10 +14,14 @@ class ScreenshotBackground : public QQuickPaintedItem public: ScreenshotBackground(QQuickItem* parent = nullptr); void paint(QPainter* painter) override; - + Q_SLOT void handleGrabResult(); + Q_INVOKABLE void capture(const QPoint& start,const QPoint& end); private: QRect _desktopGeometry; QPixmap _desktopPixmap; + qreal _devicePixelRatio; + QSharedPointer _grabResult; + QRect _captureRect; }; diff --git a/src/imports/FluentUI/Controls/FluScreenshot.qml b/src/imports/FluentUI/Controls/FluScreenshot.qml index a3c77d64..7b6f9252 100644 --- a/src/imports/FluentUI/Controls/FluScreenshot.qml +++ b/src/imports/FluentUI/Controls/FluScreenshot.qml @@ -33,10 +33,12 @@ Loader { } } Component.onCompleted: { - setGeometry(0,0,Screen.desktopAvailableWidth,Screen.height) +// setGeometry(0,0,FluTools.getVirtualGeometry().width/2,FluTools.getVirtualGeometry().height) + setGeometry(0,0,screenshot_background.width,screenshot_background.height) + console.debug(width+";"+height) } ScreenshotBackground{ - anchors.fill: parent + id:screenshot_background } Screenshot{ id:screenshot @@ -431,7 +433,7 @@ Loader { FluTools.restoreOverrideCursor() } } - Rectangle{ + Pane{ width: 100 height: 40 visible: { @@ -453,6 +455,25 @@ Loader { screenshot.height - height - d.menuMargins } } + RowLayout{ + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + FluIconButton{ + iconSource: FluentIcons.Cancel + iconSize: 18 + iconColor: Qt.rgba(247/255,75/255,77/255,1) + onClicked: { + control.sourceComponent = undefined + } + } + FluIconButton{ + iconSource: FluentIcons.AcceptMedium + iconColor: FluTheme.primaryColor.dark + onClicked: { + screenshot_background.capture(screenshot.start,screenshot.end) + } + } + } } } }