#include <QRubberBand>
#include <QMouseEvent>
#include <QCursor>
+#include <QScrollBar>
#include "SUIT_ResourceMgr.h"
#include "SUIT_Session.h"
-
+#include <iostream>
//=======================================================================
// Name : GraphicsView_ViewPort
// Purpose : Constructor
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setMouseTracking( true );
zooming = false;
previousPos = QPoint();
+
+ panning = false;
SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) );
void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event)
{
- if (!zooming && items(event->pos()).count()==0)
+ if (!zooming && !panning && items(event->pos()).count()==0)
{
startDrawingRect(event->pos().x(), event->pos().y());
}
if ((event->modifiers() & Qt::ShiftModifier) && (event->buttons() & Qt::LeftButton))
activateZoomAction();
+ if (panning && (event->buttons() & Qt::LeftButton))
+ {
+ QPoint currentPos = event->pos();
+
+ if (!previousPos.isNull())
+ {
+ double deltaX = currentPos.x() - previousPos.x();
+ double deltaY = currentPos.y() - previousPos.y();
+
+ pan(deltaX, deltaY);
+
+ }
+ previousPos = currentPos;
+
+ }
+
if (zooming && (event->buttons() & Qt::LeftButton))
{
QPoint currentPos = event->pos();
setCursor(Qt::ArrowCursor);
fittingArea = false;
zooming = false;
+ panning = false;
+ previousPos = QPoint();
+ setDragMode(QGraphicsView::RubberBandDrag);
}
void GraphicsView_ViewPort::activateZoomAction()
{
zooming = true;
fittingArea = false;
+ panning = false;
setCursor(*zoomCursor);
}
{
fittingArea = true;
zooming = false;
+ panning = false;
setCursor(Qt::PointingHandCursor);
}
+
+void GraphicsView_ViewPort::activatePanAction()
+{
+ panning = true;
+ fittingArea = false;
+ zooming = false;
+ setCursor(Qt::SizeAllCursor);
+}
+
+void GraphicsView_ViewPort::pan( double theDX, double theDY )
+{
+ std::cout << "pan : " << theDX << " " << theDY << std::endl;
+
+ if( QScrollBar* aHBar = horizontalScrollBar() )
+ {
+ int aNewValue = aHBar->value() - theDX;
+ if( aNewValue < aHBar->minimum() )
+ aHBar->setMinimum( aNewValue );
+ if( aNewValue > aHBar->maximum() )
+ aHBar->setMaximum( aNewValue );
+ }
+ if( QScrollBar* aVBar = verticalScrollBar() )
+ {
+ int aNewValue = aVBar->value() - theDY;
+ if( aNewValue < aVBar->minimum() )
+ aVBar->setMinimum( aNewValue );
+ if( aNewValue > aVBar->maximum() )
+ aVBar->setMaximum( aNewValue );
+ }
+}