moment/src/qml/Base/HDrawer.qml

84 lines
2.2 KiB
QML
Raw Normal View History

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
// 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
property int normalWidth: 300
property int minNormalWidth: resizeAreaWidth
2019-12-09 20:25:31 +11:00
property int maxNormalWidth:
referenceSizeParent.width - theme.minimumSupportedWidth
property bool collapse: window.width < 400
2019-12-09 20:25:31 +11:00
property int collapseExpandedWidth: referenceSizeParent.width
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
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)
}
property bool canResize: false
}
}
}