YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
QGraphicsViewEc.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: GPL-3.0-or-later
4 */
5
6#include "QGraphicsViewEc.h"
7#include "moc_QGraphicsViewEc.cpp"
8#include <QWheelEvent>
9#include <qmath.h>
10
11QGraphicsViewEc::QGraphicsViewEc(QWidget* parent) : QGraphicsView(parent)
12{
13 setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
14}
15
16
17void QGraphicsViewEc::wheelEvent(QWheelEvent* event)
18{
19 qreal scaleFactor = qPow(2.0, event->angleDelta().y() / 240.0); //How fast we zoom
20 qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
21 if (0.05 < factor && factor < 10) { //Zoom factor limitation
22 scale(scaleFactor, scaleFactor);
23 }
24}
void wheelEvent(QWheelEvent *event) override
QGraphicsViewEc(QWidget *parent=0)