| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2024 George Florea Bănuș <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
pragma ComponentBehavior: Bound |
| 8 |
|
| 9 |
import QtQuick |
| 10 |
import QtQuick.Controls |
| 11 |
import QtQuick.Layouts |
| 12 |
|
| 13 |
import org.kde.kirigami as Kirigami |
| 14 |
import org.kde.haruna |
| 15 |
import org.kde.haruna.settings |
| 16 |
|
| 17 |
Item { |
| 18 |
id: root |
| 19 |
|
| 20 |
required property MpvVideo m_mpv |
| 21 |
required property MenuBarLoader m_menuBarLoader |
| 22 |
required property Header m_header |
| 23 |
required property RecentFilesModel m_recentFilesModel |
| 24 |
required property Loader m_settingsLoader |
| 25 |
|
| 26 |
property alias progressBar: progressBar |
| 27 |
property string footerState: isFloating ? "hidden" : "visible" |
| 28 |
property bool isFloating: GeneralSettings.footerStyle === "floating" |
| 29 |
property bool isSmallSize: width < 600 |
| 30 |
property int buttonSize: isSmallSize ? Kirigami.Units.iconSizes.small : Kirigami.Units.iconSizes.smallMedium |
| 31 |
|
| 32 |
implicitWidth: Window.window.contentItem.width |
| 33 |
implicitHeight: root.isFloating |
| 34 |
? footer.height + Kirigami.Units.largeSpacing * (root.isSmallSize ? 1 : 2) |
| 35 |
: footer.height |
| 36 |
|
| 37 |
ToolBar { |
| 38 |
id: footer |
| 39 |
|
| 40 |
x: (root.width - width) / 2 |
| 41 |
width: root.isFloating |
| 42 |
? Math.min(Window.window.contentItem.width - Kirigami.Units.largeSpacing * (root.isSmallSize ? 2 : 4), 900) |
| 43 |
: root.width |
| 44 |
|
| 45 |
state: root.footerState |
| 46 |
padding: Kirigami.Units.smallSpacing |
| 47 |
position: ToolBar.Footer |
| 48 |
hoverEnabled: true |
| 49 |
background: Rectangle { |
| 50 |
color: Qt.alpha(Kirigami.Theme.backgroundColor, root.isFloating ? 0.8 : 1.0) |
| 51 |
radius: root.isFloating ? Kirigami.Units.cornerRadius : 0 |
| 52 |
} |
| 53 |
|
| 54 |
Connections { |
| 55 |
target: HarunaApp |
| 56 |
function onQmlApplicationMouseLeave() { |
| 57 |
if (root.isFloating) { |
| 58 |
hideFooterTimer.start() |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
Connections { |
| 64 |
target: root.m_mpv |
| 65 |
function onMousePositionChanged(x, y) { |
| 66 |
Qt.callLater(() => footer.setState()) |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
Timer { |
| 71 |
interval: 50 |
| 72 |
running: !root.isFloating |
| 73 |
repeat: true |
| 74 |
onTriggered: { |
| 75 |
Qt.callLater(() => footer.staticState()) |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
Timer { |
| 80 |
id: hideFooterTimer |
| 81 |
|
| 82 |
running: false |
| 83 |
repeat: false |
| 84 |
interval: 1000 |
| 85 |
onTriggered: { |
| 86 |
if (footer.hovered || hamburgerMenu.isOpen || progressBar.chaptersPopupIsOpen) { |
| 87 |
return |
| 88 |
} |
| 89 |
|
| 90 |
root.footerState = "hidden" |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
Component { |
| 95 |
id: togglePlaylistButton |
| 96 |
|
| 97 |
ToolButton { |
| 98 |
action: HarunaApp.actions.togglePlaylistAction |
| 99 |
icon.width: root.buttonSize |
| 100 |
icon.height: root.buttonSize |
| 101 |
display: root.isSmallSize ? AbstractButton.IconOnly : AbstractButton.TextBesideIcon |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
ColumnLayout { |
| 106 |
spacing: 0 |
| 107 |
anchors.fill: parent |
| 108 |
|
| 109 |
RowLayout { |
| 110 |
id: footerRow |
| 111 |
|
| 112 |
spacing: root.isSmallSize ? 1 : Kirigami.Units.smallSpacing |
| 113 |
|
| 114 |
HamburgerMenu { |
| 115 |
id: hamburgerMenu |
| 116 |
|
| 117 |
m_mpv: root.m_mpv |
| 118 |
m_recentFilesModel: root.m_recentFilesModel |
| 119 |
m_settingsLoader: root.m_settingsLoader |
| 120 |
m_menuBarLoader: root.m_menuBarLoader |
| 121 |
|
| 122 |
position: HamburgerMenu.Position.Footer |
| 123 |
visible: root.m_menuBarLoader.state === "hidden" && !root.m_header.visible |
| 124 |
icon.width: root.buttonSize |
| 125 |
icon.height: root.buttonSize |
| 126 |
} |
| 127 |
|
| 128 |
Loader { |
| 129 |
sourceComponent: togglePlaylistButton |
| 130 |
active: !PlaylistSettings.canToggleWithMouse && PlaylistSettings.position === "left" |
| 131 |
visible: active |
| 132 |
asynchronous: false |
| 133 |
} |
| 134 |
|
| 135 |
ToolButton { |
| 136 |
id: playPauseButton |
| 137 |
|
| 138 |
display: AbstractButton.IconOnly |
| 139 |
icon.name: root.m_mpv.pause ? "media-playback-start" : "media-playback-pause" |
| 140 |
icon.width: root.buttonSize |
| 141 |
icon.height: root.buttonSize |
| 142 |
focusPolicy: Qt.NoFocus |
| 143 |
enabled: root.m_mpv.duration !== 0 |
| 144 |
|
| 145 |
onClicked: HarunaApp.actions.playPauseAction.trigger() |
| 146 |
|
| 147 |
ToolTip { |
| 148 |
id: playPauseButtonToolTip |
| 149 |
|
| 150 |
text: root.m_mpv.pause ? i18nc("@info:tooltip", "Start playback") : i18nc("@info:tooltip", "Pause playback") |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
ToolButton { |
| 155 |
id: playPreviousFile |
| 156 |
|
| 157 |
icon.name: footer.LayoutMirroring.enabled ? "media-skip-forward" : "media-skip-backward" |
| 158 |
icon.width: root.buttonSize |
| 159 |
icon.height: root.buttonSize |
| 160 |
display: AbstractButton.IconOnly |
| 161 |
focusPolicy: Qt.NoFocus |
| 162 |
enabled: root.m_mpv.activeFilterProxyModel.itemCount > 1 |
| 163 |
|
| 164 |
onClicked: HarunaApp.actions.playPreviousAction.trigger() |
| 165 |
|
| 166 |
ToolTip { |
| 167 |
text: i18nc("@info:tooltip", "Play previous file") |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
ToolButton { |
| 172 |
id: playNextFile |
| 173 |
|
| 174 |
icon.name: footer.LayoutMirroring.enabled ? "media-skip-backward" : "media-skip-forward" |
| 175 |
icon.width: root.buttonSize |
| 176 |
icon.height: root.buttonSize |
| 177 |
display: AbstractButton.IconOnly |
| 178 |
focusPolicy: Qt.NoFocus |
| 179 |
enabled: root.m_mpv.activeFilterProxyModel.itemCount > 1 |
| 180 |
|
| 181 |
onClicked: HarunaApp.actions.playNextAction.trigger() |
| 182 |
|
| 183 |
ToolTip { |
| 184 |
text: i18nc("@info:tooltip", "Play next file") |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
ToolButton { |
| 189 |
icon.name: "overflow-menu" |
| 190 |
focusPolicy: Qt.NoFocus |
| 191 |
visible: !progressBar.showChapterMarkers && root.m_mpv.chaptersModel.rowCount > 0 |
| 192 |
|
| 193 |
onClicked: { |
| 194 |
progressBar.openChapterPopup(this) |
| 195 |
} |
| 196 |
|
| 197 |
ToolTip { |
| 198 |
text: i18nc("@info:tooltip", "Open chapters menu") |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
HProgressBar { |
| 203 |
id: progressBar |
| 204 |
|
| 205 |
m_mpv: root.m_mpv |
| 206 |
|
| 207 |
Layout.fillWidth: true |
| 208 |
Layout.preferredHeight: 20 |
| 209 |
} |
| 210 |
|
| 211 |
ToolButton { |
| 212 |
id: mute |
| 213 |
|
| 214 |
action: HarunaApp.actions.muteAction |
| 215 |
icon.name: root.m_mpv.mute || root.m_mpv.volume === 0 ? "player-volume-muted" : "player-volume" |
| 216 |
icon.width: root.buttonSize |
| 217 |
icon.height: root.buttonSize |
| 218 |
display: AbstractButton.IconOnly |
| 219 |
focusPolicy: Qt.NoFocus |
| 220 |
|
| 221 |
ToolTip { |
| 222 |
text: HarunaApp.actions.muteAction.text |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
VolumeSlider { |
| 228 |
id: volumeSlider |
| 229 |
|
| 230 |
m_mpv: root.m_mpv |
| 231 |
label.font.pointSize: root.isSmallSize ? 8 : 10 |
| 232 |
|
| 233 |
Layout.preferredWidth: root.isSmallSize ? 60 : 100 |
| 234 |
Layout.preferredHeight: 20 |
| 235 |
} |
| 236 |
|
| 237 |
Loader { |
| 238 |
sourceComponent: togglePlaylistButton |
| 239 |
active: !PlaylistSettings.canToggleWithMouse && PlaylistSettings.position === "right" |
| 240 |
visible: active |
| 241 |
asynchronous: false |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
RowLayout { |
| 246 |
LabelWithTooltip { |
| 247 |
id: mediaTitleLabel |
| 248 |
|
| 249 |
text: root.m_mpv.mediaTitle |
| 250 |
font.pointSize: 9 |
| 251 |
toolTipText: root.m_mpv.mediaTitle |
| 252 |
elide: Text.ElideRight |
| 253 |
|
| 254 |
Layout.fillWidth: true |
| 255 |
} |
| 256 |
|
| 257 |
LabelWithTooltip { |
| 258 |
id: timeInfo |
| 259 |
|
| 260 |
text: "%1 / %2".arg(root.m_mpv.formattedPosition).arg(root.m_mpv.formattedDuration) |
| 261 |
font.pointSize: 9 |
| 262 |
toolTipText: i18nc("@info:tooltip", "Remaining: %1", root.m_mpv.formattedRemaining) |
| 263 |
alwaysShowToolTip: true |
| 264 |
horizontalAlignment: Qt.AlignHCenter |
| 265 |
|
| 266 |
Layout.minimumWidth: textMetrics.width |
| 267 |
|
| 268 |
TextMetrics { |
| 269 |
id: textMetrics |
| 270 |
|
| 271 |
font: timeInfo.font |
| 272 |
text: "000:00:00 / 000:00:00" |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
function setState() : void { |
| 279 |
if (root.isFloating) { |
| 280 |
floatingState() |
| 281 |
} else { |
| 282 |
staticState() |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
function floatingState() { |
| 287 |
if (GeneralSettings.floatingFooterTrigger === "EveryMouseMovement") { |
| 288 |
hideFooterTimer.stop() |
| 289 |
root.footerState = "visible" |
| 290 |
if (root.m_mpv.mouseY < root.m_mpv.height - footer.height * 2) { |
| 291 |
hideFooterTimer.restart() |
| 292 |
} |
| 293 |
} else { |
| 294 |
if (root.m_mpv.mouseY > root.m_mpv.height - footer.height * 2) { |
| 295 |
const mainWindow = root.Window.window as Main |
| 296 |
if (mainWindow.containsMouse) { |
| 297 |
hideFooterTimer.stop() |
| 298 |
root.footerState = "visible" |
| 299 |
} |
| 300 |
} else { |
| 301 |
hideFooterTimer.start() |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
function staticState() { |
| 307 |
const mainWindow = Window.window as Main |
| 308 |
if (!mainWindow.isFullScreen() || (root.m_mpv.mouseY > root.m_mpv.height - footer.height * 2 && mainWindow.containsMouse)) { |
| 309 |
root.footerState = "visible" |
| 310 |
} else { |
| 311 |
root.footerState = "hidden" |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
states: [ |
| 316 |
State { |
| 317 |
name: "hidden" |
| 318 |
PropertyChanges { |
| 319 |
footer.y: root.height |
| 320 |
footer.visible: false |
| 321 |
} |
| 322 |
}, |
| 323 |
State { |
| 324 |
name : "visible" |
| 325 |
PropertyChanges { |
| 326 |
footer.y: 0 |
| 327 |
footer.visible: true |
| 328 |
} |
| 329 |
} |
| 330 |
] |
| 331 |
|
| 332 |
transitions: [ |
| 333 |
Transition { |
| 334 |
from: "visible" |
| 335 |
to: "hidden" |
| 336 |
|
| 337 |
SequentialAnimation { |
| 338 |
ParallelAnimation { |
| 339 |
NumberAnimation { |
| 340 |
target: footer |
| 341 |
property: "y" |
| 342 |
duration: Kirigami.Units.shortDuration |
| 343 |
easing.type: Easing.Linear |
| 344 |
} |
| 345 |
} |
| 346 |
PropertyAction { |
| 347 |
target: footer |
| 348 |
property: "visible" |
| 349 |
value: false |
| 350 |
} |
| 351 |
} |
| 352 |
}, |
| 353 |
Transition { |
| 354 |
from: "hidden" |
| 355 |
to: "visible" |
| 356 |
|
| 357 |
SequentialAnimation { |
| 358 |
PropertyAction { |
| 359 |
target: footer |
| 360 |
property: "visible" |
| 361 |
value: true |
| 362 |
} |
| 363 |
ParallelAnimation { |
| 364 |
NumberAnimation { |
| 365 |
target: footer |
| 366 |
property: "y" |
| 367 |
duration: Kirigami.Units.shortDuration |
| 368 |
easing.type: Easing.Linear |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
] |
| 374 |
} |
| 375 |
} |