| 147 | } |
| 148 | |
| 149 | void MyGraphicsView::wheelEvent(QWheelEvent *event){ |
| 150 | QPointF cursorPoint = event->position(); |
| 151 | QPointF scenePos = this->mapToScene(QPoint(cursorPoint.x(), cursorPoint.y())); |
| 152 | |
| 153 | qreal viewWidth = this->viewport()->width(); |
| 154 | qreal viewHeight = this->viewport()->height(); |
| 155 | |
| 156 | qreal hScale = cursorPoint.x() / viewWidth; |
| 157 | qreal vScale = cursorPoint.y() / viewHeight; |
| 158 | |
| 159 | qreal scaleFactor = this->transform().m11(); |
| 160 | int wheelDeltaValue = event->angleDelta().y(); |
| 161 | if (wheelDeltaValue > 0) |
| 162 | { |
| 163 | if(scaleFactor > 2) return; |
| 164 | this->scale(1.1, 1.1); |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | if(scaleFactor < 0.5) return; |
| 169 | this->scale(1.0 / 1.1, 1.0 / 1.1); |
| 170 | } |
| 171 | QPointF viewPoint = this->transform().map(scenePos); |
| 172 | horizontalScrollBar()->setValue(int(viewPoint.x() - viewWidth * hScale)); |
| 173 | verticalScrollBar()->setValue(int(viewPoint.y() - viewHeight * vScale)); |
| 174 | } |
| 175 | |
| 176 | void MyGraphicsView::changeCursor(){ |
| 177 | |