-//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--------------------//
-
-
-#if defined(HAVE_QT)
-
-#include <window_QT.h>
-
-//Static and global first
-static GuiReceiver *guiMainThread = NULL;
-static int parameterSystemC = 1;
-static char* parameterSystemV[] = {""};
-static bool multiThreads = false;
-static int last_key = -1;
-QWaitCondition key_pressed;
-QMutex mutexKey;
-static const unsigned int threshold_zoom_img_region = 15;
-//the minimum zoom value to start displaying the values in the grid
-//that is also the number of pixel per grid
-
-static CvWinProperties* global_control_panel = NULL;
-//end static and global
-
-
-
-CV_IMPL CvFont cvFontQt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing)
-{
-
- /*
- //nameFont <- only Qt
- //CvScalar color <- only Qt (blue_component, green_component, red\_component[, alpha_component])
- int font_face;//<- style in Qt
- const int* ascii;
- const int* greek;
- const int* cyrillic;
- float hscale, vscale;
- float shear;
- int thickness;//<- weight in Qt
- float dx;//spacing letter in Qt (0 default) in pixel
- int line_type;//<- pointSize in Qt
- */
- CvFont f = {nameFont,color,style,NULL,NULL,NULL,0,0,0,weight,spacing,pointSize};
- return f;
-}
-
-
-
-CV_IMPL void cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont* font)
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "putText",
- Qt::AutoConnection,
- Q_ARG(void*, (void*) img),
- Q_ARG(QString,QString(text)),
- Q_ARG(QPoint, QPoint(org.x,org.y)),
- Q_ARG(void*,(void*) font));
-}
-
-double cvGetRatioWindow_QT(const char* name)
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- double result = -1;
- QMetaObject::invokeMethod(guiMainThread,
- "getRatioWindow",
- //Qt::DirectConnection,
- Qt::AutoConnection,
- Q_RETURN_ARG(double, result),
- Q_ARG(QString, QString(name)));
- return result;
-}
-
-void cvSetRatioWindow_QT(const char* name,double prop_value)
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "setRatioWindow",
- Qt::AutoConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(double, prop_value));
-}
-
-double cvGetPropWindow_QT(const char* name)
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- double result = -1;
- QMetaObject::invokeMethod(guiMainThread,
- "getPropWindow",
- //Qt::DirectConnection,
- Qt::AutoConnection,
- Q_RETURN_ARG(double, result),
- Q_ARG(QString, QString(name)));
- return result;
-}
-
-void cvSetPropWindow_QT(const char* name,double prop_value)
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "setPropWindow",
- Qt::AutoConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(double, prop_value));
-}
-
-void cvSetModeWindow_QT(const char* name, double prop_value)
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "toggleFullScreen",
- Qt::AutoConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(double, prop_value));
-}
-
-double cvGetModeWindow_QT(const char* name)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- double result = -1;
-
- QMetaObject::invokeMethod(guiMainThread,
- "isFullScreen",
- Qt::AutoConnection,
- Q_RETURN_ARG(double, result),
- Q_ARG(QString, QString(name)));
- return result;
-}
-
-CV_IMPL void cvDisplayOverlay(const char* name, const char* text, int delayms)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "displayInfo",
- Qt::AutoConnection,
- //Qt::DirectConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(QString, QString(text)),
- Q_ARG(int, delayms));
-
-}
-
-CV_IMPL void cvSaveWindowParameters(const char* name)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "saveWindowParameters",
- Qt::AutoConnection,
- Q_ARG(QString, QString(name)));
-}
-
-CV_IMPL void cvLoadWindowParameters(const char* name)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "loadWindowParameters",
- Qt::AutoConnection,
- Q_ARG(QString, QString(name)));
-}
-
-CV_IMPL void cvDisplayStatusBar(const char* name, const char* text, int delayms)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "displayStatusBar",
- Qt::AutoConnection,
- //Qt::DirectConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(QString, QString(text)),
- Q_ARG(int, delayms));
-}
-
-
-CV_IMPL int cvWaitKey( int arg )
-{
-
- int result = -1;
-
- if (!guiMainThread)
- return result;
-
- unsigned long delayms;//in milliseconds
- if (arg<=0)
- delayms = ULONG_MAX;
- else
- delayms = arg;
-
- if (multiThreads)
- {
- mutexKey.lock();
- if(key_pressed.wait(&mutexKey,delayms))//false if timeout
- {
- result = last_key;
- }
- last_key = -1;
- mutexKey.unlock();
-
- }else{
- //cannot use wait here because events will not be distributed before processEvents (the main eventLoop is broken)
- //so I create a Thread for the QTimer
-
- if (arg>0)
- guiMainThread->timer->start(arg);
-
- //QMutex dummy;
-
- while(!guiMainThread->_bTimeOut)
- {
- qApp->processEvents(QEventLoop::AllEvents);
-
-
- if (!guiMainThread)//when all the windows are deleted
- return result;
-
- mutexKey.lock();
- if (last_key != -1)
- {
- result = last_key;
- last_key = -1;
- guiMainThread->timer->stop();
- //printf("keypressed\n");
- }
- mutexKey.unlock();
-
- if (result!=-1)
- {
- break;
- }
- else
- {
- /*
- * //will not work, I broke the event loop !!!!
- dummy.lock();
- QWaitCondition waitCondition;
- waitCondition.wait(&dummy, 2);
- */
-
- //to decrease CPU usage
- //sleep 1 millisecond
-#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
- Sleep(1);
-#else
- usleep(1000);
-#endif
-
- }
- }
- guiMainThread->_bTimeOut = false;
-
- }
-
- return result;
-}
-
-//Yannick Verdie
-//This function is experimental and some functions (such as cvSet/getWindowProperty will not work)
-//We recommend not using this function for now
-CV_IMPL int cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[])
-{
- multiThreads = true;
- QFuture<int> future = QtConcurrent::run(pt2Func,argc,argv);
- return guiMainThread->start();
-}
-
-CV_IMPL void cvStopLoop()
-{
-
- qApp->exit();
-}
-
-
-CvWindow* icvFindWindowByName( const char* arg )
-{
-
- QPointer<CvWindow> window;
-
- if( !arg )
- CV_Error( CV_StsNullPtr, "NULL name string" );
-
- QString name(arg);
- CvWindow* w;
-
- foreach (QWidget *widget, QApplication::topLevelWidgets())
- {
-
- if (widget->isWindow() && !widget->parentWidget ())//is a window without parent
- {
- w = (CvWindow*) widget;
- if (w->param_name==name)
- {
- window = w;
- break;
- }
- }
- }
-
-
- return window;
-}
-
-
-CvBar* icvFindBarbyName(QBoxLayout* layout, QString name_bar, typeBar type)
-{
- if (!layout)
- return NULL;
-
- CvBar* t;
-
- int stop_index = layout->layout()->count();
-
- for (int i = 0; i < stop_index; ++i)
- {
- t = (CvBar*) layout->layout()->itemAt(i);
- if (t->type == type && t->name_bar == name_bar)
- return t;
- }
-
- return NULL;
-}
-
-CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window, QBoxLayout* layout = NULL )
-{
- QString nameQt(name_trackbar);
- CvBar* result = NULL;
-
- if (!name_window && global_control_panel)//window name is null and we have a control panel
- layout = global_control_panel->myLayout;
-
- if (!layout)
- {
- QPointer<CvWindow> w = icvFindWindowByName( name_window );
-
- if( !w )
- CV_Error( CV_StsNullPtr, "NULL window handler" );
-
- if ( w->param_gui_mode == CV_GUI_NORMAL)
- return (CvTrackbar*) icvFindBarbyName( w->myBarLayout, nameQt, type_CvTrackbar);
-
- if ( w->param_gui_mode == CV_GUI_EXPANDED)
- {
- result = icvFindBarbyName( w->myBarLayout, nameQt, type_CvTrackbar);
-
- if (result)
- return (CvTrackbar*) result;
-
- return (CvTrackbar*) icvFindBarbyName(global_control_panel->myLayout, nameQt, type_CvTrackbar);
- }
-
- return NULL;
- }else
- //layout was specified
- {
- return (CvTrackbar*) icvFindBarbyName( layout, nameQt, type_CvTrackbar);
- }
-}
-
-CvButtonbar* icvFindButtonbarByName( const char* button_name,QBoxLayout* layout)
-{
- QString nameQt(button_name);
- return (CvButtonbar*) icvFindBarbyName( layout, nameQt, type_CvButtonbar);
-}
-
-int icvInitSystem(int *c, char** v)
-{
- static int wasInitialized = 0;
-
- // check initialization status
- if( !wasInitialized)
- {
- new QApplication(*c,v);
-
- wasInitialized = 1;
- qDebug()<<"init done";
-
-#if defined( HAVE_QT_OPENGL )//OK tested !
- qDebug()<<"opengl support available";
-#endif
- }
-
- return 0;
-}
-
-CV_IMPL int cvInitSystem( int, char** )
-{
- icvInitSystem(¶meterSystemC, parameterSystemV);
- return 0;
-}
-
-
-CV_IMPL int cvNamedWindow( const char* name, int flags )
-{
-
- if (!guiMainThread)
- guiMainThread = new GuiReceiver;
-
- if (multiThreads)
- QMetaObject::invokeMethod(guiMainThread,
- "createWindow",
- Qt::BlockingQueuedConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(int, flags));
- else
- guiMainThread->createWindow(QString(name),flags);
-
- return 1;//Dummy value
-}
-
-CV_IMPL void cvDestroyWindow( const char* name )
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "destroyWindow",
- //Qt::BlockingQueuedConnection,
- Qt::AutoConnection,
- Q_ARG(QString, QString(name))
- );
-}
-
-
-
-CV_IMPL void cvDestroyAllWindows(void)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "destroyAllWindow",
- //Qt::BlockingQueuedConnection,
- Qt::AutoConnection
- );
-}
-
-CV_IMPL void* cvGetWindowHandle( const char* name )
-{
- if( !name )
- CV_Error( CV_StsNullPtr, "NULL name string" );
-
- return (void*) icvFindWindowByName( name );
-}
-
-CV_IMPL const char* cvGetWindowName( void* window_handle )
-{
-
- if( !window_handle )
- CV_Error( CV_StsNullPtr, "NULL window handler" );
-
- return ((CvWindow*)window_handle)->windowTitle().toLatin1().data();
-}
-
-CV_IMPL void cvMoveWindow( const char* name, int x, int y )
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "moveWindow",
- //Qt::BlockingQueuedConnection,
- Qt::AutoConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(int, x),
- Q_ARG(int, y)
- );
-
-}
-
-CV_IMPL void cvResizeWindow(const char* name, int width, int height )
-{
-
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "resizeWindow",
- //Qt::BlockingQueuedConnection,
- Qt::AutoConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(int, width),
- Q_ARG(int, height)
- );
-
-}
-
-CV_IMPL int cvCreateTrackbar2( const char* name_bar, const char* window_name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata )
-{
+//IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. \r
+\r
+// By downloading, copying, installing or using the software you agree to this license.\r
+// If you do not agree to this license, do not download, install,\r
+// copy or use the software.\r
+\r
+\r
+// License Agreement\r
+// For Open Source Computer Vision Library\r
+\r
+//Copyright (C) 2000-2008, Intel Corporation, all rights reserved.\r
+//Copyright (C) 2008-2010, Willow Garage Inc., all rights reserved.\r
+//Third party copyrights are property of their respective owners.\r
+\r
+//Redistribution and use in source and binary forms, with or without modification,\r
+//are permitted provided that the following conditions are met:\r
+\r
+// * Redistribution's of source code must retain the above copyright notice,\r
+// this list of conditions and the following disclaimer.\r
+\r
+// * Redistribution's in binary form must reproduce the above copyright notice,\r
+// this list of conditions and the following disclaimer in the documentation\r
+// and/or other materials provided with the distribution.\r
+\r
+// * The name of the copyright holders may not be used to endorse or promote products\r
+// derived from this software without specific prior written permission.\r
+\r
+//This software is provided by the copyright holders and contributors "as is" and\r
+//any express or implied warranties, including, but not limited to, the implied\r
+//warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+//In no event shall the Intel Corporation or contributors be liable for any direct,\r
+//indirect, incidental, special, exemplary, or consequential damages\r
+//(including, but not limited to, procurement of substitute goods or services;\r
+//loss of use, data, or profits; or business interruption) however caused\r
+//and on any theory of liability, whether in contract, strict liability,\r
+//or tort (including negligence or otherwise) arising in any way out of\r
+//the use of this software, even if advised of the possibility of such damage.\r
+\r
+//--------------------Google Code 2010 -- Yannick Verdie--------------------//\r
+\r
+\r
+#if defined(HAVE_QT)\r
+\r
+#include <window_QT.h>\r
+\r
+//Static and global first\r
+static GuiReceiver *guiMainThread = NULL;\r
+static int parameterSystemC = 1;\r
+static char* parameterSystemV[] = {""};\r
+static bool multiThreads = false;\r
+static int last_key = -1;\r
+QWaitCondition key_pressed;\r
+QMutex mutexKey;\r
+static const unsigned int threshold_zoom_img_region = 15;\r
+//the minimum zoom value to start displaying the values in the grid\r
+//that is also the number of pixel per grid\r
+\r
+static CvWinProperties* global_control_panel = NULL;\r
+//end static and global\r
+\r
+\r
+\r
+CV_IMPL CvFont cvFontQt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing)\r
+{\r
+\r
+ /*\r
+ //nameFont <- only Qt\r
+ //CvScalar color <- only Qt (blue_component, green_component, red\_component[, alpha_component])\r
+ int font_face;//<- style in Qt\r
+ const int* ascii;\r
+ const int* greek;\r
+ const int* cyrillic;\r
+ float hscale, vscale;\r
+ float shear;\r
+ int thickness;//<- weight in Qt\r
+ float dx;//spacing letter in Qt (0 default) in pixel\r
+ int line_type;//<- pointSize in Qt\r
+ */\r
+ CvFont f = {nameFont,color,style,NULL,NULL,NULL,0,0,0,weight,spacing,pointSize};\r
+ return f;\r
+}\r
+\r
+\r
+\r
+CV_IMPL void cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont* font)\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "putText",\r
+ Qt::AutoConnection,\r
+ Q_ARG(void*, (void*) img),\r
+ Q_ARG(QString,QString(text)),\r
+ Q_ARG(QPoint, QPoint(org.x,org.y)),\r
+ Q_ARG(void*,(void*) font));\r
+}\r
+\r
+double cvGetRatioWindow_QT(const char* name)\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ double result = -1;\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "getRatioWindow",\r
+ //Qt::DirectConnection,\r
+ Qt::AutoConnection,\r
+ Q_RETURN_ARG(double, result),\r
+ Q_ARG(QString, QString(name)));\r
+ return result;\r
+}\r
+\r
+void cvSetRatioWindow_QT(const char* name,double prop_value)\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "setRatioWindow",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(double, prop_value));\r
+}\r
+\r
+double cvGetPropWindow_QT(const char* name)\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ double result = -1;\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "getPropWindow",\r
+ //Qt::DirectConnection,\r
+ Qt::AutoConnection,\r
+ Q_RETURN_ARG(double, result),\r
+ Q_ARG(QString, QString(name)));\r
+ return result;\r
+}\r
+\r
+void cvSetPropWindow_QT(const char* name,double prop_value)\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "setPropWindow",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(double, prop_value));\r
+}\r
+\r
+void cvSetModeWindow_QT(const char* name, double prop_value)\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "toggleFullScreen",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(double, prop_value));\r
+}\r
+\r
+double cvGetModeWindow_QT(const char* name)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ double result = -1;\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "isFullScreen",\r
+ Qt::AutoConnection,\r
+ Q_RETURN_ARG(double, result),\r
+ Q_ARG(QString, QString(name)));\r
+ return result;\r
+}\r
+\r
+CV_IMPL void cvDisplayOverlay(const char* name, const char* text, int delayms)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "displayInfo",\r
+ Qt::AutoConnection,\r
+ //Qt::DirectConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(QString, QString(text)),\r
+ Q_ARG(int, delayms));\r
+\r
+}\r
+\r
+CV_IMPL void cvSaveWindowParameters(const char* name)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "saveWindowParameters",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name)));\r
+}\r
+\r
+CV_IMPL void cvLoadWindowParameters(const char* name)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "loadWindowParameters",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name)));\r
+}\r
+\r
+CV_IMPL void cvDisplayStatusBar(const char* name, const char* text, int delayms)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "displayStatusBar",\r
+ Qt::AutoConnection,\r
+ //Qt::DirectConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(QString, QString(text)),\r
+ Q_ARG(int, delayms));\r
+}\r
+\r
+\r
+CV_IMPL int cvWaitKey( int arg )\r
+{\r
+\r
+ int result = -1;\r
+\r
+ if (!guiMainThread)\r
+ return result;\r
+\r
+ unsigned long delayms;//in milliseconds\r
+ if (arg<=0)\r
+ delayms = ULONG_MAX;\r
+ else\r
+ delayms = arg;\r
+\r
+ if (multiThreads)\r
+ {\r
+ mutexKey.lock();\r
+ if(key_pressed.wait(&mutexKey,delayms))//false if timeout\r
+ {\r
+ result = last_key;\r
+ }\r
+ last_key = -1;\r
+ mutexKey.unlock();\r
+\r
+ }else{\r
+ //cannot use wait here because events will not be distributed before processEvents (the main eventLoop is broken)\r
+ //so I create a Thread for the QTimer\r
+\r
+ if (arg>0)\r
+ guiMainThread->timer->start(arg);\r
+\r
+ //QMutex dummy;\r
+\r
+ while(!guiMainThread->_bTimeOut)\r
+ {\r
+ qApp->processEvents(QEventLoop::AllEvents);\r
+\r
+\r
+ if (!guiMainThread)//when all the windows are deleted\r
+ return result;\r
+\r
+ mutexKey.lock();\r
+ if (last_key != -1)\r
+ {\r
+ result = last_key;\r
+ last_key = -1;\r
+ guiMainThread->timer->stop();\r
+ //printf("keypressed\n");\r
+ }\r
+ mutexKey.unlock();\r
+\r
+ if (result!=-1)\r
+ {\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ /*\r
+ * //will not work, I broke the event loop !!!!\r
+ dummy.lock();\r
+ QWaitCondition waitCondition;\r
+ waitCondition.wait(&dummy, 2);\r
+ */\r
+\r
+ //to decrease CPU usage\r
+ //sleep 1 millisecond\r
+#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64\r
+ Sleep(1);\r
+#else\r
+ usleep(1000);\r
+#endif\r
+\r
+ }\r
+ }\r
+ guiMainThread->_bTimeOut = false;\r
+\r
+ }\r
+\r
+ return result;\r
+}\r
+\r
+//Yannick Verdie\r
+//This function is experimental and some functions (such as cvSet/getWindowProperty will not work)\r
+//We recommend not using this function for now\r
+CV_IMPL int cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[])\r
+{\r
+ multiThreads = true;\r
+ QFuture<int> future = QtConcurrent::run(pt2Func,argc,argv);\r
+ return guiMainThread->start();\r
+}\r
+\r
+CV_IMPL void cvStopLoop()\r
+{\r
+\r
+ qApp->exit();\r
+}\r
+\r
+\r
+CvWindow* icvFindWindowByName( const char* arg )\r
+{\r
+\r
+ QPointer<CvWindow> window;\r
+\r
+ if( !arg )\r
+ CV_Error( CV_StsNullPtr, "NULL name string" );\r
+\r
+ QString name(arg);\r
+ CvWindow* w;\r
+\r
+ foreach (QWidget *widget, QApplication::topLevelWidgets())\r
+ {\r
+\r
+ if (widget->isWindow() && !widget->parentWidget ())//is a window without parent\r
+ {\r
+ w = (CvWindow*) widget;\r
+ if (w->param_name==name)\r
+ {\r
+ window = w;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ return window;\r
+}\r
+\r
+\r
+CvBar* icvFindBarbyName(QBoxLayout* layout, QString name_bar, typeBar type)\r
+{\r
+ if (!layout)\r
+ return NULL;\r
+\r
+ CvBar* t;\r
+\r
+ int stop_index = layout->layout()->count();\r
+\r
+ for (int i = 0; i < stop_index; ++i)\r
+ {\r
+ t = (CvBar*) layout->layout()->itemAt(i);\r
+ if (t->type == type && t->name_bar == name_bar)\r
+ return t;\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window, QBoxLayout* layout = NULL )\r
+{\r
+ QString nameQt(name_trackbar);\r
+ CvBar* result = NULL;\r
+\r
+ if (!name_window && global_control_panel)//window name is null and we have a control panel\r
+ layout = global_control_panel->myLayout;\r
+\r
+ if (!layout)\r
+ {\r
+ QPointer<CvWindow> w = icvFindWindowByName( name_window );\r
+\r
+ if( !w )\r
+ CV_Error( CV_StsNullPtr, "NULL window handler" );\r
+\r
+ if ( w->param_gui_mode == CV_GUI_NORMAL)\r
+ return (CvTrackbar*) icvFindBarbyName( w->myBarLayout, nameQt, type_CvTrackbar);\r
+\r
+ if ( w->param_gui_mode == CV_GUI_EXPANDED)\r
+ {\r
+ result = icvFindBarbyName( w->myBarLayout, nameQt, type_CvTrackbar);\r
+\r
+ if (result)\r
+ return (CvTrackbar*) result;\r
+\r
+ return (CvTrackbar*) icvFindBarbyName(global_control_panel->myLayout, nameQt, type_CvTrackbar);\r
+ }\r
+\r
+ return NULL;\r
+ }else\r
+ //layout was specified\r
+ {\r
+ return (CvTrackbar*) icvFindBarbyName( layout, nameQt, type_CvTrackbar);\r
+ }\r
+}\r
+\r
+CvButtonbar* icvFindButtonbarByName( const char* button_name,QBoxLayout* layout)\r
+{\r
+ QString nameQt(button_name);\r
+ return (CvButtonbar*) icvFindBarbyName( layout, nameQt, type_CvButtonbar);\r
+}\r
+\r
+int icvInitSystem(int *c, char** v)\r
+{\r
+ static int wasInitialized = 0;\r
+\r
+ // check initialization status\r
+ if( !wasInitialized)\r
+ {\r
+ new QApplication(*c,v);\r
+\r
+ wasInitialized = 1;\r
+ qDebug()<<"init done";\r
+\r
+#if defined( HAVE_QT_OPENGL )\r
+ qDebug()<<"opengl support available";\r
+#endif\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+CV_IMPL int cvInitSystem( int, char** )\r
+{\r
+ icvInitSystem(¶meterSystemC, parameterSystemV);\r
+ return 0;\r
+}\r
+\r
+\r
+CV_IMPL int cvNamedWindow( const char* name, int flags )\r
+{\r
+\r
+ if (!guiMainThread)\r
+ guiMainThread = new GuiReceiver;\r
+\r
+ if (multiThreads)\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "createWindow",\r
+ Qt::BlockingQueuedConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(int, flags));\r
+ else\r
+ guiMainThread->createWindow(QString(name),flags);\r
+\r
+ return 1;//Dummy value\r
+}\r
+\r
+CV_IMPL void cvDestroyWindow( const char* name )\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "destroyWindow",\r
+ //Qt::BlockingQueuedConnection,\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name))\r
+ );\r
+}\r
+\r
+\r
+\r
+CV_IMPL void cvDestroyAllWindows(void)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "destroyAllWindow",\r
+ //Qt::BlockingQueuedConnection,\r
+ Qt::AutoConnection\r
+ );\r
+}\r
+\r
+CV_IMPL void* cvGetWindowHandle( const char* name )\r
+{\r
+ if( !name )\r
+ CV_Error( CV_StsNullPtr, "NULL name string" );\r
+\r
+ return (void*) icvFindWindowByName( name );\r
+}\r
+\r
+CV_IMPL const char* cvGetWindowName( void* window_handle )\r
+{\r
+\r
+ if( !window_handle )\r
+ CV_Error( CV_StsNullPtr, "NULL window handler" );\r
+\r
+ return ((CvWindow*)window_handle)->windowTitle().toLatin1().data();\r
+}\r
+\r
+CV_IMPL void cvMoveWindow( const char* name, int x, int y )\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "moveWindow",\r
+ //Qt::BlockingQueuedConnection,\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(int, x),\r
+ Q_ARG(int, y)\r
+ );\r
+\r
+}\r
+\r
+CV_IMPL void cvResizeWindow(const char* name, int width, int height )\r
+{\r
+\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "resizeWindow",\r
+ //Qt::BlockingQueuedConnection,\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(int, width),\r
+ Q_ARG(int, height)\r
+ );\r
+\r
+}\r
+\r
+CV_IMPL int cvCreateTrackbar2( const char* name_bar, const char* window_name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata )\r
+{\r
if (!guiMainThread) \r
CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); \r
\r
Q_ARG(void*, (void*)userdata) \r
); \r
\r
- return 1;//dummy value
-}
-
-CV_IMPL int cvStartWindowThread()
-{
- return 0;
-}
-
-CV_IMPL int cvCreateTrackbar( const char* name_bar, const char* window_name, int* value, int count, CvTrackbarCallback on_change)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "addSlider",
- Qt::AutoConnection,
- Q_ARG(QString, QString(name_bar)),
- Q_ARG(QString, QString(window_name)),
- Q_ARG(void*, (void*)value),
- Q_ARG(int, count),
- Q_ARG(void*, (void*)on_change)
- );
-
- return 1;//dummy value
-}
-
-
-
-CV_IMPL int cvCreateButton(const char* button_name,CvButtonCallback on_change, void* userdata , int button_type, int initial_button_state )
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- if (initial_button_state < 0 || initial_button_state > 1)
- return 0;
-
- QMetaObject::invokeMethod(guiMainThread,
- "addButton",
- Qt::AutoConnection,
- Q_ARG(QString, QString(button_name)),
- Q_ARG(int, button_type),
- Q_ARG(int, initial_button_state),
- Q_ARG(void*, (void*)on_change),
- Q_ARG(void*, userdata)
- );
-
- return 1;//dummy value
-}
-
-CV_IMPL void cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata, double angle, double zmin, double zmax)
-{
- if (!guiMainThread)
- CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );
-
- QMetaObject::invokeMethod(guiMainThread,
- "setOpenGLCallback",
- Qt::AutoConnection,
- Q_ARG(QString, QString(window_name)),
- Q_ARG(void*, (void*)callbackOpenGL),
- Q_ARG(void*, userdata),
- Q_ARG(double, angle),
- Q_ARG(double, zmin),
- Q_ARG(double, zmax)
- );
-}
-
-CV_IMPL int cvGetTrackbarPos( const char* name_bar, const char* window_name )
-{
- int result = -1;
-
- QPointer<CvTrackbar> t = icvFindTrackbarByName( name_bar, window_name );
-
- if (t)
- result = t->slider->value();
-
- return result;
-}
-
-CV_IMPL void cvSetTrackbarPos( const char* name_bar, const char* window_name, int pos )
-{
-
- QPointer<CvTrackbar> t = icvFindTrackbarByName( name_bar, window_name );
-
- if (t)
- t->slider->setValue(pos);
-
-}
-
-/* assign callback for mouse events */
-CV_IMPL void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,void* param )
-{
- QPointer<CvWindow> w = icvFindWindowByName( window_name );
-
- if (!w)
- CV_Error(CV_StsNullPtr, "NULL window handler" );
-
- w->setMouseCallBack(on_mouse, param);
-
-}
-
-CV_IMPL void cvShowImage( const char* name, const CvArr* arr )
-{
-
- if (!guiMainThread)
- guiMainThread = new GuiReceiver;
-
- QMetaObject::invokeMethod(guiMainThread,
- "showImage",
- //Qt::BlockingQueuedConnection,
- Qt::DirectConnection,
- Q_ARG(QString, QString(name)),
- Q_ARG(void*, (void*)arr)
- );
-}
-
-
-//----------OBJECT----------------
-
-GuiReceiver::GuiReceiver() : _bTimeOut(false), nb_windows(0)
-{
- icvInitSystem(¶meterSystemC, parameterSystemV);
-
- timer = new QTimer;
- QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timeOut()));
- timer->setSingleShot(true);
-}
-
-
-void GuiReceiver::isLastWindow()
-{
- if (--nb_windows <= 0)
- {
- delete guiMainThread;
- guiMainThread = NULL;
- qApp->quit();
- }
-}
-
-GuiReceiver::~GuiReceiver()
-{
- if (global_control_panel)
- delete global_control_panel;
-
- delete timer;
-}
-
-void GuiReceiver::putText(void* arg1, QString text, QPoint org, void* arg2)
-{
- CV_Assert(arg1)
-
- IplImage* img = (IplImage*)arg1;
-
- //for now, only support QImage::Format_RGB888
- if (img->depth !=IPL_DEPTH_8U || img->nChannels != 3)
- return;
-
- CvFont* font = (CvFont*)arg2;
-
-
-
- QImage qimg((uchar*) img->imageData, img->width, img->height,QImage::Format_RGB888);
- QPainter qp(&qimg);
- if (font)
- {
- QFont f(font->nameFont, font->line_type/*PointSize*/, font->thickness/*weight*/);
- f.setStyle((QFont::Style)font->font_face/*style*/);
- f.setLetterSpacing ( QFont::AbsoluteSpacing, font->dx/*spacing*/ );
- //cvScalar(blue_component, green_component, red\_component[, alpha_component])
- //Qt map non-transparent to 0xFF and transparent to 0
- //OpenCV scalar is the reverse, so 255-font->color.val[3]
- qp.setPen(QColor(font->color.val[2],font->color.val[1],font->color.val[0],255-font->color.val[3]));
- qp.setFont ( f );
- }
- qp.drawText (org, text );
- qp.end();
-}
-
-void GuiReceiver::saveWindowParameters(QString name)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (w)
- w->writeSettings();
-}
-
-void GuiReceiver::loadWindowParameters(QString name)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (w)
- w->readSettings();
-}
-
-double GuiReceiver::getRatioWindow(QString name)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
-
- if (!w)
- return -1;
-
- return (double)w->getView()->getRatio();
-}
-
-void GuiReceiver::setRatioWindow(QString name, double arg2 )
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (!w)
- return;
-
- int flags = (int) arg2;
-
- if (w->getView()->getRatio() == flags)//nothing to do
- return;
-
- //if valid flags
- if (flags == CV_WINDOW_FREERATIO || flags == CV_WINDOW_KEEPRATIO)
- w->getView()->setRatio(flags);
-
-}
-
-double GuiReceiver::getPropWindow(QString name)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
-
- if (!w)
- return -1;
-
- return (double)w->param_flags;
-}
-
-void GuiReceiver::setPropWindow(QString name, double arg2 )
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (!w)
- return;
-
- int flags = (int) arg2;
-
- if (w->param_flags == flags)//nothing to do
- return;
-
-
- switch(flags)
- {
- case CV_WINDOW_NORMAL:
- w->myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
- w->param_flags = flags;
-
- break;
- case CV_WINDOW_AUTOSIZE:
- w->myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize);
- w->param_flags = flags;
-
- break;
- default:;
- }
-}
-
-double GuiReceiver::isFullScreen(QString name)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (!w)
- return -1;
-
- if (w->isFullScreen())
- return CV_WINDOW_FULLSCREEN;
- else
- return CV_WINDOW_NORMAL;
-}
-
-//accept CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN
-void GuiReceiver::toggleFullScreen(QString name, double flags )
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (!w)
- return;
-
- if (w->isFullScreen() && flags == CV_WINDOW_NORMAL)
- {
- w->showTools();
- w->showNormal();
- return;
- }
-
- if (!w->isFullScreen() && flags == CV_WINDOW_FULLSCREEN)
- {
- w->hideTools();
- w->showFullScreen();
- return;
- }
-
-}
-
-void GuiReceiver::createWindow( QString name, int flags )
-{
- if (!qApp)
- CV_Error(CV_StsNullPtr, "NULL session handler" );
-
- // Check the name in the storage
- if( icvFindWindowByName( name.toLatin1().data() ))
- {
- return;
- }
-
- //QPointer<CvWindow> w1 =
- nb_windows++;
- new CvWindow(name, flags);
-}
-
-void GuiReceiver::timeOut()
-{
- _bTimeOut = true;
-}
-
-void GuiReceiver::displayInfo( QString name, QString text, int delayms )
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (w && delayms > 0)
- w->displayInfo(text,delayms);
-}
-
-void GuiReceiver::displayStatusBar( QString name, QString text, int delayms )
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (w && delayms > 0)
- if (w->myStatusBar)//if statusbar was created
- w->displayStatusBar(text,delayms);
-}
-
-void GuiReceiver::showImage(QString name, void* arr)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (!w)//as observed in the previous implementation (W32, GTK or Carbon), create a new window is the pointer returned is null
- {
- cvNamedWindow( name.toLatin1().data() );
- w = icvFindWindowByName( name.toLatin1().data() );
- }
-
- if( w && arr )
- {
- w->updateImage(arr);
- }
- else
- {
- CV_Error(CV_StsNullPtr, "Do nothing (Window or Image NULL)");
- }
-}
-
-void GuiReceiver::destroyWindow(QString name)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (w)
- {
- w->close();
- //in not-multiThreads mode, looks like the window is hidden but not deleted
- //so I do it manually
- //otherwise QApplication do it for me if the exec command was executed (in multiThread mode)
- if (!multiThreads)
- delete w;
- }
-}
-
-void GuiReceiver::destroyAllWindow()
-{
- if (!qApp)
- CV_Error(CV_StsNullPtr, "NULL session handler" );
-
- if (multiThreads)
- {
- qApp->closeAllWindows();
- }else{
-
- foreach (QObject *obj, QApplication::topLevelWidgets())
- {
- if (obj->metaObject ()->className () == "CvWindow")
- {
- delete obj;
- }
- }
-
- }
-
-}
-
-void GuiReceiver::setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata, double angle, double zmin, double zmax)
-{
- QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );
-
- if (w && callbackOpenGL)
- w->setOpenGLCallback((CvOpenGLCallback) callbackOpenGL, userdata,angle,zmin,zmax);
-}
-
-void GuiReceiver::moveWindow(QString name, int x, int y)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (w)
- w->move(x,y);
-
-}
-
-void GuiReceiver::resizeWindow(QString name, int width, int height)
-{
- QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
-
- if (w)
- w->resize(width, height);
-}
-
-void GuiReceiver::enablePropertiesButtonEachWindow()
-{
- CvWindow* w;
-
- //For each window, enable window property button
- foreach (QWidget *widget, QApplication::topLevelWidgets())
- {
-
- if (widget->isWindow() && !widget->parentWidget ())//is a window without parent
- {
- w = (CvWindow*) widget;
- //active window properties button
- w->vect_QActions[9]->setDisabled(false);
- }
- }
-}
-
-void GuiReceiver::addButton(QString button_name, int button_type, int initial_button_state , void* on_change, void* userdata)
-{
-
- if (!global_control_panel)
- return;
-
- QPointer<CvButtonbar> b;// = icvFindButtonbarByName( button_name.toLatin1().data(), global_control_panel->myLayout );
-
- //if (b)//button with this name already exist
- // return;
-
- if (global_control_panel->myLayout->count() == 0)//if that is the first button attach to the control panel, create a new button bar
- {
- b = CvWindow::createButtonbar(button_name);//the bar has the name of the first button attached to it
-
- enablePropertiesButtonEachWindow();
-
- }else{
- CvBar* lastbar = (CvBar*) global_control_panel->myLayout->itemAt(global_control_panel->myLayout->count()-1);
-
- if (lastbar->type == type_CvTrackbar)//if last bar is a trackbar, create a new buttonbar, else, attach to the current bar
- b = CvWindow::createButtonbar(button_name);//the bar has the name of the first button attached to it
- else
- b = (CvButtonbar*) lastbar;
-
- }
-
- b->addButton( button_name,(CvButtonCallback) on_change, userdata, button_type, initial_button_state);
-}
-
-void GuiReceiver::addSlider2(QString bar_name, QString window_name, void* value, int count, void* on_change, void *userdata)
-{
- QBoxLayout *layout = NULL;
- QPointer<CvWindow> w;
- if (window_name != "")
- {
- w = icvFindWindowByName( window_name.toLatin1().data() );
-
- if (!w)
- return;
- }else{
- if (global_control_panel)
- layout = global_control_panel->myLayout;
- }
-
- QPointer<CvTrackbar> t = icvFindTrackbarByName( bar_name.toLatin1().data() , window_name.toLatin1().data(), layout );
-
- if (t)//trackbar exists
- return;
-
- if (!value)
- CV_Error(CV_StsNullPtr, "NULL value pointer" );
-
- if (count<= 0)//count is the max value of the slider, so must be bigger than 0
- CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" );
-
- CvWindow::addSlider2(w,bar_name,(int*)value,count,(CvTrackbarCallback2) on_change, userdata);
-}
-
-void GuiReceiver::addSlider(QString bar_name, QString window_name, void* value, int count, void* on_change)
-{
- QBoxLayout *layout = NULL;
- QPointer<CvWindow> w;
- if (window_name != "")
- {
- w = icvFindWindowByName( window_name.toLatin1().data() );
-
- if (!w)
- return;
- }else{
- if (global_control_panel)
- layout = global_control_panel->myLayout;
- }
-
- QPointer<CvTrackbar> t = icvFindTrackbarByName( bar_name.toLatin1().data() , window_name.toLatin1().data(), layout );
-
- if (t)//trackbar exists
- return;
-
- if (!value)
- CV_Error(CV_StsNullPtr, "NULL value pointer" );
-
- if (count<= 0)//count is the max value of the slider, so must be bigger than 0
- CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" );
-
- CvWindow::addSlider(w,bar_name,(int*)value,count,(CvTrackbarCallback) on_change);
-}
-
-int GuiReceiver::start()
-{
- return qApp->exec();
-}
-
-CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTrackbarCallback2 on_change, void* data )
-{
- callback = NULL;
- callback2 = on_change;
- userdata = data;
-
- construc_trackbar(arg,name, value, count);
-}
-
-CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTrackbarCallback on_change )
-{
- callback = on_change;
- callback2 = NULL;
- userdata = NULL;
-
- construc_trackbar(arg,name, value, count);
-}
-
-void CvTrackbar::construc_trackbar(CvWindow* arg, QString name, int* value, int count)
-{
- type=type_CvTrackbar;
- myparent = arg;
- name_bar = name;
- setObjectName(name_bar);
- dataSlider = value;
-
- slider = new QSlider(Qt::Horizontal);
- slider->setFocusPolicy(Qt::StrongFocus);
- slider->setMinimum(0);
- slider->setMaximum(count);
- slider->setPageStep(5);
- slider->setValue(*value);
- slider->setTickPosition(QSlider::TicksBelow);
-
-
- //Change style of the Slider
- //slider->setStyleSheet(str_Trackbar_css);
-
- QFile qss(":/stylesheet-trackbar");
- if (qss.open(QFile::ReadOnly))
- {
- slider->setStyleSheet(QLatin1String(qss.readAll()));
- qss.close();
- }
-
-
- //this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?)
- //slider->setTickPosition(QSlider::TicksBelow);
- label = new QPushButton;
- label->setFlat(true);
- setLabel(slider->value());
-
-
- QObject::connect( slider, SIGNAL( valueChanged( int ) ),this, SLOT( update( int ) ) );
-
- QObject::connect( label, SIGNAL( clicked() ),this, SLOT( createDialog() ));
-
- //label->setStyleSheet("QPushButton:disabled {color: black}");
-
- addWidget(label,Qt::AlignLeft);//name + value
- addWidget(slider,Qt::AlignCenter);//slider
-}
-
-void CvTrackbar::createDialog()
-{
-
- bool ok= false;
-
- //crash if I access the values directly and give them to QInputDialog, so do a copy first.
- int value = slider->value();
- int step = slider->singleStep();
- int min = slider->minimum();
- int max = slider->maximum();
-
- int i =
-#if QT_VERSION >= 0x040500
- QInputDialog::getInt
-#else
- QInputDialog::getInteger
-#endif
- (this->parentWidget(),
- tr("Slider %1").arg(name_bar),
- tr("New value:"),
- value,
- min,
- max,
- step,
- &ok);
-
- if (ok)
- slider->setValue(i);
-
-}
-
-void CvTrackbar::update(int myvalue)
-{
- setLabel(myvalue);
-
- *dataSlider = myvalue;
- if (callback)
- {
- callback(myvalue);
- return;
- }
-
- if (callback2)
- {
- callback2(myvalue,userdata);
- return;
- }
-}
-
-void CvTrackbar::setLabel(int myvalue)
-{
- QString nameNormalized = name_bar.leftJustified( 10, ' ', true );
- QString valueMaximum = QString("%1").arg(slider->maximum());
- QString str = QString("%1 (%2/%3)").arg(nameNormalized).arg(myvalue,valueMaximum.length(),10,QChar('0')).arg(valueMaximum);
- label->setText(str);
-}
-
-CvTrackbar::~CvTrackbar()
-{
- delete slider;
- delete label;
-}
-
-
-
-
-//here CvButtonbar class
-CvButtonbar::CvButtonbar(QWidget* arg, QString arg2)
-{
- type=type_CvButtonbar;
- myparent = arg;
- name_bar = arg2;
- setObjectName(name_bar);
-
- group_button = new QButtonGroup;
-
- /*
- label = new QLabel;
- setLabel();
- addWidget(label,Qt::AlignLeft );
- */
-}
-
-CvButtonbar::~CvButtonbar()
-{
- QLayoutItem *child;
-
- while ((child = takeAt(0)) != 0)
- delete child;
-
- delete group_button;
-}
-
-void CvButtonbar::setLabel()
-{
- QString nameNormalized = name_bar.leftJustified( 10, ' ', true );
- label->setText(nameNormalized);
-}
-
-void CvButtonbar::addButton( QString name, CvButtonCallback call, void* userdata, int button_type, int initial_button_state)
-{
- QString button_name = name;
-
- if (button_name == "")
- button_name = tr("button %1").arg(this->count());
-
- QPointer<QAbstractButton> button;
-
- if (button_type == CV_PUSH_BUTTON)
- button = (QAbstractButton*) new CvPushButton(this, button_name,call, userdata);
-
- if (button_type == CV_CHECKBOX)
- button = (QAbstractButton*) new CvCheckBox(this, button_name,call, userdata, initial_button_state);
-
- if (button_type == CV_RADIOBOX)
- {
- button = (QAbstractButton*) new CvRadioButton(this, button_name,call, userdata, initial_button_state);
- group_button->addButton(button);
- }
-
- if (button)
- {
- QObject::connect( button, SIGNAL( toggled(bool) ),button, SLOT( callCallBack(bool) ));
- addWidget(button,Qt::AlignCenter);
- }
-}
-
-
-
-
-
-//buttons here
-CvPushButton::CvPushButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4)
-{
- myparent = arg1;
- button_name = arg2;
- callback = arg3;
- userdata=arg4;
-
- setObjectName(button_name);
- setText(button_name);
-
- if (isChecked())
- callCallBack(true);
-}
-
-void CvPushButton::callCallBack(bool checked)
-{
- if (callback)
- callback(checked,userdata);
-}
-
-CvCheckBox::CvCheckBox(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, int initial_button_state)
-{
- myparent = arg1;
- button_name = arg2;
- callback = arg3;
- userdata=arg4;
-
- setObjectName(button_name);
- setCheckState((initial_button_state == 1?Qt::Checked:Qt::Unchecked));
- setText(button_name);
-
- if (isChecked())
- callCallBack(true);
-}
-
-void CvCheckBox::callCallBack(bool checked)
-{
- if (callback)
- callback(checked,userdata);
-}
-
-CvRadioButton::CvRadioButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, int initial_button_state)
-{
- myparent = arg1;
- button_name = arg2;
- callback = arg3;
- userdata=arg4;
-
- setObjectName(button_name);
- setChecked(initial_button_state);
- setText(button_name);
-
- if (isChecked())
- callCallBack(true);
-}
-
-void CvRadioButton::callCallBack(bool checked)
-{
- if (callback)
- callback(checked,userdata);
-}
-
-
-
-
-//here CvWinProperties class
-CvWinProperties::CvWinProperties(QString name_paraWindow, QWidget* parent)
-{
- setParent(parent);
- setWindowFlags(Qt::Tool);
- setContentsMargins(0,0,0,0);
- setWindowTitle(name_paraWindow);
- setObjectName(name_paraWindow);
- resize(100,50);
-
- myLayout = new QBoxLayout(QBoxLayout::TopToBottom);
- myLayout->setObjectName(QString::fromUtf8("boxLayout"));
- myLayout->setContentsMargins(0, 0, 0, 0);
- myLayout->setSpacing(0);
- myLayout->setMargin(0);
- myLayout->setSizeConstraint(QLayout::SetFixedSize);
- setLayout(myLayout);
-
- hide();
-}
-
-void CvWinProperties::closeEvent ( QCloseEvent * e )
-{
- e->accept();//intersept the close event (not sure I really need it)
- //an hide event is also sent. I will intercept it and do some processing
-}
-
-void CvWinProperties::showEvent ( QShowEvent * event )
-{
- //why -1,-1 ?: do this trick because the first time the code is run,
- //no value pos was saved so we let Qt move the window in the middle of its parent (event ignored).
- //then hide will save the last position and thus, we want to retreive it (event accepted).
- QPoint mypos(-1,-1);
- QSettings settings("OpenCV2", this->windowTitle());
- mypos = settings.value("pos", mypos).toPoint();
-
- if (mypos.x()>=0)
- {
- move(mypos);
- event->accept();
- }
- else{
- event->ignore();
- }
-}
-
-void CvWinProperties::hideEvent ( QHideEvent * event )
-{
- QSettings settings("OpenCV2", this->windowTitle());
- settings.setValue("pos", pos());//there is an offset of 6 pixels (so the window's position is wrong -- why ?)
- event->accept();
-}
-
-CvWinProperties::~CvWinProperties()
-{
- //clear the setting pos
- QSettings settings("OpenCV2", this->windowTitle());
- settings.remove("pos");
-
-
- QLayoutItem *child;
- if (myLayout)
- {
- while ((child = myLayout->takeAt(0)) != 0)
- delete child;
-
- delete myLayout;
- }
-}
-
-
-
-
-
-
-//Here CvWindow class
-CvWindow::CvWindow(QString arg, int arg2)
-{
- moveToThread(qApp->instance()->thread());
- param_name = arg;
-
- param_flags = arg2 & 0x0000000F;
- param_gui_mode = arg2 & 0x000000F0;
- param_ratio_mode = arg2 & 0x00000F00;
-
- setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory
- setContentsMargins(0,0,0,0);
- setWindowTitle(param_name);
- setObjectName(param_name);
-
- resize(400,300);
-
- //1: create control panel
- if (!global_control_panel)
- global_control_panel = createParameterWindow();
-
- //2: Layouts
- createBarLayout();
- createGlobalLayout();
-
- //3: my view
- int mode_display = CV_MODE_NORMAL;
-#if defined( HAVE_QT_OPENGL )
- mode_display = CV_MODE_OPENGL;
-#endif
- createView(mode_display, param_ratio_mode);
-
- //4: shortcuts and actions
- createActionsandShortcuts();
-
- //5: toolBar and statusbar
- if (param_gui_mode == CV_GUI_EXPANDED)
- {
- createToolBar();
- createStatusBar();
- }
-
-
- //Now attach everything
- if (myToolBar)
- myGlobalLayout->addWidget(myToolBar,Qt::AlignCenter);
-
- myGlobalLayout->addWidget(myview,Qt::AlignCenter);
-
- myGlobalLayout->addLayout(myBarLayout,Qt::AlignCenter);
-
- if (myStatusBar)
- myGlobalLayout->addWidget(myStatusBar,Qt::AlignCenter);
-
- setLayout(myGlobalLayout);
- show();
-
-}
-
-CvWindow::~CvWindow()
-{
- QLayoutItem *child;
-
- if (myGlobalLayout)
- {
- while ((child = myGlobalLayout->takeAt(0)) != 0)
- delete child;
-
- delete myGlobalLayout;
- }
-
- if (myBarLayout)
- {
- while ((child = myBarLayout->takeAt(0)) != 0)
- delete child;
-
- delete myBarLayout;
- }
-
-
- if (myStatusBar)
- {
- delete myStatusBar;
- delete myStatusBar_msg;
- }
-
- if (myToolBar)
- {
- for (int i=0;i<vect_QActions.count();i++)
- delete vect_QActions[i];
-
- delete myToolBar;
- }
-
- for (int i=0;i<vect_QShortcuts.count();i++)
- delete vect_QShortcuts[i];
-
- if (guiMainThread)
- guiMainThread->isLastWindow();
-}
-
-
-
-CvButtonbar* CvWindow::createButtonbar(QString name_bar)
-{
- QPointer<CvButtonbar> t = new CvButtonbar(global_control_panel,name_bar);
- t->setAlignment(Qt::AlignHCenter);
-
- QPointer<QBoxLayout> myLayout = global_control_panel->myLayout;
-
- myLayout->insertLayout(myLayout->count(),t);
-
- return t;
-}
-
-
-void CvWindow::hideTools()
-{
- if (myToolBar)
- myToolBar->hide();
-
- if (myStatusBar)
- myStatusBar->hide();
-
- if (global_control_panel)
- global_control_panel->hide();
-}
-
-void CvWindow::showTools()
-{
- if (myToolBar)
- myToolBar->show();
-
- if (myStatusBar)
- myStatusBar->show();
-
-}
-
-CvWinProperties* CvWindow::createParameterWindow()
-{
- QString name_paraWindow =QFileInfo(QApplication::applicationFilePath()).fileName()+" settings";
-
- CvWinProperties *result = new CvWinProperties(name_paraWindow,this);
- return result;
-}
-
-void CvWindow::displayPropertiesWin()
-{
- if (global_control_panel->isHidden())
- global_control_panel->show();
- else
- global_control_panel->hide();
-}
-
-void CvWindow::createActionsandShortcuts()
-{
- vect_QActions.resize(10);
-
- //if the shortcuts are changed in window_QT.h, we need to update the tooltip manually
- vect_QActions[0] = new QAction(QIcon(":/left-icon"),"Panning left (CTRL+arrowLEFT)",this);
- vect_QActions[0]->setIconVisibleInMenu(true);
- vect_QActions[0]->setShortcut(shortcut_panning_left);
- QObject::connect( vect_QActions[0],SIGNAL(triggered()),myview, SLOT( siftWindowOnLeft() ));
-
- vect_QActions[1] = new QAction(QIcon(":/right-icon"),"Panning right (CTRL+arrowRIGHT)",this);
- vect_QActions[1]->setIconVisibleInMenu(true);
- vect_QActions[1]->setShortcut(shortcut_panning_right);
- QObject::connect( vect_QActions[1],SIGNAL(triggered()),myview, SLOT( siftWindowOnRight() ));
-
- vect_QActions[2] = new QAction(QIcon(":/up-icon"),"Panning up (CTRL+arrowUP)",this);
- vect_QActions[2]->setIconVisibleInMenu(true);
- vect_QActions[2]->setShortcut(shortcut_panning_up);
- QObject::connect( vect_QActions[2],SIGNAL(triggered()),myview, SLOT( siftWindowOnUp() ));
-
- vect_QActions[3] = new QAction(QIcon(":/down-icon"),"Panning down (CTRL+arrowDOWN)",this);
- vect_QActions[3]->setIconVisibleInMenu(true);
- vect_QActions[3]->setShortcut(shortcut_panning_down);
- QObject::connect( vect_QActions[3],SIGNAL(triggered()),myview, SLOT( siftWindowOnDown() ));
-
- vect_QActions[4] = new QAction(QIcon(":/zoom_x1-icon"),"Zoom x1 (CTRL+Z)",this);
- vect_QActions[4]->setIconVisibleInMenu(true);
- vect_QActions[4]->setShortcut(shortcut_zoom_normal);
- QObject::connect( vect_QActions[4],SIGNAL(triggered()),myview, SLOT( resetZoom() ));
-
- vect_QActions[5] = new QAction(QIcon(":/imgRegion-icon"),tr("Zoom x%1 (see label) (CTRL+X)")
- .arg(threshold_zoom_img_region)
- ,this);
- vect_QActions[5]->setIconVisibleInMenu(true);
- vect_QActions[5]->setShortcut(shortcut_zoom_imgRegion);
- QObject::connect( vect_QActions[5],SIGNAL(triggered()),myview, SLOT( imgRegion() ));
-
- vect_QActions[6] = new QAction(QIcon(":/zoom_in-icon"),tr("Zoom in (CTRL++)"),this);
- vect_QActions[6]->setIconVisibleInMenu(true);
- vect_QActions[6]->setShortcut(shortcut_zoom_in);
- QObject::connect( vect_QActions[6],SIGNAL(triggered()),myview, SLOT( ZoomIn() ));
-
- vect_QActions[7] = new QAction(QIcon(":/zoom_out-icon"),tr("Zoom out (CTRL+-)"),this);
- vect_QActions[7]->setIconVisibleInMenu(true);
- vect_QActions[7]->setShortcut(shortcut_zoom_out);
- QObject::connect( vect_QActions[7],SIGNAL(triggered()),myview, SLOT( ZoomOut() ));
-
- vect_QActions[8] = new QAction(QIcon(":/save-icon"),tr("Save current image (CTRL+S)"),this);
- vect_QActions[8]->setIconVisibleInMenu(true);
- vect_QActions[8]->setShortcut(shortcut_save_img);
- QObject::connect( vect_QActions[8],SIGNAL(triggered()),myview, SLOT( saveView() ));
-
- vect_QActions[9] = new QAction(QIcon(":/properties-icon"),tr("Display properties window (CTRL+P)"),this);
- vect_QActions[9]->setIconVisibleInMenu(true);
- vect_QActions[9]->setShortcut(shortcut_properties_win);
-
- if (global_control_panel->myLayout->count() == 0)
- vect_QActions[9]->setDisabled(true);
-
- QObject::connect( vect_QActions[9],SIGNAL(triggered()),this, SLOT( displayPropertiesWin() ));
-
-}
-
-void CvWindow::createToolBar()
-{
- myToolBar = new QToolBar(this);
- myToolBar->setFloatable(false);//is not a window
- myToolBar->setMaximumHeight(28);
-
- foreach (QAction *a, vect_QActions)
- myToolBar->addAction(a);
-}
-
-void CvWindow::createStatusBar()
-{
- myStatusBar = new QStatusBar(this);
- myStatusBar->setSizeGripEnabled(false);
- myStatusBar->setMaximumHeight(20);
- myStatusBar_msg = new QLabel;
- myStatusBar_msg->setFrameStyle(QFrame::Raised);
- myStatusBar_msg->setAlignment(Qt::AlignHCenter);
- myStatusBar->addWidget(myStatusBar_msg);
-}
-
-void CvWindow::createGlobalLayout()
-{
- myGlobalLayout = new QBoxLayout(QBoxLayout::TopToBottom);
- myGlobalLayout->setObjectName(QString::fromUtf8("boxLayout"));
- myGlobalLayout->setContentsMargins(0, 0, 0, 0);
- myGlobalLayout->setSpacing(0);
- myGlobalLayout->setMargin(0);
-
- if (param_flags == CV_WINDOW_AUTOSIZE)
- myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize);
-
- if (param_flags == CV_WINDOW_NORMAL)
- myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
-}
-
-void CvWindow::createBarLayout()
-{
- myBarLayout = new QBoxLayout(QBoxLayout::TopToBottom);
- myBarLayout->setObjectName(QString::fromUtf8("barLayout"));
- myBarLayout->setContentsMargins(0, 0, 0, 0);
- myBarLayout->setSpacing(0);
- myBarLayout->setMargin(0);
-}
-
-
-void CvWindow::createView(int mode, int ratio)
-{
- //mode = CV_MODE_NORMAL or CV_MODE_OPENGL
- //ratio = CV_WINDOW_KEEPRATIO or CV_WINDOW_FREERATIO
- myview = new ViewPort(this, mode,ratio);//parent, mode_display, keep_aspect_ratio
- myview->setAlignment(Qt::AlignHCenter);
-}
-
-void CvWindow::setOpenGLCallback(CvOpenGLCallback func,void* userdata, double angle, double zmin, double zmax)
-{
- myview->setOpenGLCallback(func,userdata, angle, zmin, zmax );
-}
-
-ViewPort* CvWindow::getView()
-{
- return myview;
-}
-
-void CvWindow::displayInfo(QString text,int delayms)
-{
- myview->startDisplayInfo(text, delayms);
-}
-
-void CvWindow::displayStatusBar(QString text,int delayms)
-{
- myStatusBar->showMessage(text,delayms);
-}
-
-void CvWindow::updateImage(void* arr)
-{
- myview->updateImage(arr);
-}
-
-void CvWindow::setMouseCallBack(CvMouseCallback m, void* param)
-{
- myview->setMouseCallBack(m,param);
-}
-
-//addSlider2 is static
-void CvWindow::addSlider2(CvWindow* w,QString name, int* value, int count,CvTrackbarCallback2 on_change, void* userdata)
-{
- QPointer<CvTrackbar> t = new CvTrackbar(w,name,value, count, on_change, userdata);
- t->setAlignment(Qt::AlignHCenter);
-
- QPointer<QBoxLayout> myLayout;
-
- if (w)
- {
- myLayout = w->myBarLayout;
- }
- else
- {
- myLayout = global_control_panel->myLayout;
-
- //if first one, enable control panel
- if (myLayout->count() == 0)
- guiMainThread->enablePropertiesButtonEachWindow();
- }
-
- myLayout->insertLayout( myLayout->count(),t);
-
-
-}
-
-//addSlider is static
-void CvWindow::addSlider(CvWindow* w,QString name, int* value, int count,CvTrackbarCallback on_change)
-{
- QPointer<CvTrackbar> t = new CvTrackbar(w,name,value, count, on_change);
- t->setAlignment(Qt::AlignHCenter);
-
- QPointer<QBoxLayout> myLayout;
-
- if (w)
- {
- myLayout = w->myBarLayout;
- }
- else
- {
- myLayout = global_control_panel->myLayout;
-
- //if first one, enable control panel
- if (myLayout->count() == 0)
- guiMainThread->enablePropertiesButtonEachWindow();
- }
-
- myLayout->insertLayout( myLayout->count(),t);
-
-
-}
-
-//Need more test here !
-void CvWindow::keyPressEvent(QKeyEvent *event)
-{
- //see http://doc.trolltech.com/4.6/qt.html#Key-enum
- int key = event->key();
- bool goodKey = false;
-
- if (key>=20 && key<=255 )
- {
- key = (int)event->text().toLocal8Bit().at(0);
- goodKey = true;
- }
-
- if (key == Qt::Key_Escape)
- {
- key = 27;
- goodKey = true;
- }
-
- //control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions
- if (event->modifiers() != Qt::ControlModifier && goodKey)
- {
- mutexKey.lock();
- last_key = key;
- //last_key = event->nativeVirtualKey ();
- mutexKey.unlock();
- key_pressed.wakeAll();
- //event->accept();
- }
-
- QWidget::keyPressEvent(event);
-}
-
-//TODO: load CV_GUI flag (done) and act accordingly (create win property if needed and attach trackbars)
-void CvWindow::readSettings()
-{
- //organisation and application's name
- QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
- QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
- QSize size = settings.value("size", QSize(400, 400)).toSize();
- //param_name = settings.value("name_window",param_name).toString();
- param_flags = settings.value("mode_resize",param_flags).toInt();
- param_gui_mode = settings.value("mode_gui",param_gui_mode).toInt();
-
- param_ratio_mode = settings.value("mode_ratio",param_ratio_mode).toInt();
- myview->param_keepRatio = settings.value("view_aspectRatio",myview->param_keepRatio).toInt();
-
- param_flags = settings.value("mode_resize",param_flags).toInt();
- qreal m11 = settings.value("matrix_view.m11",myview->param_matrixWorld.m11()).toDouble();
- qreal m12 = settings.value("matrix_view.m12",myview->param_matrixWorld.m12()).toDouble();
- qreal m13 = settings.value("matrix_view.m13",myview->param_matrixWorld.m13()).toDouble();
- qreal m21 = settings.value("matrix_view.m21",myview->param_matrixWorld.m21()).toDouble();
- qreal m22 = settings.value("matrix_view.m22",myview->param_matrixWorld.m22()).toDouble();
- qreal m23 = settings.value("matrix_view.m23",myview->param_matrixWorld.m23()).toDouble();
- qreal m31 = settings.value("matrix_view.m31",myview->param_matrixWorld.m31()).toDouble();
- qreal m32 = settings.value("matrix_view.m32",myview->param_matrixWorld.m32()).toDouble();
- qreal m33 = settings.value("matrix_view.m33",myview->param_matrixWorld.m33()).toDouble();
- myview->param_matrixWorld = QTransform(m11,m12,m13,m21,m22,m23,m31,m32,m33);
-
- //trackbar here
- icvLoadTrackbars(&settings);
-
- resize(size);
- move(pos);
-
- if (global_control_panel)
- {
- icvLoadControlPanel();
- global_control_panel->move(settings.value("posPanel", global_control_panel->pos()).toPoint());
- }
-}
-
-void CvWindow::writeSettings()
-{
- //organisation and application's name
- QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
- //settings.setValue("name_window",param_name);
- settings.setValue("pos", pos());
- settings.setValue("size", size());
- settings.setValue("mode_resize",param_flags);
- settings.setValue("mode_gui",param_gui_mode);
-
- settings.setValue("param_ratio_mode",param_ratio_mode);
- settings.setValue("view_aspectRatio",myview->param_keepRatio);
-
- settings.setValue("matrix_view.m11",myview->param_matrixWorld.m11());
- settings.setValue("matrix_view.m12",myview->param_matrixWorld.m12());
- settings.setValue("matrix_view.m13",myview->param_matrixWorld.m13());
- settings.setValue("matrix_view.m21",myview->param_matrixWorld.m21());
- settings.setValue("matrix_view.m22",myview->param_matrixWorld.m22());
- settings.setValue("matrix_view.m23",myview->param_matrixWorld.m23());
- settings.setValue("matrix_view.m31",myview->param_matrixWorld.m31());
- settings.setValue("matrix_view.m32",myview->param_matrixWorld.m32());
- settings.setValue("matrix_view.m33",myview->param_matrixWorld.m33());
-
- icvSaveTrackbars(&settings);
-
-
- if (global_control_panel)
- {
- icvSaveControlPanel();
- settings.setValue("posPanel", global_control_panel->pos());
- }
-}
-
-void CvWindow::icvLoadControlPanel()
-{
- QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()+" control panel");
- int size = settings.beginReadArray("bars");
- int subsize;
- CvBar* t;
- if (size == global_control_panel->myLayout->layout()->count())
- for (int i = 0; i < size; ++i) {
- t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i);
- settings.setArrayIndex(i);
- if (t->type == type_CvTrackbar)
- {
- if (t->name_bar == settings.value("namebar").toString())
- {
- ((CvTrackbar*)t)->slider->setValue(settings.value("valuebar").toInt());
- }
- }
- if (t->type == type_CvButtonbar)
- {
- subsize = settings.beginReadArray(QString("buttonbar")+i);
-
- if ( subsize == ((CvButtonbar*)t)->layout()->count() )
- icvLoadButtonbar((CvButtonbar*)t,&settings);
-
- settings.endArray();
- }
- }
- settings.endArray();
-}
-
-void CvWindow::icvSaveControlPanel()
-{
- QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()+" control panel");
- settings.beginWriteArray("bars");
-
- CvBar* t;
- for (int i = 0; i < global_control_panel->myLayout->layout()->count(); ++i) {
- t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i);
- settings.setArrayIndex(i);
- if (t->type == type_CvTrackbar)
- {
- settings.setValue("namebar", QString(t->name_bar));
- settings.setValue("valuebar",((CvTrackbar*)t)->slider->value());
- }
- if (t->type == type_CvButtonbar)
- {
- settings.beginWriteArray(QString("buttonbar")+i);
- icvSaveButtonbar((CvButtonbar*)t,&settings);
- settings.endArray();
- }
- }
- settings.endArray();
-}
-
-void CvWindow::icvSaveButtonbar(CvButtonbar* b,QSettings *settings)
-{
- QWidget* temp;
- QString myclass;
- for (int i = 0; i < b->layout()->count(); ++i) {
- settings->setArrayIndex(i);
- temp = (QWidget*) b->layout()->itemAt(i)->widget();
- myclass = QString(temp->metaObject ()->className ());
- if (myclass == "CvPushButton")
- {
- CvPushButton* button = (CvPushButton*) temp;
- settings->setValue("namebutton", QString(button->text()) );
- settings->setValue("valuebutton", int(button->isChecked()));
- }
-
- if (myclass == "CvCheckBox")
- {
- CvCheckBox* button = (CvCheckBox*) temp;
- settings->setValue("namebutton", QString(button->text()) );
- settings->setValue("valuebutton", int(button->isChecked()));
- }
-
- if (myclass == "CvRadioButton")
- {
- CvRadioButton* button = (CvRadioButton*) temp;
- settings->setValue("namebutton", QString(button->text()) );
- settings->setValue("valuebutton", int(button->isChecked()));
- }
- }
-}
-
-void CvWindow::icvLoadButtonbar(CvButtonbar* b,QSettings *settings)
-{
- QWidget* temp;
- QString myclass;
- for (int i = 0; i < b->layout()->count(); ++i)
- {
- settings->setArrayIndex(i);
- temp = (QWidget*) b->layout()->itemAt(i)->widget();
- myclass = QString(temp->metaObject ()->className ());
- if (myclass == "CvPushButton")
- {
- CvPushButton* button = (CvPushButton*) temp;
- if (button->text() == settings->value("namebutton").toString())
- button->setChecked(settings->value("valuebutton").toInt());
- }
-
- if (myclass == "CvCheckBox")
- {
- CvCheckBox* button = (CvCheckBox*) temp;
- if (button->text() == settings->value("namebutton").toString())
- button->setChecked(settings->value("valuebutton").toInt());
- }
-
- if (myclass == "CvRadioButton")
- {
- CvRadioButton* button = (CvRadioButton*) temp;
- if (button->text() == settings->value("namebutton").toString())
- button->setChecked(settings->value("valuebutton").toInt());
- }
-
- }
-}
-
-
-void CvWindow::icvLoadTrackbars(QSettings *settings)
-{
- int size = settings->beginReadArray("trackbars");
- QPointer<CvTrackbar> t;
-
- //trackbar are saved in the same order, so no need to use icvFindTrackbarByName
-
- if (myBarLayout->layout()->count() == size)//if not the same number, the window saved and loaded is not the same (nb trackbar not equal)
- for (int i = 0; i < size; ++i)
- {
- settings->setArrayIndex(i);
- t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);
-
- if (t->name_bar == settings->value("name").toString())
- t->slider->setValue(settings->value("value").toInt());
-
- }
- settings->endArray();
-
-}
-
-void CvWindow::icvSaveTrackbars(QSettings *settings)
-{
- QPointer<CvTrackbar> t;
-
- settings->beginWriteArray("trackbars");
-
- for (int i = 0; i < myBarLayout->layout()->count(); ++i) {
- t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);
- settings->setArrayIndex(i);
- settings->setValue("name", t->name_bar);
- settings->setValue("value", t->slider->value());
- }
- settings->endArray();
-}
-
-
-
-
-
-
-
-//Here is ViewPort class
-ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
-{
- centralWidget = arg,
- setParent(centralWidget);
- mode_display = arg2;
- param_keepRatio = arg3;
-
-
- //setAlignment(Qt::AlignLeft | Qt::AlignTop);
- setContentsMargins(0,0,0,0);
-
- setObjectName(QString::fromUtf8("graphicsView"));
- timerDisplay = new QTimer(this);
- timerDisplay->setSingleShot(true);
- connect(timerDisplay, SIGNAL(timeout()), this, SLOT(stopDisplayInfo()));
- drawInfo = false;
- positionGrabbing = QPointF(0,0);
- positionCorners = QRect(0,0,size().width(),size().height());
- on_mouse = NULL;
- mouseCoordinate = QPoint(-1,-1);
- on_openGL_draw3D = NULL;
-
- //no border
- setStyleSheet( "QGraphicsView { border-style: none; }" );
-
-#if defined( HAVE_QT_OPENGL )
-
- if ( mode_display == CV_MODE_OPENGL)
- {
- myGL = new QGLWidget(QGLFormat(QGL::SampleBuffers));
- setViewport(myGL);
- if (param_keepRatio == CV_WINDOW_KEEPRATIO)
- {
- //TODO: fix this bug:
- //::::blinking in OpenGL with CV_WINDOW_KEEPRATIO::::
- //The raison is that to move the widget in the middle and resize it manually to keep the aspect ratio,
- //we resize in resizeEvent() and use a trick not to be blocked in an infinity loop.
- //This is working fine if the viewport is not OpenGL, however we have two rendering with OpenGL.
- //The first rendering with the widget not moved in the midle (so stuck in top left), then the final and correct rendering.
- //This two rendering are visible with OpenGL and CV_WINDOW_KEEPRATIO but not with native rendering (why ???)
-
- //I tried to use Qt::AlignCenter of the layout manager but the widget does not expand anymore
- //I tried to center with painter.drawImage (in draw2D), but the imgRegion and all other function using the size of the widget will not work anymore.
- startDisplayInfo("WARNING: For now, you cannot use OpenGL rendering with CV_WINDOW_KEEPRATIO, so we changed to CV_WINDOW_FREERATIO", 5000);
- setRatio(CV_WINDOW_FREERATIO);
- }
-
- //setViewport(new QGLWidget());
- angle = DEFAULT_ANGLE;
- zmin = DEFAULT_ZMIN;
- zmax = DEFAULT_ZMAX;
- initGL();
- }
-
-#endif
-
- image2Draw_ipl=cvCreateImage(cvSize(viewport()->width(),viewport()->height()),IPL_DEPTH_8U,3);
-
- nbChannelOriginImage = 0;
- cvZero(image2Draw_ipl);
-
- setInteractive(false);
- setMouseTracking (true);//receive mouse event everytime
-
-}
-
-ViewPort::~ViewPort()
-{
- if (image2Draw_ipl)
- cvReleaseImage(&image2Draw_ipl);
-
-
-#if defined( HAVE_QT_OPENGL )
- if (myGL)
- delete myGL;
-#endif;
-
- qDebug()<<"kill vieport";
-
- delete timerDisplay;
-}
-
-void ViewPort::contextMenuEvent(QContextMenuEvent *event)
-{
- if (centralWidget->vect_QActions.size() > 0)
- {
- QMenu menu(this);
- foreach (QAction *a, centralWidget->vect_QActions)
- menu.addAction(a);
- // menu.popup(event->globalPos());
- menu.exec(event->globalPos());
- }
-}
-
-//can save as JPG, JPEG, BMP, PNG
-void ViewPort::saveView()
-{
- QDate date_d = QDate::currentDate ();
- QString date_s = date_d.toString("dd.MM.yyyy");
- QString name_s = centralWidget->param_name+"_screenshot_"+date_s;
-
- QString fileName = QFileDialog::getSaveFileName(this, tr("Save File %1").arg(name_s),
- name_s+".png",
- tr("Images (*.png *.jpg *.bmp *.jpeg)"));
-
- if (!fileName.isEmpty ())//save the picture
- {
- QString extension = fileName.right(3);
-
-
-#if defined( HAVE_QT_OPENGL )
- image2Draw_qt_resized = ((QGLWidget*)viewport())->grabFrameBuffer();
-#else
- // (no need anymore) create the image resized to receive the 'screenshot'
- // image2Draw_qt_resized = QImage(viewport()->width(), viewport()->height(),QImage::Format_RGB888);
-
- QPainter saveimage(&image2Draw_qt_resized);
- this->render(&saveimage);
-#endif
-
- // Save it..
- if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0)
- {
- image2Draw_qt_resized.save(fileName, "PNG");
- return;
- }
-
- if (QString::compare(extension, "jpg", Qt::CaseInsensitive) == 0)
- {
- image2Draw_qt_resized.save(fileName, "JPG");
- return;
- }
-
- if (QString::compare(extension, "bmp", Qt::CaseInsensitive) == 0)
- {
- image2Draw_qt_resized.save(fileName, "BMP");
- return;
- }
-
- if (QString::compare(extension, "jpeg", Qt::CaseInsensitive) == 0)
- {
- image2Draw_qt_resized.save(fileName, "JPEG");
- return;
- }
-
- CV_Error(CV_StsNullPtr, "file extension not recognized, please choose between JPG, JPEG, BMP or PNG");
- }
-}
-
-void ViewPort::setRatio(int flags)
-{
- centralWidget->param_ratio_mode = flags;
- param_keepRatio = flags;
- updateGeometry();
- viewport()->update();
-}
-
-void ViewPort::imgRegion()
-{
- scaleView( (threshold_zoom_img_region/param_matrixWorld.m11()-1)*5,QPointF(size().width()/2,size().height()/2));
-}
-
-int ViewPort::getRatio()
-{
- return param_keepRatio;
-}
-
-void ViewPort::resetZoom()
-{
- param_matrixWorld.reset();
- controlImagePosition();
-}
-
-void ViewPort::ZoomIn()
-{
- scaleView( 0.5,QPointF(size().width()/2,size().height()/2));
-}
-
-void ViewPort::ZoomOut()
-{
- scaleView( -0.5,QPointF(size().width()/2,size().height()/2));
-}
-
-//Note: move 2 percent of the window
-void ViewPort::siftWindowOnLeft()
-{
- float delta = 2*width()/(100.0*param_matrixWorld.m11());
- moveView(QPointF(delta,0));
-}
-
-//Note: move 2 percent of the window
-void ViewPort::siftWindowOnRight()
-{
- float delta = -2*width()/(100.0*param_matrixWorld.m11());
- moveView(QPointF(delta,0));
-}
-
-//Note: move 2 percent of the window
-void ViewPort::siftWindowOnUp()
-{
- float delta = 2*height()/(100.0*param_matrixWorld.m11());
- moveView(QPointF(0,delta));
-}
-
-//Note: move 2 percent of the window
-void ViewPort::siftWindowOnDown()
-{
- float delta = -2*height()/(100.0*param_matrixWorld.m11());
- moveView(QPointF(0,delta));
-}
-
-void ViewPort::startDisplayInfo(QString text, int delayms)
-{
- if (timerDisplay->isActive())
- stopDisplayInfo();
-
- infoText = text;
- timerDisplay->start(delayms);
- drawInfo = true;
-}
-
-void ViewPort::stopDisplayInfo()
-{
- timerDisplay->stop();
- drawInfo = false;
-}
-
-inline bool ViewPort::isSameSize(IplImage* img1,IplImage* img2)
-{
- return img1->width == img2->width && img1->height == img2->height;
-}
-
-void ViewPort::updateImage(void* arr)
-{
- //if (!arr)
- //CV_Error(CV_StsNullPtr, "NULL arr pointer (in showImage)" );
- CV_Assert(arr)
-
- IplImage* tempImage = (IplImage*)arr;
-
- if (!isSameSize(image2Draw_ipl,tempImage))
- {
- cvReleaseImage(&image2Draw_ipl);
-
- //the image in ipl (to do a deep copy with cvCvtColor)
- image2Draw_ipl=cvCreateImage(cvGetSize(tempImage),IPL_DEPTH_8U,3);
-
- //the ipl image in qt format (with shared memory)
- //image2Draw_qt = QImage((uchar*) image2Draw_ipl->imageData, image2Draw_ipl->width, image2Draw_ipl->height,QImage::Format_RGB888);
-
- //nbChannelOriginImage = tempImage->nChannels;
-
- updateGeometry();
- }
-
- nbChannelOriginImage = tempImage->nChannels;
-
-
- //cvCvtColor(tempImage,image2Draw_ipl,CV_BGR2RGB);//will not work if tempImage is 1 channel !!
- cvConvertImage(tempImage,image2Draw_ipl,CV_CVTIMG_SWAP_RB );
-
- viewport()->update();
-}
-
-void ViewPort::setMouseCallBack(CvMouseCallback m, void* param)
-{
- on_mouse = m;
- on_mouse_param = param;
-}
-
-void ViewPort::setOpenGLCallback(CvOpenGLCallback func,void* userdata, double angle_arg, double zmin_arg, double zmax_arg)
-{
- //avoid unreferenced formal parameter warning with vs 2008
- //http://msdn.microsoft.com/en-en/library/26kb9fy0%28VS.80%29.aspx
- func;userdata;angle_arg;zmin_arg;zmax_arg;
-
-#if defined( HAVE_QT_OPENGL )
- on_openGL_draw3D = func;
- on_openGL_param = userdata;
-
- if (angle_arg > 0)
- angle = angle_arg;
- else
- angle = DEFAULT_ANGLE;
-
-
- if (zmin_arg >= 0)
- zmin = zmin_arg;
- else
- zmin = DEFAULT_ZMIN;
-
-
- if (zmax_arg > 0)
- zmax = zmax_arg;
- else
- zmax = DEFAULT_ZMAX;
-#endif
-}
-
-void ViewPort::controlImagePosition()
-{
- qreal left, top, right, bottom;
-
- //after check top-left, bottom right corner to avoid getting "out" during zoom/panning
- param_matrixWorld.map(0,0,&left,&top);
-
- if (left > 0)
- {
- param_matrixWorld.translate(-left,0);
- left = 0;
- }
- if (top > 0)
- {
- param_matrixWorld.translate(0,-top);
- top = 0;
- }
- //-------
-
- QSize sizeImage = size();
- param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
- if (right < sizeImage.width())
- {
- param_matrixWorld.translate(sizeImage.width()-right,0);
- right = sizeImage.width();
- }
- if (bottom < sizeImage.height())
- {
- param_matrixWorld.translate(0,sizeImage.height()-bottom);
- bottom = sizeImage.height();
- }
-
- //save corner position
- positionCorners.setTopLeft(QPoint(left,top));
- positionCorners.setBottomRight(QPoint(right,bottom));
- //save also the inv matrix
- matrixWorld_inv = param_matrixWorld.inverted();
-
- //viewport()->update();
-}
-
-void ViewPort::moveView(QPointF delta)
-{
- param_matrixWorld.translate(delta.x(),delta.y());
- controlImagePosition();
- viewport()->update();
-}
-
-//factor is -0.5 (zoom out) or 0.5 (zoom in)
-void ViewPort::scaleView(qreal factor,QPointF center)
-{
- factor/=5;//-0.1 <-> 0.1
- factor+=1;//0.9 <-> 1.1
-
- //limit zoom out ---
- if (param_matrixWorld.m11()==1 && factor < 1)
- return;
-
- if (param_matrixWorld.m11()*factor<1)
- factor = 1/param_matrixWorld.m11();
-
-
- //limit zoom int ---
- if (param_matrixWorld.m11()>100 && factor > 1)
- return;
-
- //inverse the transform
- int a, b;
- matrixWorld_inv.map(center.x(),center.y(),&a,&b);
-
- param_matrixWorld.translate(a-factor*a,b-factor*b);
- param_matrixWorld.scale(factor,factor);
-
- controlImagePosition();
-
- //display new zoom
- if (centralWidget->myStatusBar)
- centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);
-
- if (param_matrixWorld.m11()>1)
- setCursor(Qt::OpenHandCursor);
- else
- unsetCursor();
-}
-
-void ViewPort::wheelEvent(QWheelEvent *event)
-{
- scaleView( -event->delta() / 240.0,event->pos());
- viewport()->update();
-}
-
-void ViewPort::mousePressEvent(QMouseEvent *event)
-{
- int cv_event = -1, flags = 0;
- QPoint pt = event->pos();
-
- //icvmouseHandler: pass parameters for cv_event, flags
- icvmouseHandler(event, mouse_down, cv_event, flags);
- icvmouseProcessing(QPointF(pt), cv_event, flags);
-
- if (param_matrixWorld.m11()>1)
- {
- setCursor(Qt::ClosedHandCursor);
- positionGrabbing = event->pos();
- }
-
- QWidget::mousePressEvent(event);
-}
-
-void ViewPort::mouseReleaseEvent(QMouseEvent *event)
-{
-
- int cv_event = -1, flags = 0;
- QPoint pt = event->pos();
-
- //icvmouseHandler: pass parameters for cv_event, flags
- icvmouseHandler(event, mouse_up, cv_event, flags);
- icvmouseProcessing(QPointF(pt), cv_event, flags);
-
- if (param_matrixWorld.m11()>1)
- setCursor(Qt::OpenHandCursor);
-
- QWidget::mouseReleaseEvent(event);
-}
-
-void ViewPort::mouseDoubleClickEvent(QMouseEvent *event)
-{
- int cv_event = -1, flags = 0;
- QPoint pt = event->pos();
-
- //icvmouseHandler: pass parameters for cv_event, flags
- icvmouseHandler(event, mouse_dbclick, cv_event, flags);
- icvmouseProcessing(QPointF(pt), cv_event, flags);
-
- QWidget::mouseDoubleClickEvent(event);
-}
-
-void ViewPort::mouseMoveEvent(QMouseEvent *event)
-{
- int cv_event = -1, flags = 0;
- QPoint pt = event->pos();
-
- //icvmouseHandler: pass parameters for cv_event, flags
- icvmouseHandler(event, mouse_move, cv_event, flags);
- icvmouseProcessing(QPointF(pt), cv_event, flags);
-
-
- if (param_matrixWorld.m11()>1 && event->buttons() == Qt::LeftButton)
- {
- QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11();
- positionGrabbing = event->pos();
- moveView(dxy);
- }
-
- //I update the statusbar here because if the user does a cvWaitkey(0) (like with inpaint.cpp)
- //the status bar will only be repaint when a click occurs.
- if (centralWidget->myStatusBar)
- viewport()->update();
-
- QWidget::mouseMoveEvent(event);
-}
-
-//up, down, dclick, move
-void ViewPort::icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags)
-{
-
- switch(event->modifiers())
- {
- case Qt::ShiftModifier:
- flags = CV_EVENT_FLAG_SHIFTKEY;
- break;
- case Qt::ControlModifier:
- flags = CV_EVENT_FLAG_CTRLKEY;
- break;
- case Qt::AltModifier:
- flags = CV_EVENT_FLAG_ALTKEY;
- break;
- case Qt::NoModifier :
- break;
- case Qt::MetaModifier:
- break;
- case Qt::KeypadModifier:
- break;
- default:;
- }
-
- switch(event->button())
- {
- case Qt::LeftButton:
- cv_event = tableMouseButtons[category][0];
- flags |= CV_EVENT_FLAG_LBUTTON;
- break;
- case Qt::RightButton:
- cv_event = tableMouseButtons[category][1];
- flags |= CV_EVENT_FLAG_RBUTTON;
- break;
- case Qt::MidButton:
- cv_event = tableMouseButtons[category][2];
- flags |= CV_EVENT_FLAG_MBUTTON;
- break;
- default:;
- }
-}
-
-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/ratioX);
- mouseCoordinate.ry()=floor(pfy/ratioY);
-
- if (on_mouse)
- on_mouse( cv_event, mouseCoordinate.x(),mouseCoordinate.y(), flags, on_mouse_param );
-
-}
-
-QSize ViewPort::sizeHint() const
-{
- if(image2Draw_ipl)
- {
- //qDebug()<<centralWidget->param_name<<" "<<image2Draw_ipl->width<<" "<<image2Draw_ipl->height;
- return QSize(image2Draw_ipl->width,image2Draw_ipl->height);
- } else {
- return QGraphicsView::sizeHint();
- }
-}
-
-void ViewPort::resizeEvent ( QResizeEvent *event)
-{
-
- controlImagePosition();
- ratioX=width()/float(image2Draw_ipl->width);
- ratioY=height()/float(image2Draw_ipl->height);
-
-
- if(param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
- {
- QSize newSize = QSize(image2Draw_ipl->width,image2Draw_ipl->height);
- newSize.scale(event->size(),Qt::KeepAspectRatio);
-
- //imageWidth/imageHeight = newWidth/newHeight +/- epsilon
- //ratioX = ratioY +/- epsilon
- //||ratioX - ratioY|| = epsilon
- if (fabs(ratioX - ratioY)*100> ratioX)//avoid infinity loop / epsilon = 1% of ratioX
- {
- resize(newSize);
-
- //move to the middle
- //newSize get the delta offset to place the picture in the middle of its parent
- newSize= (event->size()-newSize)/2;
-
- //if the toolbar is displayed, avoid drawing myview on top of it
- if (centralWidget->myToolBar)
- if(!centralWidget->myToolBar->isHidden())
- newSize +=QSize(0,centralWidget->myToolBar->height());
-
- move(newSize.width(),newSize.height());
- }
- }
-
- return QGraphicsView::resizeEvent(event);
-}
-
-void ViewPort::paintEvent(QPaintEvent* event)
-{
-
- QPainter myPainter(viewport());
- myPainter.setWorldTransform(param_matrixWorld);
-
- draw2D(&myPainter);
-
-#if defined( HAVE_QT_OPENGL )
- if ( mode_display == CV_MODE_OPENGL && on_openGL_draw3D)
- {
- myPainter.save(); // Needed when using the GL1 engine
- myPainter.beginNativePainting(); // Needed when using the GL2 engine
-
- setGL(width(),height());
- on_openGL_draw3D(on_openGL_param);
- unsetGL();
-
- myPainter.endNativePainting(); // Needed when using the GL2 engine
- myPainter.restore(); // Needed when using the GL1 engine
- }
-#endif
-
- //Now disable matrixWorld for overlay display
- myPainter.setWorldMatrixEnabled (false );
-
- //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 resized image's values. If you want the original image's values, use CV_WINDOW_AUTOSIZE", 1000);
-
- drawImgRegion(&myPainter);
- }
-
- drawViewOverview(&myPainter);
- }
-
- //for information overlay
- if (drawInfo)
- drawInstructions(&myPainter);
-
- //for statusbar
- if (centralWidget->myStatusBar)
- drawStatusBar();
-
- QGraphicsView::paintEvent(event);
-}
-
-void ViewPort::draw2D(QPainter *painter)
-{
- image2Draw_qt = QImage((uchar*) image2Draw_ipl->imageData, image2Draw_ipl->width, image2Draw_ipl->height,QImage::Format_RGB888);
- image2Draw_qt_resized = image2Draw_qt.scaled(viewport()->width(),viewport()->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
- painter->drawImage(0,0,image2Draw_qt_resized);
- //painter->drawImage(0,0,image2Draw_qt_resized);
-}
-
-void ViewPort::drawStatusBar()
-{
- if (mouseCoordinate.x()>=0 &&
- mouseCoordinate.y()>=0 &&
- mouseCoordinate.x()<image2Draw_ipl->width &&
- mouseCoordinate.y()<image2Draw_ipl->height)
- {
- QRgb rgbValue = image2Draw_qt.pixel(mouseCoordinate);
-
- if (nbChannelOriginImage==3)
- {
- centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
- .arg(mouseCoordinate.x())
- .arg(mouseCoordinate.y())+
- tr("<font color='red'>R:%3 </font>").arg(qRed(rgbValue))+//.arg(value.val[0])+
- tr("<font color='green'>G:%4 </font>").arg(qGreen(rgbValue))+//.arg(value.val[1])+
- tr("<font color='blue'>B:%5</font>").arg(qBlue(rgbValue))//.arg(value.val[2])
- );
- }else{
- //all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed
- centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
- .arg(mouseCoordinate.x())
- .arg(mouseCoordinate.y())+
- tr("<font color='grey'>grey:%3 </font>").arg(qRed(rgbValue))
- );
- }
- }
-}
-
-
-void ViewPort::drawImgRegion(QPainter *painter)
-{
- qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11();
- offsetX = offsetX - floor(offsetX);
- qreal offsetY = param_matrixWorld.dy()/param_matrixWorld.m11();
- offsetY = offsetY - floor(offsetY);
-
- QSize view = size();
- QVarLengthArray<QLineF, 30> linesX;
- for (qreal x = offsetX*param_matrixWorld.m11(); x < view.width(); x += param_matrixWorld.m11() )
- linesX.append(QLineF(x, 0, x, view.height()));
-
- QVarLengthArray<QLineF, 30> linesY;
- for (qreal y = offsetY*param_matrixWorld.m11(); y < view.height(); y += param_matrixWorld.m11() )
- linesY.append(QLineF(0, y, view.width(), y));
-
-
- QFont f = painter->font();
- int original_font_size = f.pointSize();
- //change font size
- //f.setPointSize(4+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
- f.setPixelSize(6+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
- painter->setFont(f);
- QString val;
- QRgb rgbValue;
-
- 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<height()/param_matrixWorld.m11();j++)//-1 because display the pixels top rows left colums
- for (int i=-1;i<width()/param_matrixWorld.m11();i++)//-1
- {
- point1.setX((i+offsetX)*param_matrixWorld.m11());
- point1.setY((j+offsetY)*param_matrixWorld.m11());
-
- matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry());
-
- point2.rx()= (long) (point2.x() + 0.5);
- point2.ry()= (long) (point2.y() + 0.5);
-
- if (point2.x() >= 0 && point2.y() >= 0)
- 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),
- Qt::AlignCenter, val);
-
- val = tr("%1").arg(qGreen(rgbValue));
- painter->setPen(QPen(Qt::green, 1));
- painter->drawText(QRect(point1.x(),point1.y()+param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
- Qt::AlignCenter, val);
-
- val = tr("%1").arg(qBlue(rgbValue));
- painter->setPen(QPen(Qt::blue, 1));
- painter->drawText(QRect(point1.x(),point1.y()+2*param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
- Qt::AlignCenter, val);
-
- }
- else
- {
-
- val = tr("%1").arg(qRed(rgbValue));
- painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()),
- Qt::AlignCenter, val);
- }
- }
-
- painter->setPen(QPen(Qt::black, 1));
- painter->drawLines(linesX.data(), linesX.size());
- painter->drawLines(linesY.data(), linesY.size());
-
- //restore font size
- f.setPointSize(original_font_size);
- painter->setFont(f);
-
-}
-
-void ViewPort::drawViewOverview(QPainter *painter)
-{
- QSize viewSize = size();
- viewSize.scale ( 100, 100,Qt::KeepAspectRatio );
-
- const int margin = 5;
-
- //draw the image's location
- painter->setBrush(QColor(0, 0, 0, 127));
- painter->setPen(Qt::darkGreen);
- painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
-
- //daw the view's location inside the image
- qreal ratioSize = 1/param_matrixWorld.m11();
- qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
- painter->setPen(Qt::darkBlue);
- painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
- -positionCorners.top()*ratioSize*ratioWindow,
- (viewSize.width()-1)*ratioSize,
- (viewSize.height()-1)*ratioSize)
- );
-}
-
-void ViewPort::drawInstructions(QPainter *painter)
-{
- QFontMetrics metrics = QFontMetrics(font());
- int border = qMax(4, metrics.leading());
-
- QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125),
- Qt::AlignCenter | Qt::TextWordWrap, infoText);
- painter->setRenderHint(QPainter::TextAntialiasing);
- painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
- QColor(0, 0, 0, 127));
- painter->setPen(Qt::white);
- painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
- QColor(0, 0, 0, 127));
-
- painter->drawText((width() - rect.width())/2, border,
- rect.width(), rect.height(),
- Qt::AlignCenter | Qt::TextWordWrap, infoText);
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#if defined( HAVE_QT_OPENGL )//all this section -> not tested
-
-void ViewPort::initGL()
-{
- glShadeModel( GL_SMOOTH );
- glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
- glEnable( GL_TEXTURE_2D );
- glEnable( GL_CULL_FACE );
- glEnable( GL_DEPTH_TEST );
-}
-
-//from http://steinsoft.net/index.php?site=Programming/Code%20Snippets/OpenGL/gluperspective
-//do not want to link glu
-void ViewPort::icvgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
-{
- GLdouble xmin, xmax, ymin, ymax;
-
- ymax = zNear * tan(fovy * M_PI / 360.0);
- ymin = -ymax;
- xmin = ymin * aspect;
- xmax = ymax * aspect;
-
-
- glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
-}
-
-
-void ViewPort::setGL(int width, int height)
-{
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- icvgluPerspective(angle, float(width) / float(height), zmin, zmax);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-}
-
-void ViewPort::unsetGL()
-{
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
-}
-#endif
-
-#endif
+ return 1;//dummy value \r
+}\r
+\r
+CV_IMPL int cvStartWindowThread()\r
+{\r
+ return 0;\r
+}\r
+\r
+CV_IMPL int cvCreateTrackbar( const char* name_bar, const char* window_name, int* value, int count, CvTrackbarCallback on_change)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "addSlider",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(name_bar)),\r
+ Q_ARG(QString, QString(window_name)),\r
+ Q_ARG(void*, (void*)value),\r
+ Q_ARG(int, count),\r
+ Q_ARG(void*, (void*)on_change)\r
+ );\r
+\r
+ return 1;//dummy value\r
+}\r
+\r
+\r
+\r
+CV_IMPL int cvCreateButton(const char* button_name,CvButtonCallback on_change, void* userdata , int button_type, int initial_button_state )\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ if (initial_button_state < 0 || initial_button_state > 1)\r
+ return 0;\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "addButton",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(button_name)),\r
+ Q_ARG(int, button_type),\r
+ Q_ARG(int, initial_button_state),\r
+ Q_ARG(void*, (void*)on_change),\r
+ Q_ARG(void*, userdata)\r
+ );\r
+\r
+ return 1;//dummy value\r
+}\r
+\r
+CV_IMPL void cvCreateOpenGLCallback( const char* window_name, CvOpenGLCallback callbackOpenGL, void* userdata, double angle, double zmin, double zmax)\r
+{\r
+ if (!guiMainThread)\r
+ CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" );\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "setOpenGLCallback",\r
+ Qt::AutoConnection,\r
+ Q_ARG(QString, QString(window_name)),\r
+ Q_ARG(void*, (void*)callbackOpenGL),\r
+ Q_ARG(void*, userdata),\r
+ Q_ARG(double, angle),\r
+ Q_ARG(double, zmin),\r
+ Q_ARG(double, zmax)\r
+ );\r
+}\r
+\r
+CV_IMPL int cvGetTrackbarPos( const char* name_bar, const char* window_name )\r
+{\r
+ int result = -1;\r
+\r
+ QPointer<CvTrackbar> t = icvFindTrackbarByName( name_bar, window_name );\r
+\r
+ if (t)\r
+ result = t->slider->value();\r
+\r
+ return result;\r
+}\r
+\r
+CV_IMPL void cvSetTrackbarPos( const char* name_bar, const char* window_name, int pos )\r
+{\r
+\r
+ QPointer<CvTrackbar> t = icvFindTrackbarByName( name_bar, window_name );\r
+\r
+ if (t)\r
+ t->slider->setValue(pos);\r
+\r
+}\r
+\r
+/* assign callback for mouse events */\r
+CV_IMPL void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,void* param )\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( window_name );\r
+\r
+ if (!w)\r
+ CV_Error(CV_StsNullPtr, "NULL window handler" );\r
+\r
+ w->setMouseCallBack(on_mouse, param);\r
+\r
+}\r
+\r
+CV_IMPL void cvShowImage( const char* name, const CvArr* arr )\r
+{\r
+\r
+ if (!guiMainThread)\r
+ guiMainThread = new GuiReceiver;\r
+\r
+ QMetaObject::invokeMethod(guiMainThread,\r
+ "showImage",\r
+ //Qt::BlockingQueuedConnection,\r
+ Qt::DirectConnection,\r
+ Q_ARG(QString, QString(name)),\r
+ Q_ARG(void*, (void*)arr)\r
+ );\r
+}\r
+\r
+\r
+//----------OBJECT----------------\r
+\r
+GuiReceiver::GuiReceiver() : _bTimeOut(false), nb_windows(0)\r
+{\r
+ icvInitSystem(¶meterSystemC, parameterSystemV);\r
+\r
+ timer = new QTimer;\r
+ QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timeOut()));\r
+ timer->setSingleShot(true);\r
+}\r
+\r
+\r
+void GuiReceiver::isLastWindow()\r
+{\r
+ if (--nb_windows <= 0)\r
+ {\r
+ delete guiMainThread;\r
+ guiMainThread = NULL;\r
+ qApp->quit();\r
+ }\r
+}\r
+\r
+GuiReceiver::~GuiReceiver()\r
+{\r
+ if (global_control_panel)\r
+ delete global_control_panel;\r
+\r
+ delete timer;\r
+}\r
+\r
+void GuiReceiver::putText(void* arg1, QString text, QPoint org, void* arg2)\r
+{\r
+ CV_Assert(arg1)\r
+\r
+ IplImage* img = (IplImage*)arg1;\r
+\r
+ //for now, only support QImage::Format_RGB888\r
+ if (img->depth !=IPL_DEPTH_8U || img->nChannels != 3)\r
+ return;\r
+\r
+ CvFont* font = (CvFont*)arg2;\r
+\r
+\r
+\r
+ QImage qimg((uchar*) img->imageData, img->width, img->height,QImage::Format_RGB888);\r
+ QPainter qp(&qimg);\r
+ if (font)\r
+ {\r
+ QFont f(font->nameFont, font->line_type/*PointSize*/, font->thickness/*weight*/);\r
+ f.setStyle((QFont::Style)font->font_face/*style*/);\r
+ f.setLetterSpacing ( QFont::AbsoluteSpacing, font->dx/*spacing*/ );\r
+ //cvScalar(blue_component, green_component, red\_component[, alpha_component])\r
+ //Qt map non-transparent to 0xFF and transparent to 0\r
+ //OpenCV scalar is the reverse, so 255-font->color.val[3]\r
+ qp.setPen(QColor(font->color.val[2],font->color.val[1],font->color.val[0],255-font->color.val[3]));\r
+ qp.setFont ( f );\r
+ }\r
+ qp.drawText (org, text );\r
+ qp.end();\r
+}\r
+\r
+void GuiReceiver::saveWindowParameters(QString name)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (w)\r
+ w->writeSettings();\r
+}\r
+\r
+void GuiReceiver::loadWindowParameters(QString name)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (w)\r
+ w->readSettings();\r
+}\r
+\r
+double GuiReceiver::getRatioWindow(QString name)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+\r
+ if (!w)\r
+ return -1;\r
+\r
+ return (double)w->getView()->getRatio();\r
+}\r
+\r
+void GuiReceiver::setRatioWindow(QString name, double arg2 )\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (!w)\r
+ return;\r
+\r
+ int flags = (int) arg2;\r
+\r
+ if (w->getView()->getRatio() == flags)//nothing to do\r
+ return;\r
+\r
+ //if valid flags\r
+ if (flags == CV_WINDOW_FREERATIO || flags == CV_WINDOW_KEEPRATIO)\r
+ w->getView()->setRatio(flags);\r
+\r
+}\r
+\r
+double GuiReceiver::getPropWindow(QString name)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+\r
+ if (!w)\r
+ return -1;\r
+\r
+ return (double)w->param_flags;\r
+}\r
+\r
+void GuiReceiver::setPropWindow(QString name, double arg2 )\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (!w)\r
+ return;\r
+\r
+ int flags = (int) arg2;\r
+\r
+ if (w->param_flags == flags)//nothing to do\r
+ return;\r
+\r
+\r
+ switch(flags)\r
+ {\r
+ case CV_WINDOW_NORMAL:\r
+ w->myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);\r
+ w->param_flags = flags;\r
+\r
+ break;\r
+ case CV_WINDOW_AUTOSIZE:\r
+ w->myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize);\r
+ w->param_flags = flags;\r
+\r
+ break;\r
+ default:;\r
+ }\r
+}\r
+\r
+double GuiReceiver::isFullScreen(QString name)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (!w)\r
+ return -1;\r
+\r
+ if (w->isFullScreen())\r
+ return CV_WINDOW_FULLSCREEN;\r
+ else\r
+ return CV_WINDOW_NORMAL;\r
+}\r
+\r
+//accept CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN\r
+void GuiReceiver::toggleFullScreen(QString name, double flags )\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (!w)\r
+ return;\r
+\r
+ if (w->isFullScreen() && flags == CV_WINDOW_NORMAL)\r
+ {\r
+ w->showTools();\r
+ w->showNormal();\r
+ return;\r
+ }\r
+\r
+ if (!w->isFullScreen() && flags == CV_WINDOW_FULLSCREEN)\r
+ {\r
+ w->hideTools();\r
+ w->showFullScreen();\r
+ return;\r
+ }\r
+\r
+}\r
+\r
+void GuiReceiver::createWindow( QString name, int flags )\r
+{\r
+ if (!qApp)\r
+ CV_Error(CV_StsNullPtr, "NULL session handler" );\r
+\r
+ // Check the name in the storage\r
+ if( icvFindWindowByName( name.toLatin1().data() ))\r
+ {\r
+ return;\r
+ }\r
+\r
+ //QPointer<CvWindow> w1 =\r
+ nb_windows++;\r
+ new CvWindow(name, flags);\r
+}\r
+\r
+void GuiReceiver::timeOut()\r
+{\r
+ _bTimeOut = true;\r
+}\r
+\r
+void GuiReceiver::displayInfo( QString name, QString text, int delayms )\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (w && delayms > 0)\r
+ w->displayInfo(text,delayms);\r
+}\r
+\r
+void GuiReceiver::displayStatusBar( QString name, QString text, int delayms )\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (w && delayms > 0)\r
+ if (w->myStatusBar)//if statusbar was created\r
+ w->displayStatusBar(text,delayms);\r
+}\r
+\r
+void GuiReceiver::showImage(QString name, void* arr)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (!w)//as observed in the previous implementation (W32, GTK or Carbon), create a new window is the pointer returned is null\r
+ {\r
+ cvNamedWindow( name.toLatin1().data() );\r
+ w = icvFindWindowByName( name.toLatin1().data() );\r
+ }\r
+\r
+ if( w && arr )\r
+ {\r
+ w->updateImage(arr);\r
+ }\r
+ else\r
+ {\r
+ CV_Error(CV_StsNullPtr, "Do nothing (Window or Image NULL)");\r
+ }\r
+}\r
+\r
+void GuiReceiver::destroyWindow(QString name)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (w)\r
+ {\r
+ w->close();\r
+ //in not-multiThreads mode, looks like the window is hidden but not deleted\r
+ //so I do it manually\r
+ //otherwise QApplication do it for me if the exec command was executed (in multiThread mode)\r
+ if (!multiThreads)\r
+ delete w;\r
+ }\r
+}\r
+\r
+void GuiReceiver::destroyAllWindow()\r
+{\r
+ if (!qApp)\r
+ CV_Error(CV_StsNullPtr, "NULL session handler" );\r
+\r
+ if (multiThreads)\r
+ {\r
+ qApp->closeAllWindows();\r
+ }else{\r
+\r
+ foreach (QObject *obj, QApplication::topLevelWidgets())\r
+ {\r
+ if (obj->metaObject ()->className () == "CvWindow")\r
+ {\r
+ delete obj;\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+}\r
+\r
+void GuiReceiver::setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata, double angle, double zmin, double zmax)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );\r
+\r
+ if (w && callbackOpenGL)\r
+ w->setOpenGLCallback((CvOpenGLCallback) callbackOpenGL, userdata,angle,zmin,zmax);\r
+}\r
+\r
+void GuiReceiver::moveWindow(QString name, int x, int y)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (w)\r
+ w->move(x,y);\r
+\r
+}\r
+\r
+void GuiReceiver::resizeWindow(QString name, int width, int height)\r
+{\r
+ QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );\r
+\r
+ if (w)\r
+ w->resize(width, height);\r
+}\r
+\r
+void GuiReceiver::enablePropertiesButtonEachWindow()\r
+{\r
+ CvWindow* w;\r
+\r
+ //For each window, enable window property button\r
+ foreach (QWidget *widget, QApplication::topLevelWidgets())\r
+ {\r
+\r
+ if (widget->isWindow() && !widget->parentWidget ())//is a window without parent\r
+ {\r
+ w = (CvWindow*) widget;\r
+ //active window properties button\r
+ w->vect_QActions[9]->setDisabled(false);\r
+ }\r
+ }\r
+}\r
+\r
+void GuiReceiver::addButton(QString button_name, int button_type, int initial_button_state , void* on_change, void* userdata)\r
+{\r
+\r
+ if (!global_control_panel)\r
+ return;\r
+\r
+ QPointer<CvButtonbar> b;// = icvFindButtonbarByName( button_name.toLatin1().data(), global_control_panel->myLayout );\r
+\r
+ //if (b)//button with this name already exist\r
+ // return;\r
+\r
+ if (global_control_panel->myLayout->count() == 0)//if that is the first button attach to the control panel, create a new button bar\r
+ {\r
+ b = CvWindow::createButtonbar(button_name);//the bar has the name of the first button attached to it\r
+ \r
+ //enablePropertiesButtonEachWindow();\r
+\r
+ }else{\r
+ CvBar* lastbar = (CvBar*) global_control_panel->myLayout->itemAt(global_control_panel->myLayout->count()-1);\r
+\r
+ if (lastbar->type == type_CvTrackbar)//if last bar is a trackbar, create a new buttonbar, else, attach to the current bar\r
+ b = CvWindow::createButtonbar(button_name);//the bar has the name of the first button attached to it\r
+ else\r
+ b = (CvButtonbar*) lastbar;\r
+\r
+ }\r
+\r
+ b->addButton( button_name,(CvButtonCallback) on_change, userdata, button_type, initial_button_state);\r
+}\r
+\r
+void GuiReceiver::addSlider2(QString bar_name, QString window_name, void* value, int count, void* on_change, void *userdata)\r
+{\r
+ QBoxLayout *layout = NULL;\r
+ QPointer<CvWindow> w;\r
+ if (window_name != "")\r
+ {\r
+ w = icvFindWindowByName( window_name.toLatin1().data() );\r
+\r
+ if (!w)\r
+ return;\r
+ }else{\r
+ if (global_control_panel)\r
+ layout = global_control_panel->myLayout;\r
+ }\r
+\r
+ QPointer<CvTrackbar> t = icvFindTrackbarByName( bar_name.toLatin1().data() , window_name.toLatin1().data(), layout );\r
+\r
+ if (t)//trackbar exists\r
+ return;\r
+\r
+ if (!value)\r
+ CV_Error(CV_StsNullPtr, "NULL value pointer" );\r
+\r
+ if (count<= 0)//count is the max value of the slider, so must be bigger than 0\r
+ CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" );\r
+\r
+ CvWindow::addSlider2(w,bar_name,(int*)value,count,(CvTrackbarCallback2) on_change, userdata);\r
+}\r
+\r
+void GuiReceiver::addSlider(QString bar_name, QString window_name, void* value, int count, void* on_change)\r
+{\r
+ QBoxLayout *layout = NULL;\r
+ QPointer<CvWindow> w;\r
+ if (window_name != "")\r
+ {\r
+ w = icvFindWindowByName( window_name.toLatin1().data() );\r
+\r
+ if (!w)\r
+ return;\r
+ }else{\r
+ if (global_control_panel)\r
+ layout = global_control_panel->myLayout;\r
+ }\r
+\r
+ QPointer<CvTrackbar> t = icvFindTrackbarByName( bar_name.toLatin1().data() , window_name.toLatin1().data(), layout );\r
+\r
+ if (t)//trackbar exists\r
+ return;\r
+\r
+ if (!value)\r
+ CV_Error(CV_StsNullPtr, "NULL value pointer" );\r
+\r
+ if (count<= 0)//count is the max value of the slider, so must be bigger than 0\r
+ CV_Error(CV_StsNullPtr, "Max value of the slider must be bigger than 0" );\r
+\r
+ CvWindow::addSlider(w,bar_name,(int*)value,count,(CvTrackbarCallback) on_change);\r
+}\r
+\r
+int GuiReceiver::start()\r
+{\r
+ return qApp->exec();\r
+}\r
+\r
+CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTrackbarCallback2 on_change, void* data )\r
+{\r
+ callback = NULL;\r
+ callback2 = on_change;\r
+ userdata = data;\r
+\r
+ construc_trackbar(arg,name, value, count);\r
+}\r
+\r
+CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTrackbarCallback on_change )\r
+{\r
+ callback = on_change;\r
+ callback2 = NULL;\r
+ userdata = NULL;\r
+\r
+ construc_trackbar(arg,name, value, count);\r
+}\r
+\r
+void CvTrackbar::construc_trackbar(CvWindow* arg, QString name, int* value, int count)\r
+{\r
+ type=type_CvTrackbar;\r
+ myparent = arg;\r
+ name_bar = name;\r
+ setObjectName(name_bar);\r
+ dataSlider = value;\r
+\r
+ slider = new QSlider(Qt::Horizontal);\r
+ slider->setFocusPolicy(Qt::StrongFocus);\r
+ slider->setMinimum(0);\r
+ slider->setMaximum(count);\r
+ slider->setPageStep(5);\r
+ slider->setValue(*value);\r
+ slider->setTickPosition(QSlider::TicksBelow);\r
+\r
+\r
+ //Change style of the Slider\r
+ //slider->setStyleSheet(str_Trackbar_css);\r
+\r
+ QFile qss(":/stylesheet-trackbar");\r
+ if (qss.open(QFile::ReadOnly))\r
+ {\r
+ slider->setStyleSheet(QLatin1String(qss.readAll()));\r
+ qss.close();\r
+ }\r
+\r
+\r
+ //this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?)\r
+ //slider->setTickPosition(QSlider::TicksBelow);\r
+ label = new QPushButton;\r
+ label->setFlat(true);\r
+ setLabel(slider->value());\r
+\r
+\r
+ QObject::connect( slider, SIGNAL( valueChanged( int ) ),this, SLOT( update( int ) ) );\r
+\r
+ QObject::connect( label, SIGNAL( clicked() ),this, SLOT( createDialog() ));\r
+\r
+ //label->setStyleSheet("QPushButton:disabled {color: black}");\r
+\r
+ addWidget(label,Qt::AlignLeft);//name + value\r
+ addWidget(slider,Qt::AlignCenter);//slider\r
+}\r
+\r
+void CvTrackbar::createDialog()\r
+{\r
+\r
+ bool ok= false;\r
+\r
+ //crash if I access the values directly and give them to QInputDialog, so do a copy first.\r
+ int value = slider->value();\r
+ int step = slider->singleStep();\r
+ int min = slider->minimum();\r
+ int max = slider->maximum();\r
+\r
+ int i =\r
+#if QT_VERSION >= 0x040500\r
+ QInputDialog::getInt\r
+#else\r
+ QInputDialog::getInteger\r
+#endif\r
+ (this->parentWidget(),\r
+ tr("Slider %1").arg(name_bar),\r
+ tr("New value:"),\r
+ value,\r
+ min,\r
+ max,\r
+ step,\r
+ &ok);\r
+\r
+ if (ok)\r
+ slider->setValue(i);\r
+\r
+}\r
+\r
+void CvTrackbar::update(int myvalue)\r
+{\r
+ setLabel(myvalue);\r
+\r
+ *dataSlider = myvalue;\r
+ if (callback)\r
+ {\r
+ callback(myvalue);\r
+ return;\r
+ }\r
+\r
+ if (callback2)\r
+ {\r
+ callback2(myvalue,userdata);\r
+ return;\r
+ }\r
+}\r
+\r
+void CvTrackbar::setLabel(int myvalue)\r
+{\r
+ QString nameNormalized = name_bar.leftJustified( 10, ' ', true );\r
+ QString valueMaximum = QString("%1").arg(slider->maximum());\r
+ QString str = QString("%1 (%2/%3)").arg(nameNormalized).arg(myvalue,valueMaximum.length(),10,QChar('0')).arg(valueMaximum);\r
+ label->setText(str);\r
+}\r
+\r
+CvTrackbar::~CvTrackbar()\r
+{\r
+ delete slider;\r
+ delete label;\r
+}\r
+\r
+\r
+\r
+\r
+//here CvButtonbar class\r
+CvButtonbar::CvButtonbar(QWidget* arg, QString arg2)\r
+{\r
+ type=type_CvButtonbar;\r
+ myparent = arg;\r
+ name_bar = arg2;\r
+ setObjectName(name_bar);\r
+\r
+ group_button = new QButtonGroup;\r
+\r
+ /*\r
+ label = new QLabel;\r
+ setLabel();\r
+ addWidget(label,Qt::AlignLeft );\r
+ */\r
+}\r
+\r
+CvButtonbar::~CvButtonbar()\r
+{\r
+ QLayoutItem *child;\r
+\r
+ while ((child = takeAt(0)) != 0)\r
+ delete child;\r
+\r
+ delete group_button;\r
+}\r
+\r
+void CvButtonbar::setLabel()\r
+{\r
+ QString nameNormalized = name_bar.leftJustified( 10, ' ', true );\r
+ label->setText(nameNormalized);\r
+}\r
+\r
+void CvButtonbar::addButton( QString name, CvButtonCallback call, void* userdata, int button_type, int initial_button_state)\r
+{\r
+ QString button_name = name;\r
+\r
+ if (button_name == "")\r
+ button_name = tr("button %1").arg(this->count());\r
+\r
+ QPointer<QAbstractButton> button;\r
+\r
+ if (button_type == CV_PUSH_BUTTON)\r
+ button = (QAbstractButton*) new CvPushButton(this, button_name,call, userdata);\r
+\r
+ if (button_type == CV_CHECKBOX)\r
+ button = (QAbstractButton*) new CvCheckBox(this, button_name,call, userdata, initial_button_state);\r
+\r
+ if (button_type == CV_RADIOBOX)\r
+ {\r
+ button = (QAbstractButton*) new CvRadioButton(this, button_name,call, userdata, initial_button_state);\r
+ group_button->addButton(button);\r
+ }\r
+\r
+ if (button)\r
+ {\r
+ QObject::connect( button, SIGNAL( toggled(bool) ),button, SLOT( callCallBack(bool) ));\r
+ addWidget(button,Qt::AlignCenter);\r
+ }\r
+}\r
+\r
+\r
+\r
+\r
+\r
+//buttons here\r
+CvPushButton::CvPushButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4)\r
+{\r
+ myparent = arg1;\r
+ button_name = arg2;\r
+ callback = arg3;\r
+ userdata=arg4;\r
+\r
+ setObjectName(button_name);\r
+ setText(button_name);\r
+\r
+ if (isChecked())\r
+ callCallBack(true);\r
+}\r
+\r
+void CvPushButton::callCallBack(bool checked)\r
+{\r
+ if (callback)\r
+ callback(checked,userdata);\r
+}\r
+\r
+CvCheckBox::CvCheckBox(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, int initial_button_state)\r
+{\r
+ myparent = arg1;\r
+ button_name = arg2;\r
+ callback = arg3;\r
+ userdata=arg4;\r
+\r
+ setObjectName(button_name);\r
+ setCheckState((initial_button_state == 1?Qt::Checked:Qt::Unchecked));\r
+ setText(button_name);\r
+\r
+ if (isChecked())\r
+ callCallBack(true);\r
+}\r
+\r
+void CvCheckBox::callCallBack(bool checked)\r
+{\r
+ if (callback)\r
+ callback(checked,userdata);\r
+}\r
+\r
+CvRadioButton::CvRadioButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, int initial_button_state)\r
+{\r
+ myparent = arg1;\r
+ button_name = arg2;\r
+ callback = arg3;\r
+ userdata=arg4;\r
+\r
+ setObjectName(button_name);\r
+ setChecked(initial_button_state);\r
+ setText(button_name);\r
+\r
+ if (isChecked())\r
+ callCallBack(true);\r
+}\r
+\r
+void CvRadioButton::callCallBack(bool checked)\r
+{\r
+ if (callback)\r
+ callback(checked,userdata);\r
+}\r
+\r
+\r
+\r
+\r
+//here CvWinProperties class\r
+CvWinProperties::CvWinProperties(QString name_paraWindow, QWidget* parent)\r
+{\r
+ setParent(parent);\r
+ setWindowFlags(Qt::Tool);\r
+ setContentsMargins(0,0,0,0);\r
+ setWindowTitle(name_paraWindow);\r
+ setObjectName(name_paraWindow);\r
+ resize(100,50);\r
+\r
+ myLayout = new QBoxLayout(QBoxLayout::TopToBottom);\r
+ myLayout->setObjectName(QString::fromUtf8("boxLayout"));\r
+ myLayout->setContentsMargins(0, 0, 0, 0);\r
+ myLayout->setSpacing(0);\r
+ myLayout->setMargin(0);\r
+ myLayout->setSizeConstraint(QLayout::SetFixedSize);\r
+ setLayout(myLayout);\r
+\r
+ hide();\r
+}\r
+\r
+void CvWinProperties::closeEvent ( QCloseEvent * e )\r
+{\r
+ e->accept();//intersept the close event (not sure I really need it)\r
+ //an hide event is also sent. I will intercept it and do some processing\r
+}\r
+\r
+void CvWinProperties::showEvent ( QShowEvent * event )\r
+{\r
+ //why -1,-1 ?: do this trick because the first time the code is run,\r
+ //no value pos was saved so we let Qt move the window in the middle of its parent (event ignored).\r
+ //then hide will save the last position and thus, we want to retreive it (event accepted).\r
+ QPoint mypos(-1,-1);\r
+ QSettings settings("OpenCV2", this->windowTitle());\r
+ mypos = settings.value("pos", mypos).toPoint();\r
+\r
+ if (mypos.x()>=0)\r
+ {\r
+ move(mypos);\r
+ event->accept();\r
+ }\r
+ else{\r
+ event->ignore();\r
+ }\r
+}\r
+\r
+void CvWinProperties::hideEvent ( QHideEvent * event )\r
+{\r
+ QSettings settings("OpenCV2", this->windowTitle());\r
+ settings.setValue("pos", pos());//there is an offset of 6 pixels (so the window's position is wrong -- why ?)\r
+ event->accept();\r
+}\r
+\r
+CvWinProperties::~CvWinProperties()\r
+{\r
+ //clear the setting pos\r
+ QSettings settings("OpenCV2", this->windowTitle());\r
+ settings.remove("pos");\r
+\r
+\r
+ QLayoutItem *child;\r
+ if (myLayout)\r
+ {\r
+ while ((child = myLayout->takeAt(0)) != 0)\r
+ delete child;\r
+\r
+ delete myLayout;\r
+ }\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+//Here CvWindow class\r
+CvWindow::CvWindow(QString arg, int arg2)\r
+{\r
+ moveToThread(qApp->instance()->thread());\r
+ param_name = arg;\r
+\r
+ param_flags = arg2 & 0x0000000F;\r
+ param_gui_mode = arg2 & 0x000000F0;\r
+ param_ratio_mode = arg2 & 0x00000F00;\r
+\r
+ setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory\r
+ setContentsMargins(0,0,0,0);\r
+ setWindowTitle(param_name);\r
+ setObjectName(param_name);\r
+\r
+ resize(400,300);\r
+\r
+ //1: create control panel\r
+ if (!global_control_panel)\r
+ global_control_panel = createParameterWindow();\r
+\r
+ //2: Layouts\r
+ createBarLayout();\r
+ createGlobalLayout();\r
+\r
+ //3: my view\r
+ int mode_display = CV_MODE_NORMAL;\r
+#if defined( HAVE_QT_OPENGL )\r
+ mode_display = CV_MODE_OPENGL;\r
+#endif\r
+ createView(mode_display, param_ratio_mode);\r
+\r
+ //4: shortcuts and actions\r
+ createActionsandShortcuts();\r
+\r
+ //5: toolBar and statusbar\r
+ if (param_gui_mode == CV_GUI_EXPANDED)\r
+ {\r
+ createToolBar();\r
+ createStatusBar();\r
+ }\r
+\r
+\r
+ //Now attach everything\r
+ if (myToolBar)\r
+ myGlobalLayout->addWidget(myToolBar,Qt::AlignCenter);\r
+\r
+ myGlobalLayout->addWidget(myview,Qt::AlignCenter);\r
+\r
+ myGlobalLayout->addLayout(myBarLayout,Qt::AlignCenter);\r
+\r
+ if (myStatusBar)\r
+ myGlobalLayout->addWidget(myStatusBar,Qt::AlignCenter);\r
+\r
+ setLayout(myGlobalLayout);\r
+ show();\r
+\r
+}\r
+\r
+CvWindow::~CvWindow()\r
+{\r
+ QLayoutItem *child;\r
+\r
+ if (myGlobalLayout)\r
+ {\r
+ while ((child = myGlobalLayout->takeAt(0)) != 0)\r
+ delete child;\r
+\r
+ delete myGlobalLayout;\r
+ }\r
+\r
+ if (myBarLayout)\r
+ {\r
+ while ((child = myBarLayout->takeAt(0)) != 0)\r
+ delete child;\r
+\r
+ delete myBarLayout;\r
+ }\r
+\r
+\r
+ if (myStatusBar)\r
+ {\r
+ delete myStatusBar;\r
+ delete myStatusBar_msg;\r
+ }\r
+\r
+ if (myToolBar)\r
+ {\r
+ for (int i=0;i<vect_QActions.count();i++)\r
+ delete vect_QActions[i];\r
+\r
+ delete myToolBar;\r
+ }\r
+\r
+ for (int i=0;i<vect_QShortcuts.count();i++)\r
+ delete vect_QShortcuts[i];\r
+\r
+ if (guiMainThread)\r
+ guiMainThread->isLastWindow();\r
+}\r
+\r
+\r
+\r
+CvButtonbar* CvWindow::createButtonbar(QString name_bar)\r
+{\r
+ QPointer<CvButtonbar> t = new CvButtonbar(global_control_panel,name_bar);\r
+ t->setAlignment(Qt::AlignHCenter);\r
+\r
+ QPointer<QBoxLayout> myLayout = global_control_panel->myLayout;\r
+\r
+ myLayout->insertLayout(myLayout->count(),t);\r
+\r
+ return t;\r
+}\r
+\r
+\r
+void CvWindow::hideTools()\r
+{\r
+ if (myToolBar)\r
+ myToolBar->hide();\r
+\r
+ if (myStatusBar)\r
+ myStatusBar->hide();\r
+\r
+ if (global_control_panel)\r
+ global_control_panel->hide();\r
+}\r
+\r
+void CvWindow::showTools()\r
+{\r
+ if (myToolBar)\r
+ myToolBar->show();\r
+\r
+ if (myStatusBar)\r
+ myStatusBar->show();\r
+\r
+}\r
+\r
+CvWinProperties* CvWindow::createParameterWindow()\r
+{\r
+ QString name_paraWindow =QFileInfo(QApplication::applicationFilePath()).fileName()+" settings";\r
+\r
+ CvWinProperties *result = new CvWinProperties(name_paraWindow,this);\r
+ return result;\r
+}\r
+\r
+void CvWindow::displayPropertiesWin()\r
+{\r
+ if (global_control_panel->isHidden())\r
+ global_control_panel->show();\r
+ else\r
+ global_control_panel->hide();\r
+}\r
+\r
+void CvWindow::createActionsandShortcuts()\r
+{\r
+ vect_QActions.resize(10);\r
+\r
+ //if the shortcuts are changed in window_QT.h, we need to update the tooltip manually\r
+ vect_QActions[0] = new QAction(QIcon(":/left-icon"),"Panning left (CTRL+arrowLEFT)",this);\r
+ vect_QActions[0]->setIconVisibleInMenu(true);\r
+ vect_QActions[0]->setShortcut(shortcut_panning_left);\r
+ QObject::connect( vect_QActions[0],SIGNAL(triggered()),myview, SLOT( siftWindowOnLeft() ));\r
+\r
+ vect_QActions[1] = new QAction(QIcon(":/right-icon"),"Panning right (CTRL+arrowRIGHT)",this);\r
+ vect_QActions[1]->setIconVisibleInMenu(true);\r
+ vect_QActions[1]->setShortcut(shortcut_panning_right);\r
+ QObject::connect( vect_QActions[1],SIGNAL(triggered()),myview, SLOT( siftWindowOnRight() ));\r
+\r
+ vect_QActions[2] = new QAction(QIcon(":/up-icon"),"Panning up (CTRL+arrowUP)",this);\r
+ vect_QActions[2]->setIconVisibleInMenu(true);\r
+ vect_QActions[2]->setShortcut(shortcut_panning_up);\r
+ QObject::connect( vect_QActions[2],SIGNAL(triggered()),myview, SLOT( siftWindowOnUp() ));\r
+\r
+ vect_QActions[3] = new QAction(QIcon(":/down-icon"),"Panning down (CTRL+arrowDOWN)",this);\r
+ vect_QActions[3]->setIconVisibleInMenu(true);\r
+ vect_QActions[3]->setShortcut(shortcut_panning_down);\r
+ QObject::connect( vect_QActions[3],SIGNAL(triggered()),myview, SLOT( siftWindowOnDown() ));\r
+\r
+ vect_QActions[4] = new QAction(QIcon(":/zoom_x1-icon"),"Zoom x1 (CTRL+Z)",this);\r
+ vect_QActions[4]->setIconVisibleInMenu(true);\r
+ vect_QActions[4]->setShortcut(shortcut_zoom_normal);\r
+ QObject::connect( vect_QActions[4],SIGNAL(triggered()),myview, SLOT( resetZoom() ));\r
+\r
+ vect_QActions[5] = new QAction(QIcon(":/imgRegion-icon"),tr("Zoom x%1 (see label) (CTRL+X)")\r
+ .arg(threshold_zoom_img_region)\r
+ ,this);\r
+ vect_QActions[5]->setIconVisibleInMenu(true);\r
+ vect_QActions[5]->setShortcut(shortcut_zoom_imgRegion);\r
+ QObject::connect( vect_QActions[5],SIGNAL(triggered()),myview, SLOT( imgRegion() ));\r
+\r
+ vect_QActions[6] = new QAction(QIcon(":/zoom_in-icon"),tr("Zoom in (CTRL++)"),this);\r
+ vect_QActions[6]->setIconVisibleInMenu(true);\r
+ vect_QActions[6]->setShortcut(shortcut_zoom_in);\r
+ QObject::connect( vect_QActions[6],SIGNAL(triggered()),myview, SLOT( ZoomIn() ));\r
+\r
+ vect_QActions[7] = new QAction(QIcon(":/zoom_out-icon"),tr("Zoom out (CTRL+-)"),this);\r
+ vect_QActions[7]->setIconVisibleInMenu(true);\r
+ vect_QActions[7]->setShortcut(shortcut_zoom_out);\r
+ QObject::connect( vect_QActions[7],SIGNAL(triggered()),myview, SLOT( ZoomOut() ));\r
+\r
+ vect_QActions[8] = new QAction(QIcon(":/save-icon"),tr("Save current image (CTRL+S)"),this);\r
+ vect_QActions[8]->setIconVisibleInMenu(true);\r
+ vect_QActions[8]->setShortcut(shortcut_save_img);\r
+ QObject::connect( vect_QActions[8],SIGNAL(triggered()),myview, SLOT( saveView() ));\r
+\r
+ vect_QActions[9] = new QAction(QIcon(":/properties-icon"),tr("Display properties window (CTRL+P)"),this);\r
+ vect_QActions[9]->setIconVisibleInMenu(true);\r
+ vect_QActions[9]->setShortcut(shortcut_properties_win);\r
+\r
+ //if (global_control_panel->myLayout->count() == 0)\r
+ // vect_QActions[9]->setDisabled(true);\r
+\r
+ QObject::connect( vect_QActions[9],SIGNAL(triggered()),this, SLOT( displayPropertiesWin() ));\r
+\r
+}\r
+\r
+void CvWindow::createToolBar()\r
+{\r
+ myToolBar = new QToolBar(this);\r
+ myToolBar->setFloatable(false);//is not a window\r
+ myToolBar->setMaximumHeight(28);\r
+\r
+ foreach (QAction *a, vect_QActions)\r
+ myToolBar->addAction(a);\r
+}\r
+\r
+void CvWindow::createStatusBar()\r
+{\r
+ myStatusBar = new QStatusBar(this);\r
+ myStatusBar->setSizeGripEnabled(false);\r
+ myStatusBar->setMaximumHeight(20);\r
+ myStatusBar_msg = new QLabel;\r
+ myStatusBar_msg->setFrameStyle(QFrame::Raised);\r
+ myStatusBar_msg->setAlignment(Qt::AlignHCenter);\r
+ myStatusBar->addWidget(myStatusBar_msg);\r
+}\r
+\r
+void CvWindow::createGlobalLayout()\r
+{\r
+ myGlobalLayout = new QBoxLayout(QBoxLayout::TopToBottom);\r
+ myGlobalLayout->setObjectName(QString::fromUtf8("boxLayout"));\r
+ myGlobalLayout->setContentsMargins(0, 0, 0, 0);\r
+ myGlobalLayout->setSpacing(0);\r
+ myGlobalLayout->setMargin(0);\r
+\r
+ if (param_flags == CV_WINDOW_AUTOSIZE)\r
+ myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize);\r
+\r
+ if (param_flags == CV_WINDOW_NORMAL)\r
+ myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);\r
+}\r
+\r
+void CvWindow::createBarLayout()\r
+{\r
+ myBarLayout = new QBoxLayout(QBoxLayout::TopToBottom);\r
+ myBarLayout->setObjectName(QString::fromUtf8("barLayout"));\r
+ myBarLayout->setContentsMargins(0, 0, 0, 0);\r
+ myBarLayout->setSpacing(0);\r
+ myBarLayout->setMargin(0);\r
+}\r
+\r
+\r
+void CvWindow::createView(int mode, int ratio)\r
+{\r
+ //mode = CV_MODE_NORMAL or CV_MODE_OPENGL\r
+ //ratio = CV_WINDOW_KEEPRATIO or CV_WINDOW_FREERATIO\r
+ myview = new ViewPort(this, mode,ratio);//parent, mode_display, keep_aspect_ratio\r
+ myview->setAlignment(Qt::AlignHCenter);\r
+}\r
+\r
+void CvWindow::setOpenGLCallback(CvOpenGLCallback func,void* userdata, double angle, double zmin, double zmax)\r
+{\r
+ myview->setOpenGLCallback(func,userdata, angle, zmin, zmax );\r
+}\r
+\r
+ViewPort* CvWindow::getView()\r
+{\r
+ return myview;\r
+}\r
+\r
+void CvWindow::displayInfo(QString text,int delayms)\r
+{\r
+ myview->startDisplayInfo(text, delayms);\r
+}\r
+\r
+void CvWindow::displayStatusBar(QString text,int delayms)\r
+{\r
+ myStatusBar->showMessage(text,delayms);\r
+}\r
+\r
+void CvWindow::updateImage(void* arr)\r
+{\r
+ myview->updateImage(arr);\r
+}\r
+\r
+void CvWindow::setMouseCallBack(CvMouseCallback m, void* param)\r
+{\r
+ myview->setMouseCallBack(m,param);\r
+}\r
+\r
+//addSlider2 is static\r
+void CvWindow::addSlider2(CvWindow* w,QString name, int* value, int count,CvTrackbarCallback2 on_change, void* userdata)\r
+{\r
+ QPointer<CvTrackbar> t = new CvTrackbar(w,name,value, count, on_change, userdata);\r
+ t->setAlignment(Qt::AlignHCenter);\r
+\r
+ QPointer<QBoxLayout> myLayout;\r
+\r
+ if (w)\r
+ {\r
+ myLayout = w->myBarLayout;\r
+ }\r
+ else\r
+ {\r
+ myLayout = global_control_panel->myLayout;\r
+\r
+ //if first one, enable control panel\r
+ //if (myLayout->count() == 0)\r
+ // guiMainThread->enablePropertiesButtonEachWindow();\r
+ }\r
+\r
+ myLayout->insertLayout( myLayout->count(),t);\r
+\r
+\r
+}\r
+\r
+//addSlider is static\r
+void CvWindow::addSlider(CvWindow* w,QString name, int* value, int count,CvTrackbarCallback on_change)\r
+{\r
+ QPointer<CvTrackbar> t = new CvTrackbar(w,name,value, count, on_change);\r
+ t->setAlignment(Qt::AlignHCenter);\r
+\r
+ QPointer<QBoxLayout> myLayout;\r
+\r
+ if (w)\r
+ {\r
+ myLayout = w->myBarLayout;\r
+ }\r
+ else\r
+ {\r
+ myLayout = global_control_panel->myLayout;\r
+\r
+ //if first one, enable control panel\r
+ //if (myLayout->count() == 0)\r
+ // guiMainThread->enablePropertiesButtonEachWindow();\r
+ }\r
+\r
+ myLayout->insertLayout( myLayout->count(),t);\r
+\r
+\r
+}\r
+\r
+//Need more test here !\r
+void CvWindow::keyPressEvent(QKeyEvent *event)\r
+{\r
+ //see http://doc.trolltech.com/4.6/qt.html#Key-enum\r
+ int key = event->key();\r
+ bool goodKey = false;\r
+\r
+ if (key>=20 && key<=255 )\r
+ {\r
+ key = (int)event->text().toLocal8Bit().at(0);\r
+ goodKey = true;\r
+ }\r
+\r
+ if (key == Qt::Key_Escape)\r
+ {\r
+ key = 27;\r
+ goodKey = true;\r
+ }\r
+\r
+ //control plus (Z, +, -, up, down, left, right) are used for zoom/panning functions\r
+ if (event->modifiers() != Qt::ControlModifier && goodKey)\r
+ {\r
+ mutexKey.lock();\r
+ last_key = key;\r
+ //last_key = event->nativeVirtualKey ();\r
+ mutexKey.unlock();\r
+ key_pressed.wakeAll();\r
+ //event->accept();\r
+ }\r
+\r
+ QWidget::keyPressEvent(event);\r
+}\r
+\r
+//TODO: load CV_GUI flag (done) and act accordingly (create win property if needed and attach trackbars)\r
+void CvWindow::readSettings()\r
+{\r
+ //organisation and application's name\r
+ QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());\r
+ QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();\r
+ QSize size = settings.value("size", QSize(400, 400)).toSize();\r
+ //param_name = settings.value("name_window",param_name).toString();\r
+ param_flags = settings.value("mode_resize",param_flags).toInt();\r
+ param_gui_mode = settings.value("mode_gui",param_gui_mode).toInt();\r
+\r
+ param_ratio_mode = settings.value("mode_ratio",param_ratio_mode).toInt();\r
+ myview->param_keepRatio = settings.value("view_aspectRatio",myview->param_keepRatio).toInt();\r
+\r
+ param_flags = settings.value("mode_resize",param_flags).toInt();\r
+ qreal m11 = settings.value("matrix_view.m11",myview->param_matrixWorld.m11()).toDouble();\r
+ qreal m12 = settings.value("matrix_view.m12",myview->param_matrixWorld.m12()).toDouble();\r
+ qreal m13 = settings.value("matrix_view.m13",myview->param_matrixWorld.m13()).toDouble();\r
+ qreal m21 = settings.value("matrix_view.m21",myview->param_matrixWorld.m21()).toDouble();\r
+ qreal m22 = settings.value("matrix_view.m22",myview->param_matrixWorld.m22()).toDouble();\r
+ qreal m23 = settings.value("matrix_view.m23",myview->param_matrixWorld.m23()).toDouble();\r
+ qreal m31 = settings.value("matrix_view.m31",myview->param_matrixWorld.m31()).toDouble();\r
+ qreal m32 = settings.value("matrix_view.m32",myview->param_matrixWorld.m32()).toDouble();\r
+ qreal m33 = settings.value("matrix_view.m33",myview->param_matrixWorld.m33()).toDouble();\r
+ myview->param_matrixWorld = QTransform(m11,m12,m13,m21,m22,m23,m31,m32,m33);\r
+\r
+ //trackbar here\r
+ icvLoadTrackbars(&settings);\r
+\r
+ resize(size);\r
+ move(pos);\r
+\r
+ if (global_control_panel)\r
+ {\r
+ icvLoadControlPanel();\r
+ global_control_panel->move(settings.value("posPanel", global_control_panel->pos()).toPoint());\r
+ }\r
+}\r
+\r
+void CvWindow::writeSettings()\r
+{\r
+ //organisation and application's name\r
+ QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());\r
+ //settings.setValue("name_window",param_name);\r
+ settings.setValue("pos", pos());\r
+ settings.setValue("size", size());\r
+ settings.setValue("mode_resize",param_flags);\r
+ settings.setValue("mode_gui",param_gui_mode);\r
+\r
+ settings.setValue("param_ratio_mode",param_ratio_mode);\r
+ settings.setValue("view_aspectRatio",myview->param_keepRatio);\r
+\r
+ settings.setValue("matrix_view.m11",myview->param_matrixWorld.m11());\r
+ settings.setValue("matrix_view.m12",myview->param_matrixWorld.m12());\r
+ settings.setValue("matrix_view.m13",myview->param_matrixWorld.m13());\r
+ settings.setValue("matrix_view.m21",myview->param_matrixWorld.m21());\r
+ settings.setValue("matrix_view.m22",myview->param_matrixWorld.m22());\r
+ settings.setValue("matrix_view.m23",myview->param_matrixWorld.m23());\r
+ settings.setValue("matrix_view.m31",myview->param_matrixWorld.m31());\r
+ settings.setValue("matrix_view.m32",myview->param_matrixWorld.m32());\r
+ settings.setValue("matrix_view.m33",myview->param_matrixWorld.m33());\r
+\r
+ icvSaveTrackbars(&settings);\r
+\r
+\r
+ if (global_control_panel)\r
+ {\r
+ icvSaveControlPanel();\r
+ settings.setValue("posPanel", global_control_panel->pos());\r
+ }\r
+}\r
+\r
+void CvWindow::icvLoadControlPanel()\r
+{\r
+ QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()+" control panel");\r
+ int size = settings.beginReadArray("bars");\r
+ int subsize;\r
+ CvBar* t;\r
+ if (size == global_control_panel->myLayout->layout()->count())\r
+ for (int i = 0; i < size; ++i) {\r
+ t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i);\r
+ settings.setArrayIndex(i);\r
+ if (t->type == type_CvTrackbar)\r
+ {\r
+ if (t->name_bar == settings.value("namebar").toString())\r
+ {\r
+ ((CvTrackbar*)t)->slider->setValue(settings.value("valuebar").toInt());\r
+ }\r
+ }\r
+ if (t->type == type_CvButtonbar)\r
+ {\r
+ subsize = settings.beginReadArray(QString("buttonbar")+i);\r
+\r
+ if ( subsize == ((CvButtonbar*)t)->layout()->count() )\r
+ icvLoadButtonbar((CvButtonbar*)t,&settings);\r
+ \r
+ settings.endArray();\r
+ }\r
+ }\r
+ settings.endArray();\r
+}\r
+\r
+void CvWindow::icvSaveControlPanel()\r
+{\r
+ QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName()+" control panel");\r
+ settings.beginWriteArray("bars");\r
+\r
+ CvBar* t;\r
+ for (int i = 0; i < global_control_panel->myLayout->layout()->count(); ++i) {\r
+ t = (CvBar*) global_control_panel->myLayout->layout()->itemAt(i);\r
+ settings.setArrayIndex(i);\r
+ if (t->type == type_CvTrackbar)\r
+ {\r
+ settings.setValue("namebar", QString(t->name_bar));\r
+ settings.setValue("valuebar",((CvTrackbar*)t)->slider->value());\r
+ }\r
+ if (t->type == type_CvButtonbar)\r
+ {\r
+ settings.beginWriteArray(QString("buttonbar")+i);\r
+ icvSaveButtonbar((CvButtonbar*)t,&settings);\r
+ settings.endArray();\r
+ }\r
+ }\r
+ settings.endArray();\r
+}\r
+\r
+void CvWindow::icvSaveButtonbar(CvButtonbar* b,QSettings *settings)\r
+{\r
+ QWidget* temp;\r
+ QString myclass;\r
+ for (int i = 0; i < b->layout()->count(); ++i) {\r
+ settings->setArrayIndex(i);\r
+ temp = (QWidget*) b->layout()->itemAt(i)->widget();\r
+ myclass = QString(temp->metaObject ()->className ());\r
+ if (myclass == "CvPushButton")\r
+ {\r
+ CvPushButton* button = (CvPushButton*) temp;\r
+ settings->setValue("namebutton", QString(button->text()) );\r
+ settings->setValue("valuebutton", int(button->isChecked()));\r
+ }\r
+\r
+ if (myclass == "CvCheckBox")\r
+ {\r
+ CvCheckBox* button = (CvCheckBox*) temp;\r
+ settings->setValue("namebutton", QString(button->text()) );\r
+ settings->setValue("valuebutton", int(button->isChecked()));\r
+ }\r
+\r
+ if (myclass == "CvRadioButton")\r
+ {\r
+ CvRadioButton* button = (CvRadioButton*) temp;\r
+ settings->setValue("namebutton", QString(button->text()) );\r
+ settings->setValue("valuebutton", int(button->isChecked()));\r
+ }\r
+ }\r
+}\r
+\r
+void CvWindow::icvLoadButtonbar(CvButtonbar* b,QSettings *settings)\r
+{\r
+ QWidget* temp;\r
+ QString myclass;\r
+ for (int i = 0; i < b->layout()->count(); ++i)\r
+ {\r
+ settings->setArrayIndex(i);\r
+ temp = (QWidget*) b->layout()->itemAt(i)->widget();\r
+ myclass = QString(temp->metaObject ()->className ());\r
+ if (myclass == "CvPushButton")\r
+ {\r
+ CvPushButton* button = (CvPushButton*) temp;\r
+ if (button->text() == settings->value("namebutton").toString())\r
+ button->setChecked(settings->value("valuebutton").toInt());\r
+ }\r
+\r
+ if (myclass == "CvCheckBox")\r
+ {\r
+ CvCheckBox* button = (CvCheckBox*) temp;\r
+ if (button->text() == settings->value("namebutton").toString())\r
+ button->setChecked(settings->value("valuebutton").toInt());\r
+ }\r
+\r
+ if (myclass == "CvRadioButton")\r
+ {\r
+ CvRadioButton* button = (CvRadioButton*) temp;\r
+ if (button->text() == settings->value("namebutton").toString())\r
+ button->setChecked(settings->value("valuebutton").toInt());\r
+ }\r
+\r
+ }\r
+}\r
+\r
+\r
+void CvWindow::icvLoadTrackbars(QSettings *settings)\r
+{\r
+ int size = settings->beginReadArray("trackbars");\r
+ QPointer<CvTrackbar> t;\r
+\r
+ //trackbar are saved in the same order, so no need to use icvFindTrackbarByName\r
+\r
+ if (myBarLayout->layout()->count() == size)//if not the same number, the window saved and loaded is not the same (nb trackbar not equal)\r
+ for (int i = 0; i < size; ++i)\r
+ {\r
+ settings->setArrayIndex(i);\r
+ t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);\r
+\r
+ if (t->name_bar == settings->value("name").toString())\r
+ t->slider->setValue(settings->value("value").toInt());\r
+\r
+ }\r
+ settings->endArray();\r
+\r
+}\r
+\r
+void CvWindow::icvSaveTrackbars(QSettings *settings)\r
+{\r
+ QPointer<CvTrackbar> t;\r
+\r
+ settings->beginWriteArray("trackbars");\r
+\r
+ for (int i = 0; i < myBarLayout->layout()->count(); ++i) {\r
+ t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);\r
+ settings->setArrayIndex(i);\r
+ settings->setValue("name", t->name_bar);\r
+ settings->setValue("value", t->slider->value());\r
+ }\r
+ settings->endArray();\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+//Here is ViewPort class\r
+ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)\r
+{\r
+ centralWidget = arg,\r
+ setParent(centralWidget);\r
+ mode_display = arg2;\r
+ param_keepRatio = arg3;\r
+\r
+\r
+ //setAlignment(Qt::AlignLeft | Qt::AlignTop);\r
+ setContentsMargins(0,0,0,0);\r
+\r
+ setObjectName(QString::fromUtf8("graphicsView"));\r
+ timerDisplay = new QTimer(this);\r
+ timerDisplay->setSingleShot(true);\r
+ connect(timerDisplay, SIGNAL(timeout()), this, SLOT(stopDisplayInfo()));\r
+ drawInfo = false;\r
+ positionGrabbing = QPointF(0,0);\r
+ positionCorners = QRect(0,0,size().width(),size().height());\r
+ on_mouse = NULL;\r
+ mouseCoordinate = QPoint(-1,-1);\r
+ on_openGL_draw3D = NULL;\r
+\r
+ //no border\r
+ setStyleSheet( "QGraphicsView { border-style: none; }" ); \r
+\r
+#if defined( HAVE_QT_OPENGL )\r
+ \r
+ if ( mode_display == CV_MODE_OPENGL)\r
+ {\r
+ myGL = new QGLWidget(QGLFormat(QGL::SampleBuffers));\r
+ setViewport(myGL);\r
+ if (param_keepRatio == CV_WINDOW_KEEPRATIO)\r
+ {\r
+ //TODO: fix this bug:\r
+ //::::blinking in OpenGL with CV_WINDOW_KEEPRATIO::::\r
+ //The raison is that to move the widget in the middle and resize it manually to keep the aspect ratio,\r
+ //we resize in resizeEvent() and use a trick not to be blocked in an infinity loop.\r
+ //This is working fine if the viewport is not OpenGL, however we have two rendering with OpenGL.\r
+ //The first rendering with the widget not moved in the midle (so stuck in top left), then the final and correct rendering.\r
+ //This two rendering are visible with OpenGL and CV_WINDOW_KEEPRATIO but not with native rendering (why ???)\r
+\r
+ //I tried to use Qt::AlignCenter of the layout manager but the widget does not expand anymore\r
+ //I tried to center with painter.drawImage (in draw2D), but the imgRegion and all other function using the size of the widget will not work anymore.\r
+ startDisplayInfo("WARNING: For now, you cannot use OpenGL rendering with CV_WINDOW_KEEPRATIO, so we changed to CV_WINDOW_FREERATIO", 5000);\r
+ setRatio(CV_WINDOW_FREERATIO);\r
+ }\r
+\r
+ //setViewport(new QGLWidget());\r
+ angle = DEFAULT_ANGLE;\r
+ zmin = DEFAULT_ZMIN;\r
+ zmax = DEFAULT_ZMAX;\r
+ initGL();\r
+ }\r
+\r
+#endif\r
+\r
+ image2Draw_ipl=cvCreateImage(cvSize(viewport()->width(),viewport()->height()),IPL_DEPTH_8U,3);\r
+ \r
+ nbChannelOriginImage = 0;\r
+ cvZero(image2Draw_ipl);\r
+\r
+ setInteractive(false);\r
+ setMouseTracking (true);//receive mouse event everytime\r
+\r
+}\r
+\r
+ViewPort::~ViewPort()\r
+{\r
+ if (image2Draw_ipl)\r
+ cvReleaseImage(&image2Draw_ipl);\r
+\r
+ \r
+#if defined( HAVE_QT_OPENGL )\r
+ if (myGL)\r
+ delete myGL;\r
+#endif;\r
+ \r
+ qDebug()<<"kill vieport";\r
+\r
+ delete timerDisplay;\r
+}\r
+\r
+void ViewPort::contextMenuEvent(QContextMenuEvent *event)\r
+{\r
+ if (centralWidget->vect_QActions.size() > 0)\r
+ {\r
+ QMenu menu(this);\r
+ foreach (QAction *a, centralWidget->vect_QActions)\r
+ menu.addAction(a);\r
+ // menu.popup(event->globalPos());\r
+ menu.exec(event->globalPos());\r
+ }\r
+}\r
+\r
+//can save as JPG, JPEG, BMP, PNG\r
+void ViewPort::saveView()\r
+{\r
+ QDate date_d = QDate::currentDate ();\r
+ QString date_s = date_d.toString("dd.MM.yyyy");\r
+ QString name_s = centralWidget->param_name+"_screenshot_"+date_s;\r
+\r
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save File %1").arg(name_s),\r
+ name_s+".png",\r
+ tr("Images (*.png *.jpg *.bmp *.jpeg)"));\r
+\r
+ if (!fileName.isEmpty ())//save the picture\r
+ {\r
+ QString extension = fileName.right(3);\r
+\r
+\r
+#if defined( HAVE_QT_OPENGL )\r
+ image2Draw_qt_resized = ((QGLWidget*)viewport())->grabFrameBuffer();\r
+#else\r
+ // (no need anymore) create the image resized to receive the 'screenshot'\r
+ // image2Draw_qt_resized = QImage(viewport()->width(), viewport()->height(),QImage::Format_RGB888);\r
+ \r
+ QPainter saveimage(&image2Draw_qt_resized);\r
+ this->render(&saveimage);\r
+#endif\r
+\r
+ // Save it..\r
+ if (QString::compare(extension, "png", Qt::CaseInsensitive) == 0)\r
+ {\r
+ image2Draw_qt_resized.save(fileName, "PNG");\r
+ return;\r
+ }\r
+\r
+ if (QString::compare(extension, "jpg", Qt::CaseInsensitive) == 0)\r
+ {\r
+ image2Draw_qt_resized.save(fileName, "JPG");\r
+ return;\r
+ }\r
+\r
+ if (QString::compare(extension, "bmp", Qt::CaseInsensitive) == 0)\r
+ {\r
+ image2Draw_qt_resized.save(fileName, "BMP");\r
+ return;\r
+ }\r
+\r
+ if (QString::compare(extension, "jpeg", Qt::CaseInsensitive) == 0)\r
+ {\r
+ image2Draw_qt_resized.save(fileName, "JPEG");\r
+ return;\r
+ }\r
+\r
+ CV_Error(CV_StsNullPtr, "file extension not recognized, please choose between JPG, JPEG, BMP or PNG");\r
+ }\r
+}\r
+\r
+void ViewPort::setRatio(int flags)\r
+{\r
+ centralWidget->param_ratio_mode = flags;\r
+ param_keepRatio = flags;\r
+ updateGeometry();\r
+ viewport()->update();\r
+}\r
+\r
+void ViewPort::imgRegion()\r
+{\r
+ scaleView( (threshold_zoom_img_region/param_matrixWorld.m11()-1)*5,QPointF(size().width()/2,size().height()/2));\r
+}\r
+\r
+int ViewPort::getRatio()\r
+{\r
+ return param_keepRatio;\r
+}\r
+\r
+void ViewPort::resetZoom()\r
+{\r
+ param_matrixWorld.reset();\r
+ controlImagePosition();\r
+}\r
+\r
+void ViewPort::ZoomIn()\r
+{\r
+ scaleView( 0.5,QPointF(size().width()/2,size().height()/2));\r
+}\r
+\r
+void ViewPort::ZoomOut()\r
+{\r
+ scaleView( -0.5,QPointF(size().width()/2,size().height()/2));\r
+}\r
+\r
+//Note: move 2 percent of the window\r
+void ViewPort::siftWindowOnLeft()\r
+{\r
+ float delta = 2*width()/(100.0*param_matrixWorld.m11());\r
+ moveView(QPointF(delta,0));\r
+}\r
+\r
+//Note: move 2 percent of the window\r
+void ViewPort::siftWindowOnRight()\r
+{\r
+ float delta = -2*width()/(100.0*param_matrixWorld.m11());\r
+ moveView(QPointF(delta,0));\r
+}\r
+\r
+//Note: move 2 percent of the window\r
+void ViewPort::siftWindowOnUp()\r
+{\r
+ float delta = 2*height()/(100.0*param_matrixWorld.m11());\r
+ moveView(QPointF(0,delta));\r
+}\r
+\r
+//Note: move 2 percent of the window\r
+void ViewPort::siftWindowOnDown()\r
+{\r
+ float delta = -2*height()/(100.0*param_matrixWorld.m11());\r
+ moveView(QPointF(0,delta));\r
+}\r
+\r
+void ViewPort::startDisplayInfo(QString text, int delayms)\r
+{\r
+ if (timerDisplay->isActive())\r
+ stopDisplayInfo();\r
+\r
+ infoText = text;\r
+ timerDisplay->start(delayms);\r
+ drawInfo = true;\r
+}\r
+\r
+void ViewPort::stopDisplayInfo()\r
+{\r
+ timerDisplay->stop();\r
+ drawInfo = false;\r
+}\r
+\r
+inline bool ViewPort::isSameSize(IplImage* img1,IplImage* img2)\r
+{\r
+ return img1->width == img2->width && img1->height == img2->height;\r
+}\r
+\r
+void ViewPort::updateImage(void* arr)\r
+{\r
+ //if (!arr)\r
+ //CV_Error(CV_StsNullPtr, "NULL arr pointer (in showImage)" );\r
+ CV_Assert(arr)\r
+\r
+ IplImage* tempImage = (IplImage*)arr;\r
+\r
+ if (!isSameSize(image2Draw_ipl,tempImage))\r
+ {\r
+ cvReleaseImage(&image2Draw_ipl);\r
+\r
+ //the image in ipl (to do a deep copy with cvCvtColor)\r
+ image2Draw_ipl=cvCreateImage(cvGetSize(tempImage),IPL_DEPTH_8U,3);\r
+\r
+ //the ipl image in qt format (with shared memory)\r
+ //image2Draw_qt = QImage((uchar*) image2Draw_ipl->imageData, image2Draw_ipl->width, image2Draw_ipl->height,QImage::Format_RGB888);\r
+\r
+ //nbChannelOriginImage = tempImage->nChannels;\r
+\r
+ updateGeometry();\r
+ }\r
+\r
+ nbChannelOriginImage = tempImage->nChannels;\r
+\r
+\r
+ //cvCvtColor(tempImage,image2Draw_ipl,CV_BGR2RGB);//will not work if tempImage is 1 channel !!\r
+ cvConvertImage(tempImage,image2Draw_ipl,CV_CVTIMG_SWAP_RB );\r
+\r
+ viewport()->update();\r
+}\r
+\r
+void ViewPort::setMouseCallBack(CvMouseCallback m, void* param)\r
+{\r
+ on_mouse = m;\r
+ on_mouse_param = param;\r
+}\r
+\r
+void ViewPort::setOpenGLCallback(CvOpenGLCallback func,void* userdata, double angle_arg, double zmin_arg, double zmax_arg)\r
+{\r
+ //avoid unreferenced formal parameter warning with vs 2008\r
+ //http://msdn.microsoft.com/en-en/library/26kb9fy0%28VS.80%29.aspx\r
+ func;userdata;angle_arg;zmin_arg;zmax_arg;\r
+\r
+#if defined( HAVE_QT_OPENGL )\r
+ on_openGL_draw3D = func;\r
+ on_openGL_param = userdata;\r
+\r
+ if (angle_arg > 0)\r
+ angle = angle_arg;\r
+ else\r
+ angle = DEFAULT_ANGLE;\r
+\r
+\r
+ if (zmin_arg >= 0)\r
+ zmin = zmin_arg;\r
+ else\r
+ zmin = DEFAULT_ZMIN;\r
+\r
+\r
+ if (zmax_arg > 0)\r
+ zmax = zmax_arg;\r
+ else\r
+ zmax = DEFAULT_ZMAX;\r
+#endif\r
+}\r
+\r
+void ViewPort::controlImagePosition()\r
+{\r
+ qreal left, top, right, bottom;\r
+\r
+ //after check top-left, bottom right corner to avoid getting "out" during zoom/panning\r
+ param_matrixWorld.map(0,0,&left,&top);\r
+\r
+ if (left > 0)\r
+ {\r
+ param_matrixWorld.translate(-left,0);\r
+ left = 0;\r
+ }\r
+ if (top > 0)\r
+ {\r
+ param_matrixWorld.translate(0,-top);\r
+ top = 0;\r
+ }\r
+ //-------\r
+\r
+ QSize sizeImage = size();\r
+ param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);\r
+ if (right < sizeImage.width())\r
+ {\r
+ param_matrixWorld.translate(sizeImage.width()-right,0);\r
+ right = sizeImage.width();\r
+ }\r
+ if (bottom < sizeImage.height())\r
+ {\r
+ param_matrixWorld.translate(0,sizeImage.height()-bottom);\r
+ bottom = sizeImage.height();\r
+ }\r
+\r
+ //save corner position\r
+ positionCorners.setTopLeft(QPoint(left,top));\r
+ positionCorners.setBottomRight(QPoint(right,bottom));\r
+ //save also the inv matrix\r
+ matrixWorld_inv = param_matrixWorld.inverted();\r
+\r
+ //viewport()->update();\r
+}\r
+\r
+void ViewPort::moveView(QPointF delta)\r
+{\r
+ param_matrixWorld.translate(delta.x(),delta.y());\r
+ controlImagePosition();\r
+ viewport()->update();\r
+}\r
+\r
+//factor is -0.5 (zoom out) or 0.5 (zoom in)\r
+void ViewPort::scaleView(qreal factor,QPointF center)\r
+{\r
+ factor/=5;//-0.1 <-> 0.1\r
+ factor+=1;//0.9 <-> 1.1\r
+\r
+ //limit zoom out ---\r
+ if (param_matrixWorld.m11()==1 && factor < 1)\r
+ return;\r
+\r
+ if (param_matrixWorld.m11()*factor<1)\r
+ factor = 1/param_matrixWorld.m11();\r
+\r
+\r
+ //limit zoom int ---\r
+ if (param_matrixWorld.m11()>100 && factor > 1)\r
+ return;\r
+\r
+ //inverse the transform\r
+ int a, b;\r
+ matrixWorld_inv.map(center.x(),center.y(),&a,&b);\r
+\r
+ param_matrixWorld.translate(a-factor*a,b-factor*b);\r
+ param_matrixWorld.scale(factor,factor);\r
+\r
+ controlImagePosition();\r
+\r
+ //display new zoom\r
+ if (centralWidget->myStatusBar)\r
+ centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);\r
+\r
+ if (param_matrixWorld.m11()>1)\r
+ setCursor(Qt::OpenHandCursor);\r
+ else\r
+ unsetCursor();\r
+}\r
+\r
+void ViewPort::wheelEvent(QWheelEvent *event)\r
+{\r
+ scaleView( -event->delta() / 240.0,event->pos());\r
+ viewport()->update();\r
+}\r
+\r
+void ViewPort::mousePressEvent(QMouseEvent *event)\r
+{\r
+ int cv_event = -1, flags = 0;\r
+ QPoint pt = event->pos();\r
+\r
+ //icvmouseHandler: pass parameters for cv_event, flags\r
+ icvmouseHandler(event, mouse_down, cv_event, flags);\r
+ icvmouseProcessing(QPointF(pt), cv_event, flags);\r
+\r
+ if (param_matrixWorld.m11()>1)\r
+ {\r
+ setCursor(Qt::ClosedHandCursor);\r
+ positionGrabbing = event->pos();\r
+ }\r
+\r
+ QWidget::mousePressEvent(event);\r
+}\r
+\r
+void ViewPort::mouseReleaseEvent(QMouseEvent *event)\r
+{\r
+\r
+ int cv_event = -1, flags = 0;\r
+ QPoint pt = event->pos();\r
+\r
+ //icvmouseHandler: pass parameters for cv_event, flags\r
+ icvmouseHandler(event, mouse_up, cv_event, flags);\r
+ icvmouseProcessing(QPointF(pt), cv_event, flags);\r
+\r
+ if (param_matrixWorld.m11()>1)\r
+ setCursor(Qt::OpenHandCursor);\r
+\r
+ QWidget::mouseReleaseEvent(event);\r
+}\r
+\r
+void ViewPort::mouseDoubleClickEvent(QMouseEvent *event)\r
+{\r
+ int cv_event = -1, flags = 0;\r
+ QPoint pt = event->pos();\r
+\r
+ //icvmouseHandler: pass parameters for cv_event, flags\r
+ icvmouseHandler(event, mouse_dbclick, cv_event, flags);\r
+ icvmouseProcessing(QPointF(pt), cv_event, flags);\r
+\r
+ QWidget::mouseDoubleClickEvent(event);\r
+}\r
+\r
+void ViewPort::mouseMoveEvent(QMouseEvent *event)\r
+{\r
+ int cv_event = -1, flags = 0;\r
+ QPoint pt = event->pos();\r
+\r
+ //icvmouseHandler: pass parameters for cv_event, flags\r
+ icvmouseHandler(event, mouse_move, cv_event, flags);\r
+ icvmouseProcessing(QPointF(pt), cv_event, flags);\r
+\r
+\r
+ if (param_matrixWorld.m11()>1 && event->buttons() == Qt::LeftButton)\r
+ {\r
+ QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11();\r
+ positionGrabbing = event->pos();\r
+ moveView(dxy);\r
+ }\r
+\r
+ //I update the statusbar here because if the user does a cvWaitkey(0) (like with inpaint.cpp)\r
+ //the status bar will only be repaint when a click occurs.\r
+ if (centralWidget->myStatusBar)\r
+ viewport()->update();\r
+\r
+ QWidget::mouseMoveEvent(event);\r
+}\r
+\r
+//up, down, dclick, move\r
+void ViewPort::icvmouseHandler(QMouseEvent *event, type_mouse_event category, int &cv_event, int &flags)\r
+{\r
+\r
+ switch(event->modifiers())\r
+ {\r
+ case Qt::ShiftModifier:\r
+ flags = CV_EVENT_FLAG_SHIFTKEY;\r
+ break;\r
+ case Qt::ControlModifier:\r
+ flags = CV_EVENT_FLAG_CTRLKEY;\r
+ break;\r
+ case Qt::AltModifier:\r
+ flags = CV_EVENT_FLAG_ALTKEY;\r
+ break;\r
+ case Qt::NoModifier :\r
+ break;\r
+ case Qt::MetaModifier:\r
+ break;\r
+ case Qt::KeypadModifier:\r
+ break;\r
+ default:;\r
+ }\r
+\r
+ switch(event->button())\r
+ {\r
+ case Qt::LeftButton:\r
+ cv_event = tableMouseButtons[category][0];\r
+ flags |= CV_EVENT_FLAG_LBUTTON;\r
+ break;\r
+ case Qt::RightButton:\r
+ cv_event = tableMouseButtons[category][1];\r
+ flags |= CV_EVENT_FLAG_RBUTTON;\r
+ break;\r
+ case Qt::MidButton:\r
+ cv_event = tableMouseButtons[category][2];\r
+ flags |= CV_EVENT_FLAG_MBUTTON;\r
+ break;\r
+ default:;\r
+ }\r
+}\r
+\r
+void ViewPort::icvmouseProcessing(QPointF pt, int cv_event, int flags)\r
+{\r
+ //to convert mouse coordinate\r
+ qreal pfx, pfy;\r
+ //qreal ratioX = float(image2Draw_qt.width())/image2Draw_qt_resized.width();\r
+ //qreal ratioY = float(image2Draw_qt.height())/image2Draw_qt_resized.height();\r
+ matrixWorld_inv.map(pt.x(),pt.y(),&pfx,&pfy);\r
+ \r
+ mouseCoordinate.rx()=floor(pfx/ratioX);\r
+ mouseCoordinate.ry()=floor(pfy/ratioY);\r
+\r
+ if (on_mouse)\r
+ on_mouse( cv_event, mouseCoordinate.x(),mouseCoordinate.y(), flags, on_mouse_param );\r
+\r
+}\r
+\r
+QSize ViewPort::sizeHint() const\r
+{\r
+ if(image2Draw_ipl)\r
+ {\r
+ //qDebug()<<centralWidget->param_name<<" "<<image2Draw_ipl->width<<" "<<image2Draw_ipl->height;\r
+ return QSize(image2Draw_ipl->width,image2Draw_ipl->height);\r
+ } else {\r
+ return QGraphicsView::sizeHint();\r
+ }\r
+}\r
+\r
+void ViewPort::resizeEvent ( QResizeEvent *event)\r
+{\r
+\r
+ controlImagePosition();\r
+ ratioX=width()/float(image2Draw_ipl->width);\r
+ ratioY=height()/float(image2Draw_ipl->height);\r
+\r
+ \r
+ if(param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio\r
+ {\r
+ QSize newSize = QSize(image2Draw_ipl->width,image2Draw_ipl->height);\r
+ newSize.scale(event->size(),Qt::KeepAspectRatio);\r
+\r
+ //imageWidth/imageHeight = newWidth/newHeight +/- epsilon\r
+ //ratioX = ratioY +/- epsilon\r
+ //||ratioX - ratioY|| = epsilon\r
+ if (fabs(ratioX - ratioY)*100> ratioX)//avoid infinity loop / epsilon = 1% of ratioX\r
+ {\r
+ resize(newSize);\r
+\r
+ //move to the middle\r
+ //newSize get the delta offset to place the picture in the middle of its parent\r
+ newSize= (event->size()-newSize)/2;\r
+\r
+ //if the toolbar is displayed, avoid drawing myview on top of it\r
+ if (centralWidget->myToolBar)\r
+ if(!centralWidget->myToolBar->isHidden())\r
+ newSize +=QSize(0,centralWidget->myToolBar->height());\r
+\r
+ move(newSize.width(),newSize.height());\r
+ }\r
+ }\r
+\r
+ return QGraphicsView::resizeEvent(event);\r
+}\r
+\r
+void ViewPort::paintEvent(QPaintEvent* event)\r
+{\r
+\r
+ QPainter myPainter(viewport());\r
+ myPainter.setWorldTransform(param_matrixWorld);\r
+\r
+ draw2D(&myPainter);\r
+\r
+#if defined( HAVE_QT_OPENGL )\r
+ if ( mode_display == CV_MODE_OPENGL && on_openGL_draw3D)\r
+ {\r
+ myPainter.save(); // Needed when using the GL1 engine\r
+ myPainter.beginNativePainting(); // Needed when using the GL2 engine\r
+\r
+ setGL(width(),height());\r
+ on_openGL_draw3D(on_openGL_param);\r
+ unsetGL();\r
+\r
+ myPainter.endNativePainting(); // Needed when using the GL2 engine\r
+ myPainter.restore(); // Needed when using the GL1 engine\r
+ }\r
+#endif\r
+\r
+ //Now disable matrixWorld for overlay display\r
+ myPainter.setWorldMatrixEnabled (false );\r
+\r
+ //in mode zoom/panning\r
+ if (param_matrixWorld.m11()>1)\r
+ {\r
+ \r
+ if (param_matrixWorld.m11()>=threshold_zoom_img_region)\r
+ {\r
+ if (centralWidget->param_flags == CV_WINDOW_NORMAL)\r
+ startDisplayInfo("WARNING: The values displayed are the resized image's values. If you want the original image's values, use CV_WINDOW_AUTOSIZE", 1000);\r
+\r
+ drawImgRegion(&myPainter);\r
+ }\r
+\r
+ drawViewOverview(&myPainter);\r
+ }\r
+\r
+ //for information overlay\r
+ if (drawInfo)\r
+ drawInstructions(&myPainter);\r
+\r
+ //for statusbar\r
+ if (centralWidget->myStatusBar)\r
+ drawStatusBar();\r
+\r
+ QGraphicsView::paintEvent(event);\r
+}\r
+\r
+void ViewPort::draw2D(QPainter *painter)\r
+{\r
+ image2Draw_qt = QImage((uchar*) image2Draw_ipl->imageData, image2Draw_ipl->width, image2Draw_ipl->height,QImage::Format_RGB888);\r
+ image2Draw_qt_resized = image2Draw_qt.scaled(viewport()->width(),viewport()->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);\r
+ painter->drawImage(0,0,image2Draw_qt_resized);\r
+ //painter->drawImage(0,0,image2Draw_qt_resized);\r
+}\r
+\r
+void ViewPort::drawStatusBar()\r
+{\r
+ if (mouseCoordinate.x()>=0 &&\r
+ mouseCoordinate.y()>=0 &&\r
+ mouseCoordinate.x()<image2Draw_ipl->width &&\r
+ mouseCoordinate.y()<image2Draw_ipl->height)\r
+ {\r
+ QRgb rgbValue = image2Draw_qt.pixel(mouseCoordinate);\r
+\r
+ if (nbChannelOriginImage==3)\r
+ {\r
+ centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")\r
+ .arg(mouseCoordinate.x())\r
+ .arg(mouseCoordinate.y())+\r
+ tr("<font color='red'>R:%3 </font>").arg(qRed(rgbValue))+//.arg(value.val[0])+\r
+ tr("<font color='green'>G:%4 </font>").arg(qGreen(rgbValue))+//.arg(value.val[1])+\r
+ tr("<font color='blue'>B:%5</font>").arg(qBlue(rgbValue))//.arg(value.val[2])\r
+ );\r
+ }else{\r
+ //all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed\r
+ centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")\r
+ .arg(mouseCoordinate.x())\r
+ .arg(mouseCoordinate.y())+\r
+ tr("<font color='grey'>grey:%3 </font>").arg(qRed(rgbValue))\r
+ );\r
+ }\r
+ }\r
+}\r
+\r
+\r
+void ViewPort::drawImgRegion(QPainter *painter)\r
+{\r
+ qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11();\r
+ offsetX = offsetX - floor(offsetX);\r
+ qreal offsetY = param_matrixWorld.dy()/param_matrixWorld.m11();\r
+ offsetY = offsetY - floor(offsetY);\r
+\r
+ QSize view = size();\r
+ QVarLengthArray<QLineF, 30> linesX;\r
+ for (qreal x = offsetX*param_matrixWorld.m11(); x < view.width(); x += param_matrixWorld.m11() )\r
+ linesX.append(QLineF(x, 0, x, view.height()));\r
+\r
+ QVarLengthArray<QLineF, 30> linesY;\r
+ for (qreal y = offsetY*param_matrixWorld.m11(); y < view.height(); y += param_matrixWorld.m11() )\r
+ linesY.append(QLineF(0, y, view.width(), y));\r
+\r
+\r
+ QFont f = painter->font();\r
+ int original_font_size = f.pointSize();\r
+ //change font size\r
+ //f.setPointSize(4+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);\r
+ f.setPixelSize(6+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);\r
+ painter->setFont(f);\r
+ QString val;\r
+ QRgb rgbValue;\r
+\r
+ QPointF point1;//sorry, I do not know how to name it\r
+ QPointF point2;//idem\r
+\r
+ //qreal ratioX = float(image2Draw_qt.width())/image2Draw_qt_resized.width();\r
+ //qreal ratioY = float(image2Draw_qt.height())/image2Draw_qt_resized.height();\r
+\r
+ for (int j=-1;j<height()/param_matrixWorld.m11();j++)//-1 because display the pixels top rows left colums\r
+ for (int i=-1;i<width()/param_matrixWorld.m11();i++)//-1\r
+ {\r
+ point1.setX((i+offsetX)*param_matrixWorld.m11());\r
+ point1.setY((j+offsetY)*param_matrixWorld.m11());\r
+\r
+ matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry());\r
+\r
+ point2.rx()= (long) (point2.x() + 0.5);\r
+ point2.ry()= (long) (point2.y() + 0.5);\r
+\r
+ if (point2.x() >= 0 && point2.y() >= 0)\r
+ rgbValue = image2Draw_qt_resized.pixel(QPoint(point2.x(),point2.y()));\r
+ else\r
+ rgbValue = qRgb(0,0,0);\r
+\r
+ if (nbChannelOriginImage==3)\r
+ {\r
+ //for debug\r
+ /*\r
+ val = tr("%1 %2").arg(point2.x()).arg(point2.y());\r
+ painter->setPen(QPen(Qt::black, 1));\r
+ painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/2),\r
+ Qt::AlignCenter, val);\r
+ */\r
+\r
+ val = tr("%1").arg(qRed(rgbValue));\r
+ painter->setPen(QPen(Qt::red, 1));\r
+ painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/3),\r
+ Qt::AlignCenter, val);\r
+\r
+ val = tr("%1").arg(qGreen(rgbValue));\r
+ painter->setPen(QPen(Qt::green, 1));\r
+ painter->drawText(QRect(point1.x(),point1.y()+param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),\r
+ Qt::AlignCenter, val);\r
+\r
+ val = tr("%1").arg(qBlue(rgbValue));\r
+ painter->setPen(QPen(Qt::blue, 1));\r
+ painter->drawText(QRect(point1.x(),point1.y()+2*param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),\r
+ Qt::AlignCenter, val);\r
+\r
+ }\r
+ else\r
+ {\r
+\r
+ val = tr("%1").arg(qRed(rgbValue));\r
+ painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()),\r
+ Qt::AlignCenter, val);\r
+ }\r
+ }\r
+\r
+ painter->setPen(QPen(Qt::black, 1));\r
+ painter->drawLines(linesX.data(), linesX.size());\r
+ painter->drawLines(linesY.data(), linesY.size());\r
+\r
+ //restore font size\r
+ f.setPointSize(original_font_size);\r
+ painter->setFont(f);\r
+\r
+}\r
+\r
+void ViewPort::drawViewOverview(QPainter *painter)\r
+{\r
+ QSize viewSize = size();\r
+ viewSize.scale ( 100, 100,Qt::KeepAspectRatio );\r
+\r
+ const int margin = 5;\r
+\r
+ //draw the image's location\r
+ painter->setBrush(QColor(0, 0, 0, 127));\r
+ painter->setPen(Qt::darkGreen);\r
+ painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));\r
+\r
+ //daw the view's location inside the image\r
+ qreal ratioSize = 1/param_matrixWorld.m11();\r
+ qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());\r
+ painter->setPen(Qt::darkBlue);\r
+ painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,\r
+ -positionCorners.top()*ratioSize*ratioWindow,\r
+ (viewSize.width()-1)*ratioSize,\r
+ (viewSize.height()-1)*ratioSize)\r
+ );\r
+}\r
+\r
+void ViewPort::drawInstructions(QPainter *painter)\r
+{\r
+ QFontMetrics metrics = QFontMetrics(font());\r
+ int border = qMax(4, metrics.leading());\r
+\r
+ QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125),\r
+ Qt::AlignCenter | Qt::TextWordWrap, infoText);\r
+ painter->setRenderHint(QPainter::TextAntialiasing);\r
+ painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),\r
+ QColor(0, 0, 0, 127));\r
+ painter->setPen(Qt::white);\r
+ painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),\r
+ QColor(0, 0, 0, 127));\r
+\r
+ painter->drawText((width() - rect.width())/2, border,\r
+ rect.width(), rect.height(),\r
+ Qt::AlignCenter | Qt::TextWordWrap, infoText);\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+#if defined( HAVE_QT_OPENGL )//all this section -> not tested\r
+\r
+void ViewPort::initGL()\r
+{\r
+ glShadeModel( GL_SMOOTH );\r
+ glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );\r
+ glEnable( GL_TEXTURE_2D );\r
+ glEnable( GL_CULL_FACE );\r
+ glEnable( GL_DEPTH_TEST );\r
+}\r
+\r
+//from http://steinsoft.net/index.php?site=Programming/Code%20Snippets/OpenGL/gluperspective\r
+//do not want to link glu\r
+void ViewPort::icvgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)\r
+{\r
+ GLdouble xmin, xmax, ymin, ymax;\r
+\r
+ ymax = zNear * tan(fovy * M_PI / 360.0);\r
+ ymin = -ymax;\r
+ xmin = ymin * aspect;\r
+ xmax = ymax * aspect;\r
+\r
+\r
+ glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);\r
+}\r
+\r
+\r
+void ViewPort::setGL(int width, int height)\r
+{\r
+ glMatrixMode(GL_PROJECTION);\r
+ glPushMatrix();\r
+ glLoadIdentity();\r
+ icvgluPerspective(angle, float(width) / float(height), zmin, zmax);\r
+ glMatrixMode(GL_MODELVIEW);\r
+ glPushMatrix();\r
+ glLoadIdentity();\r
+}\r
+\r
+void ViewPort::unsetGL()\r
+{\r
+ glPopMatrix();\r
+ glMatrixMode(GL_PROJECTION);\r
+ glPopMatrix();\r
+}\r
+#endif\r
+\r
+#endif\r