OpenWalnut  1.5.0dev
WQtNetworkEditorView.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WQTNETWORKEDITORVIEW_H
26 #define WQTNETWORKEDITORVIEW_H
27 
28 #include <QtCore/QTimeLine>
29 #include <QGraphicsView>
30 
31 class QGraphicsItem;
32 
33 /**
34  * This class extends the basic functionality of QGraphicsView to allow comfortable panning and zooming.
35  */
37 {
38  Q_OBJECT
39 public:
40  /**
41  * Constructs empty view.
42  *
43  * \param parent parent widgets containing the view
44  */
45  explicit WQtNetworkEditorView( QWidget* parent = NULL );
46 
47  /**
48  * The Item to focus on. Use this instead of QGraphicsView::ensureVisible.
49  *
50  * \param item the item.
51  */
52  void focusOn( QGraphicsItem* item );
53 
54  /**
55  * Improved version of QGraphicsView::ensureVisible for smooth scrolling.
56  *
57  * \param item the item to make visible.
58  * \param xmargin the margin to ensure between item border and visible scene border (x direction)
59  * \param ymargin the margin to ensure between item border and visible scene border (y direction)
60  */
61  void ensureVisibleSmooth( QGraphicsItem* item , int xmargin = 50, int ymargin = 50 );
62 
63  /**
64  * Set the given menu as new global add-modules menu. Can be NULL to disable.
65  *
66  * \param menu the menu to set.
67  */
68  void setGlobalAddMenu( QMenu* menu );
69 signals:
70  /**
71  * Emitted whenever the user caused a load event.
72  */
73  void loadAction();
74 
75  /**
76  * Emitted whenever the user drops something into the widget
77  *
78  * \param event event containing further info on the dropped item.
79  */
80  void dragDrop( QDropEvent* event );
81 
82 protected:
83  /**
84  * Double clicked into the view
85  *
86  * \param event contains event information.
87  */
88  virtual void mouseDoubleClickEvent( QMouseEvent* event );
89 
90  /**
91  * Mouse button pressed.
92  *
93  * \param event contains event information.
94  */
95  virtual void mousePressEvent( QMouseEvent* event );
96 
97  /**
98  * Mouse button released
99  *
100  * \param event contains event information.
101  */
102  virtual void mouseReleaseEvent( QMouseEvent* event );
103 
104  /**
105  * Mouse moved
106  *
107  * \param event contains event information.
108  */
109  virtual void mouseMoveEvent( QMouseEvent* event );
110 
111  /**
112  * Mouse wheel used.
113  *
114  * \param event contains event information.
115  */
116  virtual void wheelEvent( QWheelEvent* event );
117 
118  /**
119  * View resized. This automatically updates the virtual center for zooming after resize
120  *
121  * \param event contains event information.
122  */
123  virtual void resizeEvent( QResizeEvent* event );
124 
125  /**
126  * Key pressed.
127  *
128  * \param event contains event information.
129  */
130  void keyPressEvent( QKeyEvent *event );
131 
132  /**
133  * Mouse leaves the widget.
134  *
135  * \param event the event
136  */
137  void leaveEvent( QEvent* event );
138 
139  /**
140  * Handles the drop event for a tree item.
141  *
142  * \param event the event.
143  */
144  virtual void dropEvent( QDropEvent *event );
145 
146  /**
147  * Move scene in the view by delta units
148  *
149  * \param delta move vector.
150  */
151  void moveBy( const QPointF& delta );
152 
153  /**
154  * Move scrollarea to absolute position.
155  *
156  * \param target the new scroll position
157  */
158  void moveTo( const QPointF& target );
159 
160 private:
161  /**
162  * To keep track of mouse movement, cache last known mouse event point
163  */
165 
166  /**
167  * If true, we are in pan mode.
168  */
169  bool m_panning;
170 
171  /**
172  * The menu containing the add actions in m_addModuleActionList.
173  */
175 
176  /**
177  * Auto-pan vector
178  */
180 
181  /**
182  * Origin of auto-pan movement for proper interpolation.
183  */
185 
186  /**
187  * Auto-pan timer
188  */
189  QTimeLine* m_autoPanTimer;
190 
191 private slots:
192  /**
193  * Called every tick of the auto pan timer
194  *
195  * \param value
196  */
197  void autoPanTick( qreal value );
198 };
199 
200 #endif // WQTNETWORKEDITORVIEW_H
201 
This class extends the basic functionality of QGraphicsView to allow comfortable panning and zooming.
QPoint m_autoPanTarget
Auto-pan vector.
void ensureVisibleSmooth(QGraphicsItem *item, int xmargin=50, int ymargin=50)
Improved version of QGraphicsView::ensureVisible for smooth scrolling.
virtual void mouseReleaseEvent(QMouseEvent *event)
Mouse button released.
virtual void wheelEvent(QWheelEvent *event)
Mouse wheel used.
void focusOn(QGraphicsItem *item)
The Item to focus on.
virtual void mousePressEvent(QMouseEvent *event)
Mouse button pressed.
void moveBy(const QPointF &delta)
Move scene in the view by delta units.
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Double clicked into the view.
void dragDrop(QDropEvent *event)
Emitted whenever the user drops something into the widget.
QMenu * m_addMenu
The menu containing the add actions in m_addModuleActionList.
QPoint m_autoPanOrig
Origin of auto-pan movement for proper interpolation.
void moveTo(const QPointF &target)
Move scrollarea to absolute position.
virtual void dropEvent(QDropEvent *event)
Handles the drop event for a tree item.
void loadAction()
Emitted whenever the user caused a load event.
void leaveEvent(QEvent *event)
Mouse leaves the widget.
virtual void resizeEvent(QResizeEvent *event)
View resized.
QTimeLine * m_autoPanTimer
Auto-pan timer.
WQtNetworkEditorView(QWidget *parent=NULL)
Constructs empty view.
void keyPressEvent(QKeyEvent *event)
Key pressed.
QPoint m_lastPanPoint
To keep track of mouse movement, cache last known mouse event point.
void autoPanTick(qreal value)
Called every tick of the auto pan timer.
bool m_panning
If true, we are in pan mode.
void setGlobalAddMenu(QMenu *menu)
Set the given menu as new global add-modules menu.
virtual void mouseMoveEvent(QMouseEvent *event)
Mouse moved.