| 493 | } |
| 494 | |
| 495 | void GraphicsWave::zoom(QPoint point) |
| 496 | { |
| 497 | // Shift |
| 498 | double decX = static_cast<double>(point.x()) / this->width() - _xInit; |
| 499 | double decY = _yInit - static_cast<double>(point.y()) / this->height(); |
| 500 | |
| 501 | // Update zoom & drag |
| 502 | double newZoomX = _zoomXinit * pow(2, 25.0 * decX); |
| 503 | double newZoomY = _zoomYinit * pow(2, 5.0 * decY); |
| 504 | |
| 505 | if (newZoomX > 20 * _sizeX / this->width()) |
| 506 | newZoomX = 20 * _sizeX / this->width(); |
| 507 | if (newZoomX < 1) |
| 508 | newZoomX = 1; |
| 509 | if (newZoomY < 1) |
| 510 | newZoomY = 1; |
| 511 | else if (newZoomY > 50) |
| 512 | newZoomY = 50; |
| 513 | |
| 514 | if (newZoomX != _zoomX || newZoomY != _zoomY) |
| 515 | { |
| 516 | _zoomX = newZoomX; |
| 517 | _zoomY = newZoomY; |
| 518 | |
| 519 | // Update posX |
| 520 | if (_zoomX > 1) |
| 521 | { |
| 522 | _posX = (_zoomX * _posXinit * (_zoomXinit - 1) + _xInit * (_zoomX - _zoomXinit)) / (_zoomXinit * (_zoomX - 1)); |
| 523 | if (_posX < 0) |
| 524 | _posX = 0; |
| 525 | else if (_posX > 1) |
| 526 | _posX = 1; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | this->update(); |
| 531 | } |
| 532 | |
| 533 | void GraphicsWave::drag(QPoint point) |
| 534 | { |