crash fix

This commit is contained in:
Max-Wilhelm Bruker 2009-09-28 11:06:15 +02:00
parent 50ae90c148
commit 4186d73c88
2 changed files with 35 additions and 26 deletions

View file

@ -9,24 +9,27 @@ Counter::Counter(Player *_player, int _id, const QString &_name, QColor _color,
if (radius > Player::counterAreaWidth / 2) if (radius > Player::counterAreaWidth / 2)
radius = Player::counterAreaWidth / 2; radius = Player::counterAreaWidth / 2;
menu = new QMenu(name); if (player->getLocal()) {
aSet = new QAction(this); menu = new QMenu(name);
connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter())); aSet = new QAction(this);
menu->addAction(aSet); connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
menu->addSeparator(); menu->addAction(aSet);
for (int i = -10; i <= 10; ++i) menu->addSeparator();
if (i == 0) for (int i = -10; i <= 10; ++i)
menu->addSeparator(); if (i == 0)
else { menu->addSeparator();
QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this); else {
if (i == -1) QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
aDec = aIncrement; if (i == -1)
else if (i == 1) aDec = aIncrement;
aInc = aIncrement; else if (i == 1)
aIncrement->setData(i); aInc = aIncrement;
connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter())); aIncrement->setData(i);
menu->addAction(aIncrement); connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter()));
} menu->addAction(aIncrement);
}
} else
menu = 0;
retranslateUi(); retranslateUi();
} }
@ -38,11 +41,13 @@ Counter::~Counter()
void Counter::retranslateUi() void Counter::retranslateUi()
{ {
aSet->setText(tr("&Set counter...")); if (menu) {
if (name == "life") { aSet->setText(tr("&Set counter..."));
aSet->setShortcut(tr("Ctrl+L")); if (name == "life") {
aDec->setShortcut(tr("F11")); aSet->setShortcut(tr("Ctrl+L"));
aInc->setShortcut(tr("F12")); aDec->setShortcut(tr("F11"));
aInc->setShortcut(tr("F12"));
}
} }
} }
@ -76,7 +81,8 @@ void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)
player->client->incCounter(id, 1); player->client->incCounter(id, 1);
event->accept(); event->accept();
} else if (event->button() == Qt::RightButton) { } else if (event->button() == Qt::RightButton) {
menu->exec(event->screenPos()); if (menu)
menu->exec(event->screenPos());
event->accept(); event->accept();
} else } else
event->ignore(); event->ignore();

View file

@ -168,8 +168,10 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
playerMenu->addSeparator(); playerMenu->addSeparator();
sayMenu = playerMenu->addMenu(QString()); sayMenu = playerMenu->addMenu(QString());
initSayMenu(); initSayMenu();
} else } else {
countersMenu = 0;
sbMenu = 0; sbMenu = 0;
}
retranslateUi(); 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); Counter *c = new Counter(this, counterId, name, color, radius, value, this);
counters.insert(counterId, c); counters.insert(counterId, c);
countersMenu->addMenu(c->getMenu()); if (countersMenu)
countersMenu->addMenu(c->getMenu());
rearrangeCounters(); rearrangeCounters();
} }