VPTissue Reference Manual
MyGraphicsView.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "MyGraphicsView.h"
21 
22 #include <QWheelEvent>
23 #include <cmath>
24 
25 namespace SimShell {
26 namespace Gui {
27 
28 using namespace std;
29 
30 MyGraphicsView::MyGraphicsView(std::shared_ptr<QGraphicsScene> s, QWidget* parent)
31  : QGraphicsView(s.get(), parent), m_scene(s)
32 {
33  setInteractive(true); // required for zooming
34 }
35 
37  : QGraphicsView(parent)
38 {
39  setInteractive(true); // required for zooming
40 }
41 
42 void MyGraphicsView::wheelEvent(QWheelEvent* event)
43 {
44  double scaleFactor = pow(2.0, -event->delta() / 240.0);
45  double factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
46  if (factor > 0.07 && factor < 100.0)
47  {
48  scale(scaleFactor, scaleFactor);
49  }
50 }
51 
52 } // end of namespace Gui
53 } // end of namespace SimShell
see the online Qt documentation
STL namespace.
MyGraphicsView(std::shared_ptr< QGraphicsScene > g, QWidget *parent=nullptr)
Interface for MyGraphicsView.
see the online Qt documentation
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32