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
|
|
|
|
implicitWidth: calculatedWidth
|
2019-12-09 20:25:31 +11:00
|
|
|
implicitHeight: referenceSizeParent.height
|
|
|
|
|
|
|
|
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 20:25:31 +11:00
|
|
|
property Item referenceSizeParent: parent
|
|
|
|
|
2019-12-09 05:43:41 +11:00
|
|
|
property int normalWidth: 300
|
|
|
|
property int minNormalWidth: resizeAreaWidth
|
2019-12-09 20:25:31 +11:00
|
|
|
property int maxNormalWidth:
|
|
|
|
referenceSizeParent.width - theme.minimumSupportedWidth
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
property bool collapse: window.width < 400
|
2019-12-09 20:25:31 +11:00
|
|
|
property int collapseExpandedWidth: referenceSizeParent.width
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
property alias color: bg.color
|
|
|
|
property alias resizeAreaWidth: resizeArea.width
|
|
|
|
|
|
|
|
readonly property int calculatedWidth:
|
|
|
|
collapse ?
|
|
|
|
collapseExpandedWidth :
|
|
|
|
Math.max(minNormalWidth, Math.min(normalWidth, maxNormalWidth))
|
|
|
|
|
|
|
|
|
|
|
|
Behavior on width {
|
|
|
|
enabled: ! resizeMouseHandler.drag.active
|
|
|
|
NumberAnimation { duration: 100 }
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: resizeArea
|
2019-12-09 20:25:31 +11:00
|
|
|
x: drawer.edge === Qt.LeftEdge ? drawer.width - width : 0
|
2019-12-09 05:43:41 +11:00
|
|
|
width: theme.spacing / 2
|
|
|
|
height: parent.height
|
|
|
|
z: 9999
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: resizeMouseHandler
|
|
|
|
anchors.fill: parent
|
|
|
|
enabled: ! drawer.collapse
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
hoverEnabled: true
|
|
|
|
cursorShape:
|
|
|
|
containsMouse || drag.active ?
|
|
|
|
Qt.SizeHorCursor : Qt.ArrowCursor
|
|
|
|
|
|
|
|
onPressed: canResize = true
|
|
|
|
onReleased: { canResize = false; userResized(drawer.normalWidth) }
|
|
|
|
|
|
|
|
onMouseXChanged:
|
2019-12-09 20:25:31 +11:00
|
|
|
if (canResize) {
|
|
|
|
drawer.normalWidth =
|
|
|
|
drawer.calculatedWidth +
|
|
|
|
(drawer.edge === Qt.RightEdge ? -mouseX : mouseX)
|
|
|
|
}
|
2019-12-09 05:43:41 +11:00
|
|
|
|
|
|
|
property bool canResize: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|