This commit is contained in:
朱子楚\zhuzi 2024-02-24 22:26:54 +08:00
parent a02ee68483
commit 84b3a367b2
14 changed files with 15 additions and 1373 deletions

View File

@ -154,7 +154,6 @@
<file>qml/page/T_RatingControl.qml</file> <file>qml/page/T_RatingControl.qml</file>
<file>qml/page/T_Rectangle.qml</file> <file>qml/page/T_Rectangle.qml</file>
<file>qml/page/T_RemoteLoader.qml</file> <file>qml/page/T_RemoteLoader.qml</file>
<file>qml/page/T_Screenshot.qml</file>
<file>qml/page/T_Settings.qml</file> <file>qml/page/T_Settings.qml</file>
<file>qml/page/T_Slider.qml</file> <file>qml/page/T_Slider.qml</file>
<file>qml/page/T_StatusLayout.qml</file> <file>qml/page/T_StatusLayout.qml</file>

View File

@ -432,12 +432,6 @@ FluObject{
url:"qrc:/example/qml/page/T_Timeline.qml" url:"qrc:/example/qml/page/T_Timeline.qml"
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }
} }
FluPaneItem{
title:"Screenshot(Todo)"
menuDelegate: paneItemMenu
url:"qrc:/example/qml/page/T_Screenshot.qml"
onTap:{ navigationView.push(url) }
}
FluPaneItem{ FluPaneItem{
title:"Captcha" title:"Captcha"
menuDelegate: paneItemMenu menuDelegate: paneItemMenu

View File

@ -1,57 +0,0 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Controls
import FluentUI
import Qt.labs.platform
import "../component"
FluScrollablePage{
title:"Screenshot"
FluArea{
Layout.fillWidth: true
height: 100
paddings: 10
Layout.topMargin: 20
FluFilledButton{
anchors.verticalCenter: parent.verticalCenter
text:"Open Screenshot"
onClicked: {
screenshot.open()
}
}
}
Rectangle{
Layout.preferredHeight: 400
Layout.preferredWidth: 400
Layout.topMargin: 10
Layout.leftMargin: 4
Layout.bottomMargin: 4
radius: 4
color: FluTheme.dark ? FluColors.Black : FluColors.White
FluShadow{
radius: 4
color: FluTheme.primaryColor
}
Image{
id:image
anchors.fill: parent
fillMode: Image.PreserveAspectFit
asynchronous: true
}
}
FluScreenshot{
id:screenshot
captrueMode: FluScreenshotType.File
saveFolder: StandardPaths.writableLocation(StandardPaths.AppLocalDataLocation)+"/screenshot"
onCaptrueCompleted:
(captrue)=>{
image.source = captrue
}
}
}

View File

@ -432,12 +432,6 @@ FluObject{
url:"qrc:/example/qml/page/T_Timeline.qml" url:"qrc:/example/qml/page/T_Timeline.qml"
onTap:{ navigationView.push(url) } onTap:{ navigationView.push(url) }
} }
FluPaneItem{
title:"Screenshot(Todo)"
menuDelegate: paneItemMenu
url:"qrc:/example/qml/page/T_Screenshot.qml"
onTap:{ navigationView.push(url) }
}
FluPaneItem{ FluPaneItem{
title:"Captcha" title:"Captcha"
menuDelegate: paneItemMenu menuDelegate: paneItemMenu

View File

@ -1,57 +0,0 @@
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import FluentUI 1.0
import Qt.labs.platform 1.0
import "../component"
FluScrollablePage{
title:"Screenshot"
FluArea{
Layout.fillWidth: true
height: 100
paddings: 10
Layout.topMargin: 20
FluFilledButton{
anchors.verticalCenter: parent.verticalCenter
text:"Open Screenshot"
onClicked: {
screenshot.open()
}
}
}
Rectangle{
Layout.preferredHeight: 400
Layout.preferredWidth: 400
Layout.topMargin: 10
Layout.leftMargin: 4
Layout.bottomMargin: 4
radius: 4
color: FluTheme.dark ? FluColors.Black : FluColors.White
FluShadow{
radius: 4
color: FluTheme.primaryColor
}
Image{
id:image
anchors.fill: parent
fillMode: Image.PreserveAspectFit
asynchronous: true
}
}
FluScreenshot{
id:screenshot
captrueMode: FluScreenshotType.File
saveFolder: StandardPaths.writableLocation(StandardPaths.AppLocalDataLocation)+"/screenshot"
onCaptrueCompleted:
(captrue)=>{
image.source = captrue
}
}
}

View File

@ -26,16 +26,6 @@ Q_ENUM_NS(CacheMode)
QML_NAMED_ELEMENT(FluNetworkType) QML_NAMED_ELEMENT(FluNetworkType)
} }
namespace FluScreenshotType {
Q_NAMESPACE
enum CaptrueMode {
Pixmap = 0x0000,
File = 0x0001,
};
Q_ENUM_NS(CaptrueMode)
QML_NAMED_ELEMENT(FluScreenshotType)
}
namespace FluThemeType { namespace FluThemeType {
Q_NAMESPACE Q_NAMESPACE
enum DarkMode { enum DarkMode {

View File

@ -257,7 +257,7 @@ void FluFramelessHelper::componentComplete(){
_realWidth = QQmlProperty(window,"_realWidth"); _realWidth = QQmlProperty(window,"_realWidth");
_appBarHeight = QQmlProperty(window,"_appBarHeight"); _appBarHeight = QQmlProperty(window,"_appBarHeight");
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
window->setFlag(Qt::CustomizeWindowHint,true); window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint);
_nativeEvent =new FramelessEventFilter(this); _nativeEvent =new FramelessEventFilter(this);
qApp->installNativeEventFilter(_nativeEvent); qApp->installNativeEventFilter(_nativeEvent);
HWND hwnd = reinterpret_cast<HWND>(window->winId()); HWND hwnd = reinterpret_cast<HWND>(window->winId());
@ -272,6 +272,15 @@ void FluFramelessHelper::componentComplete(){
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle); SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle);
SetLayeredWindowAttributes(hwnd, RGB(251, 255, 242), 0, LWA_COLORKEY); SetLayeredWindowAttributes(hwnd, RGB(251, 255, 242), 0, LWA_COLORKEY);
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
connect(window,&QQuickWindow::activeChanged,this,[this,hwnd]{
if(this->window->isActive()){
LONG exstyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
if(exstyle & WS_EX_LAYERED){
exstyle = exstyle &~ WS_EX_LAYERED;
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle);
}
}
});
#else #else
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
#endif #endif

View File

@ -13,7 +13,6 @@
#include "FluEventBus.h" #include "FluEventBus.h"
#include "FluTreeModel.h" #include "FluTreeModel.h"
#include "FluViewModel.h" #include "FluViewModel.h"
#include "Screenshot.h"
#include "FluRectangle.h" #include "FluRectangle.h"
#include "FluNetwork.h" #include "FluNetwork.h"
#include "FluFramelessHelper.h" #include "FluFramelessHelper.h"
@ -32,8 +31,6 @@ void FluentUI::registerTypes(const char *uri){
qmlRegisterType<QRCode>(uri,major,minor,"QRCode"); qmlRegisterType<QRCode>(uri,major,minor,"QRCode");
qmlRegisterType<FluCaptcha>(uri,major,minor,"FluCaptcha"); qmlRegisterType<FluCaptcha>(uri,major,minor,"FluCaptcha");
qmlRegisterType<FluWatermark>(uri,major,minor,"FluWatermark"); qmlRegisterType<FluWatermark>(uri,major,minor,"FluWatermark");
qmlRegisterType<ScreenshotBackground>(uri,major,minor,"ScreenshotBackground");
qmlRegisterType<Screenshot>(uri,major,minor,"Screenshot");
qmlRegisterType<FluColorSet>(uri,major,minor,"FluColorSet"); qmlRegisterType<FluColorSet>(uri,major,minor,"FluColorSet");
qmlRegisterType<FluEvent>(uri,major,minor,"FluEvent"); qmlRegisterType<FluEvent>(uri,major,minor,"FluEvent");
qmlRegisterType<FluViewModel>(uri,major,minor,"FluViewModel"); qmlRegisterType<FluViewModel>(uri,major,minor,"FluViewModel");
@ -107,7 +104,6 @@ void FluentUI::registerTypes(const char *uri){
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRadioButtons.qml"),uri,major,minor,"FluRadioButtons"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRadioButtons.qml"),uri,major,minor,"FluRadioButtons");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRatingControl.qml"),uri,major,minor,"FluRatingControl"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRatingControl.qml"),uri,major,minor,"FluRatingControl");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRemoteLoader.qml"),uri,major,minor,"FluRemoteLoader"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluRemoteLoader.qml"),uri,major,minor,"FluRemoteLoader");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScreenshot.qml"),uri,major,minor,"FluScreenshot");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollBar.qml"),uri,major,minor,"FluScrollBar"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollBar.qml"),uri,major,minor,"FluScrollBar");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollIndicator.qml"),uri,major,minor,"FluScrollIndicator"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollIndicator.qml"),uri,major,minor,"FluScrollIndicator");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollablePage.qml"),uri,major,minor,"FluScrollablePage"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/FluScrollablePage.qml"),uri,major,minor,"FluScrollablePage");
@ -151,7 +147,6 @@ void FluentUI::registerTypes(const char *uri){
qmlRegisterUncreatableMetaObject(FluTabViewType::staticMetaObject, uri,major,minor,"FluTabViewType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluTabViewType::staticMetaObject, uri,major,minor,"FluTabViewType", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluNavigationViewType::staticMetaObject, uri,major,minor,"FluNavigationViewType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluNavigationViewType::staticMetaObject, uri,major,minor,"FluNavigationViewType", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluTimelineType::staticMetaObject, uri,major,minor,"FluTimelineType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluTimelineType::staticMetaObject, uri,major,minor,"FluTimelineType", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluScreenshotType::staticMetaObject, uri,major,minor,"FluScreenshotType", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluViewModelType::staticMetaObject, uri,major,minor,"FluViewModelType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluViewModelType::staticMetaObject, uri,major,minor,"FluViewModelType", "Access to enums & flags only");
qmlRegisterUncreatableMetaObject(FluNetworkType::staticMetaObject, uri,major,minor,"FluNetworkType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluNetworkType::staticMetaObject, uri,major,minor,"FluNetworkType", "Access to enums & flags only");

View File

@ -1,523 +0,0 @@
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import Qt.labs.platform 1.1
import FluentUI 1.0
Item{
id:control
property int captrueMode: FluScreenshotType.Pixmap
property int dotSize: 5
property int borderSize: 1
property var saveFolder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]
property color borderColor: FluTheme.primaryColor
signal captrueCompleted(var captrue)
QtObject{
id:d
property int dotMouseSize: control.dotSize+10
property int dotMargins: -(control.dotSize-control.borderSize)/2
property bool enablePosition: false
property int menuMargins: 6
}
Loader {
id:loader
}
Component{
id:com_screen
Window{
property bool isZeroPos: screenshot.start.x === 0 && screenshot.start.y === 0 && screenshot.end.x === 0 && screenshot.end.y === 0
id:window_screen
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x:-1
y:-1
width: 1
height: 1
visible: true
color: "#00000000"
onVisibleChanged: {
if(!window_screen.visible){
loader.sourceComponent = undefined
}
}
Component.onCompleted: {
setGeometry(0,0,screenshot_background.width,screenshot_background.height+1)
}
ScreenshotBackground{
id:screenshot_background
captureMode:control.captrueMode
saveFolder: {
if(typeof control.saveFolder === 'string'){
return FluTools.toLocalPath(Qt.resolvedUrl(control.saveFolder))
}else{
return FluTools.toLocalPath(control.saveFolder)
}
}
onCaptrueToPixmapCompleted:
(captrue)=>{
control.captrueCompleted(captrue)
loader.sourceComponent = undefined
}
onCaptrueToFileCompleted:
(captrue)=>{
control.captrueCompleted(captrue)
loader.sourceComponent = undefined
}
}
Screenshot{
id:screenshot
anchors.fill: parent
}
MouseArea{
anchors.fill: parent
acceptedButtons: Qt.RightButton | Qt.LeftButton
onPressed:
(mouse)=>{
if(mouse.button === Qt.LeftButton){
d.enablePosition = true
screenshot.start = Qt.point(mouse.x,mouse.y)
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onPositionChanged:
(mouse)=>{
if(d.enablePosition){
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onReleased:
(mouse)=>{
if(mouse.button === Qt.LeftButton){
d.enablePosition = false
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onCanceled:
(mouse)=>{
if(mouse.button === Qt.LeftButton){
d.enablePosition = false
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onClicked:
(mouse)=>{
if (mouse.button === Qt.RightButton){
if(isZeroPos){
loader.sourceComponent = undefined
return
}
screenshot.start = Qt.point(0,0)
screenshot.end = Qt.point(0,0)
}
}
}
Rectangle{
id:rect_capture
x:Math.min(screenshot.start.x,screenshot.end.x)
y:Math.min(screenshot.start.y,screenshot.end.y)
width: Math.abs(screenshot.end.x - screenshot.start.x)
height: Math.abs(screenshot.end.y - screenshot.start.y)
color:"#00000000"
border.width: control.borderSize
border.color: control.borderColor
MouseArea{
property point clickPos: Qt.point(0,0)
anchors.fill: parent
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
onPressed:
(mouse)=>{
clickPos = Qt.point(mouse.x, mouse.y)
}
onPositionChanged:
(mouse)=>{
var delta = Qt.point(mouse.x - clickPos.x,mouse.y - clickPos.y)
var w = Math.abs(screenshot.end.x - screenshot.start.x)
var h = Math.abs(screenshot.end.y - screenshot.start.y)
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
var y = Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
}
}
Rectangle{
id:rect_top_left
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
left: rect_capture.left
leftMargin: d.dotMargins
topMargin: d.dotMargins
top: rect_capture.top
}
}
MouseArea{
cursorShape: Qt.SizeFDiagCursor
anchors.centerIn: rect_top_left
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
FluTools.setOverrideCursor(cursorShape)
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y+h)
screenshot.end = Qt.point(x,y)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_top_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
horizontalCenter: rect_capture.horizontalCenter
topMargin: d.dotMargins
top: rect_capture.top
}
}
MouseArea{
cursorShape: Qt.SizeVerCursor
anchors.centerIn: rect_top_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
FluTools.setOverrideCursor(cursorShape)
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y+h)
screenshot.end = Qt.point(x,y)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var x = rect_capture.x
screenshot.end = Qt.point(x,mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).y)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_top_right
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
right: rect_capture.right
rightMargin: d.dotMargins
topMargin: d.dotMargins
top: rect_capture.top
}
}
MouseArea{
cursorShape: Qt.SizeBDiagCursor
anchors.centerIn: rect_top_right
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y+h)
screenshot.end = Qt.point(x+w,y)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_right_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
right: rect_capture.right
rightMargin: d.dotMargins
verticalCenter: rect_capture.verticalCenter
}
}
MouseArea{
cursorShape: Qt.SizeHorCursor
anchors.centerIn: rect_right_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var y = rect_capture.y
var h = rect_capture.height
screenshot.end = Qt.point(mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).x,y+h)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_right_bottom
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
right: rect_capture.right
rightMargin: d.dotMargins
bottom: rect_capture.bottom
bottomMargin: d.dotMargins
}
}
MouseArea{
cursorShape: Qt.SizeFDiagCursor
anchors.centerIn: rect_right_bottom
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_bottom_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
horizontalCenter: rect_capture.horizontalCenter
bottom: rect_capture.bottom
bottomMargin: d.dotMargins
}
}
MouseArea{
cursorShape: Qt.SizeVerCursor
anchors.centerIn: rect_bottom_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var x = rect_capture.x
var w = rect_capture.width
screenshot.end = Qt.point(x+w,mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).y)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_bottom_left
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
left: rect_capture.left
leftMargin: d.dotMargins
bottom: rect_capture.bottom
bottomMargin: d.dotMargins
}
}
MouseArea{
cursorShape: Qt.SizeBDiagCursor
anchors.centerIn: rect_bottom_left
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y)
screenshot.end = Qt.point(x,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_left_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
left: rect_capture.left
leftMargin: d.dotMargins
verticalCenter: rect_capture.verticalCenter
}
}
MouseArea{
cursorShape: Qt.SizeHorCursor
anchors.centerIn: rect_left_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y)
screenshot.end = Qt.point(x,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var y = rect_capture.y
var h = rect_capture.height
screenshot.end = Qt.point(mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).x,y+h)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Pane{
width: 100
height: 40
visible: {
if(isZeroPos){
return false
}
if(d.enablePosition){
return false
}
return true
}
x:rect_capture.x + rect_capture.width - width
y:{
if(rect_capture.y + rect_capture.height + d.menuMargins < screenshot.height-height){
return rect_capture.y + rect_capture.height + d.menuMargins
}else if(rect_capture.y - height - d.menuMargins > 0){
return rect_capture.y - height - d.menuMargins
}else{
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: {
loader.sourceComponent = undefined
}
}
FluIconButton{
iconSource: FluentIcons.AcceptMedium
iconColor: FluTheme.primaryColor
onClicked: {
screenshot_background.capture(screenshot.start,screenshot.end)
}
}
}
}
}
}
function open(){
loader.sourceComponent = com_screen
}
}

View File

@ -144,19 +144,6 @@ Module {
Property { name: "color"; type: "QColor" } Property { name: "color"; type: "QColor" }
Property { name: "radius"; type: "QList<int>" } Property { name: "radius"; type: "QList<int>" }
} }
Component {
name: "FluScreenshotType"
exports: ["FluentUI/FluScreenshotType 1.0"]
isCreatable: false
exportMetaObjectRevisions: [0]
Enum {
name: "CaptrueMode"
values: {
"Pixmap": 0,
"File": 1
}
}
}
Component { Component {
name: "FluStatusLayoutType" name: "FluStatusLayoutType"
exports: ["FluentUI/FluStatusLayoutType 1.0"] exports: ["FluentUI/FluStatusLayoutType 1.0"]
@ -2168,38 +2155,6 @@ Module {
Property { name: "bgColor"; type: "QColor" } Property { name: "bgColor"; type: "QColor" }
Property { name: "size"; type: "int" } Property { name: "size"; type: "int" }
} }
Component {
name: "Screenshot"
defaultProperty: "data"
prototype: "QQuickPaintedItem"
exports: ["FluentUI/Screenshot 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "start"; type: "QPoint" }
Property { name: "end"; type: "QPoint" }
Property { name: "maskColor"; type: "QColor" }
}
Component {
name: "ScreenshotBackground"
defaultProperty: "data"
prototype: "QQuickPaintedItem"
exports: ["FluentUI/ScreenshotBackground 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "saveFolder"; type: "string" }
Property { name: "captureMode"; type: "int" }
Signal {
name: "captrueToPixmapCompleted"
Parameter { name: "captrue"; type: "QPixmap" }
}
Signal {
name: "captrueToFileCompleted"
Parameter { name: "captrue"; type: "QUrl" }
}
Method {
name: "capture"
Parameter { name: "start"; type: "QPoint" }
Parameter { name: "end"; type: "QPoint" }
}
}
Component { Component {
name: "WindowLifecycle" name: "WindowLifecycle"
prototype: "QObject" prototype: "QObject"
@ -3017,15 +2972,15 @@ Module {
defaultProperty: "data" defaultProperty: "data"
Property { name: "logo"; type: "QUrl" } Property { name: "logo"; type: "QUrl" }
Property { name: "title"; type: "string" } Property { name: "title"; type: "string" }
Property { name: "items"; type: "FluObject_QMLTYPE_159"; isPointer: true } Property { name: "items"; type: "FluObject_QMLTYPE_156"; isPointer: true }
Property { name: "footerItems"; type: "FluObject_QMLTYPE_159"; isPointer: true } Property { name: "footerItems"; type: "FluObject_QMLTYPE_156"; isPointer: true }
Property { name: "displayMode"; type: "int" } Property { name: "displayMode"; type: "int" }
Property { name: "autoSuggestBox"; type: "QQmlComponent"; isPointer: true } Property { name: "autoSuggestBox"; type: "QQmlComponent"; isPointer: true }
Property { name: "actionItem"; type: "QQmlComponent"; isPointer: true } Property { name: "actionItem"; type: "QQmlComponent"; isPointer: true }
Property { name: "topPadding"; type: "int" } Property { name: "topPadding"; type: "int" }
Property { name: "pageMode"; type: "int" } Property { name: "pageMode"; type: "int" }
Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_47"; isPointer: true } Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_49"; isPointer: true }
Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_47"; isPointer: true } Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_49"; isPointer: true }
Property { name: "navCompactWidth"; type: "int" } Property { name: "navCompactWidth"; type: "int" }
Property { name: "navTopMargin"; type: "int" } Property { name: "navTopMargin"; type: "int" }
Property { name: "cellHeight"; type: "int" } Property { name: "cellHeight"; type: "int" }
@ -3274,6 +3229,7 @@ Module {
exportMetaObjectRevisions: [0] exportMetaObjectRevisions: [0]
isComposite: true isComposite: true
defaultProperty: "data" defaultProperty: "data"
Property { name: "duration"; type: "int" }
Property { name: "strokeWidth"; type: "double" } Property { name: "strokeWidth"; type: "double" }
Property { name: "progressVisible"; type: "bool" } Property { name: "progressVisible"; type: "bool" }
Property { name: "color"; type: "QColor" } Property { name: "color"; type: "QColor" }
@ -3371,24 +3327,6 @@ Module {
Method { name: "showEmptyView"; type: "QVariant" } Method { name: "showEmptyView"; type: "QVariant" }
Method { name: "showErrorView"; type: "QVariant" } Method { name: "showErrorView"; type: "QVariant" }
} }
Component {
prototype: "QQuickItem"
name: "FluentUI/FluScreenshot 1.0"
exports: ["FluentUI/FluScreenshot 1.0"]
exportMetaObjectRevisions: [0]
isComposite: true
defaultProperty: "data"
Property { name: "captrueMode"; type: "int" }
Property { name: "dotSize"; type: "int" }
Property { name: "borderSize"; type: "int" }
Property { name: "saveFolder"; type: "QVariant" }
Property { name: "borderColor"; type: "QColor" }
Signal {
name: "captrueCompleted"
Parameter { name: "captrue"; type: "QVariant" }
}
Method { name: "open"; type: "QVariant" }
}
Component { Component {
prototype: "QQuickScrollBar" prototype: "QQuickScrollBar"
name: "FluentUI/FluScrollBar 1.0" name: "FluentUI/FluScrollBar 1.0"

View File

@ -62,7 +62,6 @@
<file>FluentUI/Controls/FluRangeSlider.qml</file> <file>FluentUI/Controls/FluRangeSlider.qml</file>
<file>FluentUI/Controls/FluRatingControl.qml</file> <file>FluentUI/Controls/FluRatingControl.qml</file>
<file>FluentUI/Controls/FluRemoteLoader.qml</file> <file>FluentUI/Controls/FluRemoteLoader.qml</file>
<file>FluentUI/Controls/FluScreenshot.qml</file>
<file>FluentUI/Controls/FluScrollablePage.qml</file> <file>FluentUI/Controls/FluScrollablePage.qml</file>
<file>FluentUI/Controls/FluScrollBar.qml</file> <file>FluentUI/Controls/FluScrollBar.qml</file>
<file>FluentUI/Controls/FluScrollIndicator.qml</file> <file>FluentUI/Controls/FluScrollIndicator.qml</file>

View File

@ -1,523 +0,0 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Layouts
import Qt.labs.platform
import FluentUI
Item{
id:control
property int captrueMode: FluScreenshotType.Pixmap
property int dotSize: 5
property int borderSize: 1
property var saveFolder: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]
property color borderColor: FluTheme.primaryColor
signal captrueCompleted(var captrue)
QtObject{
id:d
property int dotMouseSize: control.dotSize+10
property int dotMargins: -(control.dotSize-control.borderSize)/2
property bool enablePosition: false
property int menuMargins: 6
}
Loader {
id:loader
}
Component{
id:com_screen
Window{
property bool isZeroPos: screenshot.start.x === 0 && screenshot.start.y === 0 && screenshot.end.x === 0 && screenshot.end.y === 0
id:window_screen
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
x:-1
y:-1
width: 1
height: 1
visible: true
color: "#00000000"
onVisibleChanged: {
if(!window_screen.visible){
loader.sourceComponent = undefined
}
}
Component.onCompleted: {
setGeometry(0,0,screenshot_background.width,screenshot_background.height+1)
}
ScreenshotBackground{
id:screenshot_background
captureMode:control.captrueMode
saveFolder: {
if(typeof control.saveFolder === 'string'){
return FluTools.toLocalPath(Qt.resolvedUrl(control.saveFolder))
}else{
return FluTools.toLocalPath(control.saveFolder)
}
}
onCaptrueToPixmapCompleted:
(captrue)=>{
control.captrueCompleted(captrue)
loader.sourceComponent = undefined
}
onCaptrueToFileCompleted:
(captrue)=>{
control.captrueCompleted(captrue)
loader.sourceComponent = undefined
}
}
Screenshot{
id:screenshot
anchors.fill: parent
}
MouseArea{
anchors.fill: parent
acceptedButtons: Qt.RightButton | Qt.LeftButton
onPressed:
(mouse)=>{
if(mouse.button === Qt.LeftButton){
d.enablePosition = true
screenshot.start = Qt.point(mouse.x,mouse.y)
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onPositionChanged:
(mouse)=>{
if(d.enablePosition){
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onReleased:
(mouse)=>{
if(mouse.button === Qt.LeftButton){
d.enablePosition = false
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onCanceled:
(mouse)=>{
if(mouse.button === Qt.LeftButton){
d.enablePosition = false
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onClicked:
(mouse)=>{
if (mouse.button === Qt.RightButton){
if(isZeroPos){
loader.sourceComponent = undefined
return
}
screenshot.start = Qt.point(0,0)
screenshot.end = Qt.point(0,0)
}
}
}
Rectangle{
id:rect_capture
x:Math.min(screenshot.start.x,screenshot.end.x)
y:Math.min(screenshot.start.y,screenshot.end.y)
width: Math.abs(screenshot.end.x - screenshot.start.x)
height: Math.abs(screenshot.end.y - screenshot.start.y)
color:"#00000000"
border.width: control.borderSize
border.color: control.borderColor
MouseArea{
property point clickPos: Qt.point(0,0)
anchors.fill: parent
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
onPressed:
(mouse)=>{
clickPos = Qt.point(mouse.x, mouse.y)
}
onPositionChanged:
(mouse)=>{
var delta = Qt.point(mouse.x - clickPos.x,mouse.y - clickPos.y)
var w = Math.abs(screenshot.end.x - screenshot.start.x)
var h = Math.abs(screenshot.end.y - screenshot.start.y)
var x = Math.min(Math.max(rect_capture.x + delta.x,0),window_screen.width-w)
var y = Math.min(Math.max(rect_capture.y + delta.y,0),window_screen.height-h)
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
}
}
Rectangle{
id:rect_top_left
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
left: rect_capture.left
leftMargin: d.dotMargins
topMargin: d.dotMargins
top: rect_capture.top
}
}
MouseArea{
cursorShape: Qt.SizeFDiagCursor
anchors.centerIn: rect_top_left
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
FluTools.setOverrideCursor(cursorShape)
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y+h)
screenshot.end = Qt.point(x,y)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_top_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
horizontalCenter: rect_capture.horizontalCenter
topMargin: d.dotMargins
top: rect_capture.top
}
}
MouseArea{
cursorShape: Qt.SizeVerCursor
anchors.centerIn: rect_top_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
FluTools.setOverrideCursor(cursorShape)
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y+h)
screenshot.end = Qt.point(x,y)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var x = rect_capture.x
screenshot.end = Qt.point(x,mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).y)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_top_right
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
right: rect_capture.right
rightMargin: d.dotMargins
topMargin: d.dotMargins
top: rect_capture.top
}
}
MouseArea{
cursorShape: Qt.SizeBDiagCursor
anchors.centerIn: rect_top_right
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y+h)
screenshot.end = Qt.point(x+w,y)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_right_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
right: rect_capture.right
rightMargin: d.dotMargins
verticalCenter: rect_capture.verticalCenter
}
}
MouseArea{
cursorShape: Qt.SizeHorCursor
anchors.centerIn: rect_right_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var y = rect_capture.y
var h = rect_capture.height
screenshot.end = Qt.point(mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).x,y+h)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_right_bottom
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
right: rect_capture.right
rightMargin: d.dotMargins
bottom: rect_capture.bottom
bottomMargin: d.dotMargins
}
}
MouseArea{
cursorShape: Qt.SizeFDiagCursor
anchors.centerIn: rect_right_bottom
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_bottom_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
horizontalCenter: rect_capture.horizontalCenter
bottom: rect_capture.bottom
bottomMargin: d.dotMargins
}
}
MouseArea{
cursorShape: Qt.SizeVerCursor
anchors.centerIn: rect_bottom_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x,y)
screenshot.end = Qt.point(x+w,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var x = rect_capture.x
var w = rect_capture.width
screenshot.end = Qt.point(x+w,mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).y)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_bottom_left
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
left: rect_capture.left
leftMargin: d.dotMargins
bottom: rect_capture.bottom
bottomMargin: d.dotMargins
}
}
MouseArea{
cursorShape: Qt.SizeBDiagCursor
anchors.centerIn: rect_bottom_left
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y)
screenshot.end = Qt.point(x,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
screenshot.end = mapToItem(screenshot,Qt.point(mouse.x,mouse.y))
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Rectangle{
id:rect_left_center
width: control.dotSize
height: control.dotSize
color: control.borderColor
visible: !isZeroPos
anchors{
left: rect_capture.left
leftMargin: d.dotMargins
verticalCenter: rect_capture.verticalCenter
}
}
MouseArea{
cursorShape: Qt.SizeHorCursor
anchors.centerIn: rect_left_center
width: d.dotMouseSize
height: d.dotMouseSize
visible: !isZeroPos
onPressed:
(mouse)=> {
var x = rect_capture.x
var y = rect_capture.y
var w = rect_capture.width
var h = rect_capture.height
screenshot.start = Qt.point(x+w,y)
screenshot.end = Qt.point(x,y+h)
}
onReleased:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
onPositionChanged:
(mouse)=> {
var y = rect_capture.y
var h = rect_capture.height
screenshot.end = Qt.point(mapToItem(screenshot,Qt.point(mouse.x,mouse.y)).x,y+h)
}
onCanceled:
(mouse)=> {
FluTools.restoreOverrideCursor()
}
}
Pane{
width: 100
height: 40
visible: {
if(isZeroPos){
return false
}
if(d.enablePosition){
return false
}
return true
}
x:rect_capture.x + rect_capture.width - width
y:{
if(rect_capture.y + rect_capture.height + d.menuMargins < screenshot.height-height){
return rect_capture.y + rect_capture.height + d.menuMargins
}else if(rect_capture.y - height - d.menuMargins > 0){
return rect_capture.y - height - d.menuMargins
}else{
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: {
loader.sourceComponent = undefined
}
}
FluIconButton{
iconSource: FluentIcons.AcceptMedium
iconColor: FluTheme.primaryColor
onClicked: {
screenshot_background.capture(screenshot.start,screenshot.end)
}
}
}
}
}
}
function open(){
loader.sourceComponent = com_screen
}
}

View File

@ -1,70 +0,0 @@
#include "Screenshot.h"
#include <QGuiApplication>
#include <QScreen>
#include <QQuickWindow>
#include <QDir>
#include <QtMath>
#include <QDateTime>
#include <QThreadPool>
#include "Def.h"
Screenshot::Screenshot(QQuickItem* parent):QQuickPaintedItem(parent){
_desktopGeometry = qApp->primaryScreen()->virtualGeometry();
maskColor(QColor(0,0,0,150));
start(QPoint(0,0));
end(QPoint(0,0));
connect(this,&Screenshot::startChanged,this,[=]{update();});
connect(this,&Screenshot::endChanged,this,[=]{update();});
}
void Screenshot::paint(QPainter* painter){
painter->save();
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){
_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();
_sourcePixmap = _desktopPixmap.copy();
painter->drawPixmap(_desktopGeometry,_sourcePixmap);
painter->restore();
}
void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
update();
auto pixelRatio = qApp->primaryScreen()->devicePixelRatio();
auto x = qMin(start.x(),end.x()) * pixelRatio;
auto y = qMin(start.y(),end.y()) * pixelRatio;
auto w = qAbs(end.x()-start.x()) * pixelRatio;
auto h = qAbs(end.y()-start.y()) * pixelRatio;
_captureRect = QRect(x,y,w,h);
if(_captureMode == FluScreenshotType::CaptrueMode::Pixmap){
Q_EMIT captrueToPixmapCompleted(_sourcePixmap.copy(_captureRect));
}
if(_captureMode == FluScreenshotType::CaptrueMode::File){
QDir dir = _saveFolder;
if (!dir.exists(_saveFolder)){
dir.mkpath(_saveFolder);
}
auto filePath = _saveFolder.append("/").append(QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch())).append(".png");
_sourcePixmap.copy(_captureRect).save(filePath);
Q_EMIT captrueToFileCompleted(QUrl::fromLocalFile(filePath));
}
}

View File

@ -1,46 +0,0 @@
#ifndef SCREENSHOT_H
#define SCREENSHOT_H
#include <QQuickItem>
#include <QQuickPaintedItem>
#include <QPainter>
#include <QQuickItemGrabResult>
#include "stdafx.h"
#include <qmath.h>
class ScreenshotBackground : public QQuickPaintedItem
{
Q_OBJECT;
QML_NAMED_ELEMENT(ScreenshotBackground)
Q_PROPERTY_AUTO(QString,saveFolder);
Q_PROPERTY_AUTO(int,captureMode);
public:
ScreenshotBackground(QQuickItem* parent = nullptr);
void paint(QPainter* painter) override;
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;
QPixmap _sourcePixmap;
qreal _devicePixelRatio;
QSharedPointer<QQuickItemGrabResult> _grabResult;
QRect _captureRect;
};
class Screenshot : public QQuickPaintedItem
{
Q_OBJECT
QML_NAMED_ELEMENT(Screenshot)
Q_PROPERTY_AUTO(QPoint,start);
Q_PROPERTY_AUTO(QPoint,end);
Q_PROPERTY_AUTO(QColor,maskColor);
public:
Screenshot(QQuickItem* parent = nullptr);
void paint(QPainter* painter) override;
private:
QRect _desktopGeometry;
};
#endif // SCREENSHOT_H