| 1 |
import QtQuick |
| 2 |
|
| 3 |
Item { |
| 4 |
id: root |
| 5 |
|
| 6 |
property double channelHeightRatio: 0.5 |
| 7 |
property alias color : splitter.color |
| 8 |
property alias thickness: splitter.height |
| 9 |
|
| 10 |
opacity: 0.05 |
| 11 |
|
| 12 |
signal ratioChanged(double v) |
| 13 |
|
| 14 |
QtObject { |
| 15 |
id: prv |
| 16 |
|
| 17 |
readonly property double minChannelHeight: 20 |
| 18 |
readonly property double minRatio: minChannelHeight / root.height |
| 19 |
readonly property double maxRatio: (root.height - minChannelHeight) / root.height |
| 20 |
} |
| 21 |
|
| 22 |
Rectangle { |
| 23 |
id: splitter |
| 24 |
|
| 25 |
height: 1 |
| 26 |
width: root.width |
| 27 |
} |
| 28 |
|
| 29 |
MouseArea { |
| 30 |
anchors.fill: splitter |
| 31 |
anchors.margins: -2 |
| 32 |
|
| 33 |
drag.target: splitter |
| 34 |
drag.axis: Drag.YAxis |
| 35 |
drag.threshold: 0 |
| 36 |
|
| 37 |
cursorShape: Qt.SplitVCursor |
| 38 |
|
| 39 |
onPositionChanged: { |
| 40 |
let ratio = splitter.y / root.height |
| 41 |
clampRatio(ratio) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
Component.onCompleted: { |
| 46 |
root.heightChanged.connect(function() { |
| 47 |
clampRatio(root.channelHeightRatio) |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
function clampRatio(ratio) { |
| 52 |
let newRatio = Math.max(prv.minRatio, Math.min(prv.maxRatio, ratio)); |
| 53 |
root.ratioChanged(newRatio) |
| 54 |
splitter.y = Math.round(newRatio * root.height - 1) |
| 55 |
} |
| 56 |
|
| 57 |
Binding { |
| 58 |
target: splitter |
| 59 |
property: "y" |
| 60 |
value: Math.round(root.channelHeightRatio * root.height - 1) |
| 61 |
} |
| 62 |
} |