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 QtQuick.Controls as QQC2
9import org.kde.kirigami as Kirigami
10
11QQC2.ToolButton {
12 id: button
13
14 icon.name: (LayoutMirroring.enabled ? "go-previous-symbolic-rtl" : "go-previous-symbolic")
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 // The gridUnit wiggle room is used to not flicker the button visibility during an animated resize for instance due to a sidebar collapse
40 visible: {
41 const pageStack = applicationWindow().pageStack;
42 const showNavButtons = globalToolBar?.showNavigationButtons ?? Kirigami.ApplicationHeaderStyle.NoNavigationButtons;
43 return pageStack.layers.depth > 1 || (pageStack.contentItem.contentWidth > pageStack.width + Kirigami.Units.gridUnit && (showNavButtons & Kirigami.ApplicationHeaderStyle.ShowBackButton));
44 }
45
46 onClicked: {
47 applicationWindow().pageStack.goBack();
48 }
49
50 text: qsTr("Navigate Back")
51 display: QQC2.ToolButton.IconOnly
52
53 QQC2.ToolTip {
54 visible: button.hovered
55 text: button.text
56 delay: Kirigami.Units.toolTipDelay
57 timeout: 5000
58 y: button.height
59 }
60}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:52:23 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.