diff --git a/cockatrice/resources/config/qtlogging.ini b/cockatrice/resources/config/qtlogging.ini index ab6fb07bd..b141cbd00 100644 --- a/cockatrice/resources/config/qtlogging.ini +++ b/cockatrice/resources/config/qtlogging.ini @@ -46,6 +46,8 @@ # cockatrice_xml.xml_4_parser = false # card_list = false +# stack_zone = false + flow_layout.debug = false flow_widget.debug = false flow_widget.size.debug = false diff --git a/cockatrice/src/game/zones/stack_zone.cpp b/cockatrice/src/game/zones/stack_zone.cpp index 99e4736f5..189a0a551 100644 --- a/cockatrice/src/game/zones/stack_zone.cpp +++ b/cockatrice/src/game/zones/stack_zone.cpp @@ -28,7 +28,7 @@ void StackZone::addCardImpl(CardItem *card, int x, int /*y*/) { // if x is negative set it to add at end if (x < 0 || x >= cards.size()) { - x = cards.size(); + x = static_cast(cards.size()); } cards.insert(x, card); @@ -44,7 +44,7 @@ void StackZone::addCardImpl(CardItem *card, int x, int /*y*/) QRectF StackZone::boundingRect() const { - return QRectF(0, 0, 100, zoneHeight); + return {0, 0, 100, zoneHeight}; } void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) @@ -60,7 +60,7 @@ void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*opti void StackZone::handleDropEvent(const QList &dragItems, CardZone *startZone, const QPoint &dropPoint) { - if (!startZone) { + if (startZone == nullptr || startZone->getPlayer() == nullptr) { return; } @@ -69,19 +69,31 @@ void StackZone::handleDropEvent(const QList &dragItems, CardZone cmd.set_start_zone(startZone->getName().toStdString()); cmd.set_target_player_id(player->getId()); cmd.set_target_zone(getName().toStdString()); - int index; + + int index = 0; if (cards.isEmpty()) { index = 0; } else { - const int cardCount = cards.size(); + const auto cardCount = static_cast(cards.size()); + const auto &card = cards.at(0); + + if (card == nullptr) { + qCWarning(StackZoneLog) << "Attempted to move card from" << startZone->getName() << ", but was null"; + return; + } + index = qRound(divideCardSpaceInZone(dropPoint.y(), cardCount, boundingRect().height(), - cards.at(0)->boundingRect().height(), true)); + card->boundingRect().height(), true)); } + if (startZone == this) { - if (dragItems.at(0) != nullptr && cards.at(index)->getId() == dragItems.at(0)->getId()) { + const auto &dragItem = dragItems.at(0); + const auto &card = cards.at(index); + if (card != nullptr && dragItem != nullptr && card->getId() == dragItem->getId()) { return; } } + cmd.set_x(index); cmd.set_y(0); @@ -99,7 +111,7 @@ void StackZone::reorganizeCards() if (!cards.isEmpty()) { QSet arrowsToUpdate; - const int cardCount = cards.size(); + const auto cardCount = static_cast(cards.size()); qreal totalWidth = boundingRect().width(); qreal cardWidth = cards.at(0)->boundingRect().width(); qreal xspace = 5; diff --git a/cockatrice/src/game/zones/stack_zone.h b/cockatrice/src/game/zones/stack_zone.h index 38dee0aca..4ef06ea9a 100644 --- a/cockatrice/src/game/zones/stack_zone.h +++ b/cockatrice/src/game/zones/stack_zone.h @@ -3,6 +3,8 @@ #include "select_zone.h" +inline Q_LOGGING_CATEGORY(StackZoneLog, "stack_zone"); + class StackZone : public SelectZone { Q_OBJECT