mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-16 07:22:16 -07:00
Tab EDHRec improvements.
This commit is contained in:
parent
854208ea0a
commit
43b0465518
38 changed files with 740 additions and 19 deletions
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "edhrec_top_commanders_api_response.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
void EdhrecTopCommandersApiResponse::fromJson(const QJsonObject &json)
|
||||||
|
{
|
||||||
|
header = json.value("header").toString();
|
||||||
|
description = json.value("description").toString();
|
||||||
|
QJsonObject containerJson = json.value("container").toObject();
|
||||||
|
container.fromJson(containerJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdhrecTopCommandersApiResponse::debugPrint() const
|
||||||
|
{
|
||||||
|
qDebug() << "Header:" << header;
|
||||||
|
qDebug() << "Description:" << description;
|
||||||
|
container.debugPrint();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef EDHREC_TOP_COMMANDERS_API_RESPONSE_H
|
||||||
|
#define EDHREC_TOP_COMMANDERS_API_RESPONSE_H
|
||||||
|
|
||||||
|
#include "../commander/edhrec_commander_api_response_card_container.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
// Represents the main structure of the JSON
|
||||||
|
class EdhrecTopCommandersApiResponse
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString header;
|
||||||
|
QString description;
|
||||||
|
EdhrecCommanderApiResponseCardContainer container;
|
||||||
|
|
||||||
|
void fromJson(const QJsonObject &json);
|
||||||
|
void debugPrint() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //EDHREC_TOP_COMMANDERS_API_RESPONSE_H
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "edhrec_top_tags_api_response.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
void EdhrecTopTagsApiResponse::fromJson(const QJsonObject &json)
|
||||||
|
{
|
||||||
|
header = json.value("header").toString();
|
||||||
|
description = json.value("description").toString();
|
||||||
|
QJsonObject containerJson = json.value("container").toObject();
|
||||||
|
container.fromJson(containerJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdhrecTopTagsApiResponse::debugPrint() const
|
||||||
|
{
|
||||||
|
qDebug() << "Header:" << header;
|
||||||
|
qDebug() << "Description:" << description;
|
||||||
|
container.debugPrint();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef EDHREC_TOP_TAGS_API_RESPONSE_H
|
||||||
|
#define EDHREC_TOP_TAGS_API_RESPONSE_H
|
||||||
|
|
||||||
|
#include "../commander/edhrec_commander_api_response_card_container.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
// Represents the main structure of the JSON
|
||||||
|
class EdhrecTopTagsApiResponse
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString header;
|
||||||
|
QString description;
|
||||||
|
EdhrecCommanderApiResponseCardContainer container;
|
||||||
|
|
||||||
|
void fromJson(const QJsonObject &json);
|
||||||
|
void debugPrint() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EDHREC_TOP_TAGS_API_RESPONSE_H
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "edhrec_commander_api_response_card_details_display_widget.h"
|
#include "edhrec_commander_api_response_card_details_display_widget.h"
|
||||||
|
|
||||||
#include "../../../../game/cards/card_database_manager.h"
|
#include "../../../../../game/cards/card_database_manager.h"
|
||||||
|
|
||||||
EdhrecCommanderApiResponseCardDetailsDisplayWidget::EdhrecCommanderApiResponseCardDetailsDisplayWidget(
|
EdhrecCommanderApiResponseCardDetailsDisplayWidget::EdhrecCommanderApiResponseCardDetailsDisplayWidget(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
|
|
@ -17,8 +17,11 @@ EdhrecCommanderApiResponseCardDetailsDisplayWidget::EdhrecCommanderApiResponseCa
|
||||||
label->setText(toDisplay.name + "\n" + toDisplay.label);
|
label->setText(toDisplay.name + "\n" + toDisplay.label);
|
||||||
label->setAlignment(Qt::AlignHCenter);
|
label->setAlignment(Qt::AlignHCenter);
|
||||||
|
|
||||||
|
int inclusionRate = 0;
|
||||||
// Set label color based on inclusion rate
|
// Set label color based on inclusion rate
|
||||||
int inclusionRate = (toDisplay.numDecks * 100) / toDisplay.potentialDecks;
|
if (toDisplay.potentialDecks != 0) {
|
||||||
|
inclusionRate = (toDisplay.numDecks * 100) / toDisplay.potentialDecks;
|
||||||
|
}
|
||||||
|
|
||||||
QColor labelColor;
|
QColor labelColor;
|
||||||
if (inclusionRate <= 30) {
|
if (inclusionRate <= 30) {
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef EDHREC_COMMANDER_API_RESPONSE_CARD_DETAILS_DISPLAY_WIDGET_H
|
#ifndef EDHREC_COMMANDER_API_RESPONSE_CARD_DETAILS_DISPLAY_WIDGET_H
|
||||||
#define EDHREC_COMMANDER_API_RESPONSE_CARD_DETAILS_DISPLAY_WIDGET_H
|
#define EDHREC_COMMANDER_API_RESPONSE_CARD_DETAILS_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
#include "../../../ui/widgets/cards/card_info_picture_widget.h"
|
#include "../../../../ui/widgets/cards/card_info_picture_widget.h"
|
||||||
#include "api_response/edhrec_commander_api_response_card_details.h"
|
#include "../api_response/commander/edhrec_commander_api_response_card_details.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "edhrec_commander_api_response_card_list_display_widget.h"
|
#include "edhrec_commander_api_response_card_list_display_widget.h"
|
||||||
|
|
||||||
#include "../../../ui/widgets/general/display/banner_widget.h"
|
#include "../../../../ui/widgets/general/display/banner_widget.h"
|
||||||
#include "edhrec_commander_api_response_card_details_display_widget.h"
|
#include "edhrec_commander_api_response_card_details_display_widget.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef EDHREC_COMMANDER_API_RESPONSE_CARD_LIST_DISPLAY_WIDGET_H
|
#ifndef EDHREC_COMMANDER_API_RESPONSE_CARD_LIST_DISPLAY_WIDGET_H
|
||||||
#define EDHREC_COMMANDER_API_RESPONSE_CARD_LIST_DISPLAY_WIDGET_H
|
#define EDHREC_COMMANDER_API_RESPONSE_CARD_LIST_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
#include "../../../ui/widgets/general/display/banner_widget.h"
|
#include "../../../../ui/widgets/general/display/banner_widget.h"
|
||||||
#include "../../../ui/widgets/general/layout_containers/flow_widget.h"
|
#include "../../../../ui/widgets/general/layout_containers/flow_widget.h"
|
||||||
#include "api_response/edhrec_commander_api_response_card_list.h"
|
#include "../api_response/commander/edhrec_commander_api_response_card_list.h"
|
||||||
|
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "edhrec_commander_api_response_commander_details_display_widget.h"
|
#include "edhrec_commander_api_response_commander_details_display_widget.h"
|
||||||
|
|
||||||
#include "../../../../game/cards/card_database_manager.h"
|
#include "../../../../../game/cards/card_database_manager.h"
|
||||||
#include "../../../ui/widgets/cards/card_info_picture_widget.h"
|
#include "../../../../ui/widgets/cards/card_info_picture_widget.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef EDHREC_COMMANDER_API_RESPONSE_COMMANDER_DETAILS_DISPLAY_WIDGET_H
|
#ifndef EDHREC_COMMANDER_API_RESPONSE_COMMANDER_DETAILS_DISPLAY_WIDGET_H
|
||||||
#define EDHREC_COMMANDER_API_RESPONSE_COMMANDER_DETAILS_DISPLAY_WIDGET_H
|
#define EDHREC_COMMANDER_API_RESPONSE_COMMANDER_DETAILS_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
#include "../../../ui/widgets/cards/card_info_picture_widget.h"
|
#include "../../../../ui/widgets/cards/card_info_picture_widget.h"
|
||||||
#include "api_response/edhrec_commander_api_response_commander_details.h"
|
#include "../api_response/commander/edhrec_commander_api_response_commander_details.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "edhrec_commander_api_response_display_widget.h"
|
#include "edhrec_commander_api_response_display_widget.h"
|
||||||
|
|
||||||
#include "../../../ui/widgets/cards/card_info_picture_widget.h"
|
#include "../../../../ui/widgets/cards/card_info_picture_widget.h"
|
||||||
#include "api_response/edhrec_commander_api_response.h"
|
#include "../api_response/commander/edhrec_commander_api_response.h"
|
||||||
#include "edhrec_commander_api_response_card_list_display_widget.h"
|
#include "edhrec_commander_api_response_card_list_display_widget.h"
|
||||||
#include "edhrec_commander_api_response_commander_details_display_widget.h"
|
#include "edhrec_commander_api_response_commander_details_display_widget.h"
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef EDHREC_COMMANDER_API_RESPONSE_DISPLAY_WIDGET_H
|
#ifndef EDHREC_COMMANDER_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
#define EDHREC_COMMANDER_API_RESPONSE_DISPLAY_WIDGET_H
|
#define EDHREC_COMMANDER_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
#include "api_response/edhrec_commander_api_response.h"
|
#include "../api_response/commander/edhrec_commander_api_response.h"
|
||||||
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "tab_edhrec.h"
|
#include "tab_edhrec.h"
|
||||||
|
|
||||||
#include "api_response/edhrec_commander_api_response.h"
|
#include "api_response/commander/edhrec_commander_api_response.h"
|
||||||
#include "edhrec_commander_api_response_display_widget.h"
|
#include "commander/edhrec_commander_api_response_display_widget.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include "../../../../game/cards/card_database.h"
|
#include "../../../../game/cards/card_database.h"
|
||||||
#include "../../../ui/widgets/general/layout_containers/flow_widget.h"
|
#include "../../../ui/widgets/general/layout_containers/flow_widget.h"
|
||||||
#include "../../tab.h"
|
#include "../../tab.h"
|
||||||
#include "edhrec_commander_api_response_display_widget.h"
|
#include "commander/edhrec_commander_api_response_display_widget.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
|
|
||||||
315
cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.cpp
Normal file
315
cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.cpp
Normal file
|
|
@ -0,0 +1,315 @@
|
||||||
|
#include "tab_edhrec_main.h"
|
||||||
|
|
||||||
|
#include "../../../../game/cards/card_completer_proxy_model.h"
|
||||||
|
#include "../../../../game/cards/card_database_manager.h"
|
||||||
|
#include "../../../../game/cards/card_search_model.h"
|
||||||
|
#include "api_response/commander/edhrec_commander_api_response.h"
|
||||||
|
#include "api_response/top_commanders/edhrec_top_commanders_api_response.h"
|
||||||
|
#include "api_response/top_tags/edhrec_top_tags_api_response.h"
|
||||||
|
#include "commander/edhrec_commander_api_response_display_widget.h"
|
||||||
|
#include "top_commander/edhrec_top_commanders_api_response_display_widget.h"
|
||||||
|
#include "top_tags/edhrec_top_tags_api_response_display_widget.h"
|
||||||
|
|
||||||
|
#include <QCompleter>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
|
||||||
|
static bool canBeCommander(const CardInfoPtr &cardInfo)
|
||||||
|
{
|
||||||
|
return ((cardInfo->getCardType().contains("Legendary", Qt::CaseInsensitive) &&
|
||||||
|
cardInfo->getCardType().contains("Creature", Qt::CaseInsensitive))) ||
|
||||||
|
cardInfo->getText().contains("can be your commander", Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
TabEdhRecMain::TabEdhRecMain(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor)
|
||||||
|
{
|
||||||
|
networkManager = new QNetworkAccessManager(this);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
networkManager->setTransferTimeout(); // Use Qt's default timeout
|
||||||
|
#endif
|
||||||
|
|
||||||
|
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||||
|
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(processApiJson(QNetworkReply *)));
|
||||||
|
|
||||||
|
container = new QWidget(this);
|
||||||
|
mainLayout = new QVBoxLayout(container);
|
||||||
|
container->setLayout(mainLayout);
|
||||||
|
|
||||||
|
navigationContainer = new QWidget(container);
|
||||||
|
navigationContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||||
|
navigationLayout = new QHBoxLayout(navigationContainer);
|
||||||
|
navigationLayout->setSpacing(5);
|
||||||
|
navigationContainer->setLayout(navigationLayout);
|
||||||
|
|
||||||
|
cardsPushButton = new QPushButton(navigationContainer);
|
||||||
|
topCommandersPushButton = new QPushButton(navigationContainer);
|
||||||
|
connect(topCommandersPushButton, &QPushButton::clicked, this, &TabEdhRecMain::getTopCommanders);
|
||||||
|
tagsPushButton = new QPushButton(navigationContainer);
|
||||||
|
connect(tagsPushButton, &QPushButton::clicked, this, &TabEdhRecMain::getTopTags);
|
||||||
|
|
||||||
|
searchBar = new QLineEdit(this);
|
||||||
|
auto cardDatabaseModel = new CardDatabaseModel(CardDatabaseManager::getInstance(), false, this);
|
||||||
|
auto displayModel = new CardDatabaseDisplayModel(this);
|
||||||
|
displayModel->setSourceModel(cardDatabaseModel);
|
||||||
|
CardSearchModel *searchModel = new CardSearchModel(displayModel, this);
|
||||||
|
|
||||||
|
CardCompleterProxyModel *proxyModel = new CardCompleterProxyModel(this);
|
||||||
|
proxyModel->setSourceModel(searchModel);
|
||||||
|
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
proxyModel->setFilterRole(Qt::DisplayRole);
|
||||||
|
|
||||||
|
QCompleter *completer = new QCompleter(proxyModel, this);
|
||||||
|
completer->setCompletionRole(Qt::DisplayRole);
|
||||||
|
completer->setCompletionMode(QCompleter::PopupCompletion);
|
||||||
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
completer->setFilterMode(Qt::MatchContains);
|
||||||
|
completer->setMaxVisibleItems(10);
|
||||||
|
searchBar->setCompleter(completer);
|
||||||
|
|
||||||
|
// Update suggestions dynamically
|
||||||
|
connect(searchBar, &QLineEdit::textChanged, searchModel, &CardSearchModel::updateSearchResults);
|
||||||
|
connect(searchBar, &QLineEdit::textChanged, this, [=](const QString &text) {
|
||||||
|
// Ensure substring matching
|
||||||
|
QString pattern = ".*" + QRegularExpression::escape(text) + ".*";
|
||||||
|
proxyModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));
|
||||||
|
|
||||||
|
if (!text.isEmpty()) {
|
||||||
|
completer->complete(); // Force the dropdown to appear
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
searchPushButton = new QPushButton(navigationContainer);
|
||||||
|
connect(searchPushButton, &QPushButton::clicked, this, [=, this]() { doSearch(); });
|
||||||
|
|
||||||
|
navigationLayout->addWidget(cardsPushButton);
|
||||||
|
navigationLayout->addWidget(topCommandersPushButton);
|
||||||
|
navigationLayout->addWidget(tagsPushButton);
|
||||||
|
navigationLayout->addWidget(searchBar);
|
||||||
|
navigationLayout->addWidget(searchPushButton);
|
||||||
|
|
||||||
|
currentPageDisplay = new QWidget(container);
|
||||||
|
currentPageLayout = new QVBoxLayout(currentPageDisplay);
|
||||||
|
currentPageDisplay->setLayout(currentPageLayout);
|
||||||
|
|
||||||
|
mainLayout->addWidget(navigationContainer);
|
||||||
|
mainLayout->addWidget(currentPageDisplay);
|
||||||
|
|
||||||
|
// Ensure navigation stays at the top and currentPageDisplay takes remaining space
|
||||||
|
mainLayout->setStretch(0, 0); // navigationContainer gets minimum space
|
||||||
|
mainLayout->setStretch(1, 1); // currentPageDisplay expands as much as possible
|
||||||
|
|
||||||
|
setCentralWidget(container);
|
||||||
|
|
||||||
|
TabEdhRecMain::retranslateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::retranslateUi()
|
||||||
|
{
|
||||||
|
cardsPushButton->setText(tr("&Cards"));
|
||||||
|
topCommandersPushButton->setText(tr("Top Commanders"));
|
||||||
|
tagsPushButton->setText(tr("Tags"));
|
||||||
|
searchBar->setPlaceholderText(tr("Search for a card ..."));
|
||||||
|
searchPushButton->setText(tr("Search"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::doSearch()
|
||||||
|
{
|
||||||
|
CardInfoPtr searchedCard = CardDatabaseManager::getInstance()->getCard(searchBar->text());
|
||||||
|
if (!searchedCard) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCard(searchedCard, canBeCommander(searchedCard));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::setCard(CardInfoPtr _cardToQuery, bool isCommander)
|
||||||
|
{
|
||||||
|
cardToQuery = _cardToQuery;
|
||||||
|
|
||||||
|
if (!cardToQuery) {
|
||||||
|
qDebug() << "Invalid card information provided.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString cardName = cardToQuery->getName();
|
||||||
|
QString formattedName = cardName.toLower().replace(" ", "-").remove(QRegularExpression("[^a-z0-9\\-]"));
|
||||||
|
|
||||||
|
QString url;
|
||||||
|
if (isCommander) {
|
||||||
|
url = QString("https://json.edhrec.com/pages/commanders/%1.json").arg(formattedName);
|
||||||
|
} else {
|
||||||
|
url = QString("https://json.edhrec.com/pages/cards/%1.json").arg(formattedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkRequest request{QUrl(url)};
|
||||||
|
|
||||||
|
networkManager->get(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::getTopCommanders()
|
||||||
|
{
|
||||||
|
QNetworkRequest request{QUrl("https://json.edhrec.com/pages/commanders/year.json")};
|
||||||
|
|
||||||
|
networkManager->get(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::getTopTags()
|
||||||
|
{
|
||||||
|
QNetworkRequest request{QUrl("https://json.edhrec.com/pages/tags.json")};
|
||||||
|
|
||||||
|
networkManager->get(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::processApiJson(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qDebug() << "Network error occurred:" << reply->errorString();
|
||||||
|
reply->deleteLater();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray responseData = reply->readAll();
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
|
||||||
|
|
||||||
|
if (!jsonDoc.isObject()) {
|
||||||
|
qDebug() << "Invalid JSON response received.";
|
||||||
|
reply->deleteLater();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject jsonObj = jsonDoc.object();
|
||||||
|
|
||||||
|
// Get the actual URL from the reply
|
||||||
|
QString responseUrl = reply->url().toString();
|
||||||
|
|
||||||
|
// Check if the response URL matches a commander request
|
||||||
|
if (responseUrl.startsWith("https://json.edhrec.com/pages/commanders/year.json")) {
|
||||||
|
processTopCommandersResponse(jsonObj);
|
||||||
|
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/commanders/")) {
|
||||||
|
processCommanderResponse(jsonObj);
|
||||||
|
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/cards/")) {
|
||||||
|
processCommanderResponse(jsonObj);
|
||||||
|
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/tags.json")) {
|
||||||
|
processTopTagsResponse(jsonObj);
|
||||||
|
} else {
|
||||||
|
prettyPrintJson(jsonObj, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
reply->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::processTopTagsResponse(QJsonObject reply)
|
||||||
|
{
|
||||||
|
EdhrecTopTagsApiResponse deckData;
|
||||||
|
deckData.fromJson(reply);
|
||||||
|
|
||||||
|
// **Remove previous page display to prevent stacking**
|
||||||
|
if (currentPageDisplay) {
|
||||||
|
mainLayout->removeWidget(currentPageDisplay);
|
||||||
|
delete currentPageDisplay;
|
||||||
|
currentPageDisplay = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// **Create new currentPageDisplay**
|
||||||
|
currentPageDisplay = new QWidget(container);
|
||||||
|
currentPageLayout = new QVBoxLayout(currentPageDisplay);
|
||||||
|
currentPageDisplay->setLayout(currentPageLayout);
|
||||||
|
|
||||||
|
auto display = new EdhrecTopTagsApiResponseDisplayWidget(currentPageDisplay, deckData);
|
||||||
|
currentPageLayout->addWidget(display);
|
||||||
|
|
||||||
|
mainLayout->addWidget(currentPageDisplay);
|
||||||
|
|
||||||
|
// **Ensure layout stays correct**
|
||||||
|
mainLayout->setStretch(0, 0); // Keep navigationContainer at the top
|
||||||
|
mainLayout->setStretch(1, 1); // Make sure currentPageDisplay takes remaining space
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::processTopCommandersResponse(QJsonObject reply)
|
||||||
|
{
|
||||||
|
EdhrecTopCommandersApiResponse deckData;
|
||||||
|
deckData.fromJson(reply);
|
||||||
|
|
||||||
|
// **Remove previous page display to prevent stacking**
|
||||||
|
if (currentPageDisplay) {
|
||||||
|
mainLayout->removeWidget(currentPageDisplay);
|
||||||
|
delete currentPageDisplay;
|
||||||
|
currentPageDisplay = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// **Create new currentPageDisplay**
|
||||||
|
currentPageDisplay = new QWidget(container);
|
||||||
|
currentPageLayout = new QVBoxLayout(currentPageDisplay);
|
||||||
|
currentPageDisplay->setLayout(currentPageLayout);
|
||||||
|
|
||||||
|
auto display = new EdhrecTopCommandersApiResponseDisplayWidget(currentPageDisplay, deckData);
|
||||||
|
currentPageLayout->addWidget(display);
|
||||||
|
|
||||||
|
mainLayout->addWidget(currentPageDisplay);
|
||||||
|
|
||||||
|
// **Ensure layout stays correct**
|
||||||
|
mainLayout->setStretch(0, 0); // Keep navigationContainer at the top
|
||||||
|
mainLayout->setStretch(1, 1); // Make sure currentPageDisplay takes remaining space
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::processCommanderResponse(QJsonObject reply)
|
||||||
|
{
|
||||||
|
EdhrecCommanderApiResponse deckData;
|
||||||
|
deckData.fromJson(reply);
|
||||||
|
|
||||||
|
// **Remove previous page display to prevent stacking**
|
||||||
|
if (currentPageDisplay) {
|
||||||
|
mainLayout->removeWidget(currentPageDisplay);
|
||||||
|
delete currentPageDisplay;
|
||||||
|
currentPageDisplay = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// **Create new currentPageDisplay**
|
||||||
|
currentPageDisplay = new QWidget(container);
|
||||||
|
currentPageLayout = new QVBoxLayout(currentPageDisplay);
|
||||||
|
currentPageDisplay->setLayout(currentPageLayout);
|
||||||
|
|
||||||
|
auto display = new EdhrecCommanderApiResponseDisplayWidget(currentPageDisplay, deckData);
|
||||||
|
currentPageLayout->addWidget(display);
|
||||||
|
|
||||||
|
mainLayout->addWidget(currentPageDisplay);
|
||||||
|
|
||||||
|
// **Ensure layout stays correct**
|
||||||
|
mainLayout->setStretch(0, 0); // Keep navigationContainer at the top
|
||||||
|
mainLayout->setStretch(1, 1); // Make sure currentPageDisplay takes remaining space
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabEdhRecMain::prettyPrintJson(const QJsonValue &value, int indentLevel)
|
||||||
|
{
|
||||||
|
const QString indent(indentLevel * 2, ' '); // Adjust spacing as needed for pretty printing
|
||||||
|
|
||||||
|
if (value.isObject()) {
|
||||||
|
QJsonObject obj = value.toObject();
|
||||||
|
for (auto it = obj.begin(); it != obj.end(); ++it) {
|
||||||
|
qDebug().noquote() << indent + it.key() + ":";
|
||||||
|
prettyPrintJson(it.value(), indentLevel + 1);
|
||||||
|
}
|
||||||
|
} else if (value.isArray()) {
|
||||||
|
QJsonArray array = value.toArray();
|
||||||
|
for (int i = 0; i < array.size(); ++i) {
|
||||||
|
qDebug().noquote() << indent + QString("[%1]:").arg(i);
|
||||||
|
prettyPrintJson(array[i], indentLevel + 1);
|
||||||
|
}
|
||||||
|
} else if (value.isString()) {
|
||||||
|
qDebug().noquote() << indent + "\"" + value.toString() + "\"";
|
||||||
|
} else if (value.isDouble()) {
|
||||||
|
qDebug().noquote() << indent + QString::number(value.toDouble());
|
||||||
|
} else if (value.isBool()) {
|
||||||
|
qDebug().noquote() << indent + (value.toBool() ? "true" : "false");
|
||||||
|
} else if (value.isNull()) {
|
||||||
|
qDebug().noquote() << indent + "null";
|
||||||
|
}
|
||||||
|
}
|
||||||
57
cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.h
Normal file
57
cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.h
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#ifndef TAB_EDHREC_MAIN_H
|
||||||
|
#define TAB_EDHREC_MAIN_H
|
||||||
|
|
||||||
|
#include "../../../../game/cards/card_database.h"
|
||||||
|
#include "../../../ui/widgets/general/layout_containers/flow_widget.h"
|
||||||
|
#include "../../tab.h"
|
||||||
|
#include "commander/edhrec_commander_api_response_display_widget.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
class TabEdhRecMain : public Tab
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TabEdhRecMain(TabSupervisor *_tabSupervisor);
|
||||||
|
|
||||||
|
void retranslateUi() override;
|
||||||
|
void doSearch();
|
||||||
|
QString getTabText() const override
|
||||||
|
{
|
||||||
|
auto cardName = cardToQuery.isNull() ? QString() : cardToQuery->getName();
|
||||||
|
return tr("EDHREC: ") + cardName;
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkAccessManager *networkManager;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void processApiJson(QNetworkReply *reply);
|
||||||
|
void processTopTagsResponse(QJsonObject reply);
|
||||||
|
void processTopCommandersResponse(QJsonObject reply);
|
||||||
|
void prettyPrintJson(const QJsonValue &value, int indentLevel);
|
||||||
|
void setCard(CardInfoPtr _cardToQuery, bool isCommander = false);
|
||||||
|
void getTopCommanders();
|
||||||
|
void getTopTags();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWidget *container;
|
||||||
|
QWidget *navigationContainer;
|
||||||
|
QWidget *currentPageDisplay;
|
||||||
|
QVBoxLayout *mainLayout;
|
||||||
|
QHBoxLayout *navigationLayout;
|
||||||
|
QVBoxLayout *currentPageLayout;
|
||||||
|
QPushButton *cardsPushButton;
|
||||||
|
QPushButton *topCommandersPushButton;
|
||||||
|
QPushButton *tagsPushButton;
|
||||||
|
QLineEdit *searchBar;
|
||||||
|
QPushButton *searchPushButton;
|
||||||
|
CardInfoPtr cardToQuery;
|
||||||
|
EdhrecCommanderApiResponseDisplayWidget *displayWidget;
|
||||||
|
|
||||||
|
void processCommanderResponse(QJsonObject reply);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TAB_EDHREC_MAIN_H
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
#include "edhrec_top_commanders_api_response_display_widget.h"
|
||||||
|
|
||||||
|
#include "../../../../ui/widgets/cards/card_info_picture_widget.h"
|
||||||
|
#include "../api_response/top_commanders/edhrec_top_commanders_api_response.h"
|
||||||
|
#include "../commander/edhrec_commander_api_response_card_list_display_widget.h"
|
||||||
|
#include "../commander/edhrec_commander_api_response_commander_details_display_widget.h"
|
||||||
|
|
||||||
|
#include <QListView>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QSplitter>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
|
EdhrecTopCommandersApiResponseDisplayWidget::EdhrecTopCommandersApiResponseDisplayWidget(
|
||||||
|
QWidget *parent,
|
||||||
|
EdhrecTopCommandersApiResponse response)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
layout = new QHBoxLayout(this);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
cardDisplayLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
|
// Create a QSplitter to hold the ListView and ScrollArea holding CardListdisplayWidgets side by side
|
||||||
|
auto splitter = new QSplitter(this);
|
||||||
|
splitter->setOrientation(Qt::Horizontal);
|
||||||
|
|
||||||
|
auto listView = new QListView(splitter);
|
||||||
|
listView->setMinimumWidth(50);
|
||||||
|
listView->setMaximumWidth(150);
|
||||||
|
auto listModel = new QStringListModel(this);
|
||||||
|
QStringList widgetNames;
|
||||||
|
|
||||||
|
// Add card list widgets
|
||||||
|
auto edhrec_commander_api_response_card_lists = response.container.getCardlists();
|
||||||
|
for (const EdhrecCommanderApiResponseCardList &card_list : edhrec_commander_api_response_card_lists) {
|
||||||
|
auto cardListDisplayWidget = new EdhrecCommanderApiResponseCardListDisplayWidget(this, card_list);
|
||||||
|
cardDisplayLayout->addWidget(cardListDisplayWidget);
|
||||||
|
widgetNames.append(cardListDisplayWidget->getBannerText());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a QScrollArea to hold the card display widgets
|
||||||
|
scrollArea = new QScrollArea(splitter);
|
||||||
|
scrollArea->setWidgetResizable(true);
|
||||||
|
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
|
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
|
// Set the cardDisplayLayout inside the scroll area
|
||||||
|
auto scrollWidget = new QWidget(scrollArea);
|
||||||
|
scrollWidget->setLayout(cardDisplayLayout);
|
||||||
|
connect(splitter, &QSplitter::splitterMoved, this, &EdhrecTopCommandersApiResponseDisplayWidget::onSplitterChange);
|
||||||
|
scrollArea->setWidget(scrollWidget);
|
||||||
|
|
||||||
|
// Configure the list view
|
||||||
|
listModel->setStringList(widgetNames);
|
||||||
|
listView->setModel(listModel);
|
||||||
|
listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
|
||||||
|
// Connect the list view to ensure the corresponding widget is visible
|
||||||
|
connect(listView, &QListView::clicked, this, [this](const QModelIndex &index) {
|
||||||
|
int widgetIndex = index.row();
|
||||||
|
qDebug() << "clicked: " << widgetIndex;
|
||||||
|
auto targetWidget = cardDisplayLayout->itemAt(widgetIndex)->widget();
|
||||||
|
if (targetWidget) {
|
||||||
|
qDebug() << "Found targetWidget" << targetWidget;
|
||||||
|
// Attempt to cast the parent to QScrollArea
|
||||||
|
auto scrollArea = qobject_cast<QScrollArea *>(this->scrollArea); // Use the scroll area instance
|
||||||
|
if (scrollArea) {
|
||||||
|
qDebug() << "ScrollArea" << scrollArea;
|
||||||
|
scrollArea->ensureWidgetVisible(targetWidget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add splitter to the main layout
|
||||||
|
splitter->addWidget(listView);
|
||||||
|
splitter->addWidget(scrollArea);
|
||||||
|
|
||||||
|
layout->addWidget(splitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdhrecTopCommandersApiResponseDisplayWidget::onSplitterChange()
|
||||||
|
{
|
||||||
|
scrollArea->widget()->resize(scrollArea->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdhrecTopCommandersApiResponseDisplayWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
qDebug() << event->size();
|
||||||
|
layout->invalidate();
|
||||||
|
layout->activate();
|
||||||
|
layout->update();
|
||||||
|
if (scrollArea && scrollArea->widget()) {
|
||||||
|
scrollArea->widget()->resize(event->size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef EDHREC_TOP_COMMANDERS_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
|
#define EDHREC_TOP_COMMANDERS_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
|
#include "../api_response/top_commanders/edhrec_top_commanders_api_response.h"
|
||||||
|
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class EdhrecTopCommandersApiResponseDisplayWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit EdhrecTopCommandersApiResponseDisplayWidget(QWidget *parent, EdhrecTopCommandersApiResponse response);
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onSplitterChange();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHBoxLayout *layout;
|
||||||
|
QVBoxLayout *cardDisplayLayout;
|
||||||
|
QScrollArea *scrollArea;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EDHREC_TOP_COMMANDERS_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
#include "edhrec_top_tags_api_response_display_widget.h"
|
||||||
|
|
||||||
|
#include "../../../../ui/widgets/cards/card_info_picture_widget.h"
|
||||||
|
#include "../api_response/top_commanders/edhrec_top_commanders_api_response.h"
|
||||||
|
#include "../commander/edhrec_commander_api_response_card_list_display_widget.h"
|
||||||
|
#include "../commander/edhrec_commander_api_response_commander_details_display_widget.h"
|
||||||
|
|
||||||
|
#include <QListView>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QSplitter>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
|
EdhrecTopTagsApiResponseDisplayWidget::EdhrecTopTagsApiResponseDisplayWidget(QWidget *parent,
|
||||||
|
EdhrecTopTagsApiResponse response)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
layout = new QHBoxLayout(this);
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
|
cardDisplayLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
|
// Create a QSplitter to hold the ListView and ScrollArea holding CardListdisplayWidgets side by side
|
||||||
|
auto splitter = new QSplitter(this);
|
||||||
|
splitter->setOrientation(Qt::Horizontal);
|
||||||
|
|
||||||
|
auto listView = new QListView(splitter);
|
||||||
|
listView->setMinimumWidth(50);
|
||||||
|
listView->setMaximumWidth(150);
|
||||||
|
auto listModel = new QStringListModel(this);
|
||||||
|
QStringList widgetNames;
|
||||||
|
|
||||||
|
// Add card list widgets
|
||||||
|
auto edhrec_commander_api_response_card_lists = response.container.getCardlists();
|
||||||
|
for (const EdhrecCommanderApiResponseCardList &card_list : edhrec_commander_api_response_card_lists) {
|
||||||
|
auto cardListDisplayWidget = new EdhrecCommanderApiResponseCardListDisplayWidget(this, card_list);
|
||||||
|
cardDisplayLayout->addWidget(cardListDisplayWidget);
|
||||||
|
widgetNames.append(cardListDisplayWidget->getBannerText());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a QScrollArea to hold the card display widgets
|
||||||
|
scrollArea = new QScrollArea(splitter);
|
||||||
|
scrollArea->setWidgetResizable(true);
|
||||||
|
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
|
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
|
// Set the cardDisplayLayout inside the scroll area
|
||||||
|
auto scrollWidget = new QWidget(scrollArea);
|
||||||
|
scrollWidget->setLayout(cardDisplayLayout);
|
||||||
|
connect(splitter, &QSplitter::splitterMoved, this, &EdhrecTopTagsApiResponseDisplayWidget::onSplitterChange);
|
||||||
|
scrollArea->setWidget(scrollWidget);
|
||||||
|
|
||||||
|
// Configure the list view
|
||||||
|
listModel->setStringList(widgetNames);
|
||||||
|
listView->setModel(listModel);
|
||||||
|
listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
|
||||||
|
// Connect the list view to ensure the corresponding widget is visible
|
||||||
|
connect(listView, &QListView::clicked, this, [this](const QModelIndex &index) {
|
||||||
|
int widgetIndex = index.row();
|
||||||
|
qDebug() << "clicked: " << widgetIndex;
|
||||||
|
auto targetWidget = cardDisplayLayout->itemAt(widgetIndex)->widget();
|
||||||
|
if (targetWidget) {
|
||||||
|
qDebug() << "Found targetWidget" << targetWidget;
|
||||||
|
// Attempt to cast the parent to QScrollArea
|
||||||
|
auto scrollArea = qobject_cast<QScrollArea *>(this->scrollArea); // Use the scroll area instance
|
||||||
|
if (scrollArea) {
|
||||||
|
qDebug() << "ScrollArea" << scrollArea;
|
||||||
|
scrollArea->ensureWidgetVisible(targetWidget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add splitter to the main layout
|
||||||
|
splitter->addWidget(listView);
|
||||||
|
splitter->addWidget(scrollArea);
|
||||||
|
|
||||||
|
layout->addWidget(splitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdhrecTopTagsApiResponseDisplayWidget::onSplitterChange()
|
||||||
|
{
|
||||||
|
scrollArea->widget()->resize(scrollArea->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EdhrecTopTagsApiResponseDisplayWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
qDebug() << event->size();
|
||||||
|
layout->invalidate();
|
||||||
|
layout->activate();
|
||||||
|
layout->update();
|
||||||
|
if (scrollArea && scrollArea->widget()) {
|
||||||
|
scrollArea->widget()->resize(event->size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef EDHREC_TOP_TAGS_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
|
#define EDHREC_TOP_TAGS_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
|
#include "../api_response/top_tags/edhrec_top_tags_api_response.h"
|
||||||
|
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class EdhrecTopTagsApiResponseDisplayWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit EdhrecTopTagsApiResponseDisplayWidget(QWidget *parent, EdhrecTopTagsApiResponse response);
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onSplitterChange();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHBoxLayout *layout;
|
||||||
|
QVBoxLayout *cardDisplayLayout;
|
||||||
|
QScrollArea *scrollArea;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EDHREC_TOP_TAGS_API_RESPONSE_DISPLAY_WIDGET_H
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../../server/user/user_list_widget.h"
|
#include "../../server/user/user_list_widget.h"
|
||||||
#include "../../settings/cache_settings.h"
|
#include "../../settings/cache_settings.h"
|
||||||
#include "../ui/pixel_map_generator.h"
|
#include "../ui/pixel_map_generator.h"
|
||||||
|
#include "api/edhrec/tab_edhrec_main.h"
|
||||||
#include "pb/event_game_joined.pb.h"
|
#include "pb/event_game_joined.pb.h"
|
||||||
#include "pb/event_notify_user.pb.h"
|
#include "pb/event_notify_user.pb.h"
|
||||||
#include "pb/event_user_message.pb.h"
|
#include "pb/event_user_message.pb.h"
|
||||||
|
|
@ -136,6 +137,9 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
|
||||||
aTabVisualDeckEditor = new QAction(this);
|
aTabVisualDeckEditor = new QAction(this);
|
||||||
connect(aTabVisualDeckEditor, &QAction::triggered, this, [this] { addVisualDeckEditorTab(nullptr); });
|
connect(aTabVisualDeckEditor, &QAction::triggered, this, [this] { addVisualDeckEditorTab(nullptr); });
|
||||||
|
|
||||||
|
aTabEdhRec = new QAction(this);
|
||||||
|
connect(aTabEdhRec, &QAction::triggered, this, [this] { addEdhrecMainTab(); });
|
||||||
|
|
||||||
aTabVisualDeckStorage = new QAction(this);
|
aTabVisualDeckStorage = new QAction(this);
|
||||||
aTabVisualDeckStorage->setCheckable(true);
|
aTabVisualDeckStorage->setCheckable(true);
|
||||||
connect(aTabVisualDeckStorage, &QAction::triggered, this, &TabSupervisor::actTabVisualDeckStorage);
|
connect(aTabVisualDeckStorage, &QAction::triggered, this, &TabSupervisor::actTabVisualDeckStorage);
|
||||||
|
|
@ -186,6 +190,7 @@ void TabSupervisor::retranslateUi()
|
||||||
// tab menu actions
|
// tab menu actions
|
||||||
aTabDeckEditor->setText(tr("Deck Editor"));
|
aTabDeckEditor->setText(tr("Deck Editor"));
|
||||||
aTabVisualDeckEditor->setText(tr("Visual Deck Editor"));
|
aTabVisualDeckEditor->setText(tr("Visual Deck Editor"));
|
||||||
|
aTabEdhRec->setText(tr("EDHRec"));
|
||||||
aTabVisualDeckStorage->setText(tr("&Visual Deck Storage"));
|
aTabVisualDeckStorage->setText(tr("&Visual Deck Storage"));
|
||||||
aTabVisualDatabaseDisplay->setText(tr("Visual Database Display"));
|
aTabVisualDatabaseDisplay->setText(tr("Visual Database Display"));
|
||||||
aTabServer->setText(tr("Server"));
|
aTabServer->setText(tr("Server"));
|
||||||
|
|
@ -383,6 +388,7 @@ void TabSupervisor::resetTabsMenu()
|
||||||
tabsMenu->clear();
|
tabsMenu->clear();
|
||||||
tabsMenu->addAction(aTabDeckEditor);
|
tabsMenu->addAction(aTabDeckEditor);
|
||||||
tabsMenu->addAction(aTabVisualDeckEditor);
|
tabsMenu->addAction(aTabVisualDeckEditor);
|
||||||
|
tabsMenu->addAction(aTabEdhRec);
|
||||||
tabsMenu->addSeparator();
|
tabsMenu->addSeparator();
|
||||||
tabsMenu->addAction(aTabVisualDeckStorage);
|
tabsMenu->addAction(aTabVisualDeckStorage);
|
||||||
tabsMenu->addAction(aTabVisualDatabaseDisplay);
|
tabsMenu->addAction(aTabVisualDatabaseDisplay);
|
||||||
|
|
@ -831,6 +837,15 @@ TabDeckEditorVisual *TabSupervisor::addVisualDeckEditorTab(const DeckLoader *dec
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TabEdhRecMain *TabSupervisor::addEdhrecMainTab()
|
||||||
|
{
|
||||||
|
auto *tab = new TabEdhRecMain(this);
|
||||||
|
|
||||||
|
myAddTab(tab);
|
||||||
|
setCurrentWidget(tab);
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
TabVisualDatabaseDisplay *TabSupervisor::addVisualDatabaseDisplayTab()
|
TabVisualDatabaseDisplay *TabSupervisor::addVisualDatabaseDisplayTab()
|
||||||
{
|
{
|
||||||
auto *tab = new TabVisualDatabaseDisplay(this);
|
auto *tab = new TabVisualDatabaseDisplay(this);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "tab_visual_database_display.h"
|
#include "tab_visual_database_display.h"
|
||||||
#include "visual_deck_editor/tab_deck_editor_visual.h"
|
#include "visual_deck_editor/tab_deck_editor_visual.h"
|
||||||
#include "visual_deck_editor/tab_deck_editor_visual_tab_widget.h"
|
#include "visual_deck_editor/tab_deck_editor_visual_tab_widget.h"
|
||||||
|
#include "api/edhrec/tab_edhrec_main.h"
|
||||||
#include "visual_deck_storage/tab_deck_storage_visual.h"
|
#include "visual_deck_storage/tab_deck_storage_visual.h"
|
||||||
|
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
|
|
@ -94,7 +95,7 @@ private:
|
||||||
QList<AbstractTabDeckEditor *> deckEditorTabs;
|
QList<AbstractTabDeckEditor *> deckEditorTabs;
|
||||||
bool isLocalGame;
|
bool isLocalGame;
|
||||||
|
|
||||||
QAction *aTabDeckEditor, *aTabVisualDeckEditor, *aTabVisualDeckStorage, *aTabVisualDatabaseDisplay, *aTabServer,
|
QAction *aTabDeckEditor, *aTabVisualDeckEditor, *aTabEdhRec, *aTabVisualDeckStorage, *aTabVisualDatabaseDisplay, *aTabServer,
|
||||||
*aTabAccount, *aTabDeckStorage, *aTabReplays, *aTabAdmin, *aTabLog;
|
*aTabAccount, *aTabDeckStorage, *aTabReplays, *aTabAdmin, *aTabLog;
|
||||||
|
|
||||||
int myAddTab(Tab *tab, QAction *manager = nullptr);
|
int myAddTab(Tab *tab, QAction *manager = nullptr);
|
||||||
|
|
@ -154,6 +155,7 @@ public slots:
|
||||||
TabDeckEditor *addDeckEditorTab(const DeckLoader *deckToOpen);
|
TabDeckEditor *addDeckEditorTab(const DeckLoader *deckToOpen);
|
||||||
TabDeckEditorVisual *addVisualDeckEditorTab(const DeckLoader *deckToOpen);
|
TabDeckEditorVisual *addVisualDeckEditorTab(const DeckLoader *deckToOpen);
|
||||||
TabVisualDatabaseDisplay *addVisualDatabaseDisplayTab();
|
TabVisualDatabaseDisplay *addVisualDatabaseDisplayTab();
|
||||||
|
TabEdhRecMain *addEdhrecMainTab();
|
||||||
TabEdhRec *addEdhrecTab(const CardInfoPtr &cardToQuery, bool isCommander = false);
|
TabEdhRec *addEdhrecTab(const CardInfoPtr &cardToQuery, bool isCommander = false);
|
||||||
void openReplay(GameReplay *replay);
|
void openReplay(GameReplay *replay);
|
||||||
void maximizeMainWindow();
|
void maximizeMainWindow();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue