mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
working on QT change/get win property (stylesheet for cvTrackBar fixed !!!)
This commit is contained in:
parent
d264907fd6
commit
9eea2a5fe6
@ -59,6 +59,7 @@ set(highgui_srcs
|
||||
|
||||
set(highgui_hdrs src/precomp.hpp src/utils.hpp)
|
||||
|
||||
#YV
|
||||
set(lib_hdr_names highgui_c.h highgui.hpp)
|
||||
set(highgui_ext_hdrs)
|
||||
foreach(h ${lib_hdr_names})
|
||||
@ -73,7 +74,7 @@ if(WIN32)
|
||||
#SET(QT_USE_QTXML 1)
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
|
||||
SET(_MOC_HEADERS src/window_QT.h)
|
||||
SET(_MOC_HEADERS src/window_QT.h )
|
||||
QT4_WRAP_CPP(_MOC_OUTFILES ${_MOC_HEADERS})
|
||||
|
||||
set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} ${QT_LIBRARIES})
|
||||
|
@ -56,6 +56,12 @@ namespace cv
|
||||
|
||||
enum { WINDOW_AUTOSIZE=1 };
|
||||
|
||||
//YV
|
||||
//-----------New for QT
|
||||
//CV_EXPORTS void information(const string& name, const string& text, int delayms);
|
||||
//------------
|
||||
|
||||
|
||||
CV_EXPORTS void namedWindow( const string& winname, int flags CV_DEFAULT(WINDOW_AUTOSIZE) );
|
||||
CV_EXPORTS void destroyWindow( const string& winname );
|
||||
CV_EXPORTS int startWindowThread();
|
||||
|
@ -56,6 +56,11 @@ extern "C" {
|
||||
/****************************************************************************************\
|
||||
* Basic GUI functions *
|
||||
\****************************************************************************************/
|
||||
//YV
|
||||
//-----------New for QT
|
||||
//CVAPI(void) cvInformation(const char* name, const char* text, int delayms);
|
||||
//----------------------
|
||||
|
||||
|
||||
/* this function is used to set some external parameters in case of X Window */
|
||||
CVAPI(int) cvInitSystem( int argc, char** argv );
|
||||
@ -76,10 +81,13 @@ enum
|
||||
CV_WINDOW_FULLSCREEN = 1
|
||||
};
|
||||
|
||||
|
||||
/* Set and Get Property of the window */
|
||||
CVAPI(void) cvSetWindowProperty(const char* name, int prop_id, double prop_value);
|
||||
CVAPI(double) cvGetWindowProperty(const char* name, int prop_id);
|
||||
|
||||
CVAPI(void) cvInformation(const char* name, const char* text, int delayms);
|
||||
|
||||
/* display image within window (highgui windows remember their content) */
|
||||
CVAPI(void) cvShowImage( const char* name, const CvArr* image );
|
||||
|
||||
@ -200,17 +208,8 @@ CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0
|
||||
/* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
|
||||
CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
|
||||
|
||||
//YV
|
||||
#if defined (HAVE_QT)
|
||||
class CvWindow;
|
||||
class ViewPort;
|
||||
struct CvTrackbar;
|
||||
void cvInformation(const char* name, const char* text, int delay);
|
||||
|
||||
CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char *argv[]);
|
||||
CVAPI(void) cvStopLoop();
|
||||
CVAPI(void) cvInformation(const char* name, const char* text, int delay);
|
||||
CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window );
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* Working with Video Files and Cameras *
|
||||
|
@ -171,6 +171,18 @@ void cvChangeMode_GTK(const char* name, double prop_value);
|
||||
void cvChangeMode_CARBON(const char* name, double prop_value);
|
||||
void cvChangeMode_QT(const char* name, double prop_value);
|
||||
|
||||
//#if defined (HAVE_QT)
|
||||
//class CvWindow;
|
||||
//class ViewPort;
|
||||
//struct CvTrackbar;
|
||||
|
||||
////new functions available to the users
|
||||
//#include "highgui_QT_extension.h"
|
||||
////new functions hidden to the users
|
||||
//CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window );
|
||||
//#endif
|
||||
|
||||
|
||||
/*namespace cv
|
||||
{
|
||||
|
||||
|
@ -131,6 +131,13 @@ double getWindowProperty(const string& winname, int prop_id)
|
||||
return cvGetWindowProperty(winname.c_str(),prop_id);
|
||||
}
|
||||
|
||||
/*
|
||||
void information(const string& name, const string& text, int delayms)
|
||||
{
|
||||
cvInformation(name.c_str(),text.c_str(), delayms);
|
||||
}
|
||||
* */
|
||||
|
||||
void imshow( const string& winname, const Mat& img )
|
||||
{
|
||||
CvMat _img = img;
|
||||
|
@ -53,29 +53,46 @@ QWaitCondition key_pressed;
|
||||
QMutex mutexKey;
|
||||
//end static and global
|
||||
|
||||
|
||||
//end declaration
|
||||
void cvChangeMode_QT(const char* name, double prop_value)
|
||||
{
|
||||
//CV_WINDOW_NORMAL or CV_WINDOW_FULLSCREEN
|
||||
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"toggleFullScreen",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QString, QString(name)),
|
||||
Q_ARG(double, prop_value));
|
||||
}
|
||||
|
||||
double cvGetMode_QT(const char* name)
|
||||
{
|
||||
double result;
|
||||
|
||||
return 0;
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"isFullScreen",
|
||||
Qt::AutoConnection,
|
||||
Q_RETURN_ARG(double, result),
|
||||
Q_ARG(QString, QString(name)));
|
||||
return result;
|
||||
}
|
||||
|
||||
CV_IMPL void cvInformation(const char* name, const char* text, int delayms)
|
||||
{
|
||||
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"displayInfo",
|
||||
Qt::AutoConnection,
|
||||
//Qt::DirectConnection,
|
||||
Q_ARG(QString, QString(name)),
|
||||
Q_ARG(QString, QString(text)),
|
||||
Q_ARG(int, delayms));
|
||||
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL int cvWaitKey( int arg )
|
||||
{
|
||||
|
||||
CV_FUNCNAME( "cvWaitKey" );
|
||||
|
||||
int result = -1;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
unsigned long delayms;//in milliseconds
|
||||
if (arg<=0)
|
||||
delayms = ULONG_MAX;
|
||||
@ -125,20 +142,18 @@ CV_IMPL int cvWaitKey( int arg )
|
||||
guiMainThread._bTimeOut = false;
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL int cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[])
|
||||
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()
|
||||
void cvStopLoop()
|
||||
{
|
||||
qApp->exit();
|
||||
}
|
||||
@ -147,12 +162,8 @@ CV_IMPL void cvStopLoop()
|
||||
CV_IMPL CvWindow* icvFindWindowByName( const char* arg )
|
||||
{
|
||||
|
||||
CV_FUNCNAME( "icvFindWindowByName" );
|
||||
|
||||
QPointer<CvWindow> window = NULL;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if( !arg )
|
||||
CV_Error( CV_StsNullPtr, "NULL name string" );
|
||||
|
||||
@ -168,19 +179,14 @@ CV_IMPL CvWindow* icvFindWindowByName( const char* arg )
|
||||
}
|
||||
}
|
||||
|
||||
__END__;
|
||||
return window;
|
||||
}
|
||||
|
||||
CV_IMPL CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window )
|
||||
CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window )
|
||||
{
|
||||
|
||||
CV_FUNCNAME( "icvFindTrackbarByName" );
|
||||
|
||||
QPointer<CvTrackbar> result = NULL;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QPointer<CvWindow> w = icvFindWindowByName( name_window );
|
||||
|
||||
if( !w )
|
||||
@ -200,15 +206,11 @@ CV_IMPL CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char
|
||||
}
|
||||
}
|
||||
|
||||
__END__;
|
||||
return result;
|
||||
}
|
||||
|
||||
CV_IMPL int cvNamedWindow( const char* name, int flags )
|
||||
{
|
||||
CV_FUNCNAME( "cvNamedWindow" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (multiThreads)
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
@ -222,30 +224,12 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
|
||||
else
|
||||
guiMainThread.createWindow(QString(name),flags);
|
||||
|
||||
__END__;
|
||||
return 1;//Dummy value
|
||||
}
|
||||
|
||||
CV_IMPL void cvInformation(const char* name, const char* text, int delayms)
|
||||
{
|
||||
CV_FUNCNAME( "cvInformation" );
|
||||
|
||||
__BEGIN__;
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"displayInfo",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QString, QString(name)),
|
||||
Q_ARG(QString, QString(text)),
|
||||
Q_ARG(int, delayms));
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL int icvInitSystem( int argc, char** argv )
|
||||
{
|
||||
CV_FUNCNAME( "icvInitSystem" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
static int wasInitialized = 0;
|
||||
|
||||
@ -258,15 +242,11 @@ CV_IMPL int icvInitSystem( int argc, char** argv )
|
||||
qDebug()<<"init done"<<endl;
|
||||
}
|
||||
|
||||
__END__;
|
||||
return 0;
|
||||
}
|
||||
|
||||
CV_IMPL void cvDestroyWindow( const char* name )
|
||||
{
|
||||
CV_FUNCNAME( "cvDestroyWindow" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"destroyWindow",
|
||||
@ -274,16 +254,11 @@ CV_IMPL void cvDestroyWindow( const char* name )
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QString, QString(name))
|
||||
);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
|
||||
CV_IMPL void cvDestroyAllWindows(void)
|
||||
{
|
||||
CV_FUNCNAME( "cvDestroyAllWindows" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"destroyAllWindow",
|
||||
@ -291,40 +266,28 @@ CV_IMPL void cvDestroyAllWindows(void)
|
||||
Qt::AutoConnection
|
||||
);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL void* cvGetWindowHandle( const char* name )
|
||||
{
|
||||
CV_FUNCNAME( "cvGetWindowHandle" );
|
||||
|
||||
__BEGIN__;
|
||||
if( !name )
|
||||
CV_Error( CV_StsNullPtr, "NULL name string" );
|
||||
|
||||
__END__;
|
||||
return (void*) icvFindWindowByName( name );
|
||||
}
|
||||
|
||||
CV_IMPL const char* cvGetWindowName( void* window_handle )
|
||||
{
|
||||
CV_FUNCNAME( "cvGetWindowName" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if( !window_handle )
|
||||
CV_Error( CV_StsNullPtr, "NULL window handler" );
|
||||
|
||||
|
||||
__END__;
|
||||
return ((CvWindow*)window_handle)->windowTitle().toLatin1().data();
|
||||
}
|
||||
|
||||
CV_IMPL void cvMoveWindow( const char* name, int x, int y )
|
||||
{
|
||||
CV_FUNCNAME( "cvMoveWindow" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"moveWindow",
|
||||
@ -335,16 +298,11 @@ CV_IMPL void cvMoveWindow( const char* name, int x, int y )
|
||||
Q_ARG(int, y)
|
||||
);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL void cvResizeWindow(const char* name, int width, int height )
|
||||
{
|
||||
|
||||
CV_FUNCNAME( "cvResizeWindow" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"resizeWindow",
|
||||
//Qt::BlockingQueuedConnection,
|
||||
@ -354,8 +312,6 @@ CV_IMPL void cvResizeWindow(const char* name, int width, int height )
|
||||
Q_ARG(int, height)
|
||||
);
|
||||
|
||||
__END__;
|
||||
|
||||
}
|
||||
|
||||
CV_IMPL int cvCreateTrackbar2( const char* trackbar_name, const char* window_name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata )
|
||||
@ -371,9 +327,6 @@ CV_IMPL int cvStartWindowThread()
|
||||
|
||||
CV_IMPL int cvCreateTrackbar( const char* trackbar_name, const char* window_name, int* value, int count, CvTrackbarCallback on_change)
|
||||
{
|
||||
CV_FUNCNAME( "cvCreateTrackbar" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
if (multiThreads)
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
@ -388,48 +341,34 @@ CV_IMPL int cvCreateTrackbar( const char* trackbar_name, const char* window_name
|
||||
else
|
||||
guiMainThread.addSlider(QString(trackbar_name),QString(window_name),(void*)value,count,(void*)on_change);
|
||||
|
||||
__END__;
|
||||
return 1;//demmy value
|
||||
}
|
||||
|
||||
CV_IMPL int cvGetTrackbarPos( const char* trackbar_name, const char* window_name )
|
||||
{
|
||||
CV_FUNCNAME( "cvGetTrackbarPos" );
|
||||
|
||||
int result = -1;
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QPointer<CvTrackbar> t = icvFindTrackbarByName( trackbar_name, window_name );
|
||||
|
||||
if (t)
|
||||
result = t->slider->value();
|
||||
|
||||
__END__;
|
||||
return result;
|
||||
}
|
||||
|
||||
CV_IMPL void cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos )
|
||||
{
|
||||
CV_FUNCNAME( "cvSetTrackbarPos" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QPointer<CvTrackbar> t = icvFindTrackbarByName( trackbar_name, window_name );
|
||||
|
||||
if (t)
|
||||
t->slider->setValue(pos);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
/* assign callback for mouse events */
|
||||
CV_IMPL void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,void* param )
|
||||
{
|
||||
CV_FUNCNAME( "cvSetMouseCallback" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
QPointer<CvWindow> w = icvFindWindowByName( window_name );
|
||||
|
||||
if (!w)
|
||||
@ -437,26 +376,18 @@ CV_IMPL void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mou
|
||||
|
||||
w->setMouseCallBack(on_mouse, param);
|
||||
|
||||
__END__;
|
||||
}
|
||||
|
||||
CV_IMPL void cvShowImage( const char* name, const CvArr* arr )
|
||||
{
|
||||
CV_FUNCNAME( "cvShowImage" );
|
||||
|
||||
__BEGIN__;
|
||||
//objects were created in GUI thread, so not using invoke method here should be fine
|
||||
guiMainThread.showImage(QString(name), (void*) arr);
|
||||
|
||||
// QMetaObject::invokeMethod(&guiMainThread,
|
||||
// "showImage",
|
||||
// //Qt::BlockingQueuedConnection,
|
||||
// Qt::AutoConnection,
|
||||
// Q_ARG(QString, QString(name)),
|
||||
// Q_ARG(void*, (void*)arr)
|
||||
// );
|
||||
|
||||
__END__;
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"showImage",
|
||||
//Qt::BlockingQueuedConnection,
|
||||
Qt::DirectConnection,
|
||||
Q_ARG(QString, QString(name)),
|
||||
Q_ARG(void*, (void*)arr)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -465,6 +396,7 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr )
|
||||
|
||||
|
||||
|
||||
|
||||
//----------OBJECT----------------
|
||||
|
||||
GuiReceiver::GuiReceiver() : _bTimeOut(false)
|
||||
@ -473,6 +405,35 @@ GuiReceiver::GuiReceiver() : _bTimeOut(false)
|
||||
qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting
|
||||
}
|
||||
|
||||
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->showNormal();
|
||||
|
||||
if (!w->isFullScreen() && flags == CV_WINDOW_FULLSCREEN)
|
||||
w->showFullScreen();
|
||||
|
||||
}
|
||||
|
||||
void GuiReceiver::createWindow( QString name, int flags )
|
||||
{
|
||||
if (!qApp)
|
||||
|
@ -37,6 +37,9 @@
|
||||
//the use of this software, even if advised of the possibility of such damage.
|
||||
|
||||
//--------------------Google Code 2010 -- Yannick Verdie--------------------//
|
||||
#ifndef __OPENCV_HIGHGUI_QT_H__
|
||||
#define __OPENCV_HIGHGUI_QT_H__
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@ -63,15 +66,15 @@
|
||||
#include <QLabel>
|
||||
#include <QIODevice>
|
||||
|
||||
|
||||
|
||||
//Macro here
|
||||
#define CV_MODE_NORMAL 0
|
||||
#define CV_MODE_OPENGL 1
|
||||
//end macro
|
||||
|
||||
//Here declare everything
|
||||
//need a .h to allow QT to use MOC (in order to use signal, slots, etc)
|
||||
class CvWindow;
|
||||
class ViewPort;
|
||||
//class CvTrackbar;
|
||||
|
||||
|
||||
class GuiReceiver : public QObject
|
||||
{
|
||||
@ -95,6 +98,8 @@ public slots:
|
||||
void displayInfo( QString name, QString text, int delayms );
|
||||
void refreshEvents();
|
||||
void timeOut();
|
||||
void toggleFullScreen(QString name, double flags );
|
||||
double isFullScreen(QString name);
|
||||
};
|
||||
|
||||
class CvTrackbar : public QHBoxLayout
|
||||
@ -263,3 +268,5 @@ static const QString str_Trackbar_css = QString("")
|
||||
+ "border: 1px solid #aaa;"
|
||||
+ "border-radius: 4px;"
|
||||
+ "}";
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user