MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / initializeTransform

Method initializeTransform

src/domain/UBGraphicsDelegateFrame.cpp:225–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223
224
225void UBGraphicsDelegateFrame::initializeTransform()
226{
227 QTransform itemTransform = delegated()->sceneTransform();
228 QRectF itemRect = delegated()->boundingRect();
229 QPointF topLeft = itemTransform.map(itemRect.topLeft());
230 QPointF topRight = itemTransform.map(itemRect.topRight());
231 QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft());
232
233 qreal horizontalFlip = (topLeft.x() > topRight.x()) ? -1 : 1;
234 mMirrorX = horizontalFlip < 0 ;
235 if(horizontalFlip < 0){
236 // why this is because of the way of calculating the translations that checks which side is the most is the
237 // nearest instead of checking which one is the left side.
238 QPointF tmp = topLeft;
239 topLeft = topRight;
240 topRight = tmp;
241
242 // because of the calculation of the height is done by lenght and not deltaY
243 bottomLeft = itemTransform.map(itemRect.bottomRight());
244 }
245
246 qreal verticalFlip = (bottomLeft.y() < topLeft.y()) ? -1 : 1;
247 // not sure that is usefull
248 mMirrorY = verticalFlip < 0;
249 if(verticalFlip < 0 && !mMirrorX){
250 topLeft = itemTransform.map(itemRect.bottomLeft());
251 topRight = itemTransform.map(itemRect.bottomRight());
252 bottomLeft = itemTransform.map(itemRect.topLeft());
253 }
254
255 QLineF topLine(topLeft, topRight);
256 QLineF leftLine(topLeft, bottomLeft);
257 qreal width = topLine.length();
258 qreal height = leftLine.length();
259
260 mAngle = topLine.angle();
261
262 // the fact the the length is used we loose the horizontalFlip information
263 // a better way to do this is using DeltaX that preserve the direction information.
264 mTotalScaleX = (width / itemRect.width()) * horizontalFlip;
265 mTotalScaleY = height / itemRect.height() * verticalFlip;
266
267 QTransform tr;
268 QPointF center = delegated()->boundingRect().center();
269 tr.translate(center.x() * mTotalScaleX, center.y() * mTotalScaleY);
270 tr.rotate(-mAngle);
271 tr.translate(-center.x() * mTotalScaleX, -center.y() * mTotalScaleY);
272 tr.scale(mTotalScaleX, mTotalScaleY);
273
274 mTotalTranslateX = delegated()->transform().dx() - tr.dx();
275 mTotalTranslateY = delegated()->transform().dy() - tr.dy();
276}
277
278
279void UBGraphicsDelegateFrame::mousePressEvent(QGraphicsSceneMouseEvent *event)

Callers

nothing calls this directly

Calls 5

boundingRectMethod · 0.45
lengthMethod · 0.45
angleMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected