Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize undocked plugins by dragging corners #78

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 141 additions & 27 deletions include/ignition/gui/qml/IgnRulers.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Rectangle {
// Left ruler
Rectangle {
width: rulersThickness
height: parent.height
height: parent.height - 20
visible: rulersRect.enabled
color: "transparent"
anchors.horizontalCenter: parent.left
Expand All @@ -60,13 +60,7 @@ Rectangle {
onMouseXChanged: {
if (drag.active)
{
var newCardX = Math.max(target.x + mouseX, 0)
var newCardWidth = Math.max(target.width + (target.x - newCardX),
rulersRect.minSize)
if (newCardWidth === target.width)
return;
target.x = newCardX
target.width = newCardWidth
resizeLeft(target, mouseX);
}
}
}
Expand All @@ -75,7 +69,7 @@ Rectangle {
// Right ruler
Rectangle {
width: rulersThickness
height: parent.height
height: parent.height - 20
visible: rulersRect.enabled
color: "transparent"
anchors.horizontalCenter: parent.right
Expand All @@ -88,18 +82,15 @@ Rectangle {
onMouseXChanged: {
if (drag.active)
{
target.width = Math.max(target.width + mouseX, rulersRect.minSize)

if (target.width + target.x > target.parent.width)
target.width = target.parent.width - target.x
resizeRight(target, mouseX);
}
}
}
}

// Top ruler
Rectangle {
width: parent.width
width: parent.width - 20
height: rulersThickness
visible: rulersRect.enabled
color: "transparent"
Expand All @@ -113,23 +104,15 @@ Rectangle {
onMouseYChanged: {
if (drag.active)
{
var newCardY = Math.max(target.y + mouseY, 0)
var newCardHeight = Math.max(target.height + (target.y - newCardY),
rulersRect.minSize)

if (newCardHeight === target.height)
return;

target.y = newCardY
target.height = newCardHeight
resizeTop(target, mouseY);
}
}
}
}

// Bottom ruler
Rectangle {
width: parent.width
width: parent.width - 20
height: rulersThickness
visible: rulersRect.enabled
color: "transparent"
Expand All @@ -143,12 +126,143 @@ Rectangle {
onMouseYChanged: {
if (drag.active)
{
target.height = Math.max(target.height + mouseY, rulersRect.minSize)
resizeBottom(target, mouseY);
}
}
}
}

// Top-Left Ruler
Rectangle {
width: 25
height: 25
visible: rulersRect.enabled
color: "transparent"
anchors.horizontalCenter: parent.left
anchors.verticalCenter: parent.top

MouseArea {
anchors.fill: parent
cursorShape: Qt.SizeFDiagCursor
drag { target: parent; axis: Drag.XAndYAxis }
onMouseYChanged: {
if (drag.active)
{
resizeTop(target, mouseY);
resizeLeft(target, mouseX);
}
}
}
}

// Top-Right Ruler
Rectangle {
width: 25
height: 25
visible: rulersRect.enabled
color: "transparent"
anchors.horizontalCenter: parent.right
anchors.verticalCenter: parent.top

MouseArea {
anchors.fill: parent
cursorShape: Qt.SizeBDiagCursor
drag { target: parent; axis: Drag.XAndYAxis }
onMouseYChanged: {
if (drag.active)
{
resizeTop(target, mouseY);
resizeRight(target, mouseX);
}
}
}
}

// Bottom-Left Ruler
Rectangle {
width: 25
height: 25
visible: rulersRect.enabled
color: "transparent"
anchors.horizontalCenter: parent.left
anchors.verticalCenter: parent.bottom

MouseArea {
anchors.fill: parent
cursorShape: Qt.SizeBDiagCursor
drag { target: parent; axis: Drag.XAndYAxis }
onMouseYChanged: {
if (drag.active)
{
resizeBottom(target, mouseY);
resizeLeft(target, mouseX);
}
}
}
}

// Bottom-Right Ruler
Rectangle {
width: 25
height: 25
visible: rulersRect.enabled
color: "transparent"
anchors.horizontalCenter: parent.right
anchors.verticalCenter: parent.bottom

if (target.height + target.y > target.parent.height)
target.height = target.parent.height - target.y
MouseArea {
anchors.fill: parent
cursorShape: Qt.SizeFDiagCursor
drag { target: parent; axis: Drag.XAndYAxis }
onMouseYChanged: {
if (drag.active)
{
resizeBottom(target, mouseY);
resizeRight(target, mouseX);
}
}
}
}

function resizeLeft(target, mouseX)
{
var newCardX = Math.max(target.x + mouseX, 0)
var newCardWidth = Math.max(target.width + (target.x - newCardX),
rulersRect.minSize)

if (newCardWidth === target.width)
return;

target.x = newCardX
target.width = newCardWidth
}

function resizeRight(target, mouseX)
{
target.width = Math.max(target.width + mouseX, rulersRect.minSize)

if (target.width + target.x > target.parent.width)
target.width = target.parent.width - target.x
}

function resizeTop(target, mouseY)
{
var newCardY = Math.max(target.y + mouseY, 0)
var newCardHeight = Math.max(target.height + (target.y - newCardY),
rulersRect.minSize)

if (newCardHeight === target.height)
return;

target.y = newCardY
target.height = newCardHeight
}

function resizeBottom(target, mouseY)
{
target.height = Math.max(target.height + mouseY, rulersRect.minSize)

if (target.height + target.y > target.parent.height)
target.height = target.parent.height - target.y
}
}