preliminary changes to make deck editor a tab

This commit is contained in:
Max-Wilhelm Bruker 2012-04-22 05:06:51 -04:00
parent eb927d77c3
commit 38cf2621b4
16 changed files with 229 additions and 135 deletions

View file

@ -38,7 +38,6 @@ SET(cockatrice_SOURCES
src/stackzone.cpp src/stackzone.cpp
src/carddragitem.cpp src/carddragitem.cpp
src/carddatabasemodel.cpp src/carddatabasemodel.cpp
src/window_deckeditor.cpp
src/setsmodel.cpp src/setsmodel.cpp
src/window_sets.cpp src/window_sets.cpp
src/abstractgraphicsitem.cpp src/abstractgraphicsitem.cpp
@ -59,6 +58,7 @@ SET(cockatrice_SOURCES
src/tab_supervisor.cpp src/tab_supervisor.cpp
src/tab_admin.cpp src/tab_admin.cpp
src/tab_userlists.cpp src/tab_userlists.cpp
src/tab_deck_editor.cpp
src/replay_timeline_widget.cpp src/replay_timeline_widget.cpp
src/chatview.cpp src/chatview.cpp
src/userlist.cpp src/userlist.cpp
@ -111,7 +111,6 @@ SET(cockatrice_HEADERS
src/stackzone.h src/stackzone.h
src/carddragitem.h src/carddragitem.h
src/carddatabasemodel.h src/carddatabasemodel.h
src/window_deckeditor.h
src/setsmodel.h src/setsmodel.h
src/window_sets.h src/window_sets.h
src/abstractgraphicsitem.h src/abstractgraphicsitem.h
@ -132,6 +131,7 @@ SET(cockatrice_HEADERS
src/tab_supervisor.h src/tab_supervisor.h
src/tab_admin.h src/tab_admin.h
src/tab_userlists.h src/tab_userlists.h
src/tab_deck_editor.h
src/replay_timeline_widget.h src/replay_timeline_widget.h
src/chatview.h src/chatview.h
src/userlist.h src/userlist.h

View file

@ -4,7 +4,7 @@
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent) Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent)
: QWidget(parent), tabMenu(0), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0) : QWidget(parent), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0)
{ {
} }

View file

@ -11,18 +11,20 @@ class Tab : public QWidget {
Q_OBJECT Q_OBJECT
signals: signals:
void userEvent(bool globalEvent = true); void userEvent(bool globalEvent = true);
void tabTextChanged(Tab *tab, const QString &newTabText);
protected: protected:
QMenu *tabMenu;
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;
void addTabMenu(QMenu *menu) { tabMenus.append(menu); }
protected slots: protected slots:
void showCardInfoPopup(const QPoint &pos, const QString &cardName); void showCardInfoPopup(const QPoint &pos, const QString &cardName);
void deleteCardInfoPopup(const QString &cardName); void deleteCardInfoPopup(const QString &cardName);
private: private:
bool contentsChanged; bool contentsChanged;
CardInfoWidget *infoPopup; CardInfoWidget *infoPopup;
QList<QMenu *> tabMenus;
public: public:
Tab(TabSupervisor *_tabSupervisor, QWidget *parent = 0); Tab(TabSupervisor *_tabSupervisor, QWidget *parent = 0);
QMenu *getTabMenu() const { return tabMenu; } const QList<QMenu *> &getTabMenus() const { return tabMenus; }
TabSupervisor *getTabSupervisor() const { return tabSupervisor; } TabSupervisor *getTabSupervisor() const { return tabSupervisor; }
bool getContentsChanged() const { return contentsChanged; } bool getContentsChanged() const { return contentsChanged; }
void setContentsChanged(bool _contentsChanged) { contentsChanged = _contentsChanged; } void setContentsChanged(bool _contentsChanged) { contentsChanged = _contentsChanged; }

View file

@ -16,7 +16,7 @@
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QTextStream> #include <QTextStream>
#include "window_deckeditor.h" #include "tab_deck_editor.h"
#include "window_sets.h" #include "window_sets.h"
#include "carddatabase.h" #include "carddatabase.h"
#include "carddatabasemodel.h" #include "carddatabasemodel.h"
@ -35,19 +35,17 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event)
QLineEdit::keyPressEvent(event); QLineEdit::keyPressEvent(event);
} }
WndDeckEditor::WndDeckEditor(QWidget *parent) TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
: QMainWindow(parent) : Tab(_tabSupervisor, parent)
{ {
setAttribute(Qt::WA_DeleteOnClose); aSearch = new QAction(QString(), this);
aSearch = new QAction(tr("&Search..."), this);
aSearch->setIcon(QIcon(":/resources/icon_search.svg")); aSearch->setIcon(QIcon(":/resources/icon_search.svg"));
connect(aSearch, SIGNAL(triggered()), this, SLOT(actSearch())); connect(aSearch, SIGNAL(triggered()), this, SLOT(actSearch()));
aClearSearch = new QAction(tr("&Clear search"), this); aClearSearch = new QAction(QString(), this);
aClearSearch->setIcon(QIcon(":/resources/icon_clearsearch.svg")); aClearSearch->setIcon(QIcon(":/resources/icon_clearsearch.svg"));
connect(aClearSearch, SIGNAL(triggered()), this, SLOT(actClearSearch())); connect(aClearSearch, SIGNAL(triggered()), this, SLOT(actClearSearch()));
QLabel *searchLabel = new QLabel(tr("&Search for:")); searchLabel = new QLabel();
searchEdit = new SearchLineEdit; searchEdit = new SearchLineEdit;
searchLabel->setBuddy(searchEdit); searchLabel->setBuddy(searchEdit);
connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &))); connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &)));
@ -108,16 +106,16 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
deckView->header()->setResizeMode(QHeaderView::ResizeToContents); deckView->header()->setResizeMode(QHeaderView::ResizeToContents);
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &))); connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
QLabel *nameLabel = new QLabel(tr("Deck &name:")); nameLabel = new QLabel();
nameEdit = new QLineEdit; nameEdit = new QLineEdit;
nameLabel->setBuddy(nameEdit); nameLabel->setBuddy(nameEdit);
connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateName(const QString &))); connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateName(const QString &)));
QLabel *commentsLabel = new QLabel(tr("&Comments:")); commentsLabel = new QLabel();
commentsEdit = new QTextEdit; commentsEdit = new QTextEdit;
commentsEdit->setMaximumHeight(70); commentsEdit->setMaximumHeight(70);
commentsLabel->setBuddy(commentsEdit); commentsLabel->setBuddy(commentsEdit);
connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments())); connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
QLabel *hashLabel1 = new QLabel(tr("Hash:")); hashLabel1 = new QLabel();
hashLabel = new QLabel; hashLabel = new QLabel;
QGridLayout *grid = new QGridLayout; QGridLayout *grid = new QGridLayout;
@ -131,8 +129,7 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
grid->addWidget(hashLabel, 2, 1); grid->addWidget(hashLabel, 2, 1);
// Update price // Update price
aUpdatePrices = new QAction(tr("&Update prices"), this); aUpdatePrices = new QAction(QString(), this);
aUpdatePrices->setShortcut(tr("Ctrl+U"));
aUpdatePrices->setIcon(QIcon(":/resources/icon_update.png")); aUpdatePrices->setIcon(QIcon(":/resources/icon_update.png"));
connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices())); connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices()));
if (!settingsCache->getPriceTagFeature()) if (!settingsCache->getPriceTagFeature())
@ -157,29 +154,26 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
mainLayout->addLayout(leftFrame, 10); mainLayout->addLayout(leftFrame, 10);
mainLayout->addLayout(middleFrame); mainLayout->addLayout(middleFrame);
mainLayout->addLayout(rightFrame, 10); mainLayout->addLayout(rightFrame, 10);
setLayout(mainLayout);
QWidget *centralWidget = new QWidget;
centralWidget->setLayout(mainLayout);
setCentralWidget(centralWidget);
setWindowTitle(tr("Deck editor [*]")); setWindowTitle(tr("Deck editor [*]"));
aNewDeck = new QAction(tr("&New deck"), this); aNewDeck = new QAction(QString(), this);
aNewDeck->setShortcuts(QKeySequence::New); aNewDeck->setShortcuts(QKeySequence::New);
connect(aNewDeck, SIGNAL(triggered()), this, SLOT(actNewDeck())); connect(aNewDeck, SIGNAL(triggered()), this, SLOT(actNewDeck()));
aLoadDeck = new QAction(tr("&Load deck..."), this); aLoadDeck = new QAction(QString(), this);
aLoadDeck->setShortcuts(QKeySequence::Open); aLoadDeck->setShortcuts(QKeySequence::Open);
connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck())); connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck()));
aSaveDeck = new QAction(tr("&Save deck"), this); aSaveDeck = new QAction(QString(), this);
aSaveDeck->setShortcuts(QKeySequence::Save); aSaveDeck->setShortcuts(QKeySequence::Save);
connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck())); connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck()));
aSaveDeckAs = new QAction(tr("Save deck &as..."), this); aSaveDeckAs = new QAction(QString(), this);
// aSaveDeckAs->setShortcuts(QKeySequence::SaveAs); // aSaveDeckAs->setShortcuts(QKeySequence::SaveAs);
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs())); connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
aLoadDeckFromClipboard = new QAction(tr("Load deck from cl&ipboard..."), this); aLoadDeckFromClipboard = new QAction(QString(), this);
connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard())); connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard()));
aLoadDeckFromClipboard->setShortcuts(QKeySequence::Paste); aLoadDeckFromClipboard->setShortcuts(QKeySequence::Paste);
aSaveDeckToClipboard = new QAction(tr("Save deck to clip&board"), this); aSaveDeckToClipboard = new QAction(QString(), this);
connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard())); connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard()));
aSaveDeckToClipboard->setShortcuts(QKeySequence::Copy); aSaveDeckToClipboard->setShortcuts(QKeySequence::Copy);
aPrintDeck = new QAction(tr("&Print deck..."), this); aPrintDeck = new QAction(tr("&Print deck..."), this);
@ -192,7 +186,7 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
aEditSets = new QAction(tr("&Edit sets..."), this); aEditSets = new QAction(tr("&Edit sets..."), this);
connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets())); connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets()));
deckMenu = menuBar()->addMenu(tr("&Deck")); deckMenu = new QMenu(this);
deckMenu->addAction(aNewDeck); deckMenu->addAction(aNewDeck);
deckMenu->addAction(aLoadDeck); deckMenu->addAction(aLoadDeck);
deckMenu->addAction(aSaveDeck); deckMenu->addAction(aSaveDeck);
@ -204,32 +198,29 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
deckMenu->addAction(aPrintDeck); deckMenu->addAction(aPrintDeck);
deckMenu->addSeparator(); deckMenu->addSeparator();
deckMenu->addAction(aClose); deckMenu->addAction(aClose);
addTabMenu(deckMenu);
dbMenu = menuBar()->addMenu(tr("&Card database")); dbMenu = new QMenu(this);
dbMenu->addAction(aEditSets); dbMenu->addAction(aEditSets);
dbMenu->addSeparator(); dbMenu->addSeparator();
dbMenu->addAction(aSearch); dbMenu->addAction(aSearch);
dbMenu->addAction(aClearSearch); dbMenu->addAction(aClearSearch);
addTabMenu(dbMenu);
aAddCard = new QAction(tr("Add card to &maindeck"), this); aAddCard = new QAction(QString(), this);
aAddCard->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Return")) << QKeySequence(tr("Enter")));
aAddCard->setIcon(QIcon(":/resources/arrow_right_green.svg")); aAddCard->setIcon(QIcon(":/resources/arrow_right_green.svg"));
connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard())); connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard()));
aAddCardToSideboard = new QAction(tr("Add card to &sideboard"), this); aAddCardToSideboard = new QAction(QString(), this);
aAddCardToSideboard->setIcon(QIcon(":/resources/add_to_sideboard.svg")); aAddCardToSideboard->setIcon(QIcon(":/resources/add_to_sideboard.svg"));
aAddCardToSideboard->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Return")) << QKeySequence(tr("Ctrl+Enter")));
connect(aAddCardToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard())); connect(aAddCardToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard()));
aRemoveCard = new QAction(tr("&Remove row"), this); aRemoveCard = new QAction(QString(), this);
aRemoveCard->setShortcut(tr("Del"));
aRemoveCard->setIcon(QIcon(":/resources/remove_row.svg")); aRemoveCard->setIcon(QIcon(":/resources/remove_row.svg"));
connect(aRemoveCard, SIGNAL(triggered()), this, SLOT(actRemoveCard())); connect(aRemoveCard, SIGNAL(triggered()), this, SLOT(actRemoveCard()));
aIncrement = new QAction(tr("&Increment number"), this); aIncrement = new QAction(QString(), this);
aIncrement->setShortcut(tr("+"));
aIncrement->setIcon(QIcon(":/resources/increment.svg")); aIncrement->setIcon(QIcon(":/resources/increment.svg"));
connect(aIncrement, SIGNAL(triggered()), this, SLOT(actIncrement())); connect(aIncrement, SIGNAL(triggered()), this, SLOT(actIncrement()));
aDecrement = new QAction(tr("&Decrement number"), this); aDecrement = new QAction(QString(), this);
aDecrement->setIcon(QIcon(":/resources/decrement.svg")); aDecrement->setIcon(QIcon(":/resources/decrement.svg"));
aDecrement->setShortcut(tr("-"));
connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement())); connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement()));
verticalToolBar->addAction(aAddCard); verticalToolBar->addAction(aAddCard);
@ -241,31 +232,78 @@ WndDeckEditor::WndDeckEditor(QWidget *parent)
dlgCardSearch = new DlgCardSearch(this); dlgCardSearch = new DlgCardSearch(this);
retranslateUi();
resize(950, 700); resize(950, 700);
} }
WndDeckEditor::~WndDeckEditor() TabDeckEditor::~TabDeckEditor()
{ {
emit deckEditorClosing(this);
} }
void WndDeckEditor::updateName(const QString &name) void TabDeckEditor::retranslateUi()
{
aSearch->setText(tr("&Search..."));
aClearSearch->setText(tr("&Clear search"));
searchLabel->setText(tr("&Search for:"));
nameLabel->setText(tr("Deck &name:"));
commentsLabel->setText(tr("&Comments:"));
hashLabel1->setText(tr("Hash:"));
aUpdatePrices->setText(tr("&Update prices"));
aUpdatePrices->setShortcut(tr("Ctrl+U"));
aNewDeck->setText(tr("&New deck"));
aLoadDeck->setText(tr("&Load deck..."));
aSaveDeck->setText(tr("&Save deck"));
aSaveDeckAs->setText(tr("Save deck &as..."));
aLoadDeckFromClipboard->setText(tr("Load deck from cl&ipboard..."));
aSaveDeckToClipboard->setText(tr("Save deck to clip&board"));
aAddCard->setText(tr("Add card to &maindeck"));
aAddCard->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Return")) << QKeySequence(tr("Enter")));
aAddCardToSideboard->setText(tr("Add card to &sideboard"));
aAddCardToSideboard->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Return")) << QKeySequence(tr("Ctrl+Enter")));
aRemoveCard->setText(tr("&Remove row"));
aRemoveCard->setShortcut(tr("Del"));
aIncrement->setText(tr("&Increment number"));
aIncrement->setShortcut(tr("+"));
aDecrement->setText(tr("&Decrement number"));
aDecrement->setShortcut(tr("-"));
deckMenu->setTitle(tr("&Deck editor"));
dbMenu->setTitle(tr("C&ard database"));
}
QString TabDeckEditor::getTabText() const
{
QString result = tr("Deck: %1").arg(nameEdit->text());
if (isWindowModified())
result.prepend("* ");
return result;
}
void TabDeckEditor::updateName(const QString &name)
{ {
deckModel->getDeckList()->setName(name); deckModel->getDeckList()->setName(name);
setWindowModified(true); setWindowModified(true);
emit tabTextChanged(this, getTabText());
} }
void WndDeckEditor::updateComments() void TabDeckEditor::updateComments()
{ {
deckModel->getDeckList()->setComments(commentsEdit->toPlainText()); deckModel->getDeckList()->setComments(commentsEdit->toPlainText());
setWindowModified(true); setWindowModified(true);
} }
void WndDeckEditor::updateCardInfoLeft(const QModelIndex &current, const QModelIndex &/*previous*/) void TabDeckEditor::updateCardInfoLeft(const QModelIndex &current, const QModelIndex &/*previous*/)
{ {
cardInfo->setCard(current.sibling(current.row(), 0).data().toString()); cardInfo->setCard(current.sibling(current.row(), 0).data().toString());
} }
void WndDeckEditor::updateCardInfoRight(const QModelIndex &current, const QModelIndex &/*previous*/) void TabDeckEditor::updateCardInfoRight(const QModelIndex &current, const QModelIndex &/*previous*/)
{ {
if (!current.isValid()) if (!current.isValid())
return; return;
@ -273,7 +311,7 @@ void WndDeckEditor::updateCardInfoRight(const QModelIndex &current, const QModel
cardInfo->setCard(current.sibling(current.row(), 1).data().toString()); cardInfo->setCard(current.sibling(current.row(), 1).data().toString());
} }
void WndDeckEditor::updateSearch(const QString &search) void TabDeckEditor::updateSearch(const QString &search)
{ {
databaseDisplayModel->setCardNameBeginning(search); databaseDisplayModel->setCardNameBeginning(search);
QModelIndexList sel = databaseView->selectionModel()->selectedRows(); QModelIndexList sel = databaseView->selectionModel()->selectedRows();
@ -281,12 +319,12 @@ void WndDeckEditor::updateSearch(const QString &search)
databaseView->selectionModel()->setCurrentIndex(databaseDisplayModel->index(0, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); databaseView->selectionModel()->setCurrentIndex(databaseDisplayModel->index(0, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
} }
void WndDeckEditor::updateHash() void TabDeckEditor::updateHash()
{ {
hashLabel->setText(deckModel->getDeckList()->getDeckHash()); hashLabel->setText(deckModel->getDeckList()->getDeckHash());
} }
bool WndDeckEditor::confirmClose() bool TabDeckEditor::confirmClose()
{ {
if (isWindowModified()) { if (isWindowModified()) {
QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("Are you sure?"), QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("Are you sure?"),
@ -300,16 +338,13 @@ bool WndDeckEditor::confirmClose()
return true; return true;
} }
void WndDeckEditor::closeEvent(QCloseEvent *event) void TabDeckEditor::closeRequest()
{ {
if (confirmClose()) { if (confirmClose())
event->accept();
deleteLater(); deleteLater();
} else
event->ignore();
} }
void WndDeckEditor::actNewDeck() void TabDeckEditor::actNewDeck()
{ {
if (!confirmClose()) if (!confirmClose())
return; return;
@ -321,7 +356,7 @@ void WndDeckEditor::actNewDeck()
setWindowModified(false); setWindowModified(false);
} }
void WndDeckEditor::actLoadDeck() void TabDeckEditor::actLoadDeck()
{ {
if (!confirmClose()) if (!confirmClose())
return; return;
@ -341,7 +376,7 @@ void WndDeckEditor::actLoadDeck()
delete l; delete l;
} }
bool WndDeckEditor::actSaveDeck() bool TabDeckEditor::actSaveDeck()
{ {
if (lastFileName.isEmpty()) if (lastFileName.isEmpty())
return actSaveDeckAs(); return actSaveDeckAs();
@ -353,7 +388,7 @@ bool WndDeckEditor::actSaveDeck()
return false; return false;
} }
bool WndDeckEditor::actSaveDeckAs() bool TabDeckEditor::actSaveDeckAs()
{ {
QFileDialog dialog(this, tr("Save deck")); QFileDialog dialog(this, tr("Save deck"));
dialog.setDirectory(settingsCache->getDeckPath()); dialog.setDirectory(settingsCache->getDeckPath());
@ -378,7 +413,7 @@ bool WndDeckEditor::actSaveDeckAs()
return false; return false;
} }
void WndDeckEditor::actLoadDeckFromClipboard() void TabDeckEditor::actLoadDeckFromClipboard()
{ {
if (!confirmClose()) if (!confirmClose())
return; return;
@ -391,7 +426,7 @@ void WndDeckEditor::actLoadDeckFromClipboard()
setWindowModified(true); setWindowModified(true);
} }
void WndDeckEditor::actSaveDeckToClipboard() void TabDeckEditor::actSaveDeckToClipboard()
{ {
QString buffer; QString buffer;
QTextStream stream(&buffer); QTextStream stream(&buffer);
@ -400,21 +435,21 @@ void WndDeckEditor::actSaveDeckToClipboard()
QApplication::clipboard()->setText(buffer, QClipboard::Selection); QApplication::clipboard()->setText(buffer, QClipboard::Selection);
} }
void WndDeckEditor::actPrintDeck() void TabDeckEditor::actPrintDeck()
{ {
QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this); QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this);
connect(dlg, SIGNAL(paintRequested(QPrinter *)), deckModel, SLOT(printDeckList(QPrinter *))); connect(dlg, SIGNAL(paintRequested(QPrinter *)), deckModel, SLOT(printDeckList(QPrinter *)));
dlg->exec(); dlg->exec();
} }
void WndDeckEditor::actEditSets() void TabDeckEditor::actEditSets()
{ {
WndSets *w = new WndSets; WndSets *w = new WndSets;
w->setWindowModality(Qt::WindowModal); w->setWindowModality(Qt::WindowModal);
w->show(); w->show();
} }
void WndDeckEditor::actSearch() void TabDeckEditor::actSearch()
{ {
if (dlgCardSearch->exec()) { if (dlgCardSearch->exec()) {
searchEdit->clear(); searchEdit->clear();
@ -425,19 +460,19 @@ void WndDeckEditor::actSearch()
} }
} }
void WndDeckEditor::actClearSearch() void TabDeckEditor::actClearSearch()
{ {
databaseDisplayModel->clearSearch(); databaseDisplayModel->clearSearch();
} }
void WndDeckEditor::recursiveExpand(const QModelIndex &index) void TabDeckEditor::recursiveExpand(const QModelIndex &index)
{ {
if (index.parent().isValid()) if (index.parent().isValid())
recursiveExpand(index.parent()); recursiveExpand(index.parent());
deckView->expand(index); deckView->expand(index);
} }
void WndDeckEditor::addCardHelper(QString zoneName) void TabDeckEditor::addCardHelper(QString zoneName)
{ {
const QModelIndex currentIndex = databaseView->selectionModel()->currentIndex(); const QModelIndex currentIndex = databaseView->selectionModel()->currentIndex();
if (!currentIndex.isValid()) if (!currentIndex.isValid())
@ -455,17 +490,17 @@ void WndDeckEditor::addCardHelper(QString zoneName)
setWindowModified(true); setWindowModified(true);
} }
void WndDeckEditor::actAddCard() void TabDeckEditor::actAddCard()
{ {
addCardHelper("main"); addCardHelper("main");
} }
void WndDeckEditor::actAddCardToSideboard() void TabDeckEditor::actAddCardToSideboard()
{ {
addCardHelper("side"); addCardHelper("side");
} }
void WndDeckEditor::actRemoveCard() void TabDeckEditor::actRemoveCard()
{ {
const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex(); const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex();
if (!currentIndex.isValid() || deckModel->hasChildren(currentIndex)) if (!currentIndex.isValid() || deckModel->hasChildren(currentIndex))
@ -474,7 +509,7 @@ void WndDeckEditor::actRemoveCard()
setWindowModified(true); setWindowModified(true);
} }
void WndDeckEditor::actIncrement() void TabDeckEditor::actIncrement()
{ {
const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex(); const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex();
if (!currentIndex.isValid()) if (!currentIndex.isValid())
@ -486,7 +521,7 @@ void WndDeckEditor::actIncrement()
setWindowModified(true); setWindowModified(true);
} }
void WndDeckEditor::actDecrement() void TabDeckEditor::actDecrement()
{ {
const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex(); const QModelIndex &currentIndex = deckView->selectionModel()->currentIndex();
if (!currentIndex.isValid()) if (!currentIndex.isValid())
@ -501,7 +536,7 @@ void WndDeckEditor::actDecrement()
setWindowModified(true); setWindowModified(true);
} }
void WndDeckEditor::actUpdatePrices() void TabDeckEditor::actUpdatePrices()
{ {
aUpdatePrices->setDisabled(true); aUpdatePrices->setDisabled(true);
PriceUpdater *up = new PriceUpdater(deckModel->getDeckList()); PriceUpdater *up = new PriceUpdater(deckModel->getDeckList());
@ -509,14 +544,14 @@ void WndDeckEditor::actUpdatePrices()
up->updatePrices(); up->updatePrices();
} }
void WndDeckEditor::finishedUpdatingPrices() void TabDeckEditor::finishedUpdatingPrices()
{ {
deckModel->pricesUpdated(); deckModel->pricesUpdated();
setWindowModified(true); setWindowModified(true);
aUpdatePrices->setDisabled(false); aUpdatePrices->setDisabled(false);
} }
void WndDeckEditor::setDeck(DeckList *_deck, const QString &_lastFileName, DeckList::FileFormat _lastFileFormat) void TabDeckEditor::setDeck(DeckList *_deck, const QString &_lastFileName, DeckList::FileFormat _lastFileFormat)
{ {
deckModel->setDeckList(_deck); deckModel->setDeckList(_deck);

View file

@ -1,7 +1,7 @@
#ifndef WINDOW_DECKEDITOR_H #ifndef WINDOW_DECKEDITOR_H
#define WINDOW_DECKEDITOR_H #define WINDOW_DECKEDITOR_H
#include <QMainWindow> #include "tab.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QLineEdit> #include <QLineEdit>
#include "decklist.h" #include "decklist.h"
@ -26,7 +26,7 @@ class SearchLineEdit : public QLineEdit {
void setTreeView(QTreeView *_treeView) { treeView = _treeView; } void setTreeView(QTreeView *_treeView) { treeView = _treeView; }
}; };
class WndDeckEditor : public QMainWindow { class TabDeckEditor : public Tab {
Q_OBJECT Q_OBJECT
private slots: private slots:
void updateName(const QString &name); void updateName(const QString &name);
@ -71,9 +71,13 @@ private:
QTreeView *databaseView; QTreeView *databaseView;
QTreeView *deckView; QTreeView *deckView;
CardInfoWidget *cardInfo; CardInfoWidget *cardInfo;
QLabel *searchLabel;
SearchLineEdit *searchEdit; SearchLineEdit *searchEdit;
QLabel *nameLabel;
QLineEdit *nameEdit; QLineEdit *nameEdit;
QLabel *commentsLabel;
QTextEdit *commentsEdit; QTextEdit *commentsEdit;
QLabel *hashLabel1;
QLabel *hashLabel; QLabel *hashLabel;
DlgCardSearch *dlgCardSearch; DlgCardSearch *dlgCardSearch;
@ -82,11 +86,14 @@ private:
QAction *aEditSets, *aSearch, *aClearSearch; QAction *aEditSets, *aSearch, *aClearSearch;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement, *aUpdatePrices;
public: public:
WndDeckEditor(QWidget *parent = 0); TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = 0);
~WndDeckEditor(); ~TabDeckEditor();
void retranslateUi();
QString getTabText() const;
void closeRequest();
void setDeck(DeckList *_deck, const QString &_lastFileName = QString(), DeckList::FileFormat _lastFileFormat = DeckList::CockatriceFormat); void setDeck(DeckList *_deck, const QString &_lastFileName = QString(), DeckList::FileFormat _lastFileFormat = DeckList::CockatriceFormat);
protected: signals:
void closeEvent(QCloseEvent *event); void deckEditorClosing(TabDeckEditor *tab);
}; };
#endif #endif

View file

@ -12,7 +12,7 @@
#include "remotedecklist_treewidget.h" #include "remotedecklist_treewidget.h"
#include "abstractclient.h" #include "abstractclient.h"
#include "decklist.h" #include "decklist.h"
#include "window_deckeditor.h" //#include "window_deckeditor.h"
#include "settingscache.h" #include "settingscache.h"
#include "pending_command.h" #include "pending_command.h"
@ -127,9 +127,9 @@ void TabDeckStorage::actOpenLocalDeck()
if (!deck->loadFromFile(filePath, DeckList::CockatriceFormat)) if (!deck->loadFromFile(filePath, DeckList::CockatriceFormat))
return; return;
WndDeckEditor *deckEditor = new WndDeckEditor; // WndDeckEditor *deckEditor = new WndDeckEditor;
deckEditor->setDeck(deck, filePath, DeckList::CockatriceFormat); // deckEditor->setDeck(deck, filePath, DeckList::CockatriceFormat);
deckEditor->show(); // deckEditor->show();
} }
void TabDeckStorage::actUpload() void TabDeckStorage::actUpload()
@ -196,9 +196,9 @@ void TabDeckStorage::openRemoteDeckFinished(const Response &r)
{ {
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext); const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
WndDeckEditor *deckEditor = new WndDeckEditor; // WndDeckEditor *deckEditor = new WndDeckEditor;
deckEditor->setDeck(new DeckList(QString::fromStdString(resp.deck()))); // deckEditor->setDeck(new DeckList(QString::fromStdString(resp.deck())));
deckEditor->show(); // deckEditor->show();
} }
void TabDeckStorage::actDownload() void TabDeckStorage::actDownload()

View file

@ -365,8 +365,9 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
connect(aCloseReplay, SIGNAL(triggered()), this, SLOT(actLeaveGame())); connect(aCloseReplay, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
phasesMenu = 0; phasesMenu = 0;
tabMenu = new QMenu(this); gameMenu = new QMenu(this);
tabMenu->addAction(aCloseReplay); gameMenu->addAction(aCloseReplay);
addTabMenu(gameMenu);
retranslateUi(); retranslateUi();
setLayout(superMainLayout); setLayout(superMainLayout);
@ -486,16 +487,17 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
phasesMenu->addSeparator(); phasesMenu->addSeparator();
phasesMenu->addAction(aNextPhase); phasesMenu->addAction(aNextPhase);
tabMenu = new QMenu(this); gameMenu = new QMenu(this);
playersSeparator = tabMenu->addSeparator(); playersSeparator = gameMenu->addSeparator();
tabMenu->addMenu(phasesMenu); gameMenu->addMenu(phasesMenu);
tabMenu->addAction(aNextTurn); gameMenu->addAction(aNextTurn);
tabMenu->addSeparator(); gameMenu->addSeparator();
tabMenu->addAction(aRemoveLocalArrows); gameMenu->addAction(aRemoveLocalArrows);
tabMenu->addSeparator(); gameMenu->addSeparator();
tabMenu->addAction(aGameInfo); gameMenu->addAction(aGameInfo);
tabMenu->addAction(aConcede); gameMenu->addAction(aConcede);
tabMenu->addAction(aLeaveGame); gameMenu->addAction(aLeaveGame);
addTabMenu(gameMenu);
retranslateUi(); retranslateUi();
setLayout(mainLayout); setLayout(mainLayout);
@ -528,7 +530,7 @@ void TabGame::retranslateUi()
phasesMenu->setTitle(tr("&Phases")); phasesMenu->setTitle(tr("&Phases"));
} }
tabMenu->setTitle(tr("&Game")); gameMenu->setTitle(tr("&Game"));
if (aNextPhase) { if (aNextPhase) {
aNextPhase->setText(tr("Next &phase")); aNextPhase->setText(tr("Next &phase"));
aNextPhase->setShortcut(tr("Ctrl+Space")); aNextPhase->setShortcut(tr("Ctrl+Space"));
@ -747,7 +749,7 @@ Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info)
deckViewContainerLayout->addWidget(deckView); deckViewContainerLayout->addWidget(deckView);
} }
tabMenu->insertMenu(playersSeparator, newPlayer->getPlayerMenu()); gameMenu->insertMenu(playersSeparator, newPlayer->getPlayerMenu());
players.insert(playerId, newPlayer); players.insert(playerId, newPlayer);
emit playerAdded(newPlayer); emit playerAdded(newPlayer);
@ -905,8 +907,8 @@ void TabGame::closeGame()
gameInfo.set_started(false); gameInfo.set_started(false);
gameClosed = true; gameClosed = true;
tabMenu->clear(); gameMenu->clear();
tabMenu->addAction(aLeaveGame); gameMenu->addAction(aLeaveGame);
} }
void TabGame::eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext & /*context*/) void TabGame::eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext & /*context*/)

View file

@ -138,6 +138,7 @@ private:
QHBoxLayout *mainLayout; QHBoxLayout *mainLayout;
ZoneViewLayout *zoneLayout; ZoneViewLayout *zoneLayout;
QAction *playersSeparator; QAction *playersSeparator;
QMenu *gameMenu;
QMenu *phasesMenu; QMenu *phasesMenu;
QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
QList<QAction *> phaseActions; QList<QAction *> phaseActions;

View file

@ -28,8 +28,9 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, c
aLeave = new QAction(this); aLeave = new QAction(this);
connect(aLeave, SIGNAL(triggered()), this, SLOT(actLeave())); connect(aLeave, SIGNAL(triggered()), this, SLOT(actLeave()));
tabMenu = new QMenu(this); messageMenu = new QMenu(this);
tabMenu->addAction(aLeave); messageMenu->addAction(aLeave);
addTabMenu(messageMenu);
retranslateUi(); retranslateUi();
setLayout(vbox); setLayout(vbox);
@ -44,7 +45,7 @@ TabMessage::~TabMessage()
void TabMessage::retranslateUi() void TabMessage::retranslateUi()
{ {
tabMenu->setTitle(tr("Personal &talk")); messageMenu->setTitle(tr("Personal &talk"));
aLeave->setText(tr("&Leave")); aLeave->setText(tr("&Leave"));
} }

View file

@ -14,6 +14,7 @@ class TabMessage : public Tab {
Q_OBJECT Q_OBJECT
private: private:
AbstractClient *client; AbstractClient *client;
QMenu *messageMenu;
ServerInfo_User *ownUserInfo; ServerInfo_User *ownUserInfo;
ServerInfo_User *otherUserInfo; ServerInfo_User *otherUserInfo;
bool userOnline; bool userOnline;

View file

@ -82,8 +82,9 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
aLeaveRoom = new QAction(this); aLeaveRoom = new QAction(this);
connect(aLeaveRoom, SIGNAL(triggered()), this, SLOT(actLeaveRoom())); connect(aLeaveRoom, SIGNAL(triggered()), this, SLOT(actLeaveRoom()));
tabMenu = new QMenu(this); roomMenu = new QMenu(this);
tabMenu->addAction(aLeaveRoom); roomMenu->addAction(aLeaveRoom);
addTabMenu(roomMenu);
retranslateUi(); retranslateUi();
setLayout(hbox); setLayout(hbox);
@ -109,7 +110,7 @@ void TabRoom::retranslateUi()
chatView->retranslateUi(); chatView->retranslateUi();
sayLabel->setText(tr("&Say:")); sayLabel->setText(tr("&Say:"));
chatGroupBox->setTitle(tr("Chat")); chatGroupBox->setTitle(tr("Chat"));
tabMenu->setTitle(tr("&Room")); roomMenu->setTitle(tr("&Room"));
aLeaveRoom->setText(tr("&Leave room")); aLeaveRoom->setText(tr("&Leave room"));
aIgnoreUnregisteredUsers->setText(tr("&Ignore unregistered users in chat")); aIgnoreUnregisteredUsers->setText(tr("&Ignore unregistered users in chat"));
} }

View file

@ -41,6 +41,7 @@ private:
QLineEdit *sayEdit; QLineEdit *sayEdit;
QGroupBox *chatGroupBox; QGroupBox *chatGroupBox;
QMenu *roomMenu;
QAction *aLeaveRoom; QAction *aLeaveRoom;
QAction *aIgnoreUnregisteredUsers; QAction *aIgnoreUnregisteredUsers;
QString sanitizeHtml(QString dirty) const; QString sanitizeHtml(QString dirty) const;

View file

@ -9,6 +9,7 @@
#include "tab_admin.h" #include "tab_admin.h"
#include "tab_message.h" #include "tab_message.h"
#include "tab_userlists.h" #include "tab_userlists.h"
#include "tab_deck_editor.h"
#include "pixmapgenerator.h" #include "pixmapgenerator.h"
#include "userlist.h" #include "userlist.h"
#include <QDebug> #include <QDebug>
@ -86,6 +87,8 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QWidget *parent)
connect(client, SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this, SLOT(gameJoined(const Event_GameJoined &))); connect(client, SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this, SLOT(gameJoined(const Event_GameJoined &)));
connect(client, SIGNAL(userMessageEventReceived(const Event_UserMessage &)), this, SLOT(processUserMessageEvent(const Event_UserMessage &))); connect(client, SIGNAL(userMessageEventReceived(const Event_UserMessage &)), this, SLOT(processUserMessageEvent(const Event_UserMessage &)));
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int))); connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
retranslateUi();
} }
TabSupervisor::~TabSupervisor() TabSupervisor::~TabSupervisor()
@ -111,6 +114,9 @@ void TabSupervisor::retranslateUi()
QListIterator<TabGame *> replayIterator(replayTabs); QListIterator<TabGame *> replayIterator(replayTabs);
while (replayIterator.hasNext()) while (replayIterator.hasNext())
tabs.append(replayIterator.next()); tabs.append(replayIterator.next());
QListIterator<TabDeckEditor *> deckEditorIterator(deckEditorTabs);
while (deckEditorIterator.hasNext())
tabs.append(deckEditorIterator.next());
for (int i = 0; i < tabs.size(); ++i) for (int i = 0; i < tabs.size(); ++i)
if (tabs[i]) { if (tabs[i]) {
@ -127,6 +133,7 @@ AbstractClient *TabSupervisor::getClient() const
int TabSupervisor::myAddTab(Tab *tab) int TabSupervisor::myAddTab(Tab *tab)
{ {
connect(tab, SIGNAL(userEvent(bool)), this, SLOT(tabUserEvent(bool))); connect(tab, SIGNAL(userEvent(bool)), this, SLOT(tabUserEvent(bool)));
connect(tab, SIGNAL(tabTextChanged(Tab *, QString)), this, SLOT(updateTabText(Tab *, QString)));
return addTab(tab, tab->getTabText()); return addTab(tab, tab->getTabText());
} }
@ -228,6 +235,10 @@ void TabSupervisor::stop()
messageIterator.next().value()->deleteLater(); messageIterator.next().value()->deleteLater();
messageTabs.clear(); messageTabs.clear();
QListIterator<TabDeckEditor *> deckEditorIterator(deckEditorTabs);
while (deckEditorIterator.hasNext())
deckEditorIterator.next()->deleteLater();
delete userInfo; delete userInfo;
userInfo = 0; userInfo = 0;
} }
@ -295,7 +306,7 @@ void TabSupervisor::localGameJoined(const Event_GameJoined &event)
void TabSupervisor::gameLeft(TabGame *tab) void TabSupervisor::gameLeft(TabGame *tab)
{ {
if (tab == currentWidget()) if (tab == currentWidget())
emit setMenu(0); emit setMenu();
gameTabs.remove(tab->getGameId()); gameTabs.remove(tab->getGameId());
removeTab(indexOf(tab)); removeTab(indexOf(tab));
@ -319,7 +330,7 @@ void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent)
void TabSupervisor::roomLeft(TabRoom *tab) void TabSupervisor::roomLeft(TabRoom *tab)
{ {
if (tab == currentWidget()) if (tab == currentWidget())
emit setMenu(0); emit setMenu();
roomTabs.remove(tab->getRoomId()); roomTabs.remove(tab->getRoomId());
removeTab(indexOf(tab)); removeTab(indexOf(tab));
@ -338,7 +349,7 @@ void TabSupervisor::openReplay(GameReplay *replay)
void TabSupervisor::replayLeft(TabGame *tab) void TabSupervisor::replayLeft(TabGame *tab)
{ {
if (tab == currentWidget()) if (tab == currentWidget())
emit setMenu(0); emit setMenu();
replayTabs.removeAt(replayTabs.indexOf(tab)); replayTabs.removeAt(replayTabs.indexOf(tab));
} }
@ -367,12 +378,32 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
void TabSupervisor::talkLeft(TabMessage *tab) void TabSupervisor::talkLeft(TabMessage *tab)
{ {
if (tab == currentWidget()) if (tab == currentWidget())
emit setMenu(0); emit setMenu();
messageTabs.remove(tab->getUserName()); messageTabs.remove(tab->getUserName());
removeTab(indexOf(tab)); removeTab(indexOf(tab));
} }
TabDeckEditor *TabSupervisor::addDeckEditorTab(DeckList *deckToOpen)
{
TabDeckEditor *tab = new TabDeckEditor(this);
connect(tab, SIGNAL(deckEditorClosing(TabDeckEditor *)), this, SLOT(deckEditorClosed(TabDeckEditor *)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
deckEditorTabs.append(tab);
setCurrentWidget(tab);
return tab;
}
void TabSupervisor::deckEditorClosed(TabDeckEditor *tab)
{
if (tab == currentWidget())
emit setMenu();
deckEditorTabs.removeAt(deckEditorTabs.indexOf(tab));
removeTab(indexOf(tab));
}
void TabSupervisor::tabUserEvent(bool globalEvent) void TabSupervisor::tabUserEvent(bool globalEvent)
{ {
Tab *tab = static_cast<Tab *>(sender()); Tab *tab = static_cast<Tab *>(sender());
@ -384,6 +415,11 @@ void TabSupervisor::tabUserEvent(bool globalEvent)
QApplication::alert(this); QApplication::alert(this);
} }
void TabSupervisor::updateTabText(Tab *tab, const QString &newTabText)
{
setTabText(indexOf(tab), newTabText);
}
void TabSupervisor::processRoomEvent(const RoomEvent &event) void TabSupervisor::processRoomEvent(const RoomEvent &event)
{ {
TabRoom *tab = roomTabs.value(event.room_id(), 0); TabRoom *tab = roomTabs.value(event.room_id(), 0);
@ -434,9 +470,9 @@ void TabSupervisor::updateCurrent(int index)
setTabIcon(index, QIcon()); setTabIcon(index, QIcon());
tab->setContentsChanged(false); tab->setContentsChanged(false);
} }
emit setMenu(static_cast<Tab *>(widget(index))->getTabMenu()); emit setMenu(static_cast<Tab *>(widget(index))->getTabMenus());
} else } else
emit setMenu(0); emit setMenu();
} }
bool TabSupervisor::getAdminLocked() const bool TabSupervisor::getAdminLocked() const

View file

@ -16,6 +16,7 @@ class TabReplays;
class TabAdmin; class TabAdmin;
class TabMessage; class TabMessage;
class TabUserLists; class TabUserLists;
class TabDeckEditor;
class RoomEvent; class RoomEvent;
class GameEventContainer; class GameEventContainer;
class Event_GameJoined; class Event_GameJoined;
@ -23,6 +24,7 @@ class Event_UserMessage;
class ServerInfo_Room; class ServerInfo_Room;
class ServerInfo_User; class ServerInfo_User;
class GameReplay; class GameReplay;
class DeckList;
class CloseButton : public QAbstractButton { class CloseButton : public QAbstractButton {
Q_OBJECT Q_OBJECT
@ -52,6 +54,7 @@ private:
QMap<int, TabGame *> gameTabs; QMap<int, TabGame *> gameTabs;
QList<TabGame *> replayTabs; QList<TabGame *> replayTabs;
QMap<QString, TabMessage *> messageTabs; QMap<QString, TabMessage *> messageTabs;
QList<TabDeckEditor *> deckEditorTabs;
int myAddTab(Tab *tab); int myAddTab(Tab *tab);
void addCloseButtonToTab(Tab *tab, int tabIndex); void addCloseButtonToTab(Tab *tab, int tabIndex);
public: public:
@ -68,9 +71,11 @@ public:
const QMap<int, TabRoom *> &getRoomTabs() const { return roomTabs; } const QMap<int, TabRoom *> &getRoomTabs() const { return roomTabs; }
bool getAdminLocked() const; bool getAdminLocked() const;
signals: signals:
void setMenu(QMenu *menu); void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>());
void localGameEnded(); void localGameEnded();
void adminLockChanged(bool lock); void adminLockChanged(bool lock);
public slots:
TabDeckEditor *addDeckEditorTab(DeckList *deckToOpen);
private slots: private slots:
void closeButtonPressed(); void closeButtonPressed();
void updateCurrent(int index); void updateCurrent(int index);
@ -86,7 +91,9 @@ private slots:
void processUserLeft(const QString &userName); void processUserLeft(const QString &userName);
void processUserJoined(const ServerInfo_User &userInfo); void processUserJoined(const ServerInfo_User &userInfo);
void talkLeft(TabMessage *tab); void talkLeft(TabMessage *tab);
void deckEditorClosed(TabDeckEditor *tab);
void tabUserEvent(bool globalEvent); void tabUserEvent(bool globalEvent);
void updateTabText(Tab *tab, const QString &newTabText);
void processRoomEvent(const RoomEvent &event); void processRoomEvent(const RoomEvent &event);
void processGameEventContainer(const GameEventContainer &cont); void processGameEventContainer(const GameEventContainer &cont);
void processUserMessageEvent(const Event_UserMessage &event); void processUserMessageEvent(const Event_UserMessage &event);

View file

@ -33,7 +33,6 @@
#include "window_main.h" #include "window_main.h"
#include "dlg_connect.h" #include "dlg_connect.h"
#include "dlg_settings.h" #include "dlg_settings.h"
#include "window_deckeditor.h"
#include "tab_supervisor.h" #include "tab_supervisor.h"
#include "remoteclient.h" #include "remoteclient.h"
#include "localserver.h" #include "localserver.h"
@ -51,13 +50,13 @@
const QString MainWindow::appName = "Cockatrice"; const QString MainWindow::appName = "Cockatrice";
void MainWindow::updateTabMenu(QMenu *menu) void MainWindow::updateTabMenu(const QList<QMenu *> &newMenuList)
{ {
if (tabMenu) for (int i = 0; i < tabMenus.size(); ++i)
menuBar()->removeAction(tabMenu->menuAction()); menuBar()->removeAction(tabMenus[i]->menuAction());
tabMenu = menu; tabMenus = newMenuList;
if (menu) for (int i = 0; i < tabMenus.size(); ++i)
menuBar()->insertMenu(helpMenu->menuAction(), menu); menuBar()->insertMenu(tabMenus[i]->menuAction(), tabMenus[i]);
} }
void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &event) void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &event)
@ -191,8 +190,7 @@ void MainWindow::localGameEnded()
void MainWindow::actDeckEditor() void MainWindow::actDeckEditor()
{ {
WndDeckEditor *deckEditor = new WndDeckEditor(this); tabSupervisor->addDeckEditorTab(0);
deckEditor->show();
} }
void MainWindow::actFullScreen(bool checked) void MainWindow::actFullScreen(bool checked)
@ -357,7 +355,7 @@ void MainWindow::createMenus()
} }
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), tabMenu(0), localServer(0) : QMainWindow(parent), localServer(0)
{ {
QPixmapCache::setCacheLimit(200000); QPixmapCache::setCacheLimit(200000);
@ -375,15 +373,16 @@ MainWindow::MainWindow(QWidget *parent)
client->moveToThread(clientThread); client->moveToThread(clientThread);
clientThread->start(); clientThread->start();
tabSupervisor = new TabSupervisor(client);
connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *)));
connect(tabSupervisor, SIGNAL(localGameEnded()), this, SLOT(localGameEnded()));
setCentralWidget(tabSupervisor);
createActions(); createActions();
createMenus(); createMenus();
tabSupervisor = new TabSupervisor(client);
connect(tabSupervisor, SIGNAL(setMenu(QList<QMenu *>)), this, SLOT(updateTabMenu(QList<QMenu *>)));
connect(tabSupervisor, SIGNAL(localGameEnded()), this, SLOT(localGameEnded()));
tabSupervisor->addDeckEditorTab(0);
setCentralWidget(tabSupervisor);
retranslateUi(); retranslateUi();
resize(900, 700); resize(900, 700);

View file

@ -34,7 +34,7 @@ class QThread;
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
private slots: private slots:
void updateTabMenu(QMenu *menu); void updateTabMenu(const QList<QMenu *> &newMenuList);
void statusChanged(ClientStatus _status); void statusChanged(ClientStatus _status);
void processConnectionClosedEvent(const Event_ConnectionClosed &event); void processConnectionClosedEvent(const Event_ConnectionClosed &event);
void processServerShutdownEvent(const Event_ServerShutdown &event); void processServerShutdownEvent(const Event_ServerShutdown &event);
@ -61,7 +61,8 @@ private:
void retranslateUi(); void retranslateUi();
void createActions(); void createActions();
void createMenus(); void createMenus();
QMenu *cockatriceMenu, *tabMenu, *helpMenu; QList<QMenu *> tabMenus;
QMenu *cockatriceMenu, *helpMenu;
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit, QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
*aAbout; *aAbout;
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;