align rect at position pos using horAlign and vertAlign
| 361 | |
| 362 | // align rect at position pos using horAlign and vertAlign |
| 363 | QPointF 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 | |
| 397 | QRectF WorksheetElement::parentRect() const { |
| 398 | QRectF rect; |
no test coverage detected