New functions with QT GUI (presented in the 4th report)
-Fullscreen -Change Autoresize dynamically (after windows are created) -Zoom on mouse location (with wheel) -Panning by click'ndrag posible after zooming
This commit is contained in:
parent
673b4404a9
commit
f4dba4686d
@ -418,6 +418,7 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr )
|
||||
|
||||
|
||||
|
||||
|
||||
//----------OBJECT----------------
|
||||
|
||||
GuiReceiver::GuiReceiver() : _bTimeOut(false)
|
||||
@ -764,13 +765,6 @@ CvWindow::~CvWindow()
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void CvWindow::startNavigate()
|
||||
{
|
||||
cout<<"here"<<endl;
|
||||
//myview->zoomIn();
|
||||
}*/
|
||||
|
||||
void CvWindow::displayInfo(QString text,int delayms)
|
||||
{
|
||||
myview->startDisplayInfo(text, delayms);
|
||||
@ -834,6 +828,7 @@ ViewPort::ViewPort(QWidget* arg, int arg2)
|
||||
previousFactor = 1;
|
||||
previousCenter = QPointF(0,0);
|
||||
previousDelta = QPointF(0,0);
|
||||
positionGrabbing = QPointF(0,0);
|
||||
|
||||
if (mode == CV_MODE_OPENGL)
|
||||
{
|
||||
@ -845,6 +840,11 @@ ViewPort::ViewPort(QWidget* arg, int arg2)
|
||||
|
||||
image2Draw=cvCreateImage(cvSize(centralWidget->width(),centralWidget->height()),IPL_DEPTH_8U,3);
|
||||
cvZero(image2Draw);
|
||||
|
||||
setSceneRect(0,0,size().width(),size().height());
|
||||
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
this->setInteractive(false);
|
||||
}
|
||||
|
||||
ViewPort::~ViewPort()
|
||||
@ -852,6 +852,7 @@ ViewPort::~ViewPort()
|
||||
if (image2Draw)
|
||||
cvReleaseImage(&image2Draw);
|
||||
|
||||
delete timerDisplay;
|
||||
}
|
||||
|
||||
void ViewPort::startDisplayInfo(QString text, int delayms)
|
||||
@ -901,8 +902,26 @@ void ViewPort::setMouseCallBack(CvMouseCallback m, void* param)
|
||||
on_mouse_param = param;
|
||||
}
|
||||
|
||||
void ViewPort::controlImagePosition()
|
||||
{
|
||||
qreal left, top, right, bottom;
|
||||
matrixWorld.map(0,0,&left,&top);
|
||||
if (left < 0)left = 0;
|
||||
if (top < 0)top = 0;
|
||||
if (left>0 || top > 0)
|
||||
matrixWorld.translate(-left,-top);
|
||||
|
||||
|
||||
QSize sizeImage = size();
|
||||
matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
|
||||
if (right > sizeImage.width()) right = sizeImage.width();
|
||||
if (bottom > sizeImage.height()) bottom = sizeImage.height();
|
||||
if (right < sizeImage.width() || bottom < sizeImage.height())
|
||||
matrixWorld.translate(sizeImage.width()-right,sizeImage.height()-bottom);
|
||||
}
|
||||
|
||||
void ViewPort::scaleView(qreal factor,QPointF center)
|
||||
{
|
||||
{
|
||||
factor += previousFactor;
|
||||
if (factor < 1 || factor > 100)
|
||||
return;
|
||||
@ -914,8 +933,10 @@ void ViewPort::scaleView(qreal factor,QPointF center)
|
||||
matrixWorld.translate(delta.x(),delta.y());//newCenter.x(),newCenter.y());
|
||||
matrixWorld.scale(factor,factor);
|
||||
|
||||
//controlImagePosition();
|
||||
|
||||
previousCenter = center;
|
||||
previousDelta = delta;
|
||||
//previousDelta = delta;
|
||||
previousFactor = factor;
|
||||
|
||||
if (previousFactor>1)
|
||||
@ -928,7 +949,7 @@ void ViewPort::scaleView(qreal factor,QPointF center)
|
||||
|
||||
void ViewPort::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
scaleView( -event->delta() / 480.0,event->pos());
|
||||
scaleView( -event->delta() / 240.0,event->pos());
|
||||
}
|
||||
|
||||
void ViewPort::mousePressEvent(QMouseEvent *event)
|
||||
@ -979,7 +1000,10 @@ void ViewPort::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
|
||||
if (previousFactor>1)
|
||||
{
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
positionGrabbing = event->pos();
|
||||
}
|
||||
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
@ -1115,6 +1139,17 @@ void ViewPort::mouseMoveEvent(QMouseEvent *event)
|
||||
if (on_mouse)
|
||||
on_mouse( cv_event, pt.x(), pt.y(), flags, on_mouse_param );
|
||||
|
||||
|
||||
if (previousFactor>1 && event->buttons() == Qt::LeftButton)
|
||||
{
|
||||
QPointF dxy = (pt - positionGrabbing)/previousFactor;
|
||||
|
||||
positionGrabbing = event->pos();
|
||||
|
||||
matrixWorld.translate(dxy.x(),dxy.y());
|
||||
controlImagePosition();
|
||||
}
|
||||
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
@ -1183,6 +1218,18 @@ void ViewPort::drawInstructions(QPainter *painter)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(OPENCV_GL)//all this section -> not tested
|
||||
|
||||
void ViewPort::initGL()
|
||||
@ -1246,3 +1293,4 @@ void ViewPort::draw3D()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -174,13 +174,14 @@ public:
|
||||
public slots:
|
||||
//reference:
|
||||
//http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming
|
||||
//http://doc.qt.nokia.com/4.6/gestures-imagegestures-imagewidget-cpp.html
|
||||
void scaleView(qreal scaleFactor, QPointF center);
|
||||
|
||||
private:
|
||||
QPointF previousCenter ;
|
||||
qreal previousFactor;//for zoom int/out
|
||||
QPointF previousDelta;
|
||||
|
||||
QPointF positionGrabbing;
|
||||
CvMouseCallback on_mouse;
|
||||
void* on_mouse_param;
|
||||
|
||||
@ -202,6 +203,8 @@ private:
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
void drawInstructions(QPainter *painter);
|
||||
void draw2D(QPainter *painter);
|
||||
void controlImagePosition();
|
||||
|
||||
|
||||
#if defined(OPENCV_GL)
|
||||
void draw3D();
|
||||
|
Loading…
x
Reference in New Issue
Block a user