2021-02-24 10:50:41 +08:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.5
|
2021-03-15 15:30:17 +08:00
|
|
|
import QtQuick.Layouts 1.15
|
2021-02-24 10:50:41 +08:00
|
|
|
|
2021-03-15 15:30:17 +08:00
|
|
|
import "util.mjs" as Util
|
2021-03-17 18:20:43 +08:00
|
|
|
import "gravity.mjs" as Gravity
|
2021-03-15 15:30:17 +08:00
|
|
|
|
|
|
|
Rectangle {
|
2021-04-07 10:41:34 +08:00
|
|
|
property var wrapper
|
2021-03-19 16:13:02 +08:00
|
|
|
|
2021-04-06 17:07:48 +08:00
|
|
|
clip: true
|
|
|
|
|
2021-03-17 18:20:43 +08:00
|
|
|
property var tag: "HLayout"
|
|
|
|
|
2021-03-15 15:30:17 +08:00
|
|
|
property var uuid: Util.uuidv4()
|
2021-03-17 18:20:43 +08:00
|
|
|
|
2021-03-15 15:30:17 +08:00
|
|
|
property int widthSpec: 0
|
|
|
|
property int heightSpec: 0
|
|
|
|
property int childrenRectWidth: childrenRect.width
|
|
|
|
property int childrenRectHeight: childrenRect.height
|
|
|
|
|
2021-04-07 10:41:34 +08:00
|
|
|
onWidthChanged: {
|
2021-03-15 15:30:17 +08:00
|
|
|
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:41:34 +08:00
|
|
|
onHeightChanged: {
|
2021-03-15 15:30:17 +08:00
|
|
|
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:41:34 +08:00
|
|
|
onWidthSpecChanged: {
|
2021-03-15 15:30:17 +08:00
|
|
|
console.log(tag, uuid + " onWidthSpecChanged: " + this.widthSpec)
|
|
|
|
console.log(tag, uuid + " parent width: " + parent.width)
|
2021-03-17 18:20:43 +08:00
|
|
|
|
2021-03-15 15:30:17 +08:00
|
|
|
if (this.widthSpec === 2) {
|
|
|
|
this.width = parent.width
|
2021-04-07 22:43:21 +08:00
|
|
|
children[1].width = parent.width
|
2021-03-15 15:30:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:41:34 +08:00
|
|
|
onHeightSpecChanged: {
|
2021-03-15 15:30:17 +08:00
|
|
|
console.log(tag, uuid + " onHeightSpecChanged: " + this.heightSpec)
|
|
|
|
console.log(tag, uuid + " parent height: " + parent.height)
|
|
|
|
|
|
|
|
if (this.heightSpec === 2) {
|
|
|
|
this.height = parent.height
|
2021-03-19 16:13:02 +08:00
|
|
|
children[1].height = parent.height
|
2021-03-15 15:30:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:41:34 +08:00
|
|
|
onChildrenRectChanged: {
|
2021-03-15 15:30:17 +08:00
|
|
|
console.log(tag, uuid + " widthSpec: " + widthSpec + " heightSpec: " + heightSpec)
|
2021-03-16 15:33:24 +08:00
|
|
|
console.log(tag, uuid + " onChildrenRectChanged: " + childrenRect)
|
2021-03-15 15:30:17 +08:00
|
|
|
this.childrenRectWidth = childrenRect.width
|
|
|
|
this.childrenRectHeight = childrenRect.height
|
|
|
|
|
|
|
|
if (this.widthSpec === 1) {
|
|
|
|
this.width = childrenRectWidth
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.heightSpec === 1) {
|
|
|
|
this.height = childrenRectHeight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
color: 'transparent'
|
|
|
|
|
2021-03-19 16:13:02 +08:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
2021-04-07 10:41:34 +08:00
|
|
|
console.log(tag, uuid + " wrapper: " + wrapper)
|
2021-03-19 16:13:02 +08:00
|
|
|
mouseAreaBridge.onClick(wrapper)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 15:30:17 +08:00
|
|
|
RowLayout {
|
2021-03-17 18:20:43 +08:00
|
|
|
property int gravity: 0
|
|
|
|
|
2021-03-15 15:30:17 +08:00
|
|
|
spacing: 0
|
2021-03-17 18:20:43 +08:00
|
|
|
|
2021-04-07 22:43:21 +08:00
|
|
|
Item {
|
|
|
|
id: head
|
|
|
|
objectName: "head"
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:41:34 +08:00
|
|
|
onChildrenChanged: {
|
2021-03-17 18:20:43 +08:00
|
|
|
console.log(tag, uuid + " gravity: " + gravity)
|
|
|
|
for (var i = 0;i !== children.length;i++) {
|
2021-04-07 22:43:21 +08:00
|
|
|
if (children[i] !== head && children[i] !== tail) {
|
|
|
|
switch(this.gravity) {
|
|
|
|
case Gravity.enumerate().CENTER_X:
|
|
|
|
children[i].Layout.alignment = Qt.AlignHCenter
|
|
|
|
break
|
|
|
|
case Gravity.enumerate().CENTER:
|
|
|
|
children[i].Layout.alignment = Qt.AlignCenter
|
|
|
|
break
|
|
|
|
}
|
2021-03-17 18:20:43 +08:00
|
|
|
}
|
|
|
|
}
|
2021-04-07 22:43:21 +08:00
|
|
|
|
2021-04-08 10:14:49 +08:00
|
|
|
if (parent.widthSpec == 1) {
|
|
|
|
tail.Layout.fillWidth = false
|
|
|
|
} else {
|
2021-04-08 10:23:23 +08:00
|
|
|
if (gravity === Gravity.enumerate().CENTER || gravity === Gravity.enumerate().CENTER_X) {
|
|
|
|
head.Layout.fillWidth = true
|
|
|
|
} else {
|
|
|
|
head.Layout.fillWidth = false
|
|
|
|
}
|
2021-04-08 10:14:49 +08:00
|
|
|
tail.Layout.fillWidth = true
|
|
|
|
}
|
2021-04-07 22:43:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: tail
|
|
|
|
objectName: "tail"
|
2021-03-17 18:20:43 +08:00
|
|
|
}
|
2021-03-15 15:30:17 +08:00
|
|
|
}
|
2021-02-24 10:50:41 +08:00
|
|
|
}
|