From 4186d73c88069b68e77fc4860d5a00c883177360 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 28 Sep 2009 11:06:15 +0200 Subject: [PATCH] crash fix --- cockatrice/src/counter.cpp | 54 +++++++++++++++++++++----------------- cockatrice/src/player.cpp | 7 +++-- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/cockatrice/src/counter.cpp b/cockatrice/src/counter.cpp index 16c965c2..d976ad7f 100644 --- a/cockatrice/src/counter.cpp +++ b/cockatrice/src/counter.cpp @@ -9,24 +9,27 @@ Counter::Counter(Player *_player, int _id, const QString &_name, QColor _color, if (radius > Player::counterAreaWidth / 2) radius = Player::counterAreaWidth / 2; - menu = new QMenu(name); - aSet = new QAction(this); - connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter())); - menu->addAction(aSet); - menu->addSeparator(); - for (int i = -10; i <= 10; ++i) - if (i == 0) - menu->addSeparator(); - else { - QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this); - if (i == -1) - aDec = aIncrement; - else if (i == 1) - aInc = aIncrement; - aIncrement->setData(i); - connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter())); - menu->addAction(aIncrement); - } + if (player->getLocal()) { + menu = new QMenu(name); + aSet = new QAction(this); + connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter())); + menu->addAction(aSet); + menu->addSeparator(); + for (int i = -10; i <= 10; ++i) + if (i == 0) + menu->addSeparator(); + else { + QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this); + if (i == -1) + aDec = aIncrement; + else if (i == 1) + aInc = aIncrement; + aIncrement->setData(i); + connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter())); + menu->addAction(aIncrement); + } + } else + menu = 0; retranslateUi(); } @@ -38,11 +41,13 @@ Counter::~Counter() void Counter::retranslateUi() { - aSet->setText(tr("&Set counter...")); - if (name == "life") { - aSet->setShortcut(tr("Ctrl+L")); - aDec->setShortcut(tr("F11")); - aInc->setShortcut(tr("F12")); + if (menu) { + aSet->setText(tr("&Set counter...")); + if (name == "life") { + aSet->setShortcut(tr("Ctrl+L")); + aDec->setShortcut(tr("F11")); + aInc->setShortcut(tr("F12")); + } } } @@ -76,7 +81,8 @@ void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event) player->client->incCounter(id, 1); event->accept(); } else if (event->button() == Qt::RightButton) { - menu->exec(event->screenPos()); + if (menu) + menu->exec(event->screenPos()); event->accept(); } else event->ignore(); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index d87340ef..781889c6 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -168,8 +168,10 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl playerMenu->addSeparator(); sayMenu = playerMenu->addMenu(QString()); initSayMenu(); - } else + } else { + countersMenu = 0; sbMenu = 0; + } retranslateUi(); } @@ -602,7 +604,8 @@ void Player::addCounter(int counterId, const QString &name, QColor color, int ra { Counter *c = new Counter(this, counterId, name, color, radius, value, this); counters.insert(counterId, c); - countersMenu->addMenu(c->getMenu()); + if (countersMenu) + countersMenu->addMenu(c->getMenu()); rearrangeCounters(); }