Cleanup ComputerModel and remove root Frame from PcView

This commit is contained in:
Cameron Gutman 2018-07-05 20:11:35 -07:00
parent b0151da455
commit f83c13ad85
3 changed files with 80 additions and 84 deletions

View File

@ -5,100 +5,96 @@ import QtQuick.Layouts 1.11
import ComputerModel 1.0 import ComputerModel 1.0
Frame { GridView {
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: 5
anchors.topMargin: 5
anchors.rightMargin: 5
anchors.bottomMargin: 5
cellWidth: 350; cellHeight: 350;
focus: true
GridView { model: ComputerModel {}
anchors.fill: parent
anchors.leftMargin: 5
anchors.topMargin: 5
anchors.rightMargin: 5
anchors.bottomMargin: 5
cellWidth: 350; cellHeight: 350;
focus: true
model: ComputerModel {} delegate: Item {
width: 300; height: 300;
delegate: Item { Image {
width: 300; height: 300; id: pcIcon
anchors.horizontalCenter: parent.horizontalCenter;
Image { source: {
id: pcIcon model.addPc ? "ic_add_to_queue_white_48px.svg" : "ic_tv_white_48px.svg"
anchors.horizontalCenter: parent.horizontalCenter;
source: {
model.addPc ? "ic_add_to_queue_white_48px.svg" : "ic_tv_white_48px.svg"
}
sourceSize {
width: 200
height: 200
}
} }
sourceSize {
Text { width: 200
id: pcNameText height: 200
text: model.name
color: "white"
width: parent.width
anchors.top: pcIcon.bottom
minimumPointSize: 12
font.pointSize: 48
horizontalAlignment: Text.AlignHCenter
fontSizeMode: Text.HorizontalFit
} }
}
Text { Text {
function getStatusText(model) id: pcNameText
{ text: model.name
if (model.online) { color: "white"
var text = "<font color=\"green\">Online</font>"
text += "<font color=\"white\"> - </font>" width: parent.width
if (model.paired) { anchors.top: pcIcon.bottom
text += "<font color=\"skyblue\">Paired</font>" minimumPointSize: 12
} font.pointSize: 48
else if (model.busy) { horizontalAlignment: Text.AlignHCenter
text += "<font color=\"red\">Busy</font>" fontSizeMode: Text.HorizontalFit
} }
else {
text += "<font color=\"red\">Not Paired</font>" Text {
} function getStatusText(model)
return text {
if (model.online) {
var text = "<font color=\"green\">Online</font>"
text += "<font color=\"white\"> - </font>"
if (model.paired) {
text += "<font color=\"skyblue\">Paired</font>"
}
else if (model.busy) {
text += "<font color=\"red\">Busy</font>"
} }
else { else {
return "<font color=\"red\">Offline</font>"; text += "<font color=\"red\">Not Paired</font>"
} }
return text
}
else {
return "<font color=\"red\">Offline</font>";
} }
id: pcPairedText
text: getStatusText(model)
visible: !model.addPc
width: parent.width
anchors.top: pcNameText.bottom
minimumPointSize: 12
font.pointSize: 36
horizontalAlignment: Text.AlignHCenter
fontSizeMode: Text.HorizontalFit
} }
MouseArea { id: pcPairedText
anchors.fill: parent text: getStatusText(model)
onClicked: { visible: !model.addPc
parent.GridView.view.currentIndex = index
if(model.addPc) {
// TODO: read the output of the dialog
inputDialog.on
inputDialog.open()
} else if(!model.paired && !model.busy) { width: parent.width
anchors.top: pcNameText.bottom
minimumPointSize: 12
font.pointSize: 36
horizontalAlignment: Text.AlignHCenter
fontSizeMode: Text.HorizontalFit
}
// TODO: generate pin MouseArea {
pairDialog.text = pairDialog.text.replace("XXXX", "1234") anchors.fill: parent
// TODO: initiate pairing request onClicked: {
pairDialog.open() parent.GridView.view.currentIndex = index
} else if (model.online) { if(model.addPc) {
// go to game view // TODO: read the output of the dialog
} inputDialog.on
inputDialog.open()
} else if(!model.paired && !model.busy) {
// TODO: generate pin
pairDialog.text = pairDialog.text.replace("XXXX", "1234")
// TODO: initiate pairing request
pairDialog.open()
} else if (model.online) {
// go to game view
} }
} }
} }

View File

@ -27,10 +27,8 @@ QVariant ComputerModel::data(const QModelIndex& index, int role) const
return QVariant(); return QVariant();
} }
} }
else if (index.row() > m_Computers.count()) {
qWarning() << "Index out of bounds: " << index.row(); Q_ASSERT(index.row() < m_Computers.count());
return QVariant();
}
NvComputer* computer = m_Computers[index.row()]; NvComputer* computer = m_Computers[index.row()];
QReadLocker lock(&computer->lock); QReadLocker lock(&computer->lock);

View File

@ -4,6 +4,8 @@
class ComputerModel : public QAbstractListModel class ComputerModel : public QAbstractListModel
{ {
Q_OBJECT
enum Roles enum Roles
{ {
NameRole = Qt::UserRole, NameRole = Qt::UserRole,
@ -14,7 +16,7 @@ class ComputerModel : public QAbstractListModel
}; };
public: public:
ComputerModel(QObject* object = nullptr); explicit ComputerModel(QObject* object = nullptr);
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;