Exemple #1
0
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (!startItem)
        return;

    QPointF endPos = event->scenePos();

    QList<QGraphicsItem *> colliding = scene()->items(endPos);
    ArrowTarget *cursorItem = 0;
    qreal cursorItemZ = -1;
    for (int i = colliding.size() - 1; i >= 0; i--)
        if (qgraphicsitem_cast<CardItem *>(colliding.at(i)))
            if (colliding.at(i)->zValue() > cursorItemZ) {
                cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
                cursorItemZ = cursorItem->zValue();
            }

            if ((cursorItem != targetItem) && targetItem)
                targetItem->setBeingPointedAt(false);
            if (!cursorItem) {
                fullColor = false;
                targetItem = 0;
                updatePath(endPos);
            } else {
                fullColor = true;
                if (cursorItem != startItem)
                    cursorItem->setBeingPointedAt(true);
                targetItem = cursorItem;
                updatePath();
            }
            update();
}
Exemple #2
0
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    // This ensures that if a mouse move event happens after a call to delArrow(),
    // the event will be discarded as it would create some stray pointers.
    if (!startItem)
        return;

    QPointF endPos = event->scenePos();

    QList<QGraphicsItem *> colliding = scene()->items(endPos);
    ArrowTarget *cursorItem = 0;
    qreal cursorItemZ = -1;
    for (int i = colliding.size() - 1; i >= 0; i--) {
        if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i))) {
            if (colliding.at(i)->zValue() > cursorItemZ) {
                cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
                cursorItemZ = cursorItem->zValue();
            }
        }
    }

    if ((cursorItem != targetItem) && targetItem) {
        targetItem->setBeingPointedAt(false);
        targetItem->removeArrowTo(this);
    }
    if (!cursorItem) {
        fullColor = false;
        targetItem = 0;
        updatePath(endPos);
    } else {
        if (cursorItem != targetItem) {
            fullColor = true;
            if (cursorItem != startItem) {
                cursorItem->setBeingPointedAt(true);
                cursorItem->addArrowTo(this);
            }
            targetItem = cursorItem;
        }
        updatePath();
    }
    update();

    for (int i = 0; i < childArrows.size(); ++i) {
        childArrows[i]->mouseMoveEvent(event);
    }
}