| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- import QtQuick 2.0
- import QtQuick.Window 2.15
- Item {
- id:rect
- property int minimumWidth: 20
- property int minimumHeight: 20
- property int mouseRegion: 5
- property var resizeTarget: rect
- anchors.fill: resizeTarget
- MouseArea{
- id: move
- anchors.fill: parent
- anchors.margins: mouseRegion
- cursorShape: Qt.ClosedHandCursor
- property int xPosition: 0
- property int yPosition: 0
- onPressed: function(mouse){
- xPosition = mouse.x
- yPosition = mouse.y
- }
- onPositionChanged: function(mouse){
- var xOffset = mouse.x-xPosition
- var yOffset = mouse.y-yPosition
- if(rect.resizeTarget.x+xOffset>0 && rect.resizeTarget.width+xOffset+rect.resizeTarget.x < rect.resizeTarget.parent.width){
- rect.resizeTarget.x = rect.resizeTarget.x+xOffset
- }
- if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height+yOffset+rect.resizeTarget.y < rect.resizeTarget.parent.height){
- rect.resizeTarget.y = rect.resizeTarget.y+yOffset
- }
- }
- }
- MouseArea {
- id:leftX
- width: mouseRegion
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- anchors.leftMargin: 0
- anchors.bottomMargin: 0
- anchors.topMargin: 0
- cursorShape: Qt.SizeHorCursor
- property int xPosition: 0
- onPressed: function(mouse){
- xPosition = mouse.x
- }
- onPositionChanged: function(mouse){
- var xOffset = mouse.x-xPosition
- if(rect.resizeTarget.x+xOffset>0 && rect.resizeTarget.width-xOffset>minimumWidth){
- rect.resizeTarget.x = rect.resizeTarget.x+xOffset
- rect.resizeTarget.width = rect.resizeTarget.width-xOffset
- }
- }
- }
- MouseArea{
- id:rightX
- width: mouseRegion
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 0
- anchors.topMargin: 0
- anchors.rightMargin: 0
- cursorShape: Qt.SizeHorCursor
- property int xPosition: 0
- onPressed: function(mouse){
- xPosition = mouse.x
- }
- onPositionChanged: function(mouse){
- var xOffset = mouse.x-xPosition
- var xWidth = rect.resizeTarget.width+xOffset
- var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
- if(xWidth+rect.resizeTarget.x<availableWidth && xWidth>minimumWidth){
- rect.resizeTarget.width = xWidth
- }
- }
- }
- MouseArea{
- id:topY
- height: mouseRegion
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.rightMargin: 0
- anchors.leftMargin: 0
- anchors.topMargin: 0
- cursorShape: Qt.SizeVerCursor
- property int yPosition: 0
- onPressed: function(mouse){
- yPosition = mouse.y
- }
- onPositionChanged: function(mouse){
- var yOffset = mouse.y-yPosition
- if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height-yOffset>minimumHeight){
- rect.resizeTarget.y = rect.resizeTarget.y+yOffset
- rect.resizeTarget.height = rect.resizeTarget.height-yOffset
- }
- }
- }
- MouseArea{
- id:bottomY
- height: mouseRegion
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- anchors.rightMargin: 0
- anchors.leftMargin: 0
- anchors.bottomMargin: 0
- cursorShape: Qt.SizeVerCursor
- property int yPosition: 0
- onPressed: function(mouse){
- yPosition = mouse.y
- }
- onPositionChanged: function(mouse){
- var yOffset = mouse.y-yPosition
- var yHeight = rect.resizeTarget.height+yOffset
- var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
- if(yHeight+rect.resizeTarget.y<availableHeight && yHeight>minimumHeight){
- rect.resizeTarget.height = yHeight
- }
- }
- }
- MouseArea{
- width: mouseRegion
- height: mouseRegion
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.topMargin: 0
- anchors.leftMargin: 0
- cursorShape: Qt.SizeFDiagCursor
- property int xPosition: 0
- property int yPosition: 0
- onPressed: function(mouse){
- xPosition = mouse.x
- yPosition = mouse.y
- }
- onPositionChanged: function(mouse){
- var xOffset = mouse.x-xPosition
- if(rect.resizeTarget.x+xOffset>0 && rect.resizeTarget.width-xOffset>minimumWidth){
- rect.resizeTarget.x = rect.resizeTarget.x+xOffset
- rect.resizeTarget.width = rect.resizeTarget.width-xOffset
- }
- var yOffset = mouse.y-yPosition
- if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height-yOffset>minimumHeight){
- rect.resizeTarget.y = rect.resizeTarget.y+yOffset
- rect.resizeTarget.height = rect.resizeTarget.height-yOffset
- }
- }
- }
- MouseArea{
- width: mouseRegion
- height: mouseRegion
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.topMargin: 0
- anchors.rightMargin: 0
- cursorShape: Qt.SizeBDiagCursor
- property int xPosition: 0
- property int yPosition: 0
- onPressed: function(mouse){
- xPosition = mouse.x
- yPosition = mouse.y
- }
- onPositionChanged: function(mouse){
- var xOffset = mouse.x-xPosition
- var xWidth = rect.resizeTarget.width+xOffset
- var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
- var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
- if(xWidth+rect.resizeTarget.x<availableWidth && xWidth>minimumWidth){
- rect.resizeTarget.width = xWidth
- }
- var yOffset = mouse.y-yPosition
- if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height-yOffset>minimumHeight){
- rect.resizeTarget.y = rect.resizeTarget.y+yOffset
- rect.resizeTarget.height = rect.resizeTarget.height-yOffset
- }
- }
- }
- MouseArea{
- width: mouseRegion
- height: mouseRegion
- anchors.left: parent.left
- anchors.bottom: parent.bottom
- anchors.leftMargin: 0
- anchors.bottomMargin: 0
- cursorShape: Qt.SizeBDiagCursor
- property int xPosition: 0
- property int yPosition: 0
- onPressed: function(mouse){
- xPosition = mouse.x
- yPosition = mouse.y
- }
- onPositionChanged: function(mouse){
- var xOffset = mouse.x-xPosition
- var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
- var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
- if(rect.resizeTarget.x+xOffset>0 && availableWidth-xOffset>minimumWidth){
- rect.resizeTarget.x = rect.resizeTarget.x+xOffset
- rect.resizeTarget.width = rect.resizeTarget.width-xOffset
- }
- var yOffset = mouse.y-yPosition
- var yHeight = rect.resizeTarget.height+yOffset
- if(yHeight+rect.resizeTarget.y<availableHeight && yHeight>minimumHeight){
- rect.resizeTarget.height = yHeight
- }
- }
- }
- MouseArea{
- width: mouseRegion
- height: mouseRegion
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- anchors.rightMargin: 0
- anchors.bottomMargin: 0
- cursorShape: Qt.SizeFDiagCursor
- property int xPosition: 0
- property int yPosition: 0
- onPressed: function(mouse){
- xPosition = mouse.x
- yPosition = mouse.y
- }
- onPositionChanged: function(mouse){
- var xOffset = mouse.x-xPosition
- var xWidth = rect.resizeTarget.width+xOffset
- var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
- var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
- if(xWidth+rect.resizeTarget.x<availableWidth && xWidth>minimumWidth){
- rect.resizeTarget.width = xWidth
- }
- var yOffset = mouse.y-yPosition
- var yHeight = rect.resizeTarget.height+yOffset
- if(yHeight+rect.resizeTarget.y<availableHeight && yHeight>minimumHeight){
- rect.resizeTarget.height = yHeight
- }
- }
- }
- }
|