Debian Codegraph @

src/qml/Header.qml

raw
1 /*
2 * SPDX-FileCopyrightText: 2020 George Florea Bănuș <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7 import QtQuick
8 import QtQuick.Controls
9 import QtQuick.Layouts
10 import QtQml
11
12 import org.kde.kirigami as Kirigami
13 import org.kde.haruna
14 import org.kde.haruna.settings
15
16 ToolBar {
17 id: root
18
19 required property MpvVideo m_mpv
20 required property MenuBarLoader m_menuBarLoader
21 required property RecentFilesModel m_recentFilesModel
22 required property Loader m_settingsLoader
23
24 property bool isSmallSize: width < 600
25 property int buttonSize: isSmallSize ? Kirigami.Units.iconSizes.small : Kirigami.Units.iconSizes.smallMedium
26
27 position: ToolBar.Header
28 state: {
29 const mainWindow = Window.window as Main
30 if (!mainWindow.isFullScreen() && GeneralSettings.showHeader) {
31 return "visible"
32 } else {
33 return "hidden"
34 }
35 }
36
37 onVisibleChanged: {
38 const mainWindow = Window.window as Main
39 mainWindow.resizeWindow()
40 }
41
42 RowLayout {
43 id: headerRow
44
45 width: parent.width
46
47 HamburgerMenu {
48 m_mpv: root.m_mpv
49 m_recentFilesModel: root.m_recentFilesModel
50 m_settingsLoader: root.m_settingsLoader
51 m_menuBarLoader: root.m_menuBarLoader
52
53 position: HamburgerMenu.Position.Header
54 visible: !root.m_menuBarLoader.visible || root.m_menuBarLoader.isShowAnimationRunning
55
56 icon.width: root.buttonSize
57 icon.height: root.buttonSize
58 }
59
60 ToolButton {
61 action: HarunaApp.actions.openFileAction
62 focusPolicy: Qt.NoFocus
63 icon.width: root.buttonSize
64 icon.height: root.buttonSize
65 }
66
67 ToolButton {
68 action: HarunaApp.actions.openUrlAction
69 focusPolicy: Qt.NoFocus
70 icon.width: root.buttonSize
71 icon.height: root.buttonSize
72 }
73
74 ToolSeparator {}
75
76 ToolButton {
77 id: subtitleMenuButton
78
79 text: i18nc("@action:intoolbar", "Subtitles")
80 icon.name: "add-subtitle"
81 icon.width: root.buttonSize
82 icon.height: root.buttonSize
83 focusPolicy: Qt.NoFocus
84 enabled: root.m_mpv.subtitleTracksModel.rowCount > 1
85 opacity: enabled ? 1.0 : 0.6
86 display: root.isSmallSize ? AbstractButton.IconOnly : AbstractButton.TextBesideIcon
87
88 onReleased: {
89 subtitleMenu.visible = !subtitleMenu.visible
90 }
91
92 SubtitleTracksMenu {
93 id: subtitleMenu
94
95 m_mpv: root.m_mpv
96 isPrimarySubtitleMenu: true
97
98 y: parent.height
99 }
100 }
101
102 ToolButton {
103 text: i18nc("@action:intoolbar", "Audio")
104 icon.name: "audio-volume-high"
105 icon.width: root.buttonSize
106 icon.height: root.buttonSize
107 focusPolicy: Qt.NoFocus
108 enabled: root.m_mpv.audioTracksModel.rowCount > 0
109 opacity: enabled ? 1.0 : 0.6
110 display: root.isSmallSize ? AbstractButton.IconOnly : AbstractButton.TextBesideIcon
111
112 onReleased: {
113 audioMenu.visible = !audioMenu.visible
114 }
115
116 AudioTracksMenu {
117 id: audioMenu
118
119 m_mpv: root.m_mpv
120
121 y: parent.height
122 model: root.m_mpv.audioTracksModel
123 }
124 }
125
126 Item {
127 Layout.fillWidth: true
128 }
129
130 ToolButton {
131 action: HarunaApp.actions.configureAction
132 focusPolicy: Qt.NoFocus
133 icon.width: root.buttonSize
134 icon.height: root.buttonSize
135 display: root.isSmallSize ? AbstractButton.IconOnly : AbstractButton.TextBesideIcon
136 }
137 }
138
139
140 states: [
141 State {
142 name: "hidden"
143 PropertyChanges {
144 root.height: 0
145 root.opacity: 0
146 root.visible: false
147 }
148 },
149 State {
150 name : "visible"
151 PropertyChanges {
152 root.height: root.implicitHeight
153 root.opacity: 1
154 root.visible: true
155 }
156 }
157 ]
158
159 transitions: [
160 Transition {
161 from: "visible"
162 to: "hidden"
163
164 SequentialAnimation {
165 ParallelAnimation {
166 NumberAnimation {
167 target: root
168 property: "opacity"
169 duration: Kirigami.Units.veryShortDuration
170 easing.type: Easing.Linear
171 }
172 NumberAnimation {
173 target: root
174 property: "height"
175 duration: Kirigami.Units.veryShortDuration
176 easing.type: Easing.Linear
177 }
178 }
179 PropertyAction {
180 target: root
181 property: "visible"
182 value: false
183 }
184 }
185 },
186 Transition {
187 from: "hidden"
188 to: "visible"
189
190 SequentialAnimation {
191 PropertyAction {
192 target: root
193 property: "visible"
194 value: true
195 }
196 ParallelAnimation {
197 NumberAnimation {
198 target: root
199 property: "height"
200 duration: Kirigami.Units.veryShortDuration
201 easing.type: Easing.Linear
202 }
203 NumberAnimation {
204 target: root
205 property: "opacity"
206 duration: Kirigami.Units.veryShortDuration
207 easing.type: Easing.Linear
208 }
209 }
210 }
211 }
212 ]
213 }