Skip to content

Commit 6ab1fcc

Browse files
committed
Use explicit bindings instead of Connections for oft-occurring changes
1 parent b773cbb commit 6ab1fcc

2 files changed

Lines changed: 55 additions & 60 deletions

File tree

resources/qml/MonitorStageMenu.qml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ Item
1414
signal showTooltip(Item item, point location, string text)
1515
signal hideTooltip()
1616

17-
property var messageStack
18-
property var stagesListContainer
19-
2017
property bool is40
2118
property bool isLE44
2219
property bool isLE46
@@ -28,25 +25,37 @@ Item
2825
isLE46 = (CuraSDKVersion <= "7.2.0") && UM.Application.version != "master"
2926

3027
// adjust message stack position for sidebar
31-
messageStack = base.contentItem.children[0].children[3].children[8]
32-
messageStack.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width) / 2)
28+
var messageStack
29+
if(is40)
30+
{
31+
messageStack = base.contentItem.children[0].children[3].children[7]
32+
}
33+
else if(isLE44)
34+
{
35+
messageStack = base.contentItem.children[2].children[3].children[7]
36+
}
37+
else
38+
{
39+
messageStack = base.contentItem.children[2].children[3].children[8]
40+
}
41+
messageStack.anchors.leftMargin = Qt.binding(function()
42+
{
43+
return Math.floor((base.width) / 2)
44+
})
3345

3446
// adjust stages menu position for sidebar
35-
stagesListContainer = mainWindowHeader.children[1]
36-
stagesListContainer.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width - stagesListContainer.width) / 2)
37-
}
38-
39-
Connections
40-
{
41-
target: base
42-
onWidthChanged:
47+
var stagesListContainer = mainWindowHeader.children[1]
48+
stagesListContainer.anchors.leftMargin = Qt.binding(function()
4349
{
44-
// adjust message stack position for sidebar
45-
messageStack.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width) / 2)
50+
return Math.floor((base.width - printSetupSelector.width - stagesListContainer.width) / 2)
51+
})
4652

47-
// adjust stages menu position for sidebar
48-
stagesListContainer.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width - stagesListContainer.width) / 2)
49-
}
53+
// hide application logo if there is no room for it
54+
var applicationLogo = mainWindowHeader.children[0] // declared as property above
55+
applicationLogo.visible = Qt.binding(function()
56+
{
57+
return stagesListContainer.anchors.leftMargin > applicationLogo.width + 2 * UM.Theme.getSize("default_margin").width
58+
})
5059
}
5160

5261
Cura.MachineSelector

resources/qml/SidebarStageMenu.qml

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ Item
1313
{
1414
id: stageMenu
1515

16-
property var messageStack
17-
property var stagesListContainer
18-
property var applicationLogo
19-
2016
property bool is40
2117
property bool isLE44
2218
property bool isLE46
2319

24-
property bool prepareStageActive: UM.Controller.activeStage.toString().indexOf("PrepareStage") > 0
20+
property bool prepareStageActive: Qt.binding(function()
21+
{
22+
return UM.Controller.activeStage.toString().indexOf("PrepareStage") > 0
23+
})
2524
property bool preSlicedData: PrintInformation !== null && PrintInformation.preSliced
2625
property bool settingsVisible: UM.Preferences.getValue("view/settings_visible")
2726
property bool settingsDocked: UM.Preferences.getValue("sidebargui/docked_sidebar")
@@ -64,34 +63,49 @@ Item
6463
viewOrientationControls.anchors.margins = 0
6564

6665
// adjust message stack position for sidebar
66+
var messageStack
6767
if(is40)
6868
{
69-
messageStack = base.contentItem.children[0].children[3].children[7] // declared as property above
69+
messageStack = base.contentItem.children[0].children[3].children[7]
7070
}
7171
else if(isLE44)
7272
{
73-
messageStack = base.contentItem.children[2].children[3].children[7] // declared as property above
73+
messageStack = base.contentItem.children[2].children[3].children[7]
7474
}
7575
else
7676
{
77-
messageStack = base.contentItem.children[2].children[3].children[8] // declared as property above
77+
messageStack = base.contentItem.children[2].children[3].children[8]
7878
}
7979
messageStack.anchors.horizontalCenter = undefined
8080
messageStack.anchors.left = messageStack.parent.left
81-
messageStack.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width) / 2)
81+
messageStack.anchors.leftMargin = Qt.binding(function()
82+
{
83+
return Math.floor((base.width - printSetupSelector.width) / 2)
84+
})
8285

8386
// adjust stages menu position for sidebar
84-
stagesListContainer = mainWindowHeader.children[1] // declared as property above
87+
var stagesListContainer = mainWindowHeader.children[1]
8588
stagesListContainer.anchors.horizontalCenter = undefined
8689
stagesListContainer.anchors.left = stagesListContainer.parent.left
87-
stagesListContainer.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width - stagesListContainer.width) / 2)
90+
stagesListContainer.anchors.leftMargin = Qt.binding(function()
91+
{
92+
return Math.floor((base.width - printSetupSelector.width - stagesListContainer.width) / 2)
93+
})
94+
8895

8996
// hide application logo if there is no room for it
90-
applicationLogo = mainWindowHeader.children[0] // declared as property above
91-
applicationLogo.visible = stagesListContainer.anchors.leftMargin > applicationLogo.width + 2 * UM.Theme.getSize("default_margin").width
97+
var applicationLogo = mainWindowHeader.children[0]
98+
applicationLogo.visible = Qt.binding(function()
99+
{
100+
return stagesListContainer.anchors.leftMargin > applicationLogo.width + 2 * UM.Theme.getSize("default_margin").width
101+
})
92102

93103
// compensate viewport for full-height sidebar
94-
base.viewportRect = Qt.rect(0, 0, (base.width - sidebarWidth) / base.width, 1.0)
104+
base.viewportRect = Qt.binding(function()
105+
{
106+
return Qt.rect(0, 0, (base.width - sidebarWidth) / base.width, 1.0)
107+
})
108+
95109

96110
// make settingview take up available height
97111
var printSetupContent = printSetupSelector.contentItem
@@ -136,25 +150,6 @@ Item
136150
printSetupTooltip = tooltip // defined in Cura.qml
137151
}
138152

139-
Connections
140-
{
141-
target: base
142-
onWidthChanged:
143-
{
144-
// compensate viewport for full-height sidebar
145-
base.viewportRect = Qt.rect(0, 0, (base.width - sidebarWidth) / base.width, 1.0)
146-
147-
// adjust message stack position for sidebar
148-
messageStack.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width) / 2)
149-
150-
// adjust stages menu position for sidebar
151-
stagesListContainer.anchors.leftMargin = Math.floor((base.width - printSetupSelector.width - stagesListContainer.width) / 2)
152-
153-
// hide application logo if there is no room for it
154-
applicationLogo.visible = stagesListContainer.anchors.leftMargin > applicationLogo.width + 2 * UM.Theme.getSize("default_margin").width
155-
}
156-
}
157-
158153
Connections
159154
{
160155
target: UM.Preferences
@@ -174,15 +169,6 @@ Item
174169
}
175170
}
176171

177-
Connections
178-
{
179-
target: UM.Controller
180-
onActiveStageChanged:
181-
{
182-
prepareStageActive = (UM.Controller.activeStage.toString().indexOf("PrepareStage") == 0)
183-
}
184-
}
185-
186172
Connections
187173
{
188174
target: tooltip

0 commit comments

Comments
 (0)