diff --git a/example/qml/page/T_Screenshot.qml b/example/qml/page/T_Screenshot.qml index 8e566a8c..37873217 100644 --- a/example/qml/page/T_Screenshot.qml +++ b/example/qml/page/T_Screenshot.qml @@ -27,7 +27,19 @@ FluScrollablePage{ } } + Image{ + id:image + Layout.preferredHeight: 400 + Layout.preferredWidth: 400 + fillMode: Image.PreserveAspectFit + } + FluScreenshot{ id:screenshot + captrueMode: FluScreenshotType.File + onCaptrueCompleted: + (captrue)=>{ + image.source = captrue + } } } diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 02efb33c..be1553d6 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -269,18 +269,6 @@ CustomWindow { } } - Shortcut { - sequence: "F7" - context: Qt.WindowShortcut - onActivated: { - screenshot.open() - } - } - - FluScreenshot{ - id:screenshot - } - FluTour{ id:tour steps:[ diff --git a/src/Def.h b/src/Def.h index 06243d02..c40cf066 100644 --- a/src/Def.h +++ b/src/Def.h @@ -4,6 +4,18 @@ #include #include + +namespace FluScreenshotType { +Q_NAMESPACE +enum CaptrueMode { + Pixmap = 0x0000, + File = 0x0001, +}; +Q_ENUM_NS(CaptrueMode) +QML_NAMED_ELEMENT(FluScreenshotType) +} + + namespace FluThemeType { Q_NAMESPACE enum DarkMode { diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index c84f287b..f6da5962 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent) @@ -60,6 +62,13 @@ void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){ } void ScreenshotBackground::handleGrabResult(){ - _sourcePixmap.copy(_captureRect).save("aaa.png"); + if(_captureMode == FluScreenshotType::CaptrueMode::Pixmap){ + Q_EMIT captrueToPixmapCompleted(_sourcePixmap.copy(_captureRect)); + } + if(_captureMode == FluScreenshotType::CaptrueMode::File){ + auto filePath = _saveFolder.toLocalFile().append("/").append(QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch())).append(".png"); + _sourcePixmap.copy(_captureRect).save(filePath); + Q_EMIT captrueToFileCompleted(QUrl::fromLocalFile(filePath)); + } } diff --git a/src/Screenshot.h b/src/Screenshot.h index a2c0527d..65b2d259 100644 --- a/src/Screenshot.h +++ b/src/Screenshot.h @@ -11,11 +11,15 @@ class ScreenshotBackground : public QQuickPaintedItem { Q_OBJECT; QML_NAMED_ELEMENT(ScreenshotBackground) + Q_PROPERTY_AUTO(QUrl,saveFolder); + Q_PROPERTY_AUTO(int,captureMode); public: ScreenshotBackground(QQuickItem* parent = nullptr); void paint(QPainter* painter) override; Q_SLOT void handleGrabResult(); Q_INVOKABLE void capture(const QPoint& start,const QPoint& end); + Q_SIGNAL void captrueToPixmapCompleted(QPixmap captrue); + Q_SIGNAL void captrueToFileCompleted(QUrl captrue); private: QRect _desktopGeometry; QPixmap _desktopPixmap; diff --git a/src/imports/FluentUI/Controls/FluScreenshot.qml b/src/imports/FluentUI/Controls/FluScreenshot.qml index 7b6f9252..aa7de11c 100644 --- a/src/imports/FluentUI/Controls/FluScreenshot.qml +++ b/src/imports/FluentUI/Controls/FluScreenshot.qml @@ -2,12 +2,18 @@ import QtQuick import QtQuick.Controls import QtQuick.Controls.Basic import QtQuick.Layouts +import Qt.labs.platform import FluentUI -Loader { +Item{ + id:control + property int captrueMode: FluScreenshotType.Pixmap property int dotSize: 5 property int borderSize: 1 + property string saveFolder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] property color borderColor: FluTheme.primaryColor.dark + signal captrueCompleted(var captrue) + QtObject{ id:d property int dotMouseSize: control.dotSize+10 @@ -15,7 +21,9 @@ Loader { property bool enablePosition: false property int menuMargins: 6 } - id:control + Loader { + id:loader + } Component{ id:com_screen Window{ @@ -29,16 +37,26 @@ Loader { color: "#00000000" onVisibleChanged: { if(!window_screen.visible){ - control.sourceComponent = undefined + loader.sourceComponent = undefined } } Component.onCompleted: { -// setGeometry(0,0,FluTools.getVirtualGeometry().width/2,FluTools.getVirtualGeometry().height) setGeometry(0,0,screenshot_background.width,screenshot_background.height) - console.debug(width+";"+height) } ScreenshotBackground{ id:screenshot_background + captureMode:control.captrueMode + saveFolder: control.saveFolder + onCaptrueToPixmapCompleted: + (captrue)=>{ + control.captrueCompleted(captrue) + loader.sourceComponent = undefined + } + onCaptrueToFileCompleted: + (captrue)=>{ + control.captrueCompleted(captrue) + loader.sourceComponent = undefined + } } Screenshot{ id:screenshot @@ -79,7 +97,7 @@ Loader { (mouse)=>{ if (mouse.button === Qt.RightButton){ if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){ - control.sourceComponent = undefined + loader.sourceComponent = undefined return } screenshot.start = Qt.point(0,0) @@ -463,7 +481,7 @@ Loader { iconSize: 18 iconColor: Qt.rgba(247/255,75/255,77/255,1) onClicked: { - control.sourceComponent = undefined + loader.sourceComponent = undefined } } FluIconButton{ @@ -478,7 +496,8 @@ Loader { } } + function open(){ - control.sourceComponent = com_screen + loader.sourceComponent = com_screen } }