diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index c998bde7..bc168f63 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -1,5 +1,9 @@ #include -#include +#include +#include +#include +#include +#include #include "carditem.h" #include "carddragitem.h" #include "carddatabase.h" diff --git a/cockatrice/src/cardzone.cpp b/cockatrice/src/cardzone.cpp index f572af1c..4cb2f735 100644 --- a/cockatrice/src/cardzone.cpp +++ b/cockatrice/src/cardzone.cpp @@ -1,4 +1,7 @@ -#include +#include +#include +#include +#include #include "cardzone.h" #include "carditem.h" #include "player.h" @@ -14,7 +17,7 @@ CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _is CardZone::~CardZone() { - qDebug(QString("CardZone destructor: %1").arg(name).toLatin1()); + qDebug() << "CardZone destructor: " << name; delete view; clearContents(); } @@ -34,7 +37,7 @@ void CardZone::clearContents() for (int j = 0; j < attachedCards.size(); ++j) attachedCards[j]->setParentItem(attachedCards[j]->getZone()); - delete cards.at(i); + player->deleteCard(cards.at(i)); } cards.clear(); emit cardCountChanged(); diff --git a/cockatrice/src/counter.cpp b/cockatrice/src/counter.cpp index c3f7a5d8..ee6d060a 100644 --- a/cockatrice/src/counter.cpp +++ b/cockatrice/src/counter.cpp @@ -1,10 +1,13 @@ #include "counter.h" #include "player.h" #include "protocol_items.h" -#include +#include +#include +#include +#include Counter::Counter(Player *_player, int _id, const QString &_name, QColor _color, int _radius, int _value, QGraphicsItem *parent) - : QGraphicsItem(parent), player(_player), id(_id), name(_name), color(_color), radius(_radius), value(_value), aDec(0), aInc(0) + : QGraphicsItem(parent), player(_player), id(_id), name(_name), color(_color), radius(_radius), value(_value), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false) { if (radius > Player::counterAreaWidth / 2) radius = Player::counterAreaWidth / 2; @@ -38,6 +41,14 @@ Counter::~Counter() delete menu; } +void Counter::delCounter() +{ + if (dialogSemaphore) + deleteAfterDialog = true; + else + deleteLater(); +} + void Counter::retranslateUi() { if (menu) { @@ -112,7 +123,13 @@ void Counter::incrementCounter() void Counter::setCounter() { bool ok; + dialogSemaphore = true; int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, 0, 2000000000, 1, &ok); + if (deleteAfterDialog) { + deleteLater(); + return; + } + dialogSemaphore = false; if (ok) player->sendGameCommand(new Command_SetCounter(-1, id, newValue)); } diff --git a/cockatrice/src/counter.h b/cockatrice/src/counter.h index 053e75da..7d7f932b 100644 --- a/cockatrice/src/counter.h +++ b/cockatrice/src/counter.h @@ -19,6 +19,7 @@ private: QAction *aSet, *aDec, *aInc; QMenu *menu; + bool dialogSemaphore, deleteAfterDialog; private slots: void incrementCounter(); void setCounter(); @@ -37,6 +38,7 @@ public: QString getName() const { return name; } int getValue() const { return value; } void setValue(int _value); + void delCounter(); void setShortcutsActive(); void setShortcutsInactive(); diff --git a/cockatrice/src/deckview.cpp b/cockatrice/src/deckview.cpp index 56988e11..16cea1d0 100644 --- a/cockatrice/src/deckview.cpp +++ b/cockatrice/src/deckview.cpp @@ -1,7 +1,9 @@ -#include +#include +#include #include "deckview.h" #include "decklist.h" #include "carddatabase.h" +#include "settingscache.h" #include "main.h" DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag) @@ -117,8 +119,7 @@ void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event) DeckViewCardContainer::DeckViewCardContainer(const QString &_name) : QGraphicsItem(), name(_name), width(0), height(0), maxWidth(0) { - QSettings settings; - QString bgPath = settings.value("zonebg/table").toString(); + QString bgPath = settingsCache->getTableBgPath(); if (!bgPath.isEmpty()) bgPixmap.load(bgPath); diff --git a/cockatrice/src/dlg_connect.cpp b/cockatrice/src/dlg_connect.cpp index 7bb385b5..9815a7ae 100644 --- a/cockatrice/src/dlg_connect.cpp +++ b/cockatrice/src/dlg_connect.cpp @@ -1,4 +1,8 @@ -#include +#include +#include +#include +#include +#include #include "dlg_connect.h" DlgConnect::DlgConnect(QWidget *parent) diff --git a/cockatrice/src/dlg_create_token.cpp b/cockatrice/src/dlg_create_token.cpp index e21c17bb..2d3ea9df 100644 --- a/cockatrice/src/dlg_create_token.cpp +++ b/cockatrice/src/dlg_create_token.cpp @@ -1,4 +1,11 @@ -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "dlg_create_token.h" DlgCreateToken::DlgCreateToken(QWidget *parent) diff --git a/cockatrice/src/dlg_creategame.cpp b/cockatrice/src/dlg_creategame.cpp index c613c273..5cf957b6 100644 --- a/cockatrice/src/dlg_creategame.cpp +++ b/cockatrice/src/dlg_creategame.cpp @@ -1,4 +1,13 @@ -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "dlg_creategame.h" #include "protocol_items.h" diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index a55cd592..24f8ca0e 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -1,5 +1,21 @@ -#include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "carddatabase.h" #include "dlg_settings.h" #include "main.h" diff --git a/cockatrice/src/pilezone.cpp b/cockatrice/src/pilezone.cpp index dc11b238..3ba9e682 100644 --- a/cockatrice/src/pilezone.cpp +++ b/cockatrice/src/pilezone.cpp @@ -1,4 +1,6 @@ -#include +#include +#include +#include #include "pilezone.h" #include "player.h" #include "carddragitem.h" @@ -20,7 +22,6 @@ QRectF PileZone::boundingRect() const void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - qDebug("PileZone::paint"); if (!cards.isEmpty()) { painter->save(); cards.at(0)->paint(painter, option, widget); @@ -51,7 +52,6 @@ void PileZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/* void PileZone::reorganizeCards() { - qDebug(QString("PileZone: reorganize, x=%1, y=%2, w=%3, h=%4").arg(boundingRect().x()).arg(boundingRect().y()).arg(boundingRect().width()).arg(boundingRect().height()).toLatin1()); update(); } diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 54780803..2c1c6b0f 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -21,7 +21,7 @@ #include Player::Player(const QString &_name, int _id, bool _local, TabGame *_parent) - : QObject(_parent), defaultNumberTopCards(3), lastTokenDestroy(true), name(_name), id(_id), active(false), local(_local), mirrored(false) + : QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), name(_name), id(_id), active(false), local(_local), mirrored(false), dialogSemaphore(false) { setCacheMode(DeviceCoordinateCache); @@ -332,6 +332,8 @@ void Player::retranslateUi() void Player::setShortcutsActive() { + shortcutsActive = true; + aViewLibrary->setShortcut(tr("F3")); aViewTopCards->setShortcut(tr("Ctrl+W")); aViewGraveyard->setShortcut(tr("F4")); @@ -351,6 +353,8 @@ void Player::setShortcutsActive() void Player::setShortcutsInactive() { + shortcutsActive = false; + aViewLibrary->setShortcut(QKeySequence()); aViewTopCards->setShortcut(QKeySequence()); aViewGraveyard->setShortcut(QKeySequence()); @@ -880,6 +884,14 @@ void Player::addCard(CardItem *c) emit newCardAdded(c); } +void Player::deleteCard(CardItem *c) +{ + if (dialogSemaphore) + cardsToDelete.append(c); + else + delete c; +} + void Player::addZone(CardZone *z) { zones.insert(z->getName(), z); @@ -896,6 +908,8 @@ Counter *Player::addCounter(int counterId, const QString &name, QColor color, in counters.insert(counterId, c); if (countersMenu) countersMenu->addMenu(c->getMenu()); + if (shortcutsActive) + c->setShortcutsActive(); rearrangeCounters(); return c; } @@ -906,7 +920,7 @@ void Player::delCounter(int counterId) if (!c) return; counters.remove(counterId); - delete c; + c->delCounter(); rearrangeCounters(); } @@ -914,7 +928,7 @@ void Player::clearCounters() { QMapIterator counterIterator(counters); while (counterIterator.hasNext()) - delete counterIterator.next().value(); + counterIterator.next().value()->delCounter(); counters.clear(); } @@ -1016,6 +1030,18 @@ void Player::sendCommandContainer(CommandContainer *cont) static_cast(parent())->sendCommandContainer(cont, id); } +bool Player::clearCardsToDelete() +{ + if (cardsToDelete.isEmpty()) + return false; + + for (int i = 0; i < cardsToDelete.size(); ++i) + cardsToDelete[i]->deleteLater(); + cardsToDelete.clear(); + + return true; +} + void Player::cardMenuAction() { QAction *a = static_cast(sender()); @@ -1073,13 +1099,17 @@ void Player::actSetPT() oldPT = card->getPT(); } bool ok; + dialogSemaphore = true; QString pt = QInputDialog::getText(0, tr("Set power/toughness"), tr("Please enter the new PT:"), QLineEdit::Normal, oldPT, &ok); + dialogSemaphore = false; + if (clearCardsToDelete()) + return; if (!ok) return; - i.toFront(); - while (i.hasNext()) { - CardItem *card = static_cast(i.next()); + QListIterator j(scene()->selectedItems()); + while (j.hasNext()) { + CardItem *card = static_cast(j.next()); sendGameCommand(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "pt", pt)); } } @@ -1095,7 +1125,11 @@ void Player::actSetAnnotation() } bool ok; + dialogSemaphore = true; QString annotation = QInputDialog::getText(0, tr("Set annotation"), tr("Please enter the new annotation:"), QLineEdit::Normal, oldAnnotation, &ok); + dialogSemaphore = false; + if (clearCardsToDelete()) + return; if (!ok) return; @@ -1147,7 +1181,11 @@ void Player::actCardCounterTrigger() } case 11: { bool ok; + dialogSemaphore = true; int number = QInputDialog::getInteger(0, tr("Set counters"), tr("Number:"), 0, 0, MAX_COUNTERS_ON_CARD, 1, &ok); + dialogSemaphore = false; + if (clearCardsToDelete()) + return; if (!ok) return; diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index b8505183..124aa1bf 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -106,6 +106,7 @@ private: *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken, *aCardMenu; + bool shortcutsActive; int defaultNumberTopCards; QString lastTokenName, lastTokenColor, lastTokenPT, lastTokenAnnotation; bool lastTokenDestroy; @@ -115,6 +116,10 @@ private: bool local; bool mirrored; + bool dialogSemaphore; + bool clearCardsToDelete(); + QList cardsToDelete; + QMap zones; TableZone *table; HandZone *hand; @@ -157,6 +162,7 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void addCard(CardItem *c); + void deleteCard(CardItem *c); void addZone(CardZone *z); Counter *addCounter(ServerInfo_Counter *counter); diff --git a/cockatrice/src/tab_chatchannel.cpp b/cockatrice/src/tab_chatchannel.cpp index b17e25cc..fd3b036d 100644 --- a/cockatrice/src/tab_chatchannel.cpp +++ b/cockatrice/src/tab_chatchannel.cpp @@ -1,4 +1,10 @@ -#include +#include +#include +#include +#include +#include +#include +#include #include "tab_chatchannel.h" #include "abstractclient.h" #include "protocol_items.h" diff --git a/cockatrice/src/tab_deck_storage.cpp b/cockatrice/src/tab_deck_storage.cpp index 08741459..6792f152 100644 --- a/cockatrice/src/tab_deck_storage.cpp +++ b/cockatrice/src/tab_deck_storage.cpp @@ -1,17 +1,27 @@ -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "tab_deck_storage.h" #include "remotedecklist_treewidget.h" #include "abstractclient.h" #include "decklist.h" #include "protocol_items.h" #include "window_deckeditor.h" +#include "settingscache.h" TabDeckStorage::TabDeckStorage(AbstractClient *_client) : Tab(), client(_client) { localDirModel = new QFileSystemModel(this); - QSettings settings; - localDirModel->setRootPath(settings.value("paths/decks").toString()); + localDirModel->setRootPath(settingsCache->getDeckPath()); sortFilter = new QSortFilterProxyModel(this); sortFilter->setSourceModel(localDirModel); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 9bbc50fa..d1a978eb 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -1,4 +1,9 @@ -#include +#include +#include +#include +#include +#include +#include #include "tab_game.h" #include "cardinfowidget.h" #include "playerlistwidget.h" @@ -18,6 +23,7 @@ #include "carditem.h" #include "arrowitem.h" #include "main.h" +#include "settingscache.h" ReadyStartButton::ReadyStartButton(QWidget *parent) : QPushButton(parent), readyStart(false) @@ -88,8 +94,7 @@ void DeckViewContainer::setButtonsVisible(bool _visible) void DeckViewContainer::loadLocalDeck() { QFileDialog dialog(this, tr("Load deck")); - QSettings settings; - dialog.setDirectory(settings.value("paths/decks").toString()); + dialog.setDirectory(settingsCache->getDeckPath()); dialog.setNameFilters(DeckList::fileNameFilters); if (!dialog.exec()) return; diff --git a/cockatrice/src/tab_server.cpp b/cockatrice/src/tab_server.cpp index 1a93dbb0..78f2050b 100644 --- a/cockatrice/src/tab_server.cpp +++ b/cockatrice/src/tab_server.cpp @@ -1,4 +1,14 @@ -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "tab_server.h" #include "gamesmodel.h" #include "dlg_creategame.h" diff --git a/cockatrice/src/tablezone.cpp b/cockatrice/src/tablezone.cpp index 2819aab6..6060386b 100644 --- a/cockatrice/src/tablezone.cpp +++ b/cockatrice/src/tablezone.cpp @@ -1,4 +1,7 @@ -#include +#include +#include +#include +#include #include "tablezone.h" #include "player.h" #include "protocol_items.h" diff --git a/cockatrice/src/window_deckeditor.cpp b/cockatrice/src/window_deckeditor.cpp index c2f2a228..ab7c6848 100644 --- a/cockatrice/src/window_deckeditor.cpp +++ b/cockatrice/src/window_deckeditor.cpp @@ -1,4 +1,21 @@ -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "window_deckeditor.h" #include "window_sets.h" #include "carddatabase.h" @@ -9,6 +26,7 @@ #include "dlg_cardsearch.h" #include "dlg_load_deck_from_clipboard.h" #include "main.h" +#include "settingscache.h" void SearchLineEdit::keyPressEvent(QKeyEvent *event) { @@ -270,8 +288,7 @@ void WndDeckEditor::actLoadDeck() return; QFileDialog dialog(this, tr("Load deck")); - QSettings settings; - dialog.setDirectory(settings.value("paths/decks").toString()); + dialog.setDirectory(settingsCache->getDeckPath()); dialog.setNameFilters(DeckList::fileNameFilters); if (!dialog.exec()) return; @@ -299,8 +316,7 @@ bool WndDeckEditor::actSaveDeck() bool WndDeckEditor::actSaveDeckAs() { QFileDialog dialog(this, tr("Save deck")); - QSettings settings; - dialog.setDirectory(settings.value("paths/decks").toString()); + dialog.setDirectory(settingsCache->getDeckPath()); dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setConfirmOverwrite(true); dialog.setDefaultSuffix("cod"); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index c815c791..94f2bdbc 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -17,7 +17,13 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include +#include +#include +#include +#include +#include +#include +#include #include "window_main.h" #include "dlg_connect.h" diff --git a/cockatrice/src/window_sets.cpp b/cockatrice/src/window_sets.cpp index 45ddcb29..dd6bcd8a 100644 --- a/cockatrice/src/window_sets.cpp +++ b/cockatrice/src/window_sets.cpp @@ -1,7 +1,8 @@ #include "window_sets.h" #include "setsmodel.h" #include "main.h" -#include +#include +#include WndSets::WndSets(QWidget *parent) : QMainWindow(parent) diff --git a/cockatrice/src/zoneviewwidget.cpp b/cockatrice/src/zoneviewwidget.cpp index 759af2e7..39ace6a3 100644 --- a/cockatrice/src/zoneviewwidget.cpp +++ b/cockatrice/src/zoneviewwidget.cpp @@ -1,4 +1,6 @@ -#include +#include +#include +#include #include "zoneviewwidget.h" #include "carditem.h" #include "zoneviewzone.h" diff --git a/cockatrice/src/zoneviewzone.cpp b/cockatrice/src/zoneviewzone.cpp index c2153cfa..5f34bd41 100644 --- a/cockatrice/src/zoneviewzone.cpp +++ b/cockatrice/src/zoneviewzone.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include "zoneviewzone.h" #include "player.h" #include "protocol_items.h"