MCPcopy Create free account
hub / github.com/KDE/labplot / align

Method align

src/backend/worksheet/WorksheetElement.cpp:363–395  ·  view source on GitHub ↗

align rect at position pos using horAlign and vertAlign

Source from the content-addressed store, hash-verified

361
362// align rect at position pos using horAlign and vertAlign
363QPointF WorksheetElement::align(QPointF pos, QRectF rect, HorizontalAlignment horAlign, VerticalAlignment vertAlign, bool positive) const {
364 // QDEBUG(Q_FUNC_INFO << ", point " << pos << " to rect " << rect << " with alignment " << horAlign << "/" << vertAlign)
365 // positive is right
366 double xAlign = 0.;
367 switch (horAlign) {
368 case HorizontalAlignment::Left:
369 xAlign = rect.width() / 2.;
370 break;
371 case HorizontalAlignment::Right:
372 xAlign = -rect.width() / 2.;
373 break;
374 case HorizontalAlignment::Center:
375 break;
376 }
377
378 // positive is to top
379 double yAlign = 0.;
380 switch (vertAlign) {
381 case VerticalAlignment::Top:
382 yAlign = rect.height() / 2.;
383 break;
384 case VerticalAlignment::Bottom:
385 yAlign = -rect.height() / 2.;
386 break;
387 case VerticalAlignment::Center:
388 break;
389 }
390
391 if (positive)
392 return {pos.x() + xAlign, pos.y() + yAlign};
393 else
394 return {pos.x() - xAlign, pos.y() - yAlign};
395}
396
397QRectF WorksheetElement::parentRect() const {
398 QRectF rect;

Callers 8

addNewMethod · 0.80
updatePositionMethod · 0.80
keyPressEventMethod · 0.80
mouseReleaseEventMethod · 0.80
itemChangeMethod · 0.80
updatePositionMethod · 0.80
addTextLabelMethod · 0.80
addImageMethod · 0.80

Calls 4

heightMethod · 0.80
xMethod · 0.80
widthMethod · 0.45
yMethod · 0.45

Tested by

no test coverage detected