2020-08-13 19:23:02 +01:00
|
|
|
/**
|
2019-10-27 17:08:51 +00:00
|
|
|
* SPDX-FileCopyrightText: 2020 Aniket Kumar <anikketkumar786@gmail.com>
|
2020-08-13 19:23:02 +01:00
|
|
|
*
|
2019-10-27 17:08:51 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2020-08-13 19:23:02 +01:00
|
|
|
*/
|
|
|
|
|
2023-12-23 16:48:04 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import QtQuick.Controls
|
|
|
|
import org.kde.kirigami as Kirigami
|
2023-09-21 18:23:06 +01:00
|
|
|
import QtMultimedia
|
2020-08-13 19:23:02 +01:00
|
|
|
|
|
|
|
Kirigami.Page {
|
|
|
|
id: root
|
2024-04-19 16:55:27 +01:00
|
|
|
|
2020-08-13 19:23:02 +01:00
|
|
|
property string filePath
|
|
|
|
property string mimeType
|
|
|
|
|
2023-09-21 18:23:06 +01:00
|
|
|
actions: [
|
2020-08-13 19:23:02 +01:00
|
|
|
Kirigami.Action {
|
|
|
|
text: i18nd("kdeconnect-sms", "Open with default")
|
|
|
|
icon.name: "window-new"
|
|
|
|
onTriggered: {
|
2024-04-19 16:55:27 +01:00
|
|
|
Qt.openUrlExternally(root.filePath);
|
2020-08-13 19:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
contentItem: Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: imageViewer
|
2024-04-19 16:55:27 +01:00
|
|
|
visible: root.mimeType.match("image")
|
2020-08-13 19:23:02 +01:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
width: image.width
|
|
|
|
height: parent.height - y
|
|
|
|
y: root.implicitHeaderHeight
|
|
|
|
color: parent.color
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: image
|
2024-04-19 16:55:27 +01:00
|
|
|
source: parent.visible ? root.filePath : ""
|
2020-08-13 19:23:02 +01:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
width: sourceSize.width
|
|
|
|
height: parent.height
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaPlayer {
|
|
|
|
id: mediaPlayer
|
2024-04-19 16:55:27 +01:00
|
|
|
source: root.filePath
|
2020-08-13 19:23:02 +01:00
|
|
|
|
|
|
|
onPositionChanged: {
|
|
|
|
if (mediaPlayer.position > 1000 && mediaPlayer.duration - mediaPlayer.position < 1000) {
|
|
|
|
playAndPauseButton.icon.name = "media-playback-start"
|
|
|
|
mediaPlayer.pause()
|
|
|
|
mediaPlayer.seek(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height - mediaControls.height
|
|
|
|
anchors.topMargin: root.implicitHeaderHeight
|
|
|
|
|
2023-09-21 18:23:06 +01:00
|
|
|
MediaPlayer {
|
2020-08-13 19:23:02 +01:00
|
|
|
source: mediaPlayer
|
2023-09-21 18:23:06 +01:00
|
|
|
videoOutput: VideoOutput {
|
|
|
|
anchors.fill: parent
|
|
|
|
fillMode: VideoOutput.PreserveAspectFit
|
2020-08-13 19:23:02 +01:00
|
|
|
|
2023-09-21 18:23:06 +01:00
|
|
|
// By default QML's videoOutput element rotates the vdeeo files by 90 degrees in clockwise direction
|
|
|
|
orientation: -90
|
|
|
|
}
|
2020-08-13 19:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: mediaControls
|
2024-04-19 16:55:27 +01:00
|
|
|
visible: root.mimeType.match("video")
|
2020-08-13 19:23:02 +01:00
|
|
|
width: parent.width
|
|
|
|
height: 50
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
color: Kirigami.Theme.backgroundColor
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
anchors.top: parent.top
|
|
|
|
width: parent.width
|
|
|
|
height: 1
|
|
|
|
color: "lightGray"
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: progressBar
|
|
|
|
Layout.fillWidth: parent
|
|
|
|
Layout.leftMargin: Kirigami.Units.largeSpacing
|
|
|
|
Layout.rightMargin: Kirigami.Units.largeSpacing
|
|
|
|
Layout.topMargin: Kirigami.Units.smallSpacing
|
|
|
|
radius: 5
|
|
|
|
height: 5
|
|
|
|
|
|
|
|
color: "gray"
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
radius: 5
|
|
|
|
|
|
|
|
width: mediaPlayer.duration > 0 ? parent.width*mediaPlayer.position/mediaPlayer.duration : 0
|
|
|
|
|
|
|
|
color: {
|
|
|
|
Kirigami.Theme.colorSet = Kirigami.Theme.View
|
|
|
|
var accentColor = Kirigami.Theme.highlightColor
|
|
|
|
return Qt.tint(Kirigami.Theme.backgroundColor, Qt.rgba(accentColor.r, accentColor.g, accentColor.b, 1))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (mediaPlayer.seekable) {
|
|
|
|
mediaPlayer.seek(mediaPlayer.duration * mouse.x/width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
spacing: Kirigami.Units.largeSpacing
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: backwardButton
|
|
|
|
icon.name: "media-seek-backward"
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (mediaPlayer.seekable) {
|
|
|
|
mediaPlayer.seek(mediaPlayer.position - 2000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: playAndPauseButton
|
|
|
|
icon.name: "media-playback-pause"
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (icon.name == "media-playback-start") {
|
|
|
|
mediaPlayer.play()
|
|
|
|
icon.name = "media-playback-pause"
|
|
|
|
} else {
|
|
|
|
mediaPlayer.pause()
|
|
|
|
icon.name = "media-playback-start"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: forwardButton
|
|
|
|
icon.name: "media-seek-forward"
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (mediaPlayer.seekable) {
|
|
|
|
mediaPlayer.seek(mediaPlayer.position + 2000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
mediaPlayer.play()
|
|
|
|
}
|
|
|
|
}
|