This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ActionBar.qml
128 lines (107 loc) · 2.58 KB
/
ActionBar.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
import QtQuick.Layouts 1.3
import de.skycoder42.quickextras 2.0
ToolBar {
id: toolbar
implicitHeight: (tabLoader.item ? tabLoader.item.implicitHeight : 0) + 56
property alias title: titleLabel.text
property alias showMenuButton: menuButton.visible
property bool showMenuAsBack: false
property Menu moreMenu: null
property alias tabBar: tabLoader.sourceComponent
property alias tabBarItem: tabLoader.item
default property alias actions: actionButtonsLayout.children
signal menuButtonClicked()
GridLayout {
id: grid
anchors.fill: parent
rowSpacing: 0
columnSpacing: 0
columns: 2 + (showMenuButton ? 1 : 0) + (moreMenu ? 1 : 0)
rows: 2
AppBarButton {
id: menuButton
imageSource: showMenuAsBack ?
"image://svg/de/skycoder42/quickextras/icons/ic_arrow_back" :
"image://svg/de/skycoder42/quickextras/icons/ic_menu"
text: showMenuAsBack ? qsTr("Go back") : qsTr("Show menu")
onClicked: menuButtonClicked()
}
Label {
id: titleLabel
font.pointSize: 16
font.bold: true
elide: Label.ElideRight
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
Layout.leftMargin: 10
Layout.minimumHeight: 56
}
RowLayout {
id: actionButtonsLayout
spacing: 0
}
AppBarButton {
id: moreButton
visible: moreMenu
imageSource: "image://svg/de/skycoder42/quickextras/icons/ic_more_vert"
text: qsTr("More…")
checkable: true
property bool skipNext: false
onPressed: uncheckTimer.stop();
onReleased: skipNext = false;
onCanceled: skipNext = false;
onCheckedChanged: {
if(skipNext) {
skipNext = false;
checked = !checked;
return;
}
if(checked) {
if(!moreMenu.visible)
moreMenu.open();
} else {
if(moreMenu.visible)
moreMenu.close();
}
}
Connections {
target: moreMenu
onClosed: {
moreButton.checked = false;
moreButton.skipNext = true;
uncheckTimer.restart();
}
}
Timer {
id: uncheckTimer
interval: 100
repeat: false
running: false
onTriggered: moreButton.skipNext = false;
}
}
Loader {
id: tabLoader
Layout.fillWidth: true
Layout.columnSpan: grid.columns
Material.background: Material.primary
onLoaded: {
tabLoader.item.position = TabBar.Header;
}
}
}
CommonStyle {
id: style
}
Component.onCompleted: {
if(moreMenu) {
moreMenu.parent = moreButton;
if(!style.isMaterial)
moreMenu.y = Qt.binding(function(){return moreButton.height});
}
}
}