In order for the elements on the flag to be rotated with the map (let's call them fixed) or to be placed on it, taking into account the location on the new upper corner of the map, it was necessary to do:
- All items are located on the stage.
- Place all items manually.
- For fixed elements, rotation is performed manually
The map turned like this:
// Поворот всей карты QPointF center = card->boundingRect().center(); QTransform transform; if (checked) { transform.translate(center.x(), center.y()) .rotate(-90) .translate(-center.x(), -center.y()); } else { transform.translate(center.x(), center.y()) .rotate(90) .translate(-center.x(), -center.y()); } card->setTransform(transform, true); card->isLandscape = !checked; needRotate = true; on_actionFill_triggered();
The placement of elements on the map is done manually, taking into account which side of the map the element is on and whether it is fixed:
for (TextElement* item: items) { QPointF pos(item->_x, item->_y); CardSide* side = item->isFrontSide ? card->frontSide : card->backSide; if (!item->isFixedPos) { // Альбомная ориентация if (card->isLandscape) { pos = side->pos() + pos; // Портретная ориентация } else { QPointF posSide = card->mapToScene(side->pos() + side->boundingRect().topRight()); pos = posSide + pos; } } else { // Поворот зафиксированного элемента QTransform transform; // временный костыль if (needRotate) if (!card->isLandscape) { transform.rotate(-90); } else { transform.rotate(90); } item->setTransform(transform, true); if (card->isLandscape) { pos = side->pos() + pos; } else { QPointF posSide = card->mapToScene(side->pos()); pos = QPointF(posSide.x() + pos.y(), posSide.y() - pos.x()); } } item->setPos(pos); }
Test project .
Screenshot:
