mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-01-23 04:14:35 +08:00
update
This commit is contained in:
parent
5fc7ae7e89
commit
94a96cf75e
@ -15,6 +15,7 @@ Item{
|
||||
signal captrueCompleted(var captrue)
|
||||
QtObject{
|
||||
id:d
|
||||
property bool isEdit: false
|
||||
property int dotMouseSize: control.dotSize+10
|
||||
property int dotMargins: -(control.dotSize-control.borderSize)/2
|
||||
property bool enablePosition: false
|
||||
@ -41,6 +42,7 @@ Item{
|
||||
}
|
||||
}
|
||||
Component.onCompleted: {
|
||||
d.isEdit = false
|
||||
setGeometry(0,0,screenshot_background.width,screenshot_background.height)
|
||||
}
|
||||
ScreenshotBackground{
|
||||
@ -108,6 +110,8 @@ Item{
|
||||
}
|
||||
screenshot.start = Qt.point(0,0)
|
||||
screenshot.end = Qt.point(0,0)
|
||||
d.isEdit = false
|
||||
screenshot_background.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,21 +126,63 @@ Item{
|
||||
border.color: control.borderColor
|
||||
MouseArea{
|
||||
property point clickPos: Qt.point(0,0)
|
||||
property var currentData
|
||||
property bool enablePositionChanged : false
|
||||
property var hitData
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.SizeAllCursor
|
||||
hoverEnabled: true
|
||||
cursorShape: d.isEdit ? Qt.ArrowCursor : Qt.SizeAllCursor
|
||||
onPressed:
|
||||
(mouse)=>{
|
||||
clickPos = Qt.point(mouse.x, mouse.y)
|
||||
if(hitData){
|
||||
return
|
||||
}
|
||||
enablePositionChanged = true
|
||||
if(d.isEdit){
|
||||
clickPos = Qt.point(mouse.x, mouse.y)
|
||||
currentData = screenshot_background.appendDrawData(0,clickPos,clickPos)
|
||||
}else{
|
||||
clickPos = Qt.point(mouse.x, mouse.y)
|
||||
}
|
||||
}
|
||||
onReleased: {
|
||||
enablePositionChanged = false
|
||||
}
|
||||
onCanceled: {
|
||||
enablePositionChanged = false
|
||||
}
|
||||
onClicked: {
|
||||
if(hitData){
|
||||
screenshot_background.hitDrawData = hitData
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
||||
if(!enablePositionChanged){
|
||||
hitData = screenshot_background.hit(Qt.point(rect_capture.x + mouse.x,rect_capture.y + mouse.y))
|
||||
if(hitData){
|
||||
FluTools.setOverrideCursor(Qt.SizeAllCursor)
|
||||
}else{
|
||||
FluTools.restoreOverrideCursor()
|
||||
}
|
||||
return
|
||||
}
|
||||
if(d.isEdit){
|
||||
var start = Qt.point(rect_capture.x + clickPos.x,rect_capture.y + clickPos.y)
|
||||
var end = Qt.point(Math.min(Math.max(rect_capture.x + mouse.x,rect_capture.x+borderSize),rect_capture.x+rect_capture.width-currentData.getLineWidth()),Math.min(Math.max(rect_capture.y + mouse.y,rect_capture.y+currentData.getLineWidth()+borderSize),rect_capture.y+rect_capture.height)-currentData.getLineWidth())
|
||||
console.debug("start->"+start)
|
||||
console.debug("end->"+end)
|
||||
screenshot_background.updateDrawData(currentData,start,end)
|
||||
}else{
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -474,7 +520,7 @@ Item{
|
||||
}
|
||||
}
|
||||
Pane{
|
||||
width: 100
|
||||
width: 140
|
||||
height: 40
|
||||
visible: {
|
||||
if(screenshot.start === Qt.point(0,0) && screenshot.end === Qt.point(0,0)){
|
||||
@ -498,6 +544,12 @@ Item{
|
||||
RowLayout{
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.right: parent.right
|
||||
FluIconButton{
|
||||
iconSource: FluentIcons.Stop
|
||||
onClicked: {
|
||||
d.isEdit = true
|
||||
}
|
||||
}
|
||||
FluIconButton{
|
||||
iconSource: FluentIcons.Cancel
|
||||
iconSize: 18
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "Def.h"
|
||||
|
||||
|
||||
Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
{
|
||||
_desktopGeometry = qApp->primaryScreen()->virtualGeometry();
|
||||
@ -42,17 +43,73 @@ ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedIt
|
||||
}
|
||||
setWidth(w);
|
||||
setHeight(h);
|
||||
connect(this,&ScreenshotBackground::hitDrawDataChanged,this,[=]{update();});
|
||||
}
|
||||
|
||||
void ScreenshotBackground::paint(QPainter* painter)
|
||||
{
|
||||
painter->save();
|
||||
_sourcePixmap = _desktopPixmap.copy();
|
||||
foreach (auto item, _drawList) {
|
||||
if(item->drawType == 0){
|
||||
QPainter p(&_sourcePixmap);
|
||||
QPen pen;
|
||||
pen.setWidth(item->lineWidth);
|
||||
pen.setColor(QColor(255,0,0));
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
p.setPen(pen);
|
||||
QRect rect(item->start.x(), item->start.y(), item->end.x()-item->start.x(), item->end.y()-item->start.y());
|
||||
p.drawRect(rect);
|
||||
}
|
||||
}
|
||||
painter->drawPixmap(_desktopGeometry,_sourcePixmap);
|
||||
foreach (auto item, _drawList) {
|
||||
if(item->drawType == 0){
|
||||
if(item == _hitDrawData){
|
||||
painter->setPen(QPen(QColor(255,0,0),3));
|
||||
painter->setBrush(QColor(255,255,255));
|
||||
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()-4,8,8));
|
||||
painter->drawEllipse(QRect(item->start.x()+item->getWidth()/2-4,item->start.y()-4,8,8));
|
||||
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()-4,8,8));
|
||||
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()+item->getHeight()/2-4,8,8));
|
||||
painter->drawEllipse(QRect(item->start.x()+item->getWidth()-4,item->start.y()+item->getHeight()-4,8,8));
|
||||
painter->drawEllipse(QRect(item->start.x()+item->getWidth()/2-4,item->start.y()+item->getHeight()-4,8,8));
|
||||
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()+item->getHeight()-4,8,8));
|
||||
painter->drawEllipse(QRect(item->start.x()-4,item->start.y()+item->getHeight()/2-4,8,8));
|
||||
}
|
||||
}
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void ScreenshotBackground::clear(){
|
||||
_drawList.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
DrawData* ScreenshotBackground::hit(const QPoint& point){
|
||||
foreach (auto item, _drawList) {
|
||||
if(item->drawType == 0){
|
||||
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->start.x()+item->lineWidth+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
|
||||
return item;
|
||||
}
|
||||
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->start.y()+item->lineWidth+mouseSpacing){
|
||||
return item;
|
||||
}
|
||||
if(point.x()>=item->end.x()-item->lineWidth-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->start.y()-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
|
||||
return item;
|
||||
}
|
||||
if(point.x()>=item->start.x()-mouseSpacing && point.x()<=item->end.x()+mouseSpacing && point.y()>=item->end.y()-item->lineWidth-mouseSpacing && point.y()<=item->end.y()+mouseSpacing){
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
|
||||
hitDrawData(nullptr);
|
||||
update();
|
||||
auto pixelRatio = qApp->primaryScreen()->devicePixelRatio();
|
||||
auto x = qMin(start.x(),end.x()) * pixelRatio;
|
||||
auto y = qMin(start.y(),end.y()) * pixelRatio;
|
||||
@ -73,3 +130,20 @@ void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){
|
||||
}
|
||||
}
|
||||
|
||||
DrawData* ScreenshotBackground::appendDrawData(int drawType,QPoint start,QPoint end){
|
||||
DrawData *data = new DrawData(this);
|
||||
data->drawType = drawType;
|
||||
data->start = start;
|
||||
data->end = end;
|
||||
data->lineWidth = 3;
|
||||
_drawList.append(data);
|
||||
update();
|
||||
return data;
|
||||
}
|
||||
|
||||
void ScreenshotBackground::updateDrawData(DrawData* data,QPoint start,QPoint end){
|
||||
data->start = start;
|
||||
data->end = end;
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,26 @@
|
||||
#include <QPainter>
|
||||
#include <QQuickItemGrabResult>
|
||||
#include "stdafx.h"
|
||||
#include <qmath.h>
|
||||
|
||||
class DrawData:public QObject{
|
||||
Q_OBJECT;
|
||||
public:
|
||||
explicit DrawData(QObject *parent = nullptr): QObject{parent}{};
|
||||
int drawType;
|
||||
int lineWidth;
|
||||
QPoint start;
|
||||
QPoint end;
|
||||
Q_INVOKABLE int getLineWidth(){
|
||||
return lineWidth;
|
||||
}
|
||||
Q_INVOKABLE int getWidth(){
|
||||
return end.x()-start.x();
|
||||
}
|
||||
Q_INVOKABLE int getHeight(){
|
||||
return end.y()-start.y();
|
||||
}
|
||||
};
|
||||
|
||||
class ScreenshotBackground : public QQuickPaintedItem
|
||||
{
|
||||
@ -13,10 +33,15 @@ class ScreenshotBackground : public QQuickPaintedItem
|
||||
QML_NAMED_ELEMENT(ScreenshotBackground)
|
||||
Q_PROPERTY_AUTO(QString,saveFolder);
|
||||
Q_PROPERTY_AUTO(int,captureMode);
|
||||
Q_PROPERTY_AUTO(DrawData*,hitDrawData);
|
||||
public:
|
||||
ScreenshotBackground(QQuickItem* parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
Q_INVOKABLE void capture(const QPoint& start,const QPoint& end);
|
||||
Q_INVOKABLE DrawData* appendDrawData(int drawType,QPoint start,QPoint end);
|
||||
Q_INVOKABLE void updateDrawData(DrawData* data,QPoint start,QPoint end);
|
||||
Q_INVOKABLE void clear();
|
||||
Q_INVOKABLE DrawData* hit(const QPoint& point);
|
||||
Q_SIGNAL void captrueToPixmapCompleted(QPixmap captrue);
|
||||
Q_SIGNAL void captrueToFileCompleted(QUrl captrue);
|
||||
private:
|
||||
@ -26,6 +51,8 @@ private:
|
||||
qreal _devicePixelRatio;
|
||||
QSharedPointer<QQuickItemGrabResult> _grabResult;
|
||||
QRect _captureRect;
|
||||
QList<DrawData*> _drawList;
|
||||
int mouseSpacing = 3;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user