From de97275a387abcbca6fcb185bcbd1b69c30f5c66 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 30 Jun 2025 11:25:28 +0200 Subject: [PATCH] Use new Kirigami builtin column resize handle Use the new Kirigami.ColumnView.interactiveResizeEnabled attached property which allows to have a built in resize handle for ColumnView pages removing the need for a custom handle with resize logic depends from https://invent.kde.org/frameworks/kirigami/-/merge_requests/1795 --- src/app/qml/Main.qml | 1 + src/rooms/RoomListPage.qml | 70 +++++++++----------------------------- 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/src/app/qml/Main.qml b/src/app/qml/Main.qml index 4388a7e46..2ccb8f1ff 100644 --- a/src/app/qml/Main.qml +++ b/src/app/qml/Main.qml @@ -41,6 +41,7 @@ Kirigami.ApplicationWindow { showExisting: true onConnectionChosen: root.load() } + columnView.columnResizeMode: pageStack.wideMode ? Kirigami.ColumnView.DynamicColumns : Kirigami.ColumnView.SingleColumn globalToolBar.canContainHandles: true globalToolBar { style: Kirigami.ApplicationHeaderStyle.ToolBar diff --git a/src/rooms/RoomListPage.qml b/src/rooms/RoomListPage.qml index 6f15c860c..9cae9f414 100644 --- a/src/rooms/RoomListPage.qml +++ b/src/rooms/RoomListPage.qml @@ -17,13 +17,22 @@ import org.kde.neochat Kirigami.Page { id: root - /** - * @brief The current width of the room list. - * - * @note Other objects can access the value but the private function makes sure - * that only the internal members can modify it. - */ - readonly property int currentWidth: _private.currentWidth + spaceDrawer.width + 1 + Kirigami.ColumnView.interactiveResizeEnabled: true + Kirigami.ColumnView.minimumWidth: _private.collapsedSize + spaceDrawer.width + 1 + Kirigami.ColumnView.maximumWidth: _private.defaultWidth + spaceDrawer.width + 1 + Kirigami.ColumnView.onInteractiveResizingChanged: { + if (!Kirigami.ColumnView.interactiveResizing && collapsed) { + Kirigami.ColumnView.preferredWidth = root.Kirigami.ColumnView.minimumWidth; + } + } + Kirigami.ColumnView.preferredWidth: _private.currentWidth + spaceDrawer.width + 1 + Kirigami.ColumnView.onPreferredWidthChanged: { + if (width > _private.collapseWidth) { + NeoChatConfig.collapsed = false; + } else if (Kirigami.ColumnView.interactiveResizing) { + NeoChatConfig.collapsed = true; + } + } required property NeoChatConnection connection @@ -31,10 +40,6 @@ Kirigami.Page { signal search - onCurrentWidthChanged: pageStack.defaultColumnWidth = root.currentWidth - Component.onCompleted: pageStack.defaultColumnWidth = root.currentWidth - - onCollapsedChanged: { if (collapsed) { RoomManager.sortFilterRoomTreeModel.filterText = ""; @@ -244,49 +249,6 @@ Kirigami.Page { sourceComponent: Kirigami.Settings.isMobile ? exploreComponentMobile : userInfoDesktop } - MouseArea { - anchors.top: parent.top - anchors.bottom: parent.bottom - parent: applicationWindow().overlay.parent - - x: root.currentWidth - width / 2 - width: Kirigami.Units.smallSpacing * 2 - z: root.z + 1 - enabled: RoomManager.hasOpenRoom && applicationWindow().width >= Kirigami.Units.gridUnit * 35 - visible: enabled - cursorShape: Qt.SplitHCursor - - property int _lastX - - onPressed: mouse => { - _lastX = mouse.x; - } - onPositionChanged: mouse => { - if (_lastX == -1) { - return; - } - if (mouse.x > _lastX) { - // we moved to the right - if (_private.currentWidth < _private.collapseWidth && _private.currentWidth + (mouse.x - _lastX) >= _private.collapseWidth) { - // Here we get back directly to a more wide mode. - _private.currentWidth = _private.defaultWidth; - NeoChatConfig.collapsed = false; - } else if (_private.currentWidth >= _private.collapseWidth) { - // Increase page width - _private.currentWidth = Math.min(_private.defaultWidth, _private.currentWidth + (mouse.x - _lastX)); - } - } else if (mouse.x < _lastX) { - const tmpWidth = _private.currentWidth - (_lastX - mouse.x); - if (tmpWidth < _private.collapseWidth) { - _private.currentWidth = Qt.binding(() => _private.collapsedSize); - NeoChatConfig.collapsed = true; - } else { - _private.currentWidth = tmpWidth; - } - } - } - } - Component { id: userInfo UserInfo {