mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-23 03:10:10 +08:00
update
This commit is contained in:
parent
1b72b840d6
commit
ec9a9a5074
@ -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:{
|
||||
@ -377,7 +383,7 @@ FluObject{
|
||||
FluPaneItem{
|
||||
title:"HotLoader"
|
||||
tapFunc:function(){
|
||||
FluApp.navigate("/hotload")
|
||||
FluApp.navigate("/hotload")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
33
example/qml/page/T_Screenshot.qml
Normal file
33
example/qml/page/T_Screenshot.qml
Normal 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
|
||||
}
|
||||
}
|
@ -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
25
src/Screenshot.cpp
Normal 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
25
src/Screenshot.h
Normal 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
|
99
src/imports/FluentUI/Controls/FluScreenshot.qml
Normal file
99
src/imports/FluentUI/Controls/FluScreenshot.qml
Normal 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
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user