From 0df4c6858b6622170a74ef33c4ec86dfc96a8be8 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 22:23:58 +0800 Subject: [PATCH] update --- src/Screenshot.cpp | 3 +- src/Screenshot.h | 1 + .../FluentUI/Controls/FluScreenshot.qml | 377 +++++++++++++++++- 3 files changed, 372 insertions(+), 9 deletions(-) diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index 9fac0c66..25e06cd3 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -5,6 +5,7 @@ Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent) { + maskColor(QColor(0,0,0,80)); start(QPoint(0,0)); end(QPoint(0,0)); _desktopGeometry = qApp->primaryScreen()->virtualGeometry(); @@ -18,7 +19,7 @@ void Screenshot::paint(QPainter* painter) painter->save(); painter->eraseRect(boundingRect()); painter->drawPixmap(_desktopGeometry,_desktopPixmap); - painter->fillRect(_desktopGeometry,QColor(0,0,0,60)); + 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(); diff --git a/src/Screenshot.h b/src/Screenshot.h index 2768545a..afacd4ea 100644 --- a/src/Screenshot.h +++ b/src/Screenshot.h @@ -12,6 +12,7 @@ class Screenshot : public QQuickPaintedItem 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; diff --git a/src/imports/FluentUI/Controls/FluScreenshot.qml b/src/imports/FluentUI/Controls/FluScreenshot.qml index 813b2965..76015896 100644 --- a/src/imports/FluentUI/Controls/FluScreenshot.qml +++ b/src/imports/FluentUI/Controls/FluScreenshot.qml @@ -5,14 +5,26 @@ import QtQuick.Layouts import FluentUI Loader { + property int dotSize: 5 + property int borderSize: 1 + property color borderColor: FluTheme.primaryColor.dark + 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 + } id:control Component{ id:com_screen Window{ id:window_screen flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint - width: Screen.desktopAvailableWidth - height: Screen.height + x:-1 + y:-1 + width: 1 + height: 1 visible: true color: "#00000000" onVisibleChanged: { @@ -20,32 +32,41 @@ Loader { control.sourceComponent = undefined } } + Component.onCompleted: { + setGeometry(0,0,Screen.desktopAvailableWidth,Screen.height) + } Screenshot{ id:screenshot anchors.fill: parent } MouseArea{ - property bool enablePosition: false anchors.fill: parent acceptedButtons: Qt.RightButton | Qt.LeftButton onPressed: (mouse)=>{ if(mouse.button === Qt.LeftButton){ - enablePosition = true + d.enablePosition = true screenshot.start = Qt.point(mouse.x,mouse.y) screenshot.end = Qt.point(mouse.x,mouse.y) } } onPositionChanged: (mouse)=>{ - if(enablePosition){ + if(d.enablePosition){ screenshot.end = Qt.point(mouse.x,mouse.y) } } onReleased: (mouse)=>{ if(mouse.button === Qt.LeftButton){ - enablePosition = false + 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) } } @@ -68,8 +89,8 @@ Loader { width: Math.abs(screenshot.end.x - screenshot.start.x) height: Math.abs(screenshot.end.y - screenshot.start.y) color:"#00000000" - border.width: 1 - border.color: FluTheme.primaryColor.dark + border.width: control.borderSize + border.color: control.borderColor MouseArea{ property point clickPos: Qt.point(0,0) anchors.fill: parent @@ -90,6 +111,346 @@ Loader { } } } + Rectangle{ + id:rect_top_left + width: control.dotSize + height: control.dotSize + color: control.borderColor + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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() + } + } + Rectangle{ + width: 100 + height: 40 + visible: { + if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){ + 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 + } + } + } } }