87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
#include "GamesPanel.h"
|
|
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QListWidget>
|
|
#include <QSplitter>
|
|
#include <QVBoxLayout>
|
|
|
|
GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
|
|
{
|
|
auto *layout = new QHBoxLayout(this);
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
|
|
|
auto *splitter = new QSplitter(Qt::Horizontal, this);
|
|
|
|
m_gameList = new QListWidget(splitter);
|
|
m_gameList->setMinimumWidth(180);
|
|
m_gameList->setMaximumWidth(300);
|
|
|
|
m_detailWidget = new QWidget(splitter);
|
|
auto *detailLayout = new QVBoxLayout(m_detailWidget);
|
|
detailLayout->setContentsMargins(8, 8, 8, 8);
|
|
|
|
m_nameLabel = new QLabel(m_detailWidget);
|
|
m_nameLabel->setStyleSheet("font-size: 14pt; font-weight: bold;");
|
|
m_codeLabel = new QLabel(m_detailWidget);
|
|
m_codeLabel->setStyleSheet("font-size: 11pt; color: gray;");
|
|
m_hintLabel = new QLabel("Select a game to view details.", m_detailWidget);
|
|
m_hintLabel->setAlignment(Qt::AlignTop);
|
|
|
|
detailLayout->addWidget(m_nameLabel);
|
|
detailLayout->addWidget(m_codeLabel);
|
|
detailLayout->addWidget(m_hintLabel);
|
|
detailLayout->addStretch(1);
|
|
|
|
splitter->addWidget(m_gameList);
|
|
splitter->addWidget(m_detailWidget);
|
|
splitter->setStretchFactor(0, 0);
|
|
splitter->setStretchFactor(1, 1);
|
|
splitter->setSizes({200, 600});
|
|
|
|
layout->addWidget(splitter);
|
|
|
|
connect(m_gameList, &QListWidget::currentTextChanged,
|
|
this, &GamesPanel::onGameSelected);
|
|
}
|
|
|
|
void GamesPanel::loadFromResponse(const QString &response)
|
|
{
|
|
// Format: "GAM list LEADVision ARCHArchitect ..."
|
|
// Each token: 4 uppercase letters = code, rest = name (_S = space)
|
|
const QStringList tokens = response.split(' ', Qt::SkipEmptyParts);
|
|
if (tokens.size() < 3 || tokens[0] != "GAM" || tokens[1] != "list") return;
|
|
|
|
m_games.clear();
|
|
m_gameList->clear();
|
|
|
|
for (const QString &entry : tokens.mid(2)) {
|
|
if (entry.isEmpty()) continue;
|
|
|
|
int splitPos = 0;
|
|
while (splitPos < entry.size() && entry[splitPos].isUpper())
|
|
++splitPos;
|
|
|
|
const QString code = entry.left(qMin(splitPos, 4));
|
|
QString name = entry.mid(code.size());
|
|
name.replace("_S", " ");
|
|
|
|
if (code.isEmpty() || name.isEmpty()) continue;
|
|
m_games[name] = code;
|
|
m_gameList->addItem(name);
|
|
}
|
|
}
|
|
|
|
void GamesPanel::onGameSelected(const QString &name)
|
|
{
|
|
if (name.isEmpty() || !m_games.contains(name)) {
|
|
m_nameLabel->clear();
|
|
m_codeLabel->clear();
|
|
m_hintLabel->setText("Select a game to view details.");
|
|
return;
|
|
}
|
|
m_nameLabel->setText(name);
|
|
m_codeLabel->setText(QString("Code: %1").arg(m_games[name]));
|
|
m_hintLabel->setText("Game selected. Future controls will appear here.");
|
|
}
|