Kirigami2

BreadcrumbControl.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.15
8 import QtQuick.Layouts 1.15
9 import org.kde.kirigami 2.19 as Kirigami
10 
11 Flickable {
12  id: root
13 
14  property Kirigami.PageRow pageRow: parent.pageRow
15 
16  readonly property Item currentItem: mainLayout.children[pageRow.currentIndex] || null
17 
18  contentHeight: height
19  contentWidth: mainLayout.width
20  clip: true
21  boundsBehavior: Flickable.StopAtBounds
22  interactive: Kirigami.Settings.hasTransientTouchInput
23 
24  contentX: currentItem
25  ? Math.max(0,
26  Math.min(currentItem.x + currentItem.width/2 - root.width/2,
27  root.contentWidth - root.width))
28  : 0
29 
30  RowLayout {
31  id: mainLayout
32  height: parent.height
33  spacing: 0
34  Repeater {
35  id: mainRepeater
36  readonly property bool useLayers: pageRow.layers.depth > 1
37  model: useLayers ? pageRow.layers.depth - 1 : pageRow.depth
38  delegate: MouseArea {
39  Layout.preferredWidth: delegateLayout.implicitWidth
40  Layout.fillHeight: true
41  onClicked: mouse => {
42  if (mainRepeater.useLayers) {
43  while (pageRow.layers.depth > modelData + 1) {
44  pageRow.layers.pop();
45  }
46  } else {
47  pageRow.currentIndex = modelData;
48  }
49  }
50  hoverEnabled: !Kirigami.Settings.tabletMode
51  Rectangle {
52  color: Kirigami.Theme.highlightColor
53  anchors.fill: parent
54  radius: 3
55  opacity: mainRepeater.count > 1 && parent.containsMouse ? 0.1 : 0
56  }
57  RowLayout {
58  id: delegateLayout
59  anchors.fill: parent
60  // We can't use Kirigami.Page here instead of Item since we now accept pushing PageRow to a new layer
61  readonly property Item page: mainRepeater.useLayers ? pageRow.layers.get(modelData + 1) : pageRow.get(modelData)
62  spacing: 0
63 
64  Kirigami.Icon {
65  visible: modelData > 0
66  Layout.alignment: Qt.AlignVCenter
67  Layout.preferredHeight: Kirigami.Units.iconSizes.small
68  Layout.preferredWidth: Layout.preferredHeight
69  isMask: true
70  color: Kirigami.Theme.textColor
71  source: LayoutMirroring.enabled ? "go-next-symbolic-rtl" : "go-next-symbolic"
72  }
73  Kirigami.Heading {
74  Layout.leftMargin: Kirigami.Units.largeSpacing
75  Layout.rightMargin: Kirigami.Units.largeSpacing
76  color: Kirigami.Theme.textColor
77  verticalAlignment: Text.AlignVCenter
78  wrapMode: Text.NoWrap
79  text: delegateLayout.page ? delegateLayout.page.title : ""
80  opacity: modelData === pageRow.currentIndex ? 1 : 0.4
81  }
82  }
83  }
84  }
85  }
86 
87  Behavior on contentX {
88  NumberAnimation {
89  duration: Kirigami.Units.longDuration
90  easing.type: Easing.InOutQuad
91  }
92  }
93 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Oct 3 2023 03:58:35 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.