Kirigami2

PrivateSwipeTabBar.qml
1 /*
2  * SPDX-FileCopyrightText: 2020 Carson Black <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.12
8 import QtQuick.Layouts 1.12
9 import QtQuick.Controls 2.12 as QQC2
10 import org.kde.kirigami 2.14 as Kirigami
11 
12 QQC2.ScrollView {
13  id: view
14  implicitWidth: bar.implicitWidth
15  QQC2.ScrollBar.horizontal.visible: false
16 
17  Item {
18  height: view.height
19  implicitHeight: bar.implicitHeight
20  implicitWidth: bar.implicitWidth
21  width: Math.max(view.width, bar.implicitWidth)
22 
23  RowLayout {
24  id: bar
25  spacing: 0
26  signal indexChanged(real xPos, real tabWidth)
27 
28  anchors.centerIn: parent
29  width: Kirigami.Settings.isMobile && swipeNavigatorRoot.height > swipeNavigatorRoot.width ? parent.width : implicitWidth
30  property real targetDestination
31  NumberAnimation {
32  id: scrollAni
33  target: view.QQC2.ScrollBar.horizontal
34  property: "position"
35  to: bar.targetDestination
36  duration: Kirigami.Units.longDuration
37  easing.type: Easing.OutExpo
38  }
39  onIndexChanged: (xPos, tabWidth) => {
40  if (xPos > (bar.width)/2) {
41  bar.targetDestination = (1-view.QQC2.ScrollBar.horizontal.size) * ((xPos+tabWidth) / bar.width)
42  scrollAni.restart()
43  } else {
44  bar.targetDestination = (1-view.QQC2.ScrollBar.horizontal.size) * ((xPos) / bar.width)
45  scrollAni.restart()
46  }
47  }
48 
49  property Item layouter: Item {
50  Row {
51  id: expandedLayouter
52  Repeater {
53  model: swipeNavigatorRoot.pages
54  delegate: PrivateSwipeTab { vertical: false }
55  }
56  }
57  }
58 
59  Repeater {
60  model: swipeNavigatorRoot.pages
61  delegate: PrivateSwipeTab {
62  Layout.fillHeight: true
63  Layout.fillWidth: true
64  Layout.alignment: Qt.AlignHCenter
65  vertical: Kirigami.Settings.isMobile
66  ? (swipeNavigatorRoot.width < swipeNavigatorRoot.height ? true : expandedLayouter.width > swipeNavigatorRoot.width)
67  : expandedLayouter.width > swipeNavigatorRoot.width
68  onIndexChanged: (xPos, tabWidth) => bar.indexChanged(xPos, tabWidth)
69  }
70  }
71  }
72  }
73 }
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.