Skip to content

Commit

Permalink
Reimplement footer
Browse files Browse the repository at this point in the history
  • Loading branch information
trin94 committed Dec 1, 2024
1 parent 9dc281f commit 9b1760e
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qml/app/MpvqcContentSplitView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import QtQuick
import QtQuick.Controls

import "../footer"
import "../footer2"
import "../player"
import "../table"

Expand Down
150 changes: 150 additions & 0 deletions qml/footer2/MpvqcFooter.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
mpvQC
Copyright (C) 2024 mpvQC developers
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import "../shared"

Item {
id: root

required property var mpvqcApplication

readonly property var controller: MpvqcFooterController {
mpvqcApplication: root.mpvqcApplication
}

readonly property int bottomMargin: root.controller.isApplicationMaximized ? 2 : 0

height: 25
visible: !mpvqcApplication.fullscreen

MenuSeparator {
id: _separator

topPadding: 1
bottomPadding: 1

anchors {
top: root.top
left: root.left
right: root.right
}
}

RowLayout {
spacing: 0

anchors {
top: _separator.top
left: root.left
right: root.right
bottom: root.bottom
}

Label {
id: _rowSelectionLabelText

text: root.controller.rowSelectionText
visible: root.controller.isRowSelectionTextVisible

verticalAlignment: Text.AlignVCenter

Layout.bottomMargin: root.bottomMargin
Layout.leftMargin: 3
}

Item {
Layout.fillWidth: true
}

Label {
id: _videoPercentLabel

text: root.controller.percentageText
visible: root.controller.isPercentageTextVisible

horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter

Layout.bottomMargin: root.bottomMargin
}

Label {
id: _videoTimeLabel

width: root.controller.videoTimeLabelWidth
text: root.controller.videoTimeText
visible: root.controller.isVideoTimeTextVisible

horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter

Layout.preferredWidth: width
Layout.bottomMargin: root.bottomMargin
Layout.leftMargin: 15
}

ToolButton {
id: _toolButton

icon.source: "qrc:/data/icons/expand_more_black_24dp.svg"
focusPolicy: Qt.NoFocus
padding: 2

Layout.maximumWidth: 22
Layout.maximumHeight: 22
Layout.bottomMargin: root.bottomMargin
Layout.leftMargin: padding

onPressed: {
_contextMenuLoader.openContextMenu();
}
}
}

Loader {
id: _contextMenuLoader

function openContextMenu(): void {
if (active) {
item.open(); // qmllint disable
} else {
active = true;
}
}

active: false
asynchronous: true
visible: active

onLoaded: item.open() // qmllint disable

sourceComponent: MpvqcFooterMenu {
x: mMirrored ? _toolButton.x : _toolButton.x + _toolButton.width - width
y: -height

transformOrigin: mMirrored ? Popup.BottomLeft : Popup.BottomRight

controller: root.controller
}
}
}
149 changes: 149 additions & 0 deletions qml/footer2/MpvqcFooterController.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
mpvQC
Copyright (C) 2024 mpvQC developers
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick

import "../settings"

QtObject {
id: root

required property var mpvqcApplication

readonly property var mpvqcSettings: mpvqcApplication.mpvqcSettings

readonly property var __: QtObject {
id: __impl

readonly property var mpvqcCommentTable: root.mpvqcApplication.mpvqcCommentTable
readonly property var mpvqcLabelWidthCalculator: root.mpvqcApplication.mpvqcLabelWidthCalculator
readonly property var mpvqcMpvPlayerPropertiesPyObject: root.mpvqcApplication.mpvqcMpvPlayerPropertiesPyObject
readonly property var mpvqcUtilityPyObject: root.mpvqcApplication.mpvqcUtilityPyObject

readonly property real playerPercentPosition: mpvqcMpvPlayerPropertiesPyObject.percent_pos
readonly property int playerDuration: mpvqcMpvPlayerPropertiesPyObject.duration
readonly property bool playerVideoLoaded: mpvqcMpvPlayerPropertiesPyObject.video_loaded
readonly property int playerTimePosition: mpvqcMpvPlayerPropertiesPyObject.time_pos
readonly property int playerTimeRemaining: mpvqcMpvPlayerPropertiesPyObject.time_remaining

readonly property bool isTimeFormatCurrentTotalTime: root.mpvqcSettings.timeFormat === MpvqcSettings.TimeFormat.CURRENT_TOTAL_TIME
readonly property bool isTimeFormatCurrentTime: root.mpvqcSettings.timeFormat === MpvqcSettings.TimeFormat.CURRENT_TIME
readonly property bool isTimeFormatRemainingTime: root.mpvqcSettings.timeFormat === MpvqcSettings.TimeFormat.REMAINING_TIME
readonly property bool isTimeFormatEmpty: root.mpvqcSettings.timeFormat === MpvqcSettings.TimeFormat.EMPTY
readonly property bool isStatusBarPercentage: root.mpvqcSettings.statusbarPercentage

readonly property string rowSelectionText: (mpvqcCommentTable.selectedCommentIndex + 1) + '/' + mpvqcCommentTable.commentCount
readonly property bool isRowSelectionTextVisible: mpvqcCommentTable.commentCount

readonly property string percentageText: `${playerPercentPosition.toFixed(0)}%`
readonly property bool isPercentageTextVisible: playerVideoLoaded && isStatusBarPercentage

readonly property int videoTimeLabelWidth: isTimeFormatEmpty ? 0 : _videoTimeLabelWidth
property int _videoTimeLabelWidth: 0

readonly property bool isVideoTimeTextVisible: playerVideoLoaded && root.mpvqcSettings.timeFormat !== MpvqcSettings.TimeFormat.EMPTY
readonly property string videoTimeText: formatVideoTimeAccordingToSettings()

readonly property var _settingsConnection: Connections {
target: root.mpvqcSettings

function onTimeFormatChanged() {
__impl.recalculateTimeLabelWidth();
}
}

readonly property var _playerPropertiesConnection: Connections {
target: __impl.mpvqcMpvPlayerPropertiesPyObject

function onDurationChanged() {
__impl.recalculateTimeLabelWidth();
}
}

function formatVideoTimeAccordingToSettings(): string {
if (isTimeFormatCurrentTotalTime) {
const current = formatTime(playerTimePosition);
const total = formatTime(playerDuration);
return `${current}/${total}`;
}

if (isTimeFormatCurrentTime) {
return formatTime(playerTimePosition);
}

if (isTimeFormatRemainingTime) {
const remaining = formatTime(playerTimeRemaining);
return `-${remaining}`;
}

return "";
}

function formatTime(time: int): string {
if (playerDuration >= 60 * 60) {
return mpvqcUtilityPyObject.formatTimeToStringLong(time);
} else {
return mpvqcUtilityPyObject.formatTimeToStringShort(time);
}
}

function recalculateTimeLabelWidth(): real {
const items = [videoTimeText];
_videoTimeLabelWidth = mpvqcLabelWidthCalculator.calculateWidthFor(items, __impl);
}
}

readonly property bool isApplicationMaximized: mpvqcApplication.maximized

readonly property alias rowSelectionText: __impl.rowSelectionText
readonly property alias isRowSelectionTextVisible: __impl.isRowSelectionTextVisible

readonly property alias percentageText: __impl.percentageText
readonly property alias isPercentageTextVisible: __impl.isPercentageTextVisible

readonly property alias videoTimeLabelWidth: __impl.videoTimeLabelWidth
readonly property alias isVideoTimeTextVisible: __impl.isVideoTimeTextVisible
readonly property alias videoTimeText: __impl.videoTimeText

readonly property alias isTimeFormatCurrentTotalTime: __impl.isTimeFormatCurrentTotalTime
readonly property alias isTimeFormatCurrentTime: __impl.isTimeFormatCurrentTime
readonly property alias isTimeFormatRemainingTime: __impl.isTimeFormatRemainingTime
readonly property alias isTimeFormatEmpty: __impl.isTimeFormatEmpty
readonly property alias isStatusBarPercentage: __impl.isStatusBarPercentage

function selectCurrentTotalTime(): void {
mpvqcSettings.timeFormat = MpvqcSettings.TimeFormat.CURRENT_TOTAL_TIME;
}

function selectCurrentTime(): void {
mpvqcSettings.timeFormat = MpvqcSettings.TimeFormat.CURRENT_TIME;
}

function selectRemainingTime(): void {
mpvqcSettings.timeFormat = MpvqcSettings.TimeFormat.REMAINING_TIME;
}

function selectEmptyTime(): void {
mpvqcSettings.timeFormat = MpvqcSettings.TimeFormat.EMPTY;
}

function toggleStatusBarPercentage(): void {
mpvqcSettings.statusbarPercentage = !root.mpvqcSettings.statusbarPercentage;
}
}
78 changes: 78 additions & 0 deletions qml/footer2/MpvqcFooterMenu.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
mpvQC
Copyright (C) 2024 mpvQC developers
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick
import QtQuick.Controls

import "../shared"

MpvqcMenu {
id: root

required property MpvqcFooterController controller

modal: true
dim: false

MenuItem {
text: qsTranslate("MainWindow", "Default format")
checked: root.controller.isTimeFormatCurrentTotalTime
autoExclusive: true
checkable: true

onTriggered: root.controller.selectCurrentTotalTime()
}

MenuItem {
text: qsTranslate("MainWindow", "Current time")
checked: root.controller.isTimeFormatCurrentTime
autoExclusive: true
checkable: true

onTriggered: root.controller.selectCurrentTime()
}

MenuItem {
text: qsTranslate("MainWindow", "Remaining time")
checked: root.controller.isTimeFormatRemainingTime
autoExclusive: true
checkable: true

onTriggered: root.controller.selectRemainingTime()
}

MenuItem {
text: qsTranslate("MainWindow", "Hide time")
checked: root.controller.isTimeFormatEmpty
autoExclusive: true
checkable: true

onTriggered: root.controller.selectEmptyTime()
}

MenuSeparator {}

Action {
text: qsTranslate("MainWindow", "Progress in percent")
checked: root.controller.isStatusBarPercentage
checkable: true

onTriggered: root.controller.toggleStatusBarPercentage()
}
}
3 changes: 3 additions & 0 deletions qml/footer2/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module footer2

MpvqcFooter MpvqcFooter.qml

0 comments on commit 9b1760e

Please sign in to comment.