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

KDE's Doxygen guidelines are available online.