moment/src/qml/SidePane/SidePane.qml

112 lines
3.0 KiB
QML
Raw Normal View History

import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../Base"
import "../utils.js" as Utils
HRectangle {
id: sidePane
clip: true
opacity: mainUI.accountsPresent && ! reduce ? 1 : 0
visible: opacity > 0
2019-04-29 01:01:38 +10:00
color: theme.sidePane.background
property bool hasFocus: paneToolBar.filterField.activeFocus
property alias accountRoomList: accountRoomList
property alias paneToolBar: paneToolBar
property real autoWidthRatio: theme.sidePane.autoWidthRatio
property bool manuallyResizing: false
property bool manuallyResized: false
property int manualWidth: 0
property bool animateWidth: true
2019-07-21 23:08:22 +10:00
Component.onCompleted: {
if (window.uiState.sidePaneManualWidth) {
manualWidth = window.uiState.sidePaneManualWidth
manuallyResized = true
}
}
onFocusChanged: if (focus) paneToolBar.filterField.forceActiveFocus()
2019-07-21 23:08:22 +10:00
onManualWidthChanged: {
window.uiState.sidePaneManualWidth = manualWidth
window.uiStateChanged()
}
property int maximumCalculatedWidth: Math.min(
manuallyResized ? manualWidth : theme.sidePane.maximumAutoWidth,
window.width - theme.minimumSupportedWidthPlusSpacing
)
property int parentWidth: parent.width
// Needed for SplitView since it breaks the binding when user manual sizes
onParentWidthChanged: width = Qt.binding(() => implicitWidth)
property int calculatedWidth: Math.min(
2019-07-21 23:08:22 +10:00
manuallyResized ? manualWidth : parentWidth * autoWidthRatio,
maximumCalculatedWidth
)
2019-07-12 12:25:50 +10:00
2019-07-16 23:21:45 +10:00
property bool collapse:
(manuallyResizing ? width : calculatedWidth) <
(manuallyResized ?
(theme.sidePane.collapsedWidth + theme.spacing * 2) :
theme.sidePane.autoCollapseBelowWidth)
2019-07-16 22:36:11 +10:00
2019-07-16 23:21:45 +10:00
property bool reduce:
window.width < theme.sidePane.autoReduceBelowWindowWidth
2019-07-16 23:21:45 +10:00
property int implicitWidth:
reduce ? 0 :
collapse ? theme.sidePane.collapsedWidth :
calculatedWidth
2019-07-17 07:08:06 +10:00
property int currentSpacing:
width <= theme.sidePane.collapsedWidth + theme.spacing * 2 ?
0 : theme.spacing
2019-07-16 23:21:45 +10:00
Behavior on currentSpacing { HNumberAnimation {} }
Behavior on implicitWidth {
HNumberAnimation { factor: animateWidth ? 1 : 0 }
}
function setFocus() {
forceActiveFocus()
if (reduce) {
pageLoader.item.currentIndex = 0
}
}
Keys.enabled: sidePane.hasFocus
Keys.onUpPressed: accountRoomList.previous(false) // do not activate
Keys.onDownPressed: accountRoomList.next(false)
Keys.onEnterPressed: Keys.onReturnPressed(event)
Keys.onReturnPressed: if (event.modifiers & Qt.ShiftModifier) {
accountRoomList.toggleCollapseAccount()
} else {
accountRoomList.activate()
}
HColumnLayout {
anchors.fill: parent
AccountRoomList {
id: accountRoomList
clip: true
Layout.fillWidth: true
Layout.fillHeight: true
}
PaneToolBar {
id: paneToolBar
}
}
}