mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 16:32:16 -07:00
Move the signals down to the widget, move the connections and slots up to the parent widgets.
This commit is contained in:
parent
29943d9127
commit
5a6374386d
7 changed files with 76 additions and 11 deletions
|
|
@ -104,6 +104,8 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|||
{
|
||||
loadLocalButton = new QPushButton;
|
||||
loadRemoteButton = new QPushButton;
|
||||
unloadDeckButton = new QPushButton;
|
||||
unloadDeckButton->setEnabled(false);
|
||||
readyStartButton = new ToggleButton;
|
||||
readyStartButton->setEnabled(false);
|
||||
forceStartGameButton = new QPushButton;
|
||||
|
|
@ -113,6 +115,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|||
|
||||
connect(loadLocalButton, SIGNAL(clicked()), this, SLOT(loadLocalDeck()));
|
||||
connect(readyStartButton, SIGNAL(clicked()), this, SLOT(readyStart()));
|
||||
connect(unloadDeckButton, &QPushButton::clicked, this, &DeckViewContainer::unloadDeck);
|
||||
connect(forceStartGameButton, &QPushButton::clicked, this, &DeckViewContainer::forceStart);
|
||||
connect(sideboardLockButton, SIGNAL(clicked()), this, SLOT(sideboardLockButtonClicked()));
|
||||
connect(sideboardLockButton, SIGNAL(stateChanged()), this, SLOT(updateSideboardLockButtonText()));
|
||||
|
|
@ -126,6 +129,7 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|||
auto *buttonHBox = new QHBoxLayout;
|
||||
buttonHBox->addWidget(loadLocalButton);
|
||||
buttonHBox->addWidget(loadRemoteButton);
|
||||
buttonHBox->addWidget(unloadDeckButton);
|
||||
buttonHBox->addWidget(readyStartButton);
|
||||
buttonHBox->addWidget(sideboardLockButton);
|
||||
if (forceStartGameButton->isEnabled()) {
|
||||
|
|
@ -139,8 +143,10 @@ DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
|
|||
connect(deckView, SIGNAL(sideboardPlanChanged()), this, SLOT(sideboardPlanChanged()));
|
||||
|
||||
visualDeckStorageWidget = new VisualDeckStorageWidget(this);
|
||||
connect(visualDeckStorageWidget, &VisualDeckStorageWidget::imageDoubleClicked, this,
|
||||
&DeckViewContainer::replaceDeckStorageWithDeckView);
|
||||
|
||||
auto *deckViewLayout = new QVBoxLayout;
|
||||
deckViewLayout = new QVBoxLayout;
|
||||
deckViewLayout->addLayout(buttonHBox);
|
||||
deckViewLayout->addWidget(visualDeckStorageWidget);
|
||||
deckViewLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
|
@ -155,6 +161,7 @@ void DeckViewContainer::retranslateUi()
|
|||
{
|
||||
loadLocalButton->setText(tr("Load deck..."));
|
||||
loadRemoteButton->setText(tr("Load remote deck..."));
|
||||
unloadDeckButton->setText(tr("Unload deck..."));
|
||||
readyStartButton->setText(tr("Ready to start"));
|
||||
forceStartGameButton->setText(tr("Force start"));
|
||||
updateSideboardLockButtonText();
|
||||
|
|
@ -289,6 +296,42 @@ void TabGame::refreshShortcuts()
|
|||
}
|
||||
}
|
||||
|
||||
void DeckViewContainer::replaceDeckStorageWithDeckView(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
QString fileName = instance->filePath;
|
||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||
QString deckString;
|
||||
DeckLoader deck;
|
||||
|
||||
bool error = !deck.loadFromFile(fileName, fmt);
|
||||
if (!error) {
|
||||
deckString = deck.writeToString_Native();
|
||||
error = deckString.length() > MAX_FILE_LENGTH;
|
||||
}
|
||||
if (error) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("The selected file could not be loaded."));
|
||||
return;
|
||||
}
|
||||
|
||||
Command_DeckSelect cmd;
|
||||
cmd.set_deck(deckString.toStdString());
|
||||
PendingCommand *pend = parentGame->prepareGameCommand(cmd);
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
SLOT(deckSelectFinished(const Response &)));
|
||||
parentGame->sendGameCommand(pend, playerId);
|
||||
deckViewLayout->removeWidget(visualDeckStorageWidget);
|
||||
deckViewLayout->addWidget(deckView);
|
||||
unloadDeckButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void DeckViewContainer::unloadDeck()
|
||||
{
|
||||
deckViewLayout->removeWidget(deckView);
|
||||
deckViewLayout->addWidget(visualDeckStorageWidget);
|
||||
unloadDeckButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void DeckViewContainer::loadLocalDeck()
|
||||
{
|
||||
QFileDialog dialog(this, tr("Load deck"));
|
||||
|
|
|
|||
|
|
@ -87,15 +87,18 @@ class DeckViewContainer : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QPushButton *loadLocalButton, *loadRemoteButton, *forceStartGameButton;
|
||||
QVBoxLayout *deckViewLayout;
|
||||
QPushButton *loadLocalButton, *loadRemoteButton, *unloadDeckButton, *forceStartGameButton;
|
||||
ToggleButton *readyStartButton, *sideboardLockButton;
|
||||
DeckView *deckView;
|
||||
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||
TabGame *parentGame;
|
||||
int playerId;
|
||||
private slots:
|
||||
void replaceDeckStorageWithDeckView(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
void loadLocalDeck();
|
||||
void loadRemoteDeck();
|
||||
void unloadDeck();
|
||||
void readyStart();
|
||||
void forceStart();
|
||||
void deckSelectFinished(const Response &r);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, Abstra
|
|||
leftToolBar->addAction(aDeleteLocalDeck);
|
||||
|
||||
visualDeckStorageWidget = new VisualDeckStorageWidget(this);
|
||||
connect(visualDeckStorageWidget, &VisualDeckStorageWidget::imageDoubleClicked, this,
|
||||
&TabDeckStorageVisual::actOpenLocalDeck);
|
||||
connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::addDeckEditorTab);
|
||||
|
||||
layout->addWidget(leftToolBar);
|
||||
layout->addWidget(visualDeckStorageWidget);
|
||||
|
|
@ -68,8 +71,6 @@ QString TabDeckStorageVisual::getTargetPath() const
|
|||
return {};
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TabDeckStorageVisual::actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||
{
|
||||
(void)event;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ DeckPreviewCardPictureWidget::DeckPreviewCardPictureWidget(QWidget *parent,
|
|||
{
|
||||
singleClickTimer = new QTimer(this);
|
||||
singleClickTimer->setSingleShot(true);
|
||||
connect(singleClickTimer, &QTimer::timeout, this, [this]() { qDebug() << "Clicked some stuff"; });
|
||||
connect(singleClickTimer, &QTimer::timeout, this, [this]() { emit imageClicked(lastMouseEvent, this); });
|
||||
}
|
||||
|
||||
void DeckPreviewCardPictureWidget::mousePressEvent(QMouseEvent *event)
|
||||
|
|
@ -43,7 +43,7 @@ void DeckPreviewCardPictureWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
singleClickTimer->stop(); // Prevent single-click logic
|
||||
emit imageClicked(lastMouseEvent, this);
|
||||
emit imageDoubleClicked(lastMouseEvent, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public:
|
|||
|
||||
signals:
|
||||
void imageClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
void imageDoubleClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
|
||||
public slots:
|
||||
void setFilePath(const QString &filePath);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include "../../../../deck/deck_loader.h"
|
||||
#include "../../../../game/cards/card_database_manager.h"
|
||||
#include "../../../../settings/cache_settings.h"
|
||||
#include "../../../ui/widgets/cards/deck_preview_card_picture_widget.h"
|
||||
|
||||
#include <QDirIterator>
|
||||
|
||||
|
|
@ -18,9 +17,16 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
|
|||
layout->addWidget(flowWidget);
|
||||
|
||||
getBannerCardsForDecks();
|
||||
}
|
||||
|
||||
// TODO: Move this to class that uses this widget (The tab one, in this instance, distinct from the game one)
|
||||
// connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::addDeckEditorTab);
|
||||
void VisualDeckStorageWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||
{
|
||||
emit imageClicked(event, instance);
|
||||
}
|
||||
|
||||
void VisualDeckStorageWidget::imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||
{
|
||||
emit imageDoubleClicked(event, instance);
|
||||
}
|
||||
|
||||
QStringList VisualDeckStorageWidget::getBannerCardsForDecks()
|
||||
|
|
@ -49,8 +55,10 @@ QStringList VisualDeckStorageWidget::getBannerCardsForDecks()
|
|||
display->setFontSize(24);
|
||||
display->setFilePath(deckLoader->getLastFileName());
|
||||
|
||||
// TODO: Connect these to the parent.
|
||||
// connect(display, &DeckPreviewCardPictureWidget::imageClicked, this, &TabDeckStorageVisual::actOpenLocalDeck);
|
||||
connect(display, &DeckPreviewCardPictureWidget::imageClicked, this,
|
||||
&VisualDeckStorageWidget::imageClickedEvent);
|
||||
connect(display, &DeckPreviewCardPictureWidget::imageDoubleClicked, this,
|
||||
&VisualDeckStorageWidget::imageDoubleClickedEvent);
|
||||
flowWidget->addWidget(display);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "../../../../deck/deck_list_model.h"
|
||||
#include "../../../../deck/deck_view.h"
|
||||
#include "../../../ui/widgets/cards/deck_preview_card_picture_widget.h"
|
||||
#include "../../../ui/widgets/general/layout_containers/flow_widget.h"
|
||||
|
||||
#include <QFileSystemModel>
|
||||
|
|
@ -14,6 +15,14 @@ public:
|
|||
explicit VisualDeckStorageWidget(QWidget *parent);
|
||||
void retranslateUi();
|
||||
|
||||
public slots:
|
||||
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
|
||||
signals:
|
||||
void imageClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
void imageDoubleClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||
|
||||
private:
|
||||
QHBoxLayout *layout;
|
||||
FlowWidget *flowWidget;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue