2019-12-09 05:43:41 +11:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import "../utils.js" as Utils
|
|
|
|
|
|
|
|
Drawer {
|
|
|
|
id: drawer
|
2019-12-10 03:16:23 +11:00
|
|
|
implicitWidth: horizontal ? calculatedSize : parent.width
|
|
|
|
implicitHeight: vertical ? calculatedSize : parent.height
|
2019-12-09 20:25:31 +11:00
|
|
|
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
leftPadding: 0
|
|
|
|
rightPadding: 0
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
// FIXME: https://bugreports.qt.io/browse/QTBUG-59141
|
|
|
|
// dragMargin: parent.width / 2
|
|
|
|
|
|
|
|
interactive: collapse
|
|
|
|
position: 1
|
|
|
|
visible: ! collapse
|
|
|
|
modal: false
|
|
|
|
closePolicy: Popup.CloseOnEscape
|
|
|
|
|
|
|
|
background: Rectangle { id: bg; color: theme.colors.strongBackground }
|
|
|
|
|
|
|
|
|
|
|
|
signal userResized(int newWidth)
|
|
|
|
|
2019-12-09 23:01:01 +11:00
|
|
|
property alias color: bg.color
|
|
|
|
|
2019-12-09 20:25:31 +11:00
|
|
|
property Item referenceSizeParent: parent
|
|
|
|
|
2019-12-09 23:10:03 +11:00
|
|
|
property int normalSize:
|
|
|
|
horizontal ? referenceSizeParent.width : referenceSizeParent.height
|
|
|
|
property int minNormalSize: resizeAreaSize
|
|
|
|
property int maxNormalSize:
|
|
|
|
horizontal ?
|
|
|
|
referenceSizeParent.width - theme.minimumSupportedWidth :
|
|
|
|
referenceSizeParent.height - theme.minimumSupportedHeight
|
2019-12-09 05:43:41 +11:00
|
|
|
|
2019-12-09 23:01:01 +11:00
|
|
|
property bool collapse:
|
2019-12-09 23:10:03 +11:00
|
|
|
(horizontal ? window.width : window.height) < 400
|
|
|
|
property int collapseExpandSize:
|
|
|
|
horizontal ? referenceSizeParent.width : referenceSizeParent.height
|
2019-12-09 05:43:41 +11:00
|
|
|
|
2019-12-09 23:10:03 +11:00
|
|
|
property int resizeAreaSize: theme.spacing / 2
|
2019-12-09 05:43:41 +11:00
|
|
|
|
2019-12-09 23:10:03 +11:00
|
|
|
readonly property int calculatedSize:
|
2019-12-09 05:43:41 +11:00
|
|
|
collapse ?
|
2019-12-09 23:10:03 +11:00
|
|
|
collapseExpandSize :
|
|
|
|
Math.max(minNormalSize, Math.min(normalSize, maxNormalSize))
|
2019-12-09 05:43:41 +11:00
|
|
|
|
2019-12-09 23:10:03 +11:00
|
|
|
readonly property bool horizontal:
|
|
|
|
edge === Qt.LeftEdge || edge === Qt.RightEdge
|
|
|
|
|
|
|
|
readonly property bool vertical: ! horizontal
|
2019-12-09 23:01:01 +11:00
|
|
|
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
Behavior on width {
|
2019-12-10 03:10:04 +11:00
|
|
|
enabled: horizontal && ! resizeMouseHandler.drag.active
|
2019-12-09 05:43:41 +11:00
|
|
|
NumberAnimation { duration: 100 }
|
|
|
|
}
|
|
|
|
|
2019-12-09 23:01:01 +11:00
|
|
|
Behavior on height {
|
2019-12-10 03:10:04 +11:00
|
|
|
enabled: vertical && ! resizeMouseHandler.drag.active
|
2019-12-09 23:01:01 +11:00
|
|
|
NumberAnimation { duration: 100 }
|
|
|
|
}
|
|
|
|
|
2019-12-09 05:43:41 +11:00
|
|
|
Item {
|
|
|
|
id: resizeArea
|
2019-12-09 23:01:01 +11:00
|
|
|
x: vertical || drawer.edge === Qt.RightEdge ? 0 : drawer.width-width
|
2019-12-09 23:10:03 +11:00
|
|
|
y: horizontal || drawer.edge !== Qt.TopEdge ? 0 : drawer.height-height
|
|
|
|
width: horizontal ? resizeAreaSize : parent.width
|
|
|
|
height: vertical ? resizeAreaSize : parent.height
|
2019-12-09 23:01:01 +11:00
|
|
|
z: 999
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: resizeMouseHandler
|
|
|
|
anchors.fill: parent
|
|
|
|
enabled: ! drawer.collapse
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
hoverEnabled: true
|
|
|
|
cursorShape:
|
|
|
|
containsMouse || drag.active ?
|
2019-12-09 23:10:03 +11:00
|
|
|
(horizontal ? Qt.SizeHorCursor : Qt.SizeVerCursor) :
|
2019-12-09 23:01:01 +11:00
|
|
|
Qt.ArrowCursor
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
onPressed: canResize = true
|
2019-12-09 23:10:03 +11:00
|
|
|
onReleased: { canResize = false; userResized(drawer.normalSize) }
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
onMouseXChanged:
|
2019-12-09 23:10:03 +11:00
|
|
|
if (horizontal && canResize) {
|
|
|
|
drawer.normalSize =
|
|
|
|
drawer.calculatedSize +
|
2019-12-09 20:25:31 +11:00
|
|
|
(drawer.edge === Qt.RightEdge ? -mouseX : mouseX)
|
|
|
|
}
|
2019-12-09 05:43:41 +11:00
|
|
|
|
2019-12-09 23:01:01 +11:00
|
|
|
onMouseYChanged:
|
|
|
|
if (vertical && canResize) {
|
2019-12-09 23:10:03 +11:00
|
|
|
drawer.normalSize =
|
|
|
|
drawer.calculatedSize +
|
2019-12-09 23:01:01 +11:00
|
|
|
(drawer.edge === Qt.BottomEdge ? -mouseY : mouseY)
|
|
|
|
}
|
|
|
|
|
2019-12-09 05:43:41 +11:00
|
|
|
property bool canResize: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|