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
This commit is contained in:
Marco Martin
2025-06-30 11:25:28 +02:00
parent d08181f56d
commit de97275a38
2 changed files with 17 additions and 54 deletions

View File

@@ -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

View File

@@ -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 {