Warning, /system/mycroft-gui/import/qml/BoxLayout.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * Copyright 2020 by Marco Martin <mart@kde.org>
0003  *
0004  * Licensed under the Apache License, Version 2.0 (the "License");
0005  * you may not use this file except in compliance with the License.
0006  * You may obtain a copy of the License at
0007  *
0008  *    http://www.apache.org/licenses/LICENSE-2.0
0009  *
0010  * Unless required by applicable law or agreed to in writing, software
0011  * distributed under the License is distributed on an "AS IS" BASIS,
0012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013  * See the License for the specific language governing permissions and
0014  * limitations under the License.
0015  *
0016  */
0017 
0018 //DEPRECATED or inherit fom c++ Delegate?
0019 import QtQuick 2.15
0020 import QtQuick.Layouts 1.15
0021 import Mycroft 2.19 as Mycroft
0022 
0023 Item {
0024     id: root
0025     property alias rowSpacing: lay.rowSpacing
0026     property alias columnSpacing: lay.columnSpacing
0027 
0028     property int orientation: width > height ? Qt.Horizontal : Qt.Vertical
0029     property bool enforceUniformSizes: true
0030 
0031     implicitWidth: lay.implicitWidth
0032     implicitHeight: lay.implicitHeight
0033 
0034     GridLayout {
0035         id: lay
0036         anchors.fill: parent
0037 
0038         columns: root.orientation === Qt.Horizontal ? Infinity : 1
0039         rows: root.orientation === Qt.Vertical ? 1 : Infinity
0040 
0041         Repeater {
0042             model: root.children.length-1
0043             delegate: Item {
0044                 Layout.fillWidth: root.enforceUniformSizes ?  true : item.Layout.fillWidth
0045                 Layout.fillHeight: root.enforceUniformSizes ?  true : item.Layout.fillHeight
0046 
0047                 Layout.minimumWidth: root.enforceUniformSizes ? 0 : item.Layout.minimumWidth
0048                 Layout.minimumHeight: root.enforceUniformSizes ? 0 : item.Layout.minimumHeight
0049 
0050                 Layout.maximumWidth: root.enforceUniformSizes ? Infinity : item.Layout.maximumWidth
0051                 Layout.maximumHeight: root.enforceUniformSizes ? Infinity : item.Layout.maximumHeight
0052 
0053                 Layout.preferredWidth: root.enforceUniformSizes ? -1 : item.Layout.preferredWidth
0054                 Layout.preferredHeight: root.enforceUniformSizes ? -1 : item.Layout.preferredHeight
0055 
0056                 readonly property Item item: root.children[modelData+1]
0057                 visible: item.visible && !(item instanceof Repeater)
0058                 onItemChanged: syncGeometry()
0059 
0060                 function syncGeometry() {
0061                     item.width = width
0062                     if (item.implicitHeight > 0
0063                         && !item.Layout.fillHeight
0064                         && root.orientation === Qt.Horizontal) {
0065                         item.height = Math.min(height, item.implicitHeight);
0066                     } else {
0067                         item.height = height;
0068                     }
0069                     item.x = x
0070                     
0071                     if (root.orientation === Qt.Horizontal) {
0072                         item.y = y + (height - item.height) / 2;
0073                     } else {
0074                         item.y = y;
0075                     }
0076                 }
0077                 onWidthChanged: Qt.callLater(syncGeometry)
0078                 onHeightChanged: Qt.callLater(syncGeometry)
0079                 onXChanged: Qt.callLater(syncGeometry)
0080                 onYChanged: Qt.callLater(syncGeometry)
0081             }
0082         }
0083     }
0084 }