Move Add PC button to toolbar

This commit is contained in:
Cameron Gutman 2019-03-26 21:31:51 -07:00
parent 4752d4966d
commit da7d532564
4 changed files with 74 additions and 74 deletions

View file

@ -77,9 +77,7 @@ GridView {
Image {
id: pcIcon
anchors.horizontalCenter: parent.horizontalCenter
source: {
model.addPc ? "qrc:/res/ic_add_to_queue_white_48px.svg" : "qrc:/res/ic_tv_white_48px.svg"
}
source: "qrc:/res/ic_tv_white_48px.svg"
sourceSize {
width: 200
height: 200
@ -92,7 +90,7 @@ GridView {
anchors.horizontalCenter: pcIcon.horizontalCenter
anchors.verticalCenter: pcIcon.verticalCenter
anchors.verticalCenterOffset: -10
visible: !model.addPc && !model.statusUnknown && (!model.online || !model.paired)
visible: !model.statusUnknown && (!model.online || !model.paired)
source: !model.online ? "qrc:/res/baseline-warning-24px.svg" : "qrc:/res/baseline-lock-24px.svg"
sourceSize {
width: 75
@ -107,7 +105,7 @@ GridView {
anchors.verticalCenterOffset: -10
width: 75
height: 75
visible: !model.addPc && model.statusUnknown
visible: model.statusUnknown
}
Label {
@ -136,15 +134,12 @@ GridView {
parentMenu: pcContextMenu
text: "Wake PC"
onTriggered: computerModel.wakeComputer(index)
visible: !model.addPc && !model.online && model.wakeable
visible: !model.online && model.wakeable
}
}
onClicked: {
if (model.addPc) {
addPcDialog.open()
}
else if (model.online) {
if (model.online) {
if (model.paired) {
// go to game view
var component = Qt.createComponent("AppView.qml")
@ -176,15 +171,13 @@ GridView {
}
onPressAndHold: {
if (!model.addPc) {
// popup() ensures the menu appears under the mouse cursor
if (pcContextMenu.popup) {
pcContextMenu.popup()
}
else {
// Qt 5.9 doesn't have popup()
pcContextMenu.open()
}
// popup() ensures the menu appears under the mouse cursor
if (pcContextMenu.popup) {
pcContextMenu.popup()
}
else {
// Qt 5.9 doesn't have popup()
pcContextMenu.open()
}
}
@ -197,11 +190,9 @@ GridView {
}
Keys.onMenuPressed: {
if (!model.addPc) {
// We must use open() here so the menu is positioned on
// the ItemDelegate and not where the mouse cursor is
pcContextMenu.open()
}
// We must use open() here so the menu is positioned on
// the ItemDelegate and not where the mouse cursor is
pcContextMenu.open()
}
}
@ -245,37 +236,6 @@ GridView {
onAccepted: deletePc()
}
Dialog {
id: addPcDialog
property string label: "Enter the IP address of your GameStream PC"
standardButtons: StandardButton.Ok | StandardButton.Cancel
onAccepted: {
if (editText.text) {
ComputerManager.addNewHost(editText.text, false)
}
}
onVisibleChanged: {
if (visible) {
editText.forceActiveFocus()
}
}
ColumnLayout {
Text {
id: addPcDialogLabel
text: addPcDialog.label
}
TextField {
id: editText
Layout.fillWidth: true
}
}
}
ScrollBar.vertical: ScrollBar {
parent: pcGrid.parent
anchors {

View file

@ -22,18 +22,6 @@ QVariant ComputerModel::data(const QModelIndex& index, int role) const
return QVariant();
}
if (index.row() == m_Computers.count()) {
// We insert a synthetic item at the end for the Add PC option
switch (role) {
case NameRole:
return "Add PC";
case AddPcRole:
return true;
default:
return QVariant();
}
}
Q_ASSERT(index.row() < m_Computers.count());
NvComputer* computer = m_Computers[index.row()];
@ -50,8 +38,6 @@ QVariant ComputerModel::data(const QModelIndex& index, int role) const
return computer->currentGameId != 0;
case WakeableRole:
return !computer->macAddress.isEmpty();
case AddPcRole:
return false;
case StatusUnknownRole:
return computer->state == NvComputer::CS_UNKNOWN;
default:
@ -67,8 +53,7 @@ int ComputerModel::rowCount(const QModelIndex& parent) const
return 0;
}
// Add PC placeholder counts as 1
return m_Computers.count() + 1;
return m_Computers.count();
}
QHash<int, QByteArray> ComputerModel::roleNames() const
@ -79,7 +64,6 @@ QHash<int, QByteArray> ComputerModel::roleNames() const
names[OnlineRole] = "online";
names[PairedRole] = "paired";
names[BusyRole] = "busy";
names[AddPcRole] = "addPc";
names[WakeableRole] = "wakeable";
names[StatusUnknownRole] = "statusUnknown";

View file

@ -14,8 +14,7 @@ class ComputerModel : public QAbstractListModel
PairedRole,
BusyRole,
WakeableRole,
StatusUnknownRole,
AddPcRole
StatusUnknownRole
};
public:

View file

@ -218,6 +218,33 @@ ApplicationWindow {
Layout.fillWidth: true
}
NavigableToolButton {
id: addPcButton
visible: stackView.currentItem.objectName === "Computers"
Image {
source: "qrc:/res/ic_add_to_queue_white_48px.svg"
anchors.centerIn: parent
sourceSize {
width: toolBar.height - toolBar.anchors.bottomMargin - toolBar.anchors.topMargin
height: toolBar.height - toolBar.anchors.bottomMargin - toolBar.anchors.topMargin
}
}
ToolTip.delay: 1000
ToolTip.timeout: 3000
ToolTip.visible: hovered
ToolTip.text: "Add a new PC manually"
onClicked: {
addPcDialog.open()
}
Keys.onDownPressed: {
stackView.currentItem.forceActiveFocus(Qt.TabFocus)
}
}
NavigableToolButton {
property string browserUrl: ""
@ -403,4 +430,34 @@ ApplicationWindow {
// For keyboard/gamepad navigation
onAccepted: Qt.quit()
}
Dialog {
id: addPcDialog
property string label: "Enter the IP address of your GameStream PC"
standardButtons: StandardButton.Ok | StandardButton.Cancel
onAccepted: {
if (editText.text) {
ComputerManager.addNewHost(editText.text, false)
}
}
onVisibleChanged: {
if (visible) {
editText.forceActiveFocus()
}
}
ColumnLayout {
Text {
text: addPcDialog.label
}
TextField {
id: editText
Layout.fillWidth: true
}
}
}
}