Verified Commit 7b7da92f authored by ivan tkachenko's avatar ivan tkachenko
Browse files

CompactApplet: Port a bunch of imperative code to declarative expressions

It was throwing errors from time to time because references to
fullRepresentation in dynamically created bound expressions turn to null
causing expressions to fail.

Note 1: resetting anchors.fill to null before assigning parent avoid
potential warnings from anchors about filling something that it not a
parent nor a sibling.

Note 2: Popup dialog with full representation will no longer resize to
the applet's explicit width/height, to avoid binding loops conflicting
with `anchors.fill: parent` and non-deterministic ordering of events.

Nit: the /****/ markers are there just for the code alignment.
parent 49b11a2d
Pipeline #184465 passed with stage
in 2 minutes and 56 seconds
......@@ -29,6 +29,7 @@ PlasmaCore.ToolTipArea {
onCompactRepresentationChanged: {
if (compactRepresentation) {
compactRepresentation.anchors.fill = null;
compactRepresentation.parent = compactRepresentationParent;
compactRepresentation.anchors.fill = compactRepresentationParent;
compactRepresentation.visible = true;
......@@ -37,50 +38,11 @@ PlasmaCore.ToolTipArea {
}
onFullRepresentationChanged: {
if (!fullRepresentation) {
return;
}
//if the fullRepresentation size was restored to a stored size, or if is dragged from the desktop, restore popup size
if (fullRepresentation.Layout.preferredWidth > 0) {
popupWindow.mainItem.width = Qt.binding(function() {
return fullRepresentation.Layout.preferredWidth
})
} else if (fullRepresentation.implicitWidth > 0) {
popupWindow.mainItem.width = Qt.binding(function() {
return fullRepresentation.implicitWidth
})
} else if (fullRepresentation.width > 0) {
popupWindow.mainItem.width = Qt.binding(function() {
return fullRepresentation.width
})
} else {
popupWindow.mainItem.width = Qt.binding(function() {
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).width * 35
})
if (fullRepresentation) {
fullRepresentation.anchors.fill = null;
fullRepresentation.parent = appletParent;
fullRepresentation.anchors.fill = appletParent;
}
if (fullRepresentation.Layout.preferredHeight > 0) {
popupWindow.mainItem.height = Qt.binding(function() {
return fullRepresentation.Layout.preferredHeight
})
} else if (fullRepresentation.implicitHeight > 0) {
popupWindow.mainItem.height = Qt.binding(function() {
return fullRepresentation.implicitHeight
})
} else if (fullRepresentation.height > 0) {
popupWindow.mainItem.height = Qt.binding(function() {
return fullRepresentation.height
})
} else {
popupWindow.mainItem.height = Qt.binding(function() {
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height * 25
})
}
fullRepresentation.parent = appletParent;
fullRepresentation.anchors.fill = fullRepresentation.parent;
}
FocusScope {
......@@ -236,6 +198,27 @@ PlasmaCore.ToolTipArea {
Layout.maximumWidth: fullRepresentation ? fullRepresentation.Layout.maximumWidth : Infinity
Layout.maximumHeight: fullRepresentation ? fullRepresentation.Layout.maximumHeight : Infinity
width: {
if (root.fullRepresentation !== null) {
/****/ if (root.fullRepresentation.Layout.preferredWidth > 0) {
return root.fullRepresentation.Layout.preferredWidth;
} else if (root.fullRepresentation.implicitWidth > 0) {
return root.fullRepresentation.implicitWidth;
}
}
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).width * 35;
}
height: {
if (root.fullRepresentation !== null) {
/****/ if (fullRepresentation.Layout.preferredHeight > 0) {
return fullRepresentation.Layout.preferredHeight;
} else if (fullRepresentation.implicitHeight > 0) {
return fullRepresentation.implicitHeight;
}
}
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height * 25;
}
onActiveFocusChanged: {
if (activeFocus && fullRepresentation) {
fullRepresentation.forceActiveFocus()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment