From 93b46dcfee2d6ec66d1dba61a4264967d3c9899b Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 20 Jul 2020 21:37:08 -0400 Subject: [PATCH] Move AutoDirectionLayout sum function to Utils --- src/gui/Base/AutoDirectionLayout.qml | 14 ++------------ src/gui/Utils.qml | 13 +++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/gui/Base/AutoDirectionLayout.qml b/src/gui/Base/AutoDirectionLayout.qml index d14c911b..2cd8ab7b 100644 --- a/src/gui/Base/AutoDirectionLayout.qml +++ b/src/gui/Base/AutoDirectionLayout.qml @@ -4,18 +4,8 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 HGridLayout { - readonly property real summedImplicitWidth: { - let sum = 0 - - for (let i = 0; i < visibleChildren.length; i++) { - const item = visibleChildren[i] - - if (item) - sum += (item.width > 0 ? item.implicitWidth : 0) +columnSpacing - } - - return sum - } + readonly property real summedImplicitWidth: + utils.sumChildrenImplicitWidths(visibleChildren, columnSpacing) flow: diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index d4525b55..e05cc88e 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -498,4 +498,17 @@ QtObject { userId, "send_file", [roomId, path], onSuccess, onError, ) } + + function sumChildrenImplicitWidths(visibleChildren, spacing=0) { + let sum = 0 + + for (let i = 0; i < visibleChildren.length; i++) { + const item = visibleChildren[i] + + if (item) + sum += (item.width > 0 ? item.implicitWidth : 0) + spacing + } + + return sum + } }