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
|
|
|
|
2019-12-11 22:53:27 +11:00
|
|
|
// Prevents this: open a popup, make the window small enough for the
|
|
|
|
// drawer to collapse, then make it big again → popup is now behind drawer
|
|
|
|
z: -1
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
|
2019-12-11 07:29:49 +11:00
|
|
|
property string saveName: ""
|
2019-12-11 08:04:03 +11:00
|
|
|
property var saveId: "ALL"
|
2019-12-11 07:29:49 +11:00
|
|
|
property var saveProperties: ["preferredSize"]
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2019-12-09 23:01:01 +11:00
|
|
|
property alias color: bg.color
|
|
|
|
|
2019-12-11 05:46:05 +11:00
|
|
|
property int defaultSize: 300
|
2019-12-09 20:25:31 +11:00
|
|
|
|
2019-12-11 05:19:25 +11:00
|
|
|
property int preferredSize:
|
2019-12-11 07:29:49 +11:00
|
|
|
window.getState(this, "preferredSize", defaultSize)
|
2019-12-11 05:46:05 +11:00
|
|
|
|
2019-12-11 05:19:25 +11:00
|
|
|
property int minimumSize: resizeAreaSize
|
|
|
|
property int maximumSize:
|
2019-12-09 23:10:03 +11:00
|
|
|
horizontal ?
|
|
|
|
referenceSizeParent.width - theme.minimumSupportedWidth :
|
|
|
|
referenceSizeParent.height - theme.minimumSupportedHeight
|
2019-12-09 05:43:41 +11:00
|
|
|
|
2019-12-11 05:46:05 +11:00
|
|
|
//
|
|
|
|
|
|
|
|
property Item referenceSizeParent: parent
|
|
|
|
|
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
|
2019-12-11 05:19:25 +11:00
|
|
|
property int peekSizeWhileCollapsed:
|
2019-12-09 23:10:03 +11:00
|
|
|
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-11 05:19:25 +11:00
|
|
|
peekSizeWhileCollapsed :
|
|
|
|
Math.max(minimumSize, Math.min(preferredSize, maximumSize))
|
2019-12-09 05:43:41 +11:00
|
|
|
|
2019-12-11 05:46:05 +11:00
|
|
|
//
|
|
|
|
|
2019-12-10 04:52:02 +11:00
|
|
|
readonly property int visibleSize: visible ? width * position : 0
|
|
|
|
|
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
|
2019-12-15 18:45:46 +11:00
|
|
|
preventStealing: true
|
2019-12-09 05:43:41 +11:00
|
|
|
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
|
|
|
|
|
|
|
onMouseXChanged:
|
2019-12-11 05:23:14 +11:00
|
|
|
if (horizontal && pressed) {
|
2019-12-11 05:19:25 +11:00
|
|
|
drawer.preferredSize =
|
2019-12-09 23:10:03 +11:00
|
|
|
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:
|
2019-12-11 05:23:14 +11:00
|
|
|
if (vertical && pressed) {
|
2019-12-11 05:19:25 +11:00
|
|
|
drawer.preferredSize =
|
2019-12-09 23:10:03 +11:00
|
|
|
drawer.calculatedSize +
|
2019-12-09 23:01:01 +11:00
|
|
|
(drawer.edge === Qt.BottomEdge ? -mouseY : mouseY)
|
|
|
|
}
|
|
|
|
|
2019-12-11 07:29:49 +11:00
|
|
|
onReleased: window.saveState(drawer)
|
2019-12-09 05:43:41 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|