From d6bbaea28ace762684be1ae77bf184fcab163ceb Mon Sep 17 00:00:00 2001 From: Yannick Verdie Date: Mon, 2 Aug 2010 10:58:25 +0000 Subject: [PATCH] Qt imgRegion bug fixed Qt compilation pb with OpenGL flags fixed --- CMakeLists.txt | 2 + modules/highgui/src/window_QT.cpp | 37 +- modules/highgui/src/window_QT.h | 891 +++++++++++++++++++------------------- 3 files changed, 486 insertions(+), 444 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a62107..092d130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -525,6 +525,8 @@ if (WITH_QT) if (QT_QTOPENGL_FOUND AND OPENGL_FOUND) set(HAVE_QT_OPENGL 1) add_definitions(-DHAVE_QT_OPENGL) + link_directories("${OPENGL_LIBRARIES}") + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${OPENGL_LIBRARIES}) endif() endif() diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index bd2f985..8a6a232 100755 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -2241,7 +2241,7 @@ void ViewPort::controlImagePosition() //save also the inv matrix matrixWorld_inv = param_matrixWorld.inverted(); - viewport()->update(); + //viewport()->update(); } void ViewPort::moveView(QPointF delta) @@ -2409,9 +2409,12 @@ void ViewPort::icvmouseProcessing(QPointF pt, int cv_event, int flags) { //to convert mouse coordinate qreal pfx, pfy; + //qreal ratioX = float(image2Draw_qt.width())/image2Draw_qt_resized.width(); + //qreal ratioY = float(image2Draw_qt.height())/image2Draw_qt_resized.height(); matrixWorld_inv.map(pt.x(),pt.y(),&pfx,&pfy); - mouseCoordinate.rx()=floor(pfx); - mouseCoordinate.ry()=floor(pfy); + + mouseCoordinate.rx()=floor(pfx/ratioX); + mouseCoordinate.ry()=floor(pfy/ratioY); if (on_mouse) on_mouse( cv_event, mouseCoordinate.x(),mouseCoordinate.y(), flags, on_mouse_param ); @@ -2430,7 +2433,6 @@ QSize ViewPort::sizeHint() const void ViewPort::resizeEvent ( QResizeEvent *event) { - image2Draw_qt_resized = image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation); controlImagePosition(); ratioX=width()/float(image2Draw_ipl->width); @@ -2493,8 +2495,14 @@ void ViewPort::paintEvent(QPaintEvent* event) //in mode zoom/panning if (param_matrixWorld.m11()>1) { + if (param_matrixWorld.m11()>=threshold_zoom_img_region) + { + if (centralWidget->param_flags == CV_WINDOW_NORMAL) + startDisplayInfo("WARNING: The values displayed are the values of the resized image. If you want the values of the original image, use CV_WINDOW_AUTORESIZE", 1000); + drawImgRegion(&myPainter); + } drawViewOverview(&myPainter); } @@ -2512,7 +2520,8 @@ void ViewPort::paintEvent(QPaintEvent* event) void ViewPort::draw2D(QPainter *painter) { - painter->drawImage(0,0,image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); + image2Draw_qt_resized = image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation); + painter->drawImage(0,0,image2Draw_qt_resized); } void ViewPort::drawStatusBar() @@ -2544,6 +2553,7 @@ void ViewPort::drawStatusBar() } } + void ViewPort::drawImgRegion(QPainter *painter) { qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11(); @@ -2573,22 +2583,33 @@ void ViewPort::drawImgRegion(QPainter *painter) QPointF point1;//sorry, I do not know how to name it QPointF point2;//idem + //qreal ratioX = float(image2Draw_qt.width())/image2Draw_qt_resized.width(); + //qreal ratioY = float(image2Draw_qt.height())/image2Draw_qt_resized.height(); - for (int j=-1;j= 0 && point2.y() >= 0) - rgbValue = image2Draw_qt.pixel(QPoint(point2.x(),point2.y())); + rgbValue = image2Draw_qt_resized.pixel(QPoint(point2.x(),point2.y())); else rgbValue = qRgb(0,0,0); if (nbChannelOriginImage==3) { + //for debug + val = tr("%1 %2").arg(point2.x()).arg(point2.y()); + painter->setPen(QPen(Qt::black, 1)); + painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/2), + Qt::AlignCenter, val); + val = tr("%1").arg(qRed(rgbValue)); painter->setPen(QPen(Qt::red, 1)); painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/3), diff --git a/modules/highgui/src/window_QT.h b/modules/highgui/src/window_QT.h index 513eac2..32592e2 100644 --- a/modules/highgui/src/window_QT.h +++ b/modules/highgui/src/window_QT.h @@ -1,436 +1,455 @@ -//IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. - -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. - - -// License Agreement -// For Open Source Computer Vision Library - -//Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -//Copyright (C) 2008-2010, Willow Garage Inc., all rights reserved. -//Third party copyrights are property of their respective owners. - -//Redistribution and use in source and binary forms, with or without modification, -//are permitted provided that the following conditions are met: - -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. - -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. - -//This software is provided by the copyright holders and contributors "as is" and -//any express or implied warranties, including, but not limited to, the implied -//warranties of merchantability and fitness for a particular purpose are disclaimed. -//In no event shall the Intel Corporation or contributors be liable for any direct, -//indirect, incidental, special, exemplary, or consequential damages -//(including, but not limited to, procurement of substitute goods or services; -//loss of use, data, or profits; or business interruption) however caused -//and on any theory of liability, whether in contract, strict liability, -//or tort (including negligence or otherwise) arising in any way out of -//the use of this software, even if advised of the possibility of such damage. - -//--------------------Google Code 2010 -- Yannick Verdie--------------------// -#ifndef __OPENCV_HIGHGUI_QT_H__ -#define __OPENCV_HIGHGUI_QT_H__ - - -#include "precomp.hpp" - -#if defined( HAVE_QT_OPENGL ) -#include -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//start private enum -enum {CV_MODE_NORMAL= 0, CV_MODE_OPENGL = 1}; - -//we can change the keyboard shortcuts from here ! -enum { shortcut_zoom_normal = Qt::CTRL + Qt::Key_Z, - shortcut_zoom_imgRegion = Qt::CTRL + Qt::Key_X, - shortcut_save_img = Qt::CTRL + Qt::Key_S, - shortcut_properties_win = Qt::CTRL + Qt::Key_P, - shortcut_zoom_in = Qt::CTRL + Qt::Key_Plus,//QKeySequence(QKeySequence::ZoomIn), - shortcut_zoom_out = Qt::CTRL + Qt::Key_Minus,//QKeySequence(QKeySequence::ZoomOut), - shortcut_panning_left = Qt::CTRL + Qt::Key_Left, - shortcut_panning_right = Qt::CTRL + Qt::Key_Right, - shortcut_panning_up = Qt::CTRL + Qt::Key_Up, - shortcut_panning_down = Qt::CTRL + Qt::Key_Down - }; - - -//end enum - -class CvWindow; -class ViewPort; - - -class GuiReceiver : public QObject -{ - Q_OBJECT - -public: - GuiReceiver(); - ~GuiReceiver(); - int start(); - void isLastWindow(); - - bool _bTimeOut; - QTimer *timer; - -private: - int nb_windows; - -public slots: - void createWindow( QString name, int flags = 0 ); - void destroyWindow(QString name); - void destroyAllWindow(); - void addSlider(QString trackbar_name, QString window_name, void* value, int count, void* on_change); - void moveWindow(QString name, int x, int y); - void resizeWindow(QString name, int width, int height); - void showImage(QString name, void* arr); - void displayInfo( QString name, QString text, int delayms ); - void displayStatusBar( QString name, QString text, int delayms ); - void timeOut(); - void toggleFullScreen(QString name, double flags ); - double isFullScreen(QString name); - double getPropWindow(QString name); - void setPropWindow(QString name, double flags ); - double getRatioWindow(QString name); - void setRatioWindow(QString name, double arg2 ); - void saveWindowParameters(QString name); - void loadWindowParameters(QString name); - void setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata, double angle, double zmin, double zmax); - void putText(void* arg1, QString text, QPoint org, void* font); - void addButton(QString button_name, int button_type, int initial_button_state , void* on_change, void* userdata); -}; - -enum typeBar{type_CvTrackbar = 0, type_CvButtonbar = 1}; -class CvBar : public QHBoxLayout -{ -public: - typeBar type; - QString name_bar; - QPointer myparent; -}; - - -class CvButtonbar : public CvBar -{ - Q_OBJECT -public: - CvButtonbar(QWidget* arg, QString bar_name); - ~CvButtonbar(); - void addButton( QString button_name, CvButtonCallback call, void* userdata, int button_type, int initial_button_state); - -private: - void setLabel(); - - QPointer label; - QPointer group_button; -}; - - -class CvPushButton : public QPushButton -{ - Q_OBJECT -public: - CvPushButton(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata); - -private: - CvButtonbar* myparent; - QString button_name ; - CvButtonCallback callback; - void* userdata; - -private slots: - void callCallBack(bool); -}; - - - -class CvCheckBox : public QCheckBox -{ - Q_OBJECT -public: - CvCheckBox(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata, int initial_button_state); - -private: - CvButtonbar* myparent; - QString button_name ; - CvButtonCallback callback; - void* userdata; - -private slots: - void callCallBack(bool); -}; - -class CvRadioButton : public QRadioButton -{ - Q_OBJECT -public: - CvRadioButton(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata, int initial_button_state); - -private: - CvButtonbar* myparent; - QString button_name ; - CvButtonCallback callback; - void* userdata; - -private slots: - void callCallBack(bool); -}; - - - -class CvTrackbar : public CvBar -{ - Q_OBJECT -public: - CvTrackbar(CvWindow* parent, QString name, int* value, int count, CvTrackbarCallback on_change = NULL); - ~CvTrackbar(); - - //QString trackbar_name; - QPointer slider; - -private slots: - void createDialog(); - void update(int myvalue); - -private: - void setLabel(int myvalue); - QString createLabel(); - QPointer label; - CvTrackbarCallback callback; - int* dataSlider; - -}; - -class CvWinProperties : public QWidget -{ - Q_OBJECT -public: - CvWinProperties(QString name,QWidget* parent); - ~CvWinProperties(); - QPointer myLayout; - -private: - void closeEvent ( QCloseEvent * e ); - void showEvent ( QShowEvent * event ) ; - void hideEvent ( QHideEvent * event ) ; -}; - -class CvWindow : public QWidget -{ - Q_OBJECT -public: - CvWindow(QString arg2, int flag = CV_WINDOW_NORMAL); - ~CvWindow(); - static void addSlider(CvWindow* w,QString name, int* value, int count, CvTrackbarCallback on_change CV_DEFAULT(NULL)); - void setMouseCallBack(CvMouseCallback m, void* param); - void updateImage(void* arr); - void displayInfo(QString text, int delayms ); - void displayStatusBar(QString text, int delayms ); - void readSettings(); - void writeSettings(); - void setOpenGLCallback(CvOpenGLCallback arg1,void* userdata, double angle, double zmin, double zmax); - void hideTools(); - void showTools(); - static CvButtonbar* createButtonbar(QString bar_name); - - - - ViewPort* getView(); - - QPointer myGlobalLayout;//All the widget (toolbar, view, LayoutBar, ...) are attached to it - QPointer myBarLayout; - QPointer myStatusBar; - QPointer myToolBar; - QPointer myStatusBar_msg; - - //parameters (will be save/load) - QString param_name; - CvWinProperties* parameters_window ; - int param_flags; - int param_gui_mode; - int param_ratio_mode; - QVector vect_QActions; - - -protected: - virtual void keyPressEvent(QKeyEvent *event); - -private: - QPointer myview; - QVector vect_QShortcuts; - - void icvLoadTrackbars(QSettings *settings); - void icvSaveTrackbars(QSettings *settings); - void icvLoadControlPanel(); - void icvSaveControlPanel(); - void icvLoadButtonbar(CvButtonbar* t,QSettings *settings); - void icvSaveButtonbar(CvButtonbar* t,QSettings *settings); - - void createShortcuts(); - void createActions(); - void createToolBar(); - void createView(int display_mode, int ratio_mode); - void createStatusBar(); - void createGlobalLayout(); - void createBarLayout(); - CvWinProperties* createParameterWindow(); - -private slots: - void displayPropertiesWin(); -}; - - - - -enum type_mouse_event {mouse_up = 0, mouse_down = 1, mouse_dbclick = 2, mouse_move = 3}; - -static const int tableMouseButtons[][3]={ - {CV_EVENT_LBUTTONUP,CV_EVENT_RBUTTONUP,CV_EVENT_MBUTTONUP}, //mouse_up - {CV_EVENT_LBUTTONDOWN,CV_EVENT_RBUTTONDOWN,CV_EVENT_MBUTTONDOWN}, //mouse_down - {CV_EVENT_LBUTTONDBLCLK,CV_EVENT_RBUTTONDBLCLK,CV_EVENT_MBUTTONDBLCLK}, //mouse_dbclick - {CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE} //mouse_move -}; - - -static const double DEFAULT_ANGLE = 45.0; -static const double DEFAULT_ZMIN = 0.01; -static const double DEFAULT_ZMAX = 1000.0; -class ViewPort : public QGraphicsView -{ - Q_OBJECT -public: - ViewPort(CvWindow* centralWidget, int mode = CV_MODE_NORMAL, int keepRatio = CV_WINDOW_KEEPRATIO); - ~ViewPort(); - void updateImage(void* arr); - void startDisplayInfo(QString text, int delayms); - void setMouseCallBack(CvMouseCallback m, void* param); - void setOpenGLCallback(CvOpenGLCallback func,void* userdata, double arg3, double arg4, double arg5); - int getRatio(); - void setRatio(int arg); - - //parameters (will be save/load) - QTransform param_matrixWorld; - - int param_keepRatio; - - IplImage* image2Draw_ipl; - QImage image2Draw_qt; - QImage image2Draw_qt_resized; - int mode_display;//opengl or native - int nbChannelOriginImage; - -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); - void imgRegion(); - void moveView(QPointF delta); - void resetZoom(); - void ZoomIn(); - void ZoomOut(); - void siftWindowOnLeft(); - void siftWindowOnRight(); - void siftWindowOnUp() ; - void siftWindowOnDown(); - void resizeEvent ( QResizeEvent * ); - void saveView(); - void contextMenuEvent(QContextMenuEvent *event); - - -private: - QPoint mouseCoordinate; - QPointF positionGrabbing; - QRect positionCorners; - QTransform matrixWorld_inv; - float ratioX, ratioY; - - //for mouse callback - CvMouseCallback on_mouse; - void* on_mouse_param; - - //for opengl callback - CvOpenGLCallback on_openGL_draw3D; - void* on_openGL_param; - - bool isSameSize(IplImage* img1,IplImage* img2); - QSize sizeHint() const; - QPointer centralWidget; - QPointer timerDisplay; - bool drawInfo; - QString infoText; - //QImage* image; - - void paintEvent(QPaintEvent* paintEventInfo); - void wheelEvent(QWheelEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event); - void drawInstructions(QPainter *painter); - void drawViewOverview(QPainter *painter); - void drawImgRegion(QPainter *painter); - void draw2D(QPainter *painter); - void drawStatusBar(); - void controlImagePosition(); - void icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags); - void icvmouseProcessing(QPointF pt, int cv_event, int flags); - -#if defined( HAVE_QT_OPENGL ) - double angle; - double zmin; - double zmax; - void unsetGL(); - void initGL(); - void setGL(int width, int height); - void icvgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); -#endif - -private slots: - void stopDisplayInfo(); -}; - -#endif +//IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. + + +// License Agreement +// For Open Source Computer Vision Library + +//Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +//Copyright (C) 2008-2010, Willow Garage Inc., all rights reserved. +//Third party copyrights are property of their respective owners. + +//Redistribution and use in source and binary forms, with or without modification, +//are permitted provided that the following conditions are met: + +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. + +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. + +//This software is provided by the copyright holders and contributors "as is" and +//any express or implied warranties, including, but not limited to, the implied +//warranties of merchantability and fitness for a particular purpose are disclaimed. +//In no event shall the Intel Corporation or contributors be liable for any direct, +//indirect, incidental, special, exemplary, or consequential damages +//(including, but not limited to, procurement of substitute goods or services; +//loss of use, data, or profits; or business interruption) however caused +//and on any theory of liability, whether in contract, strict liability, +//or tort (including negligence or otherwise) arising in any way out of +//the use of this software, even if advised of the possibility of such damage. + +//--------------------Google Code 2010 -- Yannick Verdie--------------------// +#ifndef __OPENCV_HIGHGUI_QT_H__ +#define __OPENCV_HIGHGUI_QT_H__ + + +#include "precomp.hpp" + +#if defined( HAVE_QT_OPENGL ) +#include +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//start private enum +enum {CV_MODE_NORMAL= 0, CV_MODE_OPENGL = 1}; + +//we can change the keyboard shortcuts from here ! +enum { shortcut_zoom_normal = Qt::CTRL + Qt::Key_Z, + shortcut_zoom_imgRegion = Qt::CTRL + Qt::Key_X, + shortcut_save_img = Qt::CTRL + Qt::Key_S, + shortcut_properties_win = Qt::CTRL + Qt::Key_P, + shortcut_zoom_in = Qt::CTRL + Qt::Key_Plus,//QKeySequence(QKeySequence::ZoomIn), + shortcut_zoom_out = Qt::CTRL + Qt::Key_Minus,//QKeySequence(QKeySequence::ZoomOut), + shortcut_panning_left = Qt::CTRL + Qt::Key_Left, + shortcut_panning_right = Qt::CTRL + Qt::Key_Right, + shortcut_panning_up = Qt::CTRL + Qt::Key_Up, + shortcut_panning_down = Qt::CTRL + Qt::Key_Down + }; + + +//end enum + +class CvWindow; +class ViewPort; +#if defined( HAVE_QT_OPENGL ) +class OpenGLWidget; +#endif + + +class GuiReceiver : public QObject +{ + Q_OBJECT + +public: + GuiReceiver(); + ~GuiReceiver(); + int start(); + void isLastWindow(); + + bool _bTimeOut; + QTimer *timer; + +private: + int nb_windows; + +public slots: + void createWindow( QString name, int flags = 0 ); + void destroyWindow(QString name); + void destroyAllWindow(); + void addSlider(QString trackbar_name, QString window_name, void* value, int count, void* on_change); + void moveWindow(QString name, int x, int y); + void resizeWindow(QString name, int width, int height); + void showImage(QString name, void* arr); + void displayInfo( QString name, QString text, int delayms ); + void displayStatusBar( QString name, QString text, int delayms ); + void timeOut(); + void toggleFullScreen(QString name, double flags ); + double isFullScreen(QString name); + double getPropWindow(QString name); + void setPropWindow(QString name, double flags ); + double getRatioWindow(QString name); + void setRatioWindow(QString name, double arg2 ); + void saveWindowParameters(QString name); + void loadWindowParameters(QString name); + void setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata, double angle, double zmin, double zmax); + void putText(void* arg1, QString text, QPoint org, void* font); + void addButton(QString button_name, int button_type, int initial_button_state , void* on_change, void* userdata); +}; + +enum typeBar{type_CvTrackbar = 0, type_CvButtonbar = 1}; +class CvBar : public QHBoxLayout +{ +public: + typeBar type; + QString name_bar; + QPointer myparent; +}; + + +class CvButtonbar : public CvBar +{ + Q_OBJECT +public: + CvButtonbar(QWidget* arg, QString bar_name); + ~CvButtonbar(); + void addButton( QString button_name, CvButtonCallback call, void* userdata, int button_type, int initial_button_state); + +private: + void setLabel(); + + QPointer label; + QPointer group_button; +}; + + +class CvPushButton : public QPushButton +{ + Q_OBJECT +public: + CvPushButton(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata); + +private: + CvButtonbar* myparent; + QString button_name ; + CvButtonCallback callback; + void* userdata; + +private slots: + void callCallBack(bool); +}; + + + +class CvCheckBox : public QCheckBox +{ + Q_OBJECT +public: + CvCheckBox(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata, int initial_button_state); + +private: + CvButtonbar* myparent; + QString button_name ; + CvButtonCallback callback; + void* userdata; + +private slots: + void callCallBack(bool); +}; + +class CvRadioButton : public QRadioButton +{ + Q_OBJECT +public: + CvRadioButton(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata, int initial_button_state); + +private: + CvButtonbar* myparent; + QString button_name ; + CvButtonCallback callback; + void* userdata; + +private slots: + void callCallBack(bool); +}; + + + +class CvTrackbar : public CvBar +{ + Q_OBJECT +public: + CvTrackbar(CvWindow* parent, QString name, int* value, int count, CvTrackbarCallback on_change = NULL); + ~CvTrackbar(); + + //QString trackbar_name; + QPointer slider; + +private slots: + void createDialog(); + void update(int myvalue); + +private: + void setLabel(int myvalue); + QString createLabel(); + QPointer label; + CvTrackbarCallback callback; + int* dataSlider; + +}; + +class CvWinProperties : public QWidget +{ + Q_OBJECT +public: + CvWinProperties(QString name,QWidget* parent); + ~CvWinProperties(); + QPointer myLayout; + +private: + void closeEvent ( QCloseEvent * e ); + void showEvent ( QShowEvent * event ) ; + void hideEvent ( QHideEvent * event ) ; +}; + + + +class GlobalLayout : public QBoxLayout +{ + Q_OBJECT +public: + GlobalLayout(QWidget* parent) : QBoxLayout(QBoxLayout::TopToBottom,parent){}; + bool hasHeightForWidth () {return true;}; + int heightForWidth( int w ) {qDebug()<<"yopyopypp";return w;}; +}; + + +class CvWindow : public QWidget +{ + Q_OBJECT +public: + CvWindow(QString arg2, int flag = CV_WINDOW_NORMAL); + ~CvWindow(); + static void addSlider(CvWindow* w,QString name, int* value, int count, CvTrackbarCallback on_change CV_DEFAULT(NULL)); + void setMouseCallBack(CvMouseCallback m, void* param); + void updateImage(void* arr); + void displayInfo(QString text, int delayms ); + void displayStatusBar(QString text, int delayms ); + void readSettings(); + void writeSettings(); + void setOpenGLCallback(CvOpenGLCallback arg1,void* userdata, double angle, double zmin, double zmax); + void hideTools(); + void showTools(); + static CvButtonbar* createButtonbar(QString bar_name); + QSize getAvailableSize(); + + + ViewPort* getView(); + + QPointer myGlobalLayout;//All the widget (toolbar, view, LayoutBar, ...) are attached to it + QPointer myBarLayout; + QPointer myStatusBar; + QPointer myToolBar; + QPointer myStatusBar_msg; + + //parameters (will be save/load) + QString param_name; + CvWinProperties* parameters_window ; + int param_flags; + int param_gui_mode; + int param_ratio_mode; + QVector vect_QActions; + + +protected: + virtual void keyPressEvent(QKeyEvent *event); + +private: + QPointer myview; + QVector vect_QShortcuts; + + void icvLoadTrackbars(QSettings *settings); + void icvSaveTrackbars(QSettings *settings); + void icvLoadControlPanel(); + void icvSaveControlPanel(); + void icvLoadButtonbar(CvButtonbar* t,QSettings *settings); + void icvSaveButtonbar(CvButtonbar* t,QSettings *settings); + + void createShortcuts(); + void createActions(); + void createToolBar(); + void createView(int display_mode, int ratio_mode); + void createStatusBar(); + void createGlobalLayout(); + void createBarLayout(); + CvWinProperties* createParameterWindow(); + +private slots: + void displayPropertiesWin(); +}; + + + + +enum type_mouse_event {mouse_up = 0, mouse_down = 1, mouse_dbclick = 2, mouse_move = 3}; + +static const int tableMouseButtons[][3]={ + {CV_EVENT_LBUTTONUP,CV_EVENT_RBUTTONUP,CV_EVENT_MBUTTONUP}, //mouse_up + {CV_EVENT_LBUTTONDOWN,CV_EVENT_RBUTTONDOWN,CV_EVENT_MBUTTONDOWN}, //mouse_down + {CV_EVENT_LBUTTONDBLCLK,CV_EVENT_RBUTTONDBLCLK,CV_EVENT_MBUTTONDBLCLK}, //mouse_dbclick + {CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE,CV_EVENT_MOUSEMOVE} //mouse_move +}; + + +static const double DEFAULT_ANGLE = 45.0; +static const double DEFAULT_ZMIN = 0.01; +static const double DEFAULT_ZMAX = 1000.0; +class ViewPort : public QGraphicsView +{ + Q_OBJECT +public: + ViewPort(CvWindow* centralWidget, int mode = CV_MODE_NORMAL, int keepRatio = CV_WINDOW_KEEPRATIO); + ~ViewPort(); + void updateImage(void* arr); + void startDisplayInfo(QString text, int delayms); + void setMouseCallBack(CvMouseCallback m, void* param); + void setOpenGLCallback(CvOpenGLCallback func,void* userdata, double arg3, double arg4, double arg5); + int getRatio(); + void setRatio(int arg); + int heightForWidth( int w );// {qDebug()<<"yopyopypp";return w;}; + bool hasHeightForWidth (){qDebug()<<"ask";return true;}; + + //parameters (will be save/load) + QTransform param_matrixWorld; + + int param_keepRatio; + + IplImage* image2Draw_ipl; + QImage image2Draw_qt; + QImage image2Draw_qt_resized; + int mode_display;//opengl or native + int nbChannelOriginImage; + +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); + void imgRegion(); + void moveView(QPointF delta); + void resetZoom(); + void ZoomIn(); + void ZoomOut(); + void siftWindowOnLeft(); + void siftWindowOnRight(); + void siftWindowOnUp() ; + void siftWindowOnDown(); + void resizeEvent ( QResizeEvent * ); + void saveView(); + void contextMenuEvent(QContextMenuEvent *event); + + +private: + QPoint mouseCoordinate; + QPointF positionGrabbing; + QRect positionCorners; + QTransform matrixWorld_inv; + float ratioX, ratioY; + + //for mouse callback + CvMouseCallback on_mouse; + void* on_mouse_param; + + //for opengl callback + CvOpenGLCallback on_openGL_draw3D; + void* on_openGL_param; + + bool isSameSize(IplImage* img1,IplImage* img2); + QSize sizeHint() const; + QPointer centralWidget; + QPointer timerDisplay; + bool drawInfo; + QString infoText; + QRectF target; + //QImage* image; + + void paintEvent(QPaintEvent* paintEventInfo); + void wheelEvent(QWheelEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void drawInstructions(QPainter *painter); + void drawViewOverview(QPainter *painter); + void drawImgRegion(QPainter *painter); + void draw2D(QPainter *painter); + void drawStatusBar(); + void controlImagePosition(); + void icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags); + void icvmouseProcessing(QPointF pt, int cv_event, int flags); + +#if defined( HAVE_QT_OPENGL ) + QPointer myGL; + double angle; + double zmin; + double zmax; + void unsetGL(); + void initGL(); + void setGL(int width, int height); + void icvgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); +#endif + +private slots: + void stopDisplayInfo(); +}; + +#endif -- 2.7.4