From ce5dac07d3c269f965f8a5bce610357e389693d7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 1 Apr 2019 22:12:49 -0700 Subject: [PATCH] Ensure the anchor hack stays in sync with changing margins prior to Qt 5.12 --- app/gui/AppView.qml | 20 ++++++++++++++++---- app/gui/PcView.qml | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/gui/AppView.qml b/app/gui/AppView.qml index 16a8dc6b..2e9e9a9c 100644 --- a/app/gui/AppView.qml +++ b/app/gui/AppView.qml @@ -9,13 +9,20 @@ GridView { property AppModel appModel : createModel() property bool activated + // Prevent the margin from dropping below 10. By keeping a floor on the margin value + // this prevents a binding loop caused by the ternary condition changing and decreasing + // the margin size, thus causing it to change back. + property real horizontalMargin: Math.max(10, + contentHeight > cellHeight && parent.width > cellWidth ? + (parent.width % cellWidth) / 2 : 0) + id: appGrid focus: true activeFocusOnTab: true topMargin: 20 bottomMargin: 5 - leftMargin: contentHeight > cellHeight && parent.width > cellWidth ? (parent.width % cellWidth) / 2 : 10 - rightMargin: leftMargin + leftMargin: horizontalMargin + rightMargin: horizontalMargin cellWidth: 230; cellHeight: 297; function computerLost() @@ -24,6 +31,13 @@ GridView { stackView.pop() } + onHorizontalMarginChanged: { + if (this.synchronousDrag === undefined) { + anchors.leftMargin = horizontalMargin + anchors.rightMargin = horizontalMargin + } + } + Component.onCompleted: { // Don't show any highlighted item until interacting with them. // We do this here instead of onActivated to avoid losing the user's @@ -36,8 +50,6 @@ GridView { // the grid will not be centered in the window. if (this.synchronousDrag === undefined) { anchors.fill = parent - anchors.leftMargin = leftMargin - anchors.rightMargin = rightMargin anchors.topMargin = topMargin anchors.bottomMargin = bottomMargin } diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index a6c56ed7..04ce943e 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -9,16 +9,30 @@ import StreamingPreferences 1.0 GridView { property ComputerModel computerModel : createModel() + // Prevent the margin from dropping below 10. By keeping a floor on the margin value + // this prevents a binding loop caused by the ternary condition changing and decreasing + // the margin size, thus causing it to change back. + property real horizontalMargin: Math.max(10, + contentHeight > cellHeight && parent.width > cellWidth ? + (parent.width % cellWidth) / 2 : 0) + id: pcGrid focus: true activeFocusOnTab: true topMargin: 20 bottomMargin: 5 - leftMargin: contentHeight > cellHeight && parent.width > cellWidth ? (parent.width % cellWidth) / 2 : 10 - rightMargin: leftMargin + leftMargin: horizontalMargin + rightMargin: horizontalMargin cellWidth: 310; cellHeight: 350; objectName: "Computers" + onHorizontalMarginChanged: { + if (this.synchronousDrag === undefined) { + anchors.leftMargin = horizontalMargin + anchors.rightMargin = horizontalMargin + } + } + Component.onCompleted: { // Don't show any highlighted item until interacting with them. // We do this here instead of onActivated to avoid losing the user's @@ -31,8 +45,6 @@ GridView { // the grid will not be centered in the window. if (this.synchronousDrag === undefined) { anchors.fill = parent - anchors.leftMargin = leftMargin - anchors.rightMargin = rightMargin anchors.topMargin = topMargin anchors.bottomMargin = bottomMargin }