|
| 1 | +import QtQuick 2.14 |
| 2 | +import QtQuick.Controls 2.14 |
| 3 | + |
| 4 | +import Theme 1.0 |
| 5 | + |
| 6 | +Container { |
| 7 | + id: container |
| 8 | + |
| 9 | + enum Direction { |
| 10 | + Up, |
| 11 | + Down, |
| 12 | + Left, |
| 13 | + Right |
| 14 | + } |
| 15 | + |
| 16 | + property string name: '' |
| 17 | + property real size: 48 |
| 18 | + property int direction: QfToolButtonDrawer.Direction.Down |
| 19 | + property bool collapsed: true |
| 20 | + property alias round: toggleButton.round |
| 21 | + property alias bgcolor: toggleButton.bgcolor |
| 22 | + property alias iconSource: toggleButton.iconSource |
| 23 | + property alias iconColor: toggleButton.iconColor |
| 24 | + |
| 25 | + onNameChanged: { |
| 26 | + collapsed = settings.valueBool("QField/QfToolButtonContainer/"+name+"/collapsed", true) |
| 27 | + } |
| 28 | + |
| 29 | + width: { |
| 30 | + switch(container.direction) { |
| 31 | + case QfToolButtonDrawer.Direction.Up: |
| 32 | + case QfToolButtonDrawer.Direction.Down: |
| 33 | + return size |
| 34 | + case QfToolButtonDrawer.Direction.Left: |
| 35 | + case QfToolButtonDrawer.Direction.Right: |
| 36 | + return collapsed ? size : size + content.contentWidth + container.spacing * 2 |
| 37 | + } |
| 38 | + } |
| 39 | + height: { |
| 40 | + switch(container.direction) { |
| 41 | + case QfToolButtonDrawer.Direction.Up: |
| 42 | + case QfToolButtonDrawer.Direction.Down: |
| 43 | + return collapsed ? size : size + content.contentHeight + container.spacing * 2 |
| 44 | + case QfToolButtonDrawer.Direction.Left: |
| 45 | + case QfToolButtonDrawer.Direction.Right: |
| 46 | + return size |
| 47 | + } |
| 48 | + } |
| 49 | + spacing: 4 |
| 50 | + clip: true |
| 51 | + |
| 52 | + Behavior on width { |
| 53 | + enabled: true |
| 54 | + NumberAnimation { duration: 200 } |
| 55 | + } |
| 56 | + |
| 57 | + Behavior on height { |
| 58 | + enabled: true |
| 59 | + NumberAnimation { duration: 200 } |
| 60 | + } |
| 61 | + |
| 62 | + contentItem: Rectangle { |
| 63 | + radius: size / 2 |
| 64 | + color: Qt.hsla(toggleButton.bgcolor.hslHue, toggleButton.bgcolor.hslSaturation, toggleButton.bgcolor.hslLightness, 0.3) |
| 65 | + clip: true |
| 66 | + |
| 67 | + ListView { |
| 68 | + id: content |
| 69 | + width: { |
| 70 | + switch(container.direction) { |
| 71 | + case QfToolButtonDrawer.Direction.Up: |
| 72 | + case QfToolButtonDrawer.Direction.Down: |
| 73 | + return container.size |
| 74 | + case QfToolButtonDrawer.Direction.Left: |
| 75 | + case QfToolButtonDrawer.Direction.Right: |
| 76 | + return content.contentWidth |
| 77 | + } |
| 78 | + } |
| 79 | + height: { |
| 80 | + switch(container.direction) { |
| 81 | + case QfToolButtonDrawer.Direction.Up: |
| 82 | + case QfToolButtonDrawer.Direction.Down: |
| 83 | + return content.contentHeight |
| 84 | + case QfToolButtonDrawer.Direction.Left: |
| 85 | + case QfToolButtonDrawer.Direction.Right: |
| 86 | + return container.size |
| 87 | + } |
| 88 | + } |
| 89 | + x: { |
| 90 | + switch (container.direction) { |
| 91 | + case QfToolButtonDrawer.Direction.Up: |
| 92 | + case QfToolButtonDrawer.Direction.Down: |
| 93 | + case QfToolButtonDrawer.Direction.Left: |
| 94 | + return container.spacing |
| 95 | + case QfToolButtonDrawer.Direction.Right: |
| 96 | + return container.size + container.spacing |
| 97 | + } |
| 98 | + } |
| 99 | + y: { |
| 100 | + switch (container.direction) { |
| 101 | + case QfToolButtonDrawer.Direction.Up: |
| 102 | + case QfToolButtonDrawer.Direction.Left: |
| 103 | + case QfToolButtonDrawer.Direction.Right: |
| 104 | + return container.spacing |
| 105 | + case QfToolButtonDrawer.Direction.Down: |
| 106 | + return container.size + container.spacing |
| 107 | + } |
| 108 | + } |
| 109 | + model: container.contentModel |
| 110 | + snapMode: ListView.SnapToItem |
| 111 | + orientation: container.direction === QfToolButtonDrawer.Direction.Up || container.direction === QfToolButtonDrawer.Direction.Down |
| 112 | + ? ListView.Vertical |
| 113 | + : ListView.Horizontal |
| 114 | + spacing: container.spacing |
| 115 | + } |
| 116 | + |
| 117 | + QfToolButton { |
| 118 | + id: toggleButton |
| 119 | + width: container.size |
| 120 | + height: container.size |
| 121 | + x: { |
| 122 | + switch(direction) { |
| 123 | + case QfToolButtonDrawer.Direction.Down: |
| 124 | + case QfToolButtonDrawer.Direction.Right: |
| 125 | + return 0 |
| 126 | + case QfToolButtonDrawer.Direction.Up: |
| 127 | + case QfToolButtonDrawer.Direction.Left: |
| 128 | + return container.width - container.size |
| 129 | + } |
| 130 | + } |
| 131 | + y: { |
| 132 | + switch(direction) { |
| 133 | + case QfToolButtonDrawer.Direction.Down: |
| 134 | + case QfToolButtonDrawer.Direction.Right: |
| 135 | + return 0 |
| 136 | + case QfToolButtonDrawer.Direction.Up: |
| 137 | + case QfToolButtonDrawer.Direction.Left: |
| 138 | + return container.height - container.size |
| 139 | + } |
| 140 | + } |
| 141 | + round: true |
| 142 | + |
| 143 | + onClicked: { |
| 144 | + container.collapsed = !container.collapsed |
| 145 | + if (name != "") { |
| 146 | + settings.setValue("QField/QfToolButtonContainer/" + name + "/collapsed", container.collapsed) |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments