25 #include <QMouseEvent>
27 #include <QWheelEvent>
28 #include <QGraphicsItem>
30 #include "core/common/WLogger.h"
31 #include "core/kernel/WModuleFactory.h"
32 #include "../WQtCombinerActionList.h"
33 #include "../WQtGui.h"
34 #include "../WMainWindow.h"
35 #include "../guiElements/WQtMenuFiltered.h"
37 #include "WQtNetworkEditorGlobals.h"
38 #include "WQtNetworkEditorView.h"
45 setDragMode( QGraphicsView::NoDrag );
46 setRenderHint( QPainter::Antialiasing );
47 setMinimumSize( 20, 20 );
49 setResizeAnchor( QGraphicsView::AnchorUnderMouse );
50 setAcceptDrops(
true );
72 QRectF viewRect = mapFromScene( item->sceneBoundingRect() ).boundingRect();
75 qreal top = verticalScrollBar()->value();
76 qreal left = horizontalScrollBar()->value();
77 qreal width = viewport()->width();
78 qreal height = viewport()->height();
84 if( viewRect.left() < xmargin )
89 if( viewRect.right() + xmargin > width )
94 if( viewRect.top() < ymargin )
100 if( viewRect.bottom() + ymargin > height )
116 QScrollBar* horiz = horizontalScrollBar();
117 QScrollBar* vert = verticalScrollBar();
118 horiz->setValue( horiz->value() - delta.x() );
119 vert->setValue( vert->value() - delta.y() );
124 horizontalScrollBar()->setValue( target.x() );
125 verticalScrollBar()->setValue( target.y() );
138 QGraphicsView::leaveEvent( event );
144 if( items( event->pos() ).size() != 0 )
146 QGraphicsView::mouseDoubleClickEvent( event );
151 if( ( event->modifiers() == Qt::ShiftModifier ) ||
152 ( event->modifiers() == Qt::ControlModifier )
160 else if( event->modifiers() == Qt::NoModifier )
170 if( items( event->pos() ).size() != 0 )
172 QGraphicsView::mousePressEvent( event );
177 if( event->button() == Qt::MiddleButton )
183 if( event->button() == Qt::LeftButton )
188 setCursor( Qt::ClosedHandCursor );
190 QGraphicsView::mousePressEvent( event );
196 if( event->button() == Qt::MiddleButton )
205 setCursor( Qt::ArrowCursor );
208 QGraphicsView::mouseReleaseEvent( event );
217 QPointF delta = mapToScene(
m_lastPanPoint ) - mapToScene( event->pos() );
227 QGraphicsView::mouseMoveEvent( event );
233 double scaleFactor = 1.15;
235 if( event->angleDelta().y() > 0 )
238 scale( scaleFactor, scaleFactor );
242 else if( event->angleDelta().y() < 0 )
245 scale( 1.0 / scaleFactor, 1.0 / scaleFactor );
255 QGraphicsView::resizeEvent( event );
261 double scaleFactor = 1.15;
262 if( event->matches( QKeySequence::ZoomIn ) )
265 scale( scaleFactor, scaleFactor );
267 if( event->matches( QKeySequence::ZoomOut ) )
270 scale( 1.0 / scaleFactor, 1.0 / scaleFactor );
272 QGraphicsView::keyPressEvent( event );
280 QGraphicsView::dropEvent( event );
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.