Commit f4dba468 authored by Yannick Verdie's avatar Yannick Verdie

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
parent 673b4404
...@@ -418,63 +418,64 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr ) ...@@ -418,63 +418,64 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr )
//----------OBJECT---------------- //----------OBJECT----------------
GuiReceiver::GuiReceiver() : _bTimeOut(false) GuiReceiver::GuiReceiver() : _bTimeOut(false)
{ {
icvInitSystem(); icvInitSystem();
qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting
} }
double GuiReceiver::getPropWindow(QString name) double GuiReceiver::getPropWindow(QString name)
{ {
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() ); QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
if (!w) if (!w)
return -1; return -1;
return (double)w->flags; return (double)w->flags;
} }
void GuiReceiver::setPropWindow(QString name, double arg2 ) void GuiReceiver::setPropWindow(QString name, double arg2 )
{ {
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() ); QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
if (!w) if (!w)
return; return;
int flags = (int) arg2; int flags = (int) arg2;
if (w->flags == flags)//nothing to do if (w->flags == flags)//nothing to do
return; return;
switch(flags) switch(flags)
{ {
case CV_WINDOW_NORMAL: case CV_WINDOW_NORMAL:
w->layout->setSizeConstraint(QLayout::SetMinAndMaxSize); w->layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
w->flags = flags; w->flags = flags;
break; break;
case CV_WINDOW_AUTOSIZE: case CV_WINDOW_AUTOSIZE:
w->layout->setSizeConstraint(QLayout::SetFixedSize); w->layout->setSizeConstraint(QLayout::SetFixedSize);
w->flags = flags; w->flags = flags;
break; break;
default:; default:;
} }
} }
double GuiReceiver::isFullScreen(QString name) double GuiReceiver::isFullScreen(QString name)
{ {
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() ); QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
if (!w) if (!w)
return -1; return -1;
if (w->isFullScreen()) if (w->isFullScreen())
return CV_WINDOW_FULLSCREEN; return CV_WINDOW_FULLSCREEN;
else else
return CV_WINDOW_NORMAL; return CV_WINDOW_NORMAL;
} }
//accept CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN //accept CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN
...@@ -484,12 +485,12 @@ void GuiReceiver::toggleFullScreen(QString name, double flags ) ...@@ -484,12 +485,12 @@ void GuiReceiver::toggleFullScreen(QString name, double flags )
if (!w) if (!w)
return; return;
if (w->isFullScreen() && flags == CV_WINDOW_NORMAL) if (w->isFullScreen() && flags == CV_WINDOW_NORMAL)
w->showNormal(); w->showNormal();
if (!w->isFullScreen() && flags == CV_WINDOW_FULLSCREEN) if (!w->isFullScreen() && flags == CV_WINDOW_FULLSCREEN)
w->showFullScreen(); w->showFullScreen();
} }
...@@ -643,14 +644,14 @@ CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTra ...@@ -643,14 +644,14 @@ CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTra
//Change style of the Slider //Change style of the Slider
slider->setStyleSheet(str_Trackbar_css); slider->setStyleSheet(str_Trackbar_css);
//QFile qss(PATH_QSLIDERCSS); //QFile qss(PATH_QSLIDERCSS);
//if (qss.open(QFile::ReadOnly)) //if (qss.open(QFile::ReadOnly))
//{ //{
// slider->setStyleSheet(QLatin1String(qss.readAll())); // slider->setStyleSheet(QLatin1String(qss.readAll()));
// qss.close(); // qss.close();
//} //}
//this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?) //this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?)
//slider->setTickPosition(QSlider::TicksBelow); //slider->setTickPosition(QSlider::TicksBelow);
...@@ -764,13 +765,6 @@ CvWindow::~CvWindow() ...@@ -764,13 +765,6 @@ CvWindow::~CvWindow()
} }
/*
void CvWindow::startNavigate()
{
cout<<"here"<<endl;
//myview->zoomIn();
}*/
void CvWindow::displayInfo(QString text,int delayms) void CvWindow::displayInfo(QString text,int delayms)
{ {
myview->startDisplayInfo(text, delayms); myview->startDisplayInfo(text, delayms);
...@@ -783,7 +777,7 @@ void CvWindow::updateImage(void* arr) ...@@ -783,7 +777,7 @@ void CvWindow::updateImage(void* arr)
void CvWindow::setMouseCallBack(CvMouseCallback m, void* param) void CvWindow::setMouseCallBack(CvMouseCallback m, void* param)
{ {
myview->setMouseCallBack(m,param); myview->setMouseCallBack(m,param);
} }
void CvWindow::addSlider(QString name, int* value, int count,CvTrackbarCallback on_change) void CvWindow::addSlider(QString name, int* value, int count,CvTrackbarCallback on_change)
...@@ -834,6 +828,7 @@ ViewPort::ViewPort(QWidget* arg, int arg2) ...@@ -834,6 +828,7 @@ ViewPort::ViewPort(QWidget* arg, int arg2)
previousFactor = 1; previousFactor = 1;
previousCenter = QPointF(0,0); previousCenter = QPointF(0,0);
previousDelta = QPointF(0,0); previousDelta = QPointF(0,0);
positionGrabbing = QPointF(0,0);
if (mode == CV_MODE_OPENGL) if (mode == CV_MODE_OPENGL)
{ {
...@@ -845,6 +840,11 @@ ViewPort::ViewPort(QWidget* arg, int arg2) ...@@ -845,6 +840,11 @@ ViewPort::ViewPort(QWidget* arg, int arg2)
image2Draw=cvCreateImage(cvSize(centralWidget->width(),centralWidget->height()),IPL_DEPTH_8U,3); image2Draw=cvCreateImage(cvSize(centralWidget->width(),centralWidget->height()),IPL_DEPTH_8U,3);
cvZero(image2Draw); cvZero(image2Draw);
setSceneRect(0,0,size().width(),size().height());
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setInteractive(false);
} }
ViewPort::~ViewPort() ViewPort::~ViewPort()
...@@ -852,6 +852,7 @@ ViewPort::~ViewPort() ...@@ -852,6 +852,7 @@ ViewPort::~ViewPort()
if (image2Draw) if (image2Draw)
cvReleaseImage(&image2Draw); cvReleaseImage(&image2Draw);
delete timerDisplay;
} }
void ViewPort::startDisplayInfo(QString text, int delayms) void ViewPort::startDisplayInfo(QString text, int delayms)
...@@ -888,7 +889,7 @@ void ViewPort::updateImage(void* arr) ...@@ -888,7 +889,7 @@ void ViewPort::updateImage(void* arr)
image2Draw=cvCreateImage(cvGetSize(tempImage),IPL_DEPTH_8U,3); image2Draw=cvCreateImage(cvGetSize(tempImage),IPL_DEPTH_8U,3);
updateGeometry(); updateGeometry();
} }
cvConvertImage(tempImage,image2Draw,CV_CVTIMG_SWAP_RB ); cvConvertImage(tempImage,image2Draw,CV_CVTIMG_SWAP_RB );
viewport()->update(); viewport()->update();
...@@ -896,16 +897,34 @@ void ViewPort::updateImage(void* arr) ...@@ -896,16 +897,34 @@ void ViewPort::updateImage(void* arr)
void ViewPort::setMouseCallBack(CvMouseCallback m, void* param) void ViewPort::setMouseCallBack(CvMouseCallback m, void* param)
{ {
setMouseTracking (true);//receive mouse event everytime setMouseTracking (true);//receive mouse event everytime
on_mouse = m; on_mouse = m;
on_mouse_param = 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) void ViewPort::scaleView(qreal factor,QPointF center)
{ {
factor += previousFactor; factor += previousFactor;
if (factor < 1 || factor > 100) if (factor < 1 || factor > 100)
return; return;
center= (center-previousCenter)/previousFactor + previousCenter;//move to global coordinate center= (center-previousCenter)/previousFactor + previousCenter;//move to global coordinate
QPointF delta = QPointF(center-center*factor); QPointF delta = QPointF(center-center*factor);
...@@ -914,21 +933,23 @@ void ViewPort::scaleView(qreal factor,QPointF center) ...@@ -914,21 +933,23 @@ void ViewPort::scaleView(qreal factor,QPointF center)
matrixWorld.translate(delta.x(),delta.y());//newCenter.x(),newCenter.y()); matrixWorld.translate(delta.x(),delta.y());//newCenter.x(),newCenter.y());
matrixWorld.scale(factor,factor); matrixWorld.scale(factor,factor);
//controlImagePosition();
previousCenter = center; previousCenter = center;
previousDelta = delta; //previousDelta = delta;
previousFactor = factor; previousFactor = factor;
if (previousFactor>1) if (previousFactor>1)
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
else else
unsetCursor(); unsetCursor();
viewport()->update(); viewport()->update();
} }
void ViewPort::wheelEvent(QWheelEvent *event) void ViewPort::wheelEvent(QWheelEvent *event)
{ {
scaleView( -event->delta() / 480.0,event->pos()); scaleView( -event->delta() / 240.0,event->pos());
} }
void ViewPort::mousePressEvent(QMouseEvent *event) void ViewPort::mousePressEvent(QMouseEvent *event)
...@@ -979,7 +1000,10 @@ void ViewPort::mousePressEvent(QMouseEvent *event) ...@@ -979,7 +1000,10 @@ void ViewPort::mousePressEvent(QMouseEvent *event)
if (previousFactor>1) if (previousFactor>1)
setCursor(Qt::ClosedHandCursor); {
setCursor(Qt::ClosedHandCursor);
positionGrabbing = event->pos();
}
QWidget::mousePressEvent(event); QWidget::mousePressEvent(event);
} }
...@@ -1032,7 +1056,7 @@ void ViewPort::mouseReleaseEvent(QMouseEvent *event) ...@@ -1032,7 +1056,7 @@ void ViewPort::mouseReleaseEvent(QMouseEvent *event)
on_mouse( cv_event, pt.x(), pt.y(), flags, on_mouse_param ); on_mouse( cv_event, pt.x(), pt.y(), flags, on_mouse_param );
if (previousFactor>1) if (previousFactor>1)
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
QWidget::mouseReleaseEvent(event); QWidget::mouseReleaseEvent(event);
} }
...@@ -1115,6 +1139,17 @@ void ViewPort::mouseMoveEvent(QMouseEvent *event) ...@@ -1115,6 +1139,17 @@ void ViewPort::mouseMoveEvent(QMouseEvent *event)
if (on_mouse) if (on_mouse)
on_mouse( cv_event, pt.x(), pt.y(), flags, on_mouse_param ); 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); QWidget::mouseMoveEvent(event);
} }
...@@ -1183,6 +1218,18 @@ void ViewPort::drawInstructions(QPainter *painter) ...@@ -1183,6 +1218,18 @@ void ViewPort::drawInstructions(QPainter *painter)
} }
#if defined(OPENCV_GL)//all this section -> not tested #if defined(OPENCV_GL)//all this section -> not tested
void ViewPort::initGL() void ViewPort::initGL()
...@@ -1246,3 +1293,4 @@ void ViewPort::draw3D() ...@@ -1246,3 +1293,4 @@ void ViewPort::draw3D()
#endif #endif
#endif #endif
...@@ -172,15 +172,16 @@ public: ...@@ -172,15 +172,16 @@ public:
qreal scaleFactor;//for zoom int/out qreal scaleFactor;//for zoom int/out
public slots: public slots:
//reference: //reference:
//http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming //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); void scaleView(qreal scaleFactor, QPointF center);
private: private:
QPointF previousCenter ; QPointF previousCenter ;
qreal previousFactor;//for zoom int/out qreal previousFactor;//for zoom int/out
QPointF previousDelta; QPointF previousDelta;
QPointF positionGrabbing;
CvMouseCallback on_mouse; CvMouseCallback on_mouse;
void* on_mouse_param; void* on_mouse_param;
...@@ -202,6 +203,8 @@ private: ...@@ -202,6 +203,8 @@ private:
void mouseDoubleClickEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event);
void drawInstructions(QPainter *painter); void drawInstructions(QPainter *painter);
void draw2D(QPainter *painter); void draw2D(QPainter *painter);
void controlImagePosition();
#if defined(OPENCV_GL) #if defined(OPENCV_GL)
void draw3D(); void draw3D();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment