mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-15 05:42:28 +00:00
183 lines
5.4 KiB
QML
183 lines
5.4 KiB
QML
import QtQuick 2.9
|
|
import QtQuick.Dialogs 1.2
|
|
import QtQuick.Controls 2.2
|
|
|
|
import AppModel 1.0
|
|
|
|
import ComputerManager 1.0
|
|
|
|
GridView {
|
|
property int computerIndex
|
|
property AppModel appModel : createModel()
|
|
|
|
id: appGrid
|
|
anchors.fill: parent
|
|
anchors.leftMargin: (parent.width % (cellWidth + anchors.rightMargin)) / 2
|
|
anchors.topMargin: 20
|
|
anchors.rightMargin: 5
|
|
anchors.bottomMargin: 5
|
|
cellWidth: 225; cellHeight: 350;
|
|
focus: true
|
|
|
|
// Cache delegates for 1000px in both directions to improve
|
|
// scrolling and resizing performance
|
|
cacheBuffer: 1000
|
|
|
|
// The StackView will trigger a visibility change when
|
|
// we're pushed onto it, causing our onVisibleChanged
|
|
// routine to run, but only if we start as invisible
|
|
visible: false
|
|
|
|
function computerLost()
|
|
{
|
|
// Go back to the PC view on PC loss
|
|
stackView.pop()
|
|
}
|
|
|
|
onVisibleChanged: {
|
|
if (visible) {
|
|
appModel.computerLost.connect(computerLost)
|
|
}
|
|
else {
|
|
appModel.computerLost.disconnect(computerLost)
|
|
}
|
|
}
|
|
|
|
function createModel()
|
|
{
|
|
var model = Qt.createQmlObject('import AppModel 1.0; AppModel {}', parent, '')
|
|
model.initialize(ComputerManager, computerIndex)
|
|
return model
|
|
}
|
|
|
|
model: appModel
|
|
|
|
delegate: Item {
|
|
width: 200; height: 300;
|
|
|
|
Image {
|
|
id: appIcon
|
|
anchors.horizontalCenter: parent.horizontalCenter;
|
|
source: model.boxart
|
|
sourceSize {
|
|
width: 150
|
|
height: 200
|
|
}
|
|
}
|
|
|
|
Image {
|
|
id: runningIcon
|
|
anchors.centerIn: appIcon
|
|
visible: model.running
|
|
source: "qrc:/res/baseline-play_circle_filled_white-48px.svg"
|
|
sourceSize {
|
|
width: 75
|
|
height: 75
|
|
}
|
|
}
|
|
|
|
Text {
|
|
id: appNameText
|
|
text: model.name
|
|
color: "white"
|
|
width: parent.width
|
|
height: 125
|
|
anchors.top: appIcon.bottom
|
|
font.pointSize: 22
|
|
horizontalAlignment: Text.AlignHCenter
|
|
wrapMode: Text.Wrap
|
|
elide: Text.ElideRight
|
|
}
|
|
|
|
function launchOrResumeSelectedApp()
|
|
{
|
|
var runningIndex = appModel.getRunningAppIndex()
|
|
if (runningIndex >= 0 && runningIndex !== index) {
|
|
quitAppDialog.appName = appModel.getRunningAppName()
|
|
quitAppDialog.segueToStream = true
|
|
quitAppDialog.open()
|
|
return
|
|
}
|
|
|
|
var component = Qt.createComponent("StreamSegue.qml")
|
|
var segue = component.createObject(stackView, {"appName": model.name, "session": appModel.createSessionForApp(index)})
|
|
stackView.push(segue)
|
|
}
|
|
|
|
MessageDialog {
|
|
id: quitAppDialog
|
|
modality:Qt.WindowModal
|
|
property string appName : "";
|
|
property bool segueToStream : false
|
|
text:"Are you sure you want to quit " + appName +"? Any unsaved progress will be lost."
|
|
standardButtons: StandardButton.Yes | StandardButton.No
|
|
onYes: {
|
|
var component = Qt.createComponent("QuitSegue.qml")
|
|
var params = {"appName": appName}
|
|
if (segueToStream) {
|
|
// Store the session and app name if we're going to stream after
|
|
// successfully quitting the old app.
|
|
params.nextAppName = model.name
|
|
params.nextSession = appModel.createSessionForApp(index)
|
|
}
|
|
else {
|
|
params.nextAppName = null
|
|
params.nextSession = null
|
|
}
|
|
|
|
stackView.push(component.createObject(stackView, params))
|
|
|
|
// Trigger the quit after pushing the quit segue on screen
|
|
appModel.quitRunningApp()
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
onClicked: {
|
|
if (mouse.button === Qt.LeftButton) {
|
|
// Nothing is running or this app is running
|
|
launchOrResumeSelectedApp()
|
|
}
|
|
else {
|
|
// Right click
|
|
appContextMenu.open()
|
|
}
|
|
}
|
|
}
|
|
|
|
Menu {
|
|
id: appContextMenu
|
|
MenuItem {
|
|
text: model.running ? "Resume Game" : "Launch Game"
|
|
onTriggered: {
|
|
appContextMenu.close()
|
|
launchOrResumeSelectedApp()
|
|
}
|
|
height: visible ? implicitHeight : 0
|
|
}
|
|
MenuItem {
|
|
text: "Quit Game"
|
|
onTriggered: {
|
|
quitAppDialog.appName = appModel.getRunningAppName()
|
|
quitAppDialog.segueToStream = false
|
|
quitAppDialog.open()
|
|
}
|
|
visible: model.running
|
|
height: visible ? implicitHeight : 0
|
|
}
|
|
}
|
|
}
|
|
|
|
ScrollBar.vertical: ScrollBar {
|
|
parent: appGrid.parent
|
|
anchors {
|
|
top: appGrid.top
|
|
left: appGrid.right
|
|
bottom: appGrid.bottom
|
|
|
|
leftMargin: -10
|
|
}
|
|
}
|
|
}
|