This commit is contained in:
zhuzichu 2023-08-16 18:05:49 +08:00
parent 1b72b840d6
commit ec9a9a5074
7 changed files with 203 additions and 1 deletions

View File

@ -349,6 +349,12 @@ FluObject{
navigationView.push("qrc:/example/qml/page/T_Timeline.qml")
}
}
FluPaneItem{
title:"Screenshot"
onTap:{
navigationView.push("qrc:/example/qml/page/T_Screenshot.qml")
}
}
FluPaneItem{
title:"Chart"
onTap:{

View File

@ -0,0 +1,33 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Controls
import FluentUI
import "qrc:///example/qml/component"
FluScrollablePage{
title:"Screenshot"
FluArea{
Layout.fillWidth: true
height: 100
paddings: 10
Layout.topMargin: 20
FluFilledButton{
anchors{
top: parent.top
topMargin: 14
}
text:"Open Screenshot"
onClicked: {
screenshot.open()
}
}
}
FluScreenshot{
id:screenshot
}
}

View File

@ -269,6 +269,18 @@ CustomWindow {
}
}
Shortcut {
sequence: "F7"
context: Qt.WindowShortcut
onActivated: {
screenshot.open()
}
}
FluScreenshot{
id:screenshot
}
FluTour{
id:tour
steps:[

25
src/Screenshot.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "Screenshot.h"
#include <QGuiApplication>
#include <QScreen>
#include <QQuickWindow>
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();});
}
void Screenshot::paint(QPainter* painter)
{
painter->save();
painter->eraseRect(boundingRect());
painter->drawPixmap(_desktopGeometry,_desktopPixmap);
painter->fillRect(_desktopGeometry,QColor(0,0,0,60));
painter->setCompositionMode(QPainter::CompositionMode_Clear);
painter->fillRect(QRect(_start.x(),_start.y(),_end.x()-_start.x(),_end.y()-_start.y()), Qt::black);
painter->restore();
}

25
src/Screenshot.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef SCREENSHOT_H
#define SCREENSHOT_H
#include <QQuickItem>
#include <QQuickPaintedItem>
#include <QPainter>
#include "stdafx.h"
class Screenshot : public QQuickPaintedItem
{
Q_OBJECT
QML_NAMED_ELEMENT(Screenshot)
Q_PROPERTY_AUTO(QPoint,start);
Q_PROPERTY_AUTO(QPoint,end);
public:
Screenshot(QQuickItem* parent = nullptr);
void paint(QPainter* painter) override;
private:
QRect _desktopGeometry;
QPixmap _desktopPixmap;
bool _isFirst = true;
};
#endif // SCREENSHOT_H

View File

@ -0,0 +1,99 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Layouts
import FluentUI
Loader {
id:control
Component{
id:com_screen
Window{
id:window_screen
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
width: Screen.desktopAvailableWidth
height: Screen.height
visible: true
color: "#00000000"
onVisibleChanged: {
if(!window_screen.visible){
control.sourceComponent = undefined
}
}
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
screenshot.start = Qt.point(mouse.x,mouse.y)
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onPositionChanged:
(mouse)=>{
if(enablePosition){
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onReleased:
(mouse)=>{
if(mouse.button === Qt.LeftButton){
enablePosition = false
screenshot.end = Qt.point(mouse.x,mouse.y)
}
}
onClicked:
(mouse)=>{
if (mouse.button === Qt.RightButton){
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){
control.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: 1
border.color: FluTheme.primaryColor.dark
MouseArea{
property point clickPos: Qt.point(0,0)
anchors.fill: parent
cursorShape: 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)
}
}
}
}
}
function open(){
control.sourceComponent = com_screen
}
}

View File

@ -84,4 +84,6 @@ FluWindow 1.0 Controls/FluWindow.qml
FluTimeline 1.0 Controls/FluTimeline.qml
FluChart 1.0 Controls/FluChart.qml
FluQRCode 1.0 Controls/FluQRCode.qml
FluScreenshot 1.0 Controls/FluScreenshot.qml
plugin fluentuiplugin