Kirigami2

BackButton.qml
1/*
2 * SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick
8import org.kde.kirigami as Kirigami
9
10NavigationButton {
11 id: button
12
13 icon.name: (LayoutMirroring.enabled ? "go-previous-symbolic-rtl" : "go-previous-symbolic")
14 text: qsTr("Navigate Back")
15
16 enabled: {
17 const pageStack = applicationWindow().pageStack;
18
19 if (pageStack.layers.depth > 1) {
20 return true;
21 }
22
23 if (pageStack.depth > 1) {
24 if (pageStack.currentIndex > 0) {
25 return true;
26 }
27
28 const view = pageStack.columnView;
29 if (LayoutMirroring.enabled) {
30 return view.contentWidth - view.width < view.contentX
31 } else {
32 return view.contentX > 0;
33 }
34 }
35
36 return false;
37 }
38
39 onClicked: {
40 applicationWindow().pageStack.goBack();
41 }
42
43 // The gridUnit wiggle room is used to not flicker the button visibility during an animated resize for instance due to a sidebar collapse
44 state: {
45 const pageStack = applicationWindow().pageStack;
46 const globalToolBar = pageStack.globalToolBar;
47 let showNavButtons = Kirigami.ApplicationHeaderStyle.NoNavigationButtons;
48 if (pageStack.leadingVisibleItem instanceof Kirigami.Page
49 && pageStack.leadingVisibleItem.globalToolBarStyle == Kirigami.ApplicationHeaderStyle.None) {
50 showNavButtons = Kirigami.ApplicationHeaderStyle.NoNavigationButtons
51 } else {
52 showNavButtons = showNavButtons = globalToolBar?.showNavigationButtons ?? Kirigami.ApplicationHeaderStyle.NoNavigationButtons;
53 }
54
55 if (pageStack.layers.depth > 1
56 || (pageStack.contentItem.contentWidth > pageStack.width + Kirigami.Units.gridUnit
57 && (showNavButtons & Kirigami.ApplicationHeaderStyle.ShowBackButton))) {
58 return ""
59 }
60 return "invisible"
61 }
62}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 12:02:15 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.