void MapView::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { MapItem *item = dynamic_cast<MapItem *>(itemAt(event->pos())); if (item) { if (qApp->keyboardModifiers() & (Qt::ControlModifier | Qt::ShiftModifier)) { item->setSelected(!item->selected()); mapScene()->setSelectedLevelObject(nullptr); } else { if (!item->selected()) mapScene()->selectSingleItem(item); } startPos_ = event->pos(); prevPos_ = event->pos(); draggedItems_ = mapScene()->selectedItems(); dragInitialBounds_ = mapScene()->itemsBoundingRect(draggedItems_); dragPrevBounds_ = dragInitialBounds_; dragState_ = AboutToDrag; if (macroStarted_) { qerr << "Unterminated macro" << endl; mapScene()->undoStack()->endMacro(); } } else { if (!(qApp->keyboardModifiers() & Qt::ShiftModifier)) mapScene()->selectSingleItem(nullptr); startPos_ = event->pos(); selecting_ = true; } } else if (event->button() == Qt::RightButton) { prevPos_ = event->pos(); scrolling_ = true; } }
QJsonArray MapScene::toJsonArray(bool selectedOnly) const { QJsonArray objects; foreach (QGraphicsItem *item, items()) { MapItem *mapItem = dynamic_cast<MapItem *>(item); if (!mapItem) continue; if (selectedOnly &&!mapItem->selected()) continue; LevelObject *obj = mapItem->levelObject(); if (!obj) continue; QJsonObject json = obj->toJsonObject(); objects.append(json); }