2018-07-06 03:07:05 +00:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
|
|
|
|
import AppModel 1.0
|
2018-07-06 05:08:55 +00:00
|
|
|
import ComputerManager 1.0
|
|
|
|
|
2018-07-06 03:07:05 +00:00
|
|
|
GridView {
|
|
|
|
property int computerIndex
|
2018-07-07 23:30:26 +00:00
|
|
|
property AppModel appModel : createModel()
|
2019-03-27 08:28:46 +00:00
|
|
|
property bool activated
|
2018-07-06 03:07:05 +00:00
|
|
|
|
2019-04-02 05:12:49 +00:00
|
|
|
// Prevent the margin from dropping below 10. By keeping a floor on the margin value
|
|
|
|
// this prevents a binding loop caused by the ternary condition changing and decreasing
|
|
|
|
// the margin size, thus causing it to change back.
|
|
|
|
property real horizontalMargin: Math.max(10,
|
|
|
|
contentHeight > cellHeight && parent.width > cellWidth ?
|
|
|
|
(parent.width % cellWidth) / 2 : 0)
|
|
|
|
|
2018-07-09 06:05:36 +00:00
|
|
|
id: appGrid
|
2018-09-23 22:16:27 +00:00
|
|
|
focus: true
|
|
|
|
activeFocusOnTab: true
|
2019-03-27 08:28:46 +00:00
|
|
|
topMargin: 20
|
|
|
|
bottomMargin: 5
|
2019-04-02 05:12:49 +00:00
|
|
|
leftMargin: horizontalMargin
|
|
|
|
rightMargin: horizontalMargin
|
2019-04-02 02:49:33 +00:00
|
|
|
cellWidth: 230; cellHeight: 297;
|
2018-07-06 03:07:05 +00:00
|
|
|
|
2018-08-10 01:48:40 +00:00
|
|
|
function computerLost()
|
|
|
|
{
|
|
|
|
// Go back to the PC view on PC loss
|
|
|
|
stackView.pop()
|
|
|
|
}
|
|
|
|
|
2019-04-02 05:12:49 +00:00
|
|
|
onHorizontalMarginChanged: {
|
|
|
|
if (this.synchronousDrag === undefined) {
|
|
|
|
anchors.leftMargin = horizontalMargin
|
|
|
|
anchors.rightMargin = horizontalMargin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 06:44:09 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
// Don't show any highlighted item until interacting with them.
|
|
|
|
// We do this here instead of onActivated to avoid losing the user's
|
|
|
|
// selection when backing out of a different page of the app.
|
|
|
|
currentIndex = -1
|
2019-03-30 19:28:18 +00:00
|
|
|
|
|
|
|
// HACK: If this is not Qt 5.12 (which has synchronousDrag),
|
|
|
|
// set anchors on creation. This will cause an anchor conflict
|
|
|
|
// with the parent StackView which breaks animation, but otherwise
|
|
|
|
// the grid will not be centered in the window.
|
|
|
|
if (this.synchronousDrag === undefined) {
|
|
|
|
anchors.fill = parent
|
|
|
|
anchors.topMargin = topMargin
|
|
|
|
anchors.bottomMargin = bottomMargin
|
|
|
|
}
|
2019-02-23 06:44:09 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 06:14:06 +00:00
|
|
|
StackView.onActivated: {
|
|
|
|
appModel.computerLost.connect(computerLost)
|
2019-03-27 08:28:46 +00:00
|
|
|
activated = true
|
2019-02-23 06:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StackView.onDeactivating: {
|
|
|
|
appModel.computerLost.disconnect(computerLost)
|
2019-03-27 08:28:46 +00:00
|
|
|
activated = false
|
2018-07-06 07:34:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 03:07:05 +00:00
|
|
|
function createModel()
|
|
|
|
{
|
2018-07-06 05:08:55 +00:00
|
|
|
var model = Qt.createQmlObject('import AppModel 1.0; AppModel {}', parent, '')
|
|
|
|
model.initialize(ComputerManager, computerIndex)
|
2018-07-06 03:07:05 +00:00
|
|
|
return model
|
|
|
|
}
|
|
|
|
|
2018-07-07 23:30:26 +00:00
|
|
|
model: appModel
|
2018-07-06 03:07:05 +00:00
|
|
|
|
2018-09-23 22:16:27 +00:00
|
|
|
delegate: NavigableItemDelegate {
|
2019-04-02 02:49:33 +00:00
|
|
|
width: 220; height: 287;
|
2018-09-24 02:06:26 +00:00
|
|
|
grid: appGrid
|
2018-07-06 03:07:05 +00:00
|
|
|
|
|
|
|
Image {
|
2019-04-02 02:49:33 +00:00
|
|
|
property bool isPlaceholder: false
|
|
|
|
|
2018-07-06 03:07:05 +00:00
|
|
|
id: appIcon
|
2019-01-27 07:57:02 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2019-04-02 02:49:33 +00:00
|
|
|
y: 10
|
2018-07-06 03:07:05 +00:00
|
|
|
source: model.boxart
|
2019-04-02 02:49:33 +00:00
|
|
|
|
|
|
|
onSourceSizeChanged: {
|
|
|
|
if ((width == 130 && height == 180) || // GFE 2.0 placeholder image
|
|
|
|
(width == 628 && height == 888) || // GFE 3.0 placeholder image
|
|
|
|
(width == 200 && height == 266)) // Our no_app_image.png
|
|
|
|
{
|
|
|
|
isPlaceholder = true
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isPlaceholder = false
|
|
|
|
}
|
|
|
|
|
|
|
|
width = 200
|
|
|
|
height = 267
|
2018-07-06 03:07:05 +00:00
|
|
|
}
|
2019-04-02 02:49:33 +00:00
|
|
|
|
|
|
|
// Display a tooltip with the full name if it's truncated
|
|
|
|
ToolTip.text: model.name
|
|
|
|
ToolTip.delay: 1000
|
|
|
|
ToolTip.timeout: 5000
|
|
|
|
ToolTip.visible: (parent.hovered || parent.highlighted) && (!appNameText.visible || appNameText.truncated)
|
2018-07-06 03:07:05 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 03:07:48 +00:00
|
|
|
ToolButton {
|
|
|
|
id: resumeButton
|
2019-04-02 02:49:33 +00:00
|
|
|
anchors.horizontalCenterOffset: appIcon.isPlaceholder ? -47 : 0
|
|
|
|
anchors.verticalCenterOffset: appIcon.isPlaceholder ? -75 : -60
|
2018-08-05 19:19:54 +00:00
|
|
|
anchors.centerIn: appIcon
|
|
|
|
visible: model.running
|
2019-02-13 03:07:48 +00:00
|
|
|
implicitWidth: 125
|
|
|
|
implicitHeight: 125
|
|
|
|
|
|
|
|
Image {
|
|
|
|
source: "qrc:/res/baseline-play_circle_filled_white-48px.svg"
|
|
|
|
anchors.centerIn: parent
|
|
|
|
sourceSize {
|
|
|
|
width: 75
|
|
|
|
height: 75
|
2019-01-27 07:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-13 03:07:48 +00:00
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
launchOrResumeSelectedApp()
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTip.text: "Resume Game"
|
|
|
|
ToolTip.delay: 1000
|
|
|
|
ToolTip.timeout: 3000
|
|
|
|
ToolTip.visible: hovered
|
2019-01-27 07:57:02 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 03:07:48 +00:00
|
|
|
ToolButton {
|
|
|
|
id: quitButton
|
2019-04-02 02:49:33 +00:00
|
|
|
anchors.horizontalCenterOffset: appIcon.isPlaceholder ? 47 : 0
|
|
|
|
anchors.verticalCenterOffset: appIcon.isPlaceholder ? -75 : 60
|
2019-01-27 07:57:02 +00:00
|
|
|
anchors.centerIn: appIcon
|
|
|
|
visible: model.running
|
2019-02-13 03:07:48 +00:00
|
|
|
implicitWidth: 125
|
|
|
|
implicitHeight: 125
|
|
|
|
|
|
|
|
Image {
|
|
|
|
source: "qrc:/res/baseline-cancel-24px.svg"
|
|
|
|
anchors.centerIn: parent
|
|
|
|
sourceSize {
|
|
|
|
width: 75
|
|
|
|
height: 75
|
2019-01-27 07:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-13 03:07:48 +00:00
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
doQuitGame()
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTip.text: "Quit Game"
|
|
|
|
ToolTip.delay: 1000
|
|
|
|
ToolTip.timeout: 3000
|
|
|
|
ToolTip.visible: hovered
|
2018-08-05 19:19:54 +00:00
|
|
|
}
|
2018-08-02 05:32:21 +00:00
|
|
|
|
2018-11-22 10:35:25 +00:00
|
|
|
Label {
|
2018-08-05 19:19:54 +00:00
|
|
|
id: appNameText
|
2019-04-02 02:49:33 +00:00
|
|
|
visible: appIcon.isPlaceholder
|
2018-08-05 19:19:54 +00:00
|
|
|
text: model.name
|
2019-04-02 02:49:33 +00:00
|
|
|
width: appIcon.width
|
2019-04-02 03:55:11 +00:00
|
|
|
height: model.running ? 175 : appIcon.height
|
2019-04-02 02:49:33 +00:00
|
|
|
anchors.left: appIcon.left
|
|
|
|
anchors.right: appIcon.right
|
|
|
|
anchors.bottom: appIcon.bottom
|
2018-07-27 05:39:45 +00:00
|
|
|
font.pointSize: 22
|
2019-04-02 03:55:11 +00:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
2018-07-06 03:07:05 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
wrapMode: Text.Wrap
|
2018-07-27 05:39:45 +00:00
|
|
|
elide: Text.ElideRight
|
2018-07-06 03:07:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 05:32:21 +00:00
|
|
|
function launchOrResumeSelectedApp()
|
|
|
|
{
|
|
|
|
var runningIndex = appModel.getRunningAppIndex()
|
|
|
|
if (runningIndex >= 0 && runningIndex !== index) {
|
|
|
|
quitAppDialog.appName = appModel.getRunningAppName()
|
|
|
|
quitAppDialog.segueToStream = true
|
2018-09-09 17:08:23 +00:00
|
|
|
quitAppDialog.nextAppName = model.name
|
|
|
|
quitAppDialog.nextAppIndex = index
|
2018-08-02 05:32:21 +00:00
|
|
|
quitAppDialog.open()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var component = Qt.createComponent("StreamSegue.qml")
|
2018-08-17 06:29:46 +00:00
|
|
|
var segue = component.createObject(stackView, {"appName": model.name, "session": appModel.createSessionForApp(index)})
|
2018-08-02 05:32:21 +00:00
|
|
|
stackView.push(segue)
|
|
|
|
}
|
|
|
|
|
2019-04-04 03:27:00 +00:00
|
|
|
Keys.onReturnPressed: {
|
2019-01-27 07:57:02 +00:00
|
|
|
if (model.running) {
|
2019-04-04 03:27:00 +00:00
|
|
|
// This will be keyboard/gamepad driven so use
|
2019-01-27 07:57:02 +00:00
|
|
|
// open() instead of popup()
|
|
|
|
appContextMenu.open()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
launchOrResumeSelectedApp()
|
2018-08-02 05:32:21 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-08 04:52:20 +00:00
|
|
|
|
2019-02-10 03:59:01 +00:00
|
|
|
Keys.onMenuPressed: {
|
|
|
|
if (model.running) {
|
2019-04-04 03:27:00 +00:00
|
|
|
// This will be keyboard/gamepad driven so use
|
2019-02-10 03:59:01 +00:00
|
|
|
// open() instead of popup()
|
|
|
|
appContextMenu.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-27 07:57:02 +00:00
|
|
|
function doQuitGame() {
|
|
|
|
quitAppDialog.appName = appModel.getRunningAppName()
|
|
|
|
quitAppDialog.segueToStream = false
|
|
|
|
quitAppDialog.open()
|
2018-09-30 20:41:32 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 03:59:01 +00:00
|
|
|
NavigableMenu {
|
2018-08-02 05:32:21 +00:00
|
|
|
id: appContextMenu
|
2018-09-30 20:41:32 +00:00
|
|
|
NavigableMenuItem {
|
2019-02-10 03:59:01 +00:00
|
|
|
parentMenu: appContextMenu
|
2018-08-02 05:32:21 +00:00
|
|
|
text: model.running ? "Resume Game" : "Launch Game"
|
2019-04-01 02:40:30 +00:00
|
|
|
onTriggered: launchOrResumeSelectedApp()
|
2018-08-02 05:32:21 +00:00
|
|
|
}
|
2018-09-24 02:06:26 +00:00
|
|
|
NavigableMenuItem {
|
2019-02-10 03:59:01 +00:00
|
|
|
parentMenu: appContextMenu
|
2018-08-02 05:32:21 +00:00
|
|
|
text: "Quit Game"
|
2019-01-27 07:57:02 +00:00
|
|
|
onTriggered: doQuitGame()
|
2018-08-02 05:32:21 +00:00
|
|
|
visible: model.running
|
2018-07-06 03:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 06:05:36 +00:00
|
|
|
|
2019-03-31 20:57:57 +00:00
|
|
|
NavigableMessageDialog {
|
2018-09-08 00:33:34 +00:00
|
|
|
id: quitAppDialog
|
2018-09-09 17:08:23 +00:00
|
|
|
property string appName : ""
|
2018-09-08 00:33:34 +00:00
|
|
|
property bool segueToStream : false
|
2018-09-09 17:08:23 +00:00
|
|
|
property string nextAppName: ""
|
|
|
|
property int nextAppIndex: 0
|
2018-09-08 00:33:34 +00:00
|
|
|
text:"Are you sure you want to quit " + appName +"? Any unsaved progress will be lost."
|
2019-04-01 00:24:25 +00:00
|
|
|
standardButtons: Dialog.Yes | Dialog.No
|
2018-10-01 05:20:19 +00:00
|
|
|
|
|
|
|
function quitApp() {
|
2018-09-08 00:33:34 +00:00
|
|
|
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.
|
2018-09-09 17:08:23 +00:00
|
|
|
params.nextAppName = nextAppName
|
|
|
|
params.nextSession = appModel.createSessionForApp(nextAppIndex)
|
2018-09-08 00:33:34 +00:00
|
|
|
}
|
|
|
|
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()
|
|
|
|
}
|
2018-10-01 05:20:19 +00:00
|
|
|
|
|
|
|
onAccepted: quitApp()
|
2018-09-08 00:33:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 06:05:36 +00:00
|
|
|
ScrollBar.vertical: ScrollBar {
|
2019-03-27 08:28:46 +00:00
|
|
|
// Manually hide the scrollbar to prevent it from being drawn on top
|
|
|
|
// of the StreamSegue during the transition. It can sometimes get stuck
|
|
|
|
// there since we're not consistently pumping the event loop while
|
|
|
|
// starting the stream.
|
|
|
|
visible: activated
|
|
|
|
|
2018-07-09 06:05:36 +00:00
|
|
|
parent: appGrid.parent
|
|
|
|
anchors {
|
2019-04-02 03:40:52 +00:00
|
|
|
top: parent.top
|
|
|
|
right: parent.right
|
|
|
|
bottom: parent.bottom
|
2018-07-09 06:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-06 03:07:05 +00:00
|
|
|
}
|