! * \brief parentPosToRelativePos * Converts the absolute position of the element in parent coordinates into the distance between the * alignment point of the parent and the element * \param parentPos Element position in parent coordinates * \param parentRect Parent data rect * \param rect element's rect * \param position contains the alignement of the element to the parent * \return dista
| 426 | * \return distance between the parent position to the element |
| 427 | */ |
| 428 | QPointF WorksheetElement::parentPosToRelativePos(QPointF parentPos, PositionWrapper position) const { |
| 429 | // increasing relative pos hor --> right |
| 430 | // increasing relative pos vert --> top |
| 431 | // increasing parent pos hor --> right |
| 432 | // increasing parent pos vert --> bottom |
| 433 | |
| 434 | QRectF parentRect = this->parentRect(); |
| 435 | QPointF relPos; |
| 436 | |
| 437 | double percentage = 0.; |
| 438 | switch (position.horizontalPosition) { |
| 439 | case HorizontalPosition::Left: |
| 440 | break; |
| 441 | case HorizontalPosition::Center: |
| 442 | percentage = 0.5; |
| 443 | break; |
| 444 | case HorizontalPosition::Right: |
| 445 | percentage = 1.0; |
| 446 | break; |
| 447 | case HorizontalPosition::Relative: |
| 448 | percentage = position.point.x(); |
| 449 | } |
| 450 | |
| 451 | relPos.setX(parentPos.x() - (parentRect.x() + parentRect.width() * percentage)); |
| 452 | |
| 453 | switch (position.verticalPosition) { |
| 454 | case VerticalPosition::Top: |
| 455 | percentage = 0.; |
| 456 | break; |
| 457 | case VerticalPosition::Center: |
| 458 | percentage = 0.5; |
| 459 | break; |
| 460 | case VerticalPosition::Bottom: |
| 461 | percentage = 1.0; |
| 462 | break; |
| 463 | case VerticalPosition::Relative: |
| 464 | percentage = position.point.y(); |
| 465 | } |
| 466 | |
| 467 | relPos.setY(parentRect.y() + parentRect.height() * percentage - parentPos.y()); |
| 468 | |
| 469 | return relPos; |
| 470 | } |
| 471 | |
| 472 | /*! |
| 473 | * \brief relativePosToParentPos |
no test coverage detected