EnhancedGraphicsView.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ArmarXGui::EnhancedGraphicsView
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <QGraphicsView>
26 #include <QPointF>
27 #include <QMouseEvent>
28 #include <QWheelEvent>
29 #include <cmath>
30 namespace armarx
31 {
32  /**
33  * @brief The EnhancedGraphicsView is a QGraphicsView with some additional
34  * functions.
35  *
36  * Additional functions are:
37  * - Zooming (default ctrl+scroll)
38  * - Roatating (default shift+scroll)
39  * - Dragging the scene (default ctrl+left click+dragging)
40  */
41  class EnhancedGraphicsView: public QGraphicsView
42  {
43  Q_OBJECT
44  public:
45  using QGraphicsView::QGraphicsView;
46 
47  Qt::KeyboardModifier getRotationKeyboardModifier() const;
48  qreal getRotationFactor() const;
49 
50  Qt::KeyboardModifier getZoomKeyboardModifier() const;
51  qreal setZoomFactor();
52  qreal getZoomFactor() const;
53 
54  Qt::KeyboardModifier getDraggingKeyboardModifier() const;
55  Qt::MouseButton getDraggingMouseButton() const;
56  public slots:
57  void setRotationEnabled(bool enabled = true);
58  void setRotationDisabled(bool disabled = true);
59  void setRotationKeyboardModifier(Qt::KeyboardModifier mod);
60  void setRotationFactor(qreal factor);
61 
62  void setZoomEnabled(bool enabled = true);
63  void setZoomDisabled(bool disabled = true);
64  void setZoomKeyboardModifier(Qt::KeyboardModifier mod);
65  void setZoomFactor(qreal factor);
66 
67  void setDraggingEnabled(bool enabled = true);
68  void setDraggingDisabled(bool disabled = true);
69  void setDraggingKeyboardModifier(Qt::KeyboardModifier mod);
70  void setDraggingMouseButton(Qt::MouseButton button);
71 
72  void setAllVisible(bool visible);
73 
74  protected:
75  void mousePressEvent(QMouseEvent* e) override;
76  void mouseMoveEvent(QMouseEvent* e) override;
77  void wheelEvent(QWheelEvent* e) override;
78 
79  bool rotationEnabled {true};
80  Qt::KeyboardModifier rotationModifier {Qt::ShiftModifier};
81  qreal rotationFactor {0.01};
82 
83  bool zoomEnabled {true};
84  Qt::KeyboardModifier zoomModifier {Qt::ControlModifier};
85  qreal zoomFacor {1.05};
86 
87  bool draggingEnabled {true};
88  Qt::KeyboardModifier draggingModifier {Qt::ControlModifier};
89  Qt::MouseButton draggingButton {Qt::LeftButton};
91  };
92 }
armarx::EnhancedGraphicsView::getZoomKeyboardModifier
Qt::KeyboardModifier getZoomKeyboardModifier() const
Definition: EnhancedGraphicsView.cpp:39
armarx::EnhancedGraphicsView::setZoomEnabled
void setZoomEnabled(bool enabled=true)
Definition: EnhancedGraphicsView.cpp:79
armarx::EnhancedGraphicsView::setRotationKeyboardModifier
void setRotationKeyboardModifier(Qt::KeyboardModifier mod)
Definition: EnhancedGraphicsView.cpp:69
armarx::EnhancedGraphicsView::setRotationFactor
void setRotationFactor(qreal factor)
Definition: EnhancedGraphicsView.cpp:74
armarx::EnhancedGraphicsView::getZoomFactor
qreal getZoomFactor() const
Definition: EnhancedGraphicsView.cpp:44
armarx::EnhancedGraphicsView::draggingEnabled
bool draggingEnabled
Definition: EnhancedGraphicsView.h:87
armarx::EnhancedGraphicsView::zoomEnabled
bool zoomEnabled
Definition: EnhancedGraphicsView.h:83
armarx::EnhancedGraphicsView::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e) override
Definition: EnhancedGraphicsView.cpp:133
armarx::EnhancedGraphicsView::rotationEnabled
bool rotationEnabled
Definition: EnhancedGraphicsView.h:79
armarx::EnhancedGraphicsView::zoomFacor
qreal zoomFacor
Definition: EnhancedGraphicsView.h:85
armarx::EnhancedGraphicsView::draggingButton
Qt::MouseButton draggingButton
Definition: EnhancedGraphicsView.h:89
armarx::EnhancedGraphicsView::setZoomDisabled
void setZoomDisabled(bool disabled=true)
Definition: EnhancedGraphicsView.cpp:84
armarx::EnhancedGraphicsView::setZoomKeyboardModifier
void setZoomKeyboardModifier(Qt::KeyboardModifier mod)
Definition: EnhancedGraphicsView.cpp:89
armarx::EnhancedGraphicsView::setDraggingDisabled
void setDraggingDisabled(bool disabled=true)
Definition: EnhancedGraphicsView.cpp:104
armarx::EnhancedGraphicsView::mousePressEvent
void mousePressEvent(QMouseEvent *e) override
Definition: EnhancedGraphicsView.cpp:127
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::EnhancedGraphicsView::rotationFactor
qreal rotationFactor
Definition: EnhancedGraphicsView.h:81
armarx::EnhancedGraphicsView::rotationModifier
Qt::KeyboardModifier rotationModifier
Definition: EnhancedGraphicsView.h:80
armarx::EnhancedGraphicsView::getRotationFactor
qreal getRotationFactor() const
Definition: EnhancedGraphicsView.cpp:34
armarx::EnhancedGraphicsView::getDraggingMouseButton
Qt::MouseButton getDraggingMouseButton() const
Definition: EnhancedGraphicsView.cpp:54
armarx::EnhancedGraphicsView::setRotationDisabled
void setRotationDisabled(bool disabled=true)
Definition: EnhancedGraphicsView.cpp:64
armarx::EnhancedGraphicsView::setDraggingKeyboardModifier
void setDraggingKeyboardModifier(Qt::KeyboardModifier mod)
Definition: EnhancedGraphicsView.cpp:109
armarx::EnhancedGraphicsView::zoomModifier
Qt::KeyboardModifier zoomModifier
Definition: EnhancedGraphicsView.h:84
armarx::EnhancedGraphicsView::setZoomFactor
qreal setZoomFactor()
armarx::EnhancedGraphicsView::wheelEvent
void wheelEvent(QWheelEvent *e) override
Definition: EnhancedGraphicsView.cpp:154
armarx::EnhancedGraphicsView::setDraggingMouseButton
void setDraggingMouseButton(Qt::MouseButton button)
Definition: EnhancedGraphicsView.cpp:114
armarx::EnhancedGraphicsView::setRotationEnabled
void setRotationEnabled(bool enabled=true)
Definition: EnhancedGraphicsView.cpp:59
armarx::EnhancedGraphicsView::draggingModifier
Qt::KeyboardModifier draggingModifier
Definition: EnhancedGraphicsView.h:88
armarx::EnhancedGraphicsView::setDraggingEnabled
void setDraggingEnabled(bool enabled=true)
Definition: EnhancedGraphicsView.cpp:99
armarx::EnhancedGraphicsView
The EnhancedGraphicsView is a QGraphicsView with some additional functions.
Definition: EnhancedGraphicsView.h:41
armarx::EnhancedGraphicsView::draggingStartPosition
QPointF draggingStartPosition
Definition: EnhancedGraphicsView.h:90
armarx::EnhancedGraphicsView::setAllVisible
void setAllVisible(bool visible)
Definition: EnhancedGraphicsView.cpp:119
armarx::EnhancedGraphicsView::getDraggingKeyboardModifier
Qt::KeyboardModifier getDraggingKeyboardModifier() const
Definition: EnhancedGraphicsView.cpp:49
armarx::EnhancedGraphicsView::getRotationKeyboardModifier
Qt::KeyboardModifier getRotationKeyboardModifier() const
Definition: EnhancedGraphicsView.cpp:29
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28