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

Method relativePosToParentPos

src/backend/worksheet/WorksheetElement.cpp:479–529  ·  view source on GitHub ↗

! * \brief relativePosToParentPos * \param parentRect * \param rect element's rect * \param position contains the alignment of the element to the parent * \return parent position */

Source from the content-addressed store, hash-verified

477 * \return parent position
478 */
479QPointF WorksheetElement::relativePosToParentPos(PositionWrapper position) const {
480 // QDEBUG(Q_FUNC_INFO << ", pos point = " << position.point)
481 // increasing relative pos hor --> right
482 // increasing relative pos vert --> top
483 // increasing parent pos hor --> right
484 // increasing parent pos vert --> bottom
485
486 QRectF parentRect = this->parentRect();
487 QPointF parentPos;
488
489 double percentage = 0.;
490 switch (position.horizontalPosition) {
491 case HorizontalPosition::Left:
492 case HorizontalPosition::Relative:
493 break;
494 case HorizontalPosition::Center:
495 percentage = 0.5;
496 break;
497 case HorizontalPosition::Right:
498 percentage = 1.0;
499 break;
500 }
501
502 // DEBUG("parent x = " << parentRect.x() << ", width = " << parentRect.width() << ", pos x = " << position.point.x())
503 if (position.horizontalPosition == HorizontalPosition::Relative)
504 parentPos.setX(parentRect.x() + parentRect.width() * position.point.x());
505 else
506 parentPos.setX(parentRect.x() + parentRect.width() * percentage + position.point.x());
507
508 switch (position.verticalPosition) {
509 case VerticalPosition::Top:
510 percentage = 0.;
511 break;
512 case VerticalPosition::Center:
513 percentage = 0.5;
514 break;
515 case VerticalPosition::Bottom:
516 percentage = 1.0;
517 break;
518 case VerticalPosition::Relative:
519 break;
520 }
521
522 // DEBUG("parent y = " << parentRect.y() << ", height = " << parentRect.height() << ", pos y = " << position.point.y())
523 if (position.verticalPosition == VerticalPosition::Relative)
524 parentPos.setY(parentRect.y() + parentRect.height() * position.point.y());
525 else
526 parentPos.setY(parentRect.y() + parentRect.height() * percentage - position.point.y());
527
528 return parentPos;
529}
530
531/*!
532 * \brief handleAspectUpdated

Callers 2

updatePositionMethod · 0.80
retransformLineMethod · 0.80

Calls 7

parentRectMethod · 0.95
setXMethod · 0.80
xMethod · 0.80
setYMethod · 0.80
heightMethod · 0.80
widthMethod · 0.45
yMethod · 0.45

Tested by

no test coverage detected