kdeconnect-kde/app/qml/main.qml
Karthik Nishanth 9e53696e35 Close the overlay drawer when window width is reduced
Previously when the window width was reduced, the overlay drawer
was still visible except it was hidden behind the main view.

Taking inspiration from the binding in OverlayDrawer.qml source,
I set up a callback to match it closely. Now, it closes the
drawer when the window is resized.

Note: Both before and after this commit, there is a warning when
one collapses the window width.

> QQuickItem::stackBefore: Cannot stack
> QQuickRectangle(0x55b4746513d0, parent=0x55b4744a4750,
> geometry=0,0 0x0) before QQuickPopupItem(0x55b4747871c0),
> which must be a sibling
2023-09-11 13:11:03 +00:00

132 lines
4.6 KiB
QML

/*
* SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.20 as Kirigami
import org.kde.kdeconnect 1.0
Kirigami.ApplicationWindow {
id: root
property int columnWidth: Kirigami.Units.gridUnit * 13
minimumWidth: Kirigami.Units.gridUnit * 15
minimumHeight: Kirigami.Units.gridUnit * 15
wideScreen: width > columnWidth * 5
pageStack.globalToolBar.canContainHandles: true
pageStack.globalToolBar.showNavigationButtons: applicationWindow().pageStack.currentIndex > 0 ? Kirigami.ApplicationHeaderStyle.ShowBackButton : 0
globalDrawer: Kirigami.OverlayDrawer {
id: drawer
edge: Qt.application.layoutDirection === Qt.RightToLeft ? Qt.RightEdge : Qt.LeftEdge
modal: Kirigami.Settings.isMobile || (applicationWindow().width < Kirigami.Units.gridUnit * 50 && !collapsed) // Only modal when not collapsed, otherwise collapsed won't show.
width: Kirigami.Units.gridUnit * 16
onModalChanged: drawerOpen = !modal
Behavior on width {
NumberAnimation {
duration: Kirigami.Units.longDuration
easing.type: Easing.InOutQuad
}
}
Kirigami.Theme.colorSet: Kirigami.Theme.Window
handleClosedIcon.source: modal ? null : "sidebar-expand-left"
handleOpenIcon.source: modal ? null : "sidebar-collapse-left"
handleVisible: modal
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
contentItem: ColumnLayout {
spacing: 0
QQC2.ToolBar {
Layout.fillWidth: true
Layout.preferredHeight: pageStack.globalToolBar.preferredHeight
leftPadding: Kirigami.Units.largeSpacing
rightPadding: Kirigami.Units.largeSpacing
topPadding: Kirigami.Units.smallSpacing
bottomPadding: Kirigami.Units.smallSpacing
contentItem: Kirigami.Heading {
text: announcedNameProperty.value
elide: Qt.ElideRight
DBusProperty {
id: announcedNameProperty
object: DaemonDbusInterface
read: "announcedName"
defaultValue: ""
}
}
}
Kirigami.BasicListItem {
id: findDevicesAction
text: i18nd("kdeconnect-app", "Find devices...")
@KIRIGAMI_ICON@: "list-add"
checked: pageStack.currentItem && pageStack.currentItem.objectName == "FindDevices"
Layout.fillWidth: true
onClicked: {
root.pageStack.clear()
root.pageStack.push(Qt.resolvedUrl("FindDevicesPage.qml"));
}
}
Kirigami.Separator {
Layout.fillWidth: true
}
Repeater {
model: DevicesSortProxyModel {
sourceModel: DevicesModel {
displayFilter: DevicesModel.Paired | DevicesModel.Reachable
}
}
Kirigami.BasicListItem {
Layout.fillWidth: true
text: model.name + "\n" + toolTip
enabled: status & DevicesModel.Reachable
checked: pageStack.currentItem && pageStack.currentItem.currentDevice == device
@KIRIGAMI_ICON@: model.iconName
iconColor: "transparent"
onClicked: {
root.pageStack.clear()
root.pageStack.push(
Qt.resolvedUrl("DevicePage.qml"),
{currentDevice: device}
);
}
}
}
Item {
Layout.fillHeight: true
Layout.fillWidth: true
}
Kirigami.BasicListItem {
text: i18n("Settings")
@KIRIGAMI_ICON@: "settings-configure"
onClicked: pageStack.pushDialogLayer('qrc:/qml/Settings.qml', {}, {
title: i18n("Settings"),
});
}
}
}
contextDrawer: Kirigami.ContextDrawer {
id: contextDrawer
}
pageStack.initialPage: Qt.resolvedUrl("FindDevicesPage.qml")
}