crash fix

This commit is contained in:
Max-Wilhelm Bruker 2010-12-01 14:56:50 +01:00
parent 8bd8b6218e
commit 6e567d5b2f
6 changed files with 34 additions and 26 deletions

View file

@ -176,6 +176,8 @@ void AbstractCardItem::setHovered(bool _hovered)
if (isHovered == _hovered) if (isHovered == _hovered)
return; return;
if (_hovered)
processHoverEvent();
isHovered = _hovered; isHovered = _hovered;
setZValue(_hovered ? 2000000004 : realZValue); setZValue(_hovered ? 2000000004 : realZValue);
update(); update();
@ -226,19 +228,6 @@ void AbstractCardItem::processHoverEvent()
emit hovered(this); emit hovered(this);
} }
void AbstractCardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
processHoverEvent();
isHovered = true;
QGraphicsItem::hoverEnterEvent(event);
}
void AbstractCardItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
isHovered = false;
QGraphicsItem::hoverLeaveEvent(event);
}
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if (change == ItemSelectedHasChanged) { if (change == ItemSelectedHasChanged) {

View file

@ -55,8 +55,6 @@ protected:
void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle); void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
}; };

View file

@ -106,19 +106,35 @@ CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsI
CardItem::~CardItem() CardItem::~CardItem()
{ {
if (owner->getCardMenu() == cardMenu) prepareDelete();
owner->setCardMenu(0); deleteDragItem();
}
void CardItem::prepareDelete()
{
if (owner) {
if (owner->getCardMenu() == cardMenu)
owner->setCardMenu(0);
owner = 0;
}
delete cardMenu; delete cardMenu;
cardMenu = 0;
while (!attachedCards.isEmpty()) { while (!attachedCards.isEmpty()) {
attachedCards.first()->setZone(0); // so that it won't try to call reorganizeCards() attachedCards.first()->setZone(0); // so that it won't try to call reorganizeCards()
attachedCards.first()->setAttachedTo(0); attachedCards.first()->setAttachedTo(0);
} }
if (attachedTo) if (attachedTo) {
attachedTo->removeAttachedCard(this); attachedTo->removeAttachedCard(this);
attachedTo = 0;
}
}
deleteDragItem(); void CardItem::deleteLater()
{
prepareDelete();
AbstractCardItem::deleteLater();
} }
void CardItem::retranslateUi() void CardItem::retranslateUi()
@ -236,10 +252,12 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
gridPoint.setX(-1); gridPoint.setX(-1);
attachedTo = _attachedTo; attachedTo = _attachedTo;
if (attachedTo) { if (attachedTo) {
setParentItem(attachedTo->getZone());
attachedTo->addAttachedCard(this); attachedTo->addAttachedCard(this);
if (zone != attachedTo->getZone()) if (zone != attachedTo->getZone())
attachedTo->getZone()->reorganizeCards(); attachedTo->getZone()->reorganizeCards();
} } else
setParentItem(zone);
if (zone) if (zone)
zone->reorganizeCards(); zone->reorganizeCards();

View file

@ -35,6 +35,9 @@ private:
QMenu *cardMenu, *moveMenu; QMenu *cardMenu, *moveMenu;
void playCard(QGraphicsSceneMouseEvent *event); void playCard(QGraphicsSceneMouseEvent *event);
void prepareDelete();
public slots:
void deleteLater();
public: public:
enum { Type = typeCard }; enum { Type = typeCard };
int type() const { return Type; } int type() const { return Type; }

View file

@ -170,8 +170,12 @@ bool GameScene::event(QEvent *event)
CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]); CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
if (!card) if (!card)
continue; continue;
if (card->getZone() != zone) if (card->getAttachedTo()) {
if (card->getAttachedTo()->getZone() != zone)
continue;
} else if (card->getZone() != zone)
continue; continue;
if (card->getRealZValue() > maxZ) { if (card->getRealZValue() > maxZ) {
maxZ = card->getRealZValue(); maxZ = card->getRealZValue();
maxZCard = card; maxZCard = card;

View file

@ -252,7 +252,7 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
Player::~Player() Player::~Player()
{ {
qDebug("Player destructor"); qDebug() << "Player destructor:" << getName();
static_cast<GameScene *>(scene())->removePlayer(this); static_cast<GameScene *>(scene())->removePlayer(this);
@ -889,10 +889,6 @@ void Player::eventAttachCard(Event_AttachCard *event)
CardItem *oldParent = startCard->getAttachedTo(); CardItem *oldParent = startCard->getAttachedTo();
if (targetZone)
startCard->setParentItem(targetZone);
else
startCard->setParentItem(startZone);
startCard->setAttachedTo(targetCard); startCard->setAttachedTo(targetCard);
startZone->reorganizeCards(); startZone->reorganizeCards();