mirror of
https://github.com/opencv/opencv.git
synced 2025-01-21 00:20:59 +08:00
QT new functions:
- cvAddButton changed to match requirement - CV_GUI_NORMAL and CV_GUI_EXPANDED done - context menu with right click
This commit is contained in:
parent
912607a387
commit
2c923c7eba
@ -79,8 +79,8 @@ CV_EXPORTS void loadWindowParameters(const string& windowName);
|
||||
CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
|
||||
CV_EXPORTS void stopLoop();
|
||||
|
||||
typedef void (CV_CDECL *ButtonCallback)(void* userdata);
|
||||
CV_EXPORTS int createButton( const char* bar_name, const char* window_name, ButtonCallback on_change, const char* button_name CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL));
|
||||
typedef void (CV_CDECL *ButtonCallback)(int state, void* userdata);
|
||||
CV_EXPORTS int createButton( const string& bar_name, ButtonCallback on_change , void* userdata CV_DEFAULT(NULL), int type CV_DEFAULT(CV_PUSH_BUTTON), bool initial_button_state CV_DEFAULT(0));
|
||||
//-------------------------
|
||||
|
||||
CV_EXPORTS void imshow( const string& winname, const Mat& mat );
|
||||
|
@ -94,8 +94,9 @@ CVAPI(void) cvLoadWindowParameters(const char* name);
|
||||
CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
|
||||
CVAPI(void) cvStopLoop();
|
||||
|
||||
typedef void (CV_CDECL *CvButtonCallback)(void* userdata);
|
||||
CVAPI(int) cvCreateButton( const char* bar_name, const char* window_name, CvButtonCallback on_change, const char* button_name CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL));
|
||||
typedef void (CV_CDECL *CvButtonCallback)(int state, void* userdata);
|
||||
enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1};
|
||||
CVAPI(int) cvCreateButton( const char* button_name CV_DEFAULT(NULL),CvButtonCallback on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL) , int button_type CV_DEFAULT(CV_PUSH_BUTTON), bool initial_button_state CV_DEFAULT(0));
|
||||
//----------------------
|
||||
|
||||
|
||||
|
@ -231,9 +231,9 @@ void loadWindowParameters(const string& windowName)
|
||||
cvLoadWindowParameters(windowName.c_str());
|
||||
}
|
||||
|
||||
int createButton( const string& bar_name, const string& window_name, ButtonCallback on_change, const string& button_name, void* userdata)
|
||||
int createButton(const string& button_name, ButtonCallback on_change, void* userdata, int button_type , bool initial_button_state )
|
||||
{
|
||||
return cvCreateButton( bar_name.c_str(), window_name.c_str(), on_change, button_name.c_str(), userdata);
|
||||
return cvCreateButton(button_name.c_str(), on_change, userdata, button_type , initial_button_state );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -55,6 +55,7 @@ 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
|
||||
|
||||
|
||||
@ -264,7 +265,7 @@ CV_IMPL int cvWaitKey( int arg )
|
||||
waitCondition.wait(&dummy, 2);
|
||||
*/
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
|
||||
sleep(2);
|
||||
#else
|
||||
usleep(2);//to decrease CPU usage
|
||||
@ -321,101 +322,63 @@ CvWindow* icvFindWindowByName( const char* arg )
|
||||
return window;
|
||||
}
|
||||
|
||||
CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_window )
|
||||
|
||||
CvBar* icvFindBarbyName(QBoxLayout* layout, QString name_bar, typeBar type)
|
||||
{
|
||||
if (!layout)
|
||||
return NULL;
|
||||
|
||||
QPointer<CvTrackbar> result = 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 (!layout)
|
||||
{
|
||||
QPointer<CvWindow> w = icvFindWindowByName( name_window );
|
||||
|
||||
if( !w )
|
||||
CV_Error( CV_StsNullPtr, "NULL window handler" );
|
||||
|
||||
QString nameQt(name_trackbar);
|
||||
CvBar* t;
|
||||
|
||||
int start_index = 0;
|
||||
int stop_index = 0;
|
||||
QPointer<QLayout> myLayout;
|
||||
|
||||
if ( w->param_gui_mode == CV_GUI_NORMAL)
|
||||
{
|
||||
myLayout = w->myLayout;
|
||||
|
||||
start_index = 1;
|
||||
if (w->myToolBar)
|
||||
start_index = 2;
|
||||
//Warning ---- , asume the location 0 is toolbar, 1 is myview and max-1 the status bar
|
||||
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
||||
|
||||
stop_index = myLayout->layout()->count()-1;
|
||||
}
|
||||
return (CvTrackbar*) icvFindBarbyName( w->myBarLayout, nameQt, type_CvTrackbar);
|
||||
|
||||
if ( w->param_gui_mode == CV_GUI_EXPANDED)
|
||||
{
|
||||
myLayout = w->getWinProp()->myLayout;
|
||||
if (!myLayout)
|
||||
CV_Error( CV_StsNullPtr, "NULL window prop handler" );
|
||||
result = icvFindBarbyName( w->myBarLayout, nameQt, type_CvTrackbar);
|
||||
|
||||
start_index = 0;
|
||||
stop_index = myLayout->layout()->count();
|
||||
if (result)
|
||||
return (CvTrackbar*) result;
|
||||
|
||||
return (CvTrackbar*) icvFindBarbyName(w->parameters_window->myLayout, nameQt, type_CvTrackbar);
|
||||
}
|
||||
|
||||
|
||||
for (int i = start_index; i < stop_index; ++i)
|
||||
return NULL;
|
||||
}else
|
||||
//layout was specified
|
||||
{
|
||||
t = (CvBar*) myLayout->layout()->itemAt(i);
|
||||
if (t->type == type_CvTrackbar && t->name_bar == nameQt)
|
||||
return (CvTrackbar*) icvFindBarbyName( layout, nameQt, type_CvTrackbar);
|
||||
}
|
||||
}
|
||||
|
||||
CvButtonbar* icvFindButtonbarByName( const char* button_name,QBoxLayout* layout)
|
||||
{
|
||||
result = (CvTrackbar*) t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
CvButtonbar* icvFindButtonbarByName( const char* name_Buttonbar, const char* name_window )
|
||||
{
|
||||
|
||||
QPointer<CvButtonbar> result = NULL;
|
||||
|
||||
QPointer<CvWindow> w = icvFindWindowByName( name_window );
|
||||
|
||||
if( !w )
|
||||
CV_Error( CV_StsNullPtr, "NULL window handler" );
|
||||
|
||||
QString nameQt = QString(name_Buttonbar);
|
||||
CvBar* t;
|
||||
int start_index;
|
||||
int stop_index;
|
||||
QPointer<QLayout> myLayout;
|
||||
|
||||
if (w->param_gui_mode == CV_GUI_EXPANDED)
|
||||
{
|
||||
myLayout = w->getWinProp()->myLayout;
|
||||
if (!myLayout)
|
||||
CV_Error( CV_StsNullPtr, "NULL window prop handler" );
|
||||
|
||||
start_index = 0;
|
||||
stop_index = myLayout->layout()->count();
|
||||
|
||||
|
||||
|
||||
for (int i = start_index; i < stop_index; ++i)
|
||||
{
|
||||
t = (CvBar*) myLayout->layout()->itemAt(i);
|
||||
if (t->type == type_CvButtonbar && t->name_bar == nameQt)
|
||||
{
|
||||
result = (CvButtonbar*) t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
QString nameQt(button_name);
|
||||
return (CvButtonbar*) icvFindBarbyName( layout, nameQt, type_CvButtonbar);
|
||||
}
|
||||
|
||||
int icvInitSystem()
|
||||
@ -550,14 +513,16 @@ CV_IMPL int cvCreateTrackbar( const char* name_bar, const char* window_name, int
|
||||
return 1;//dummy value
|
||||
}
|
||||
|
||||
CV_IMPL int cvCreateButton( const char* bar_name, const char* window_name, CvButtonCallback on_change, const char* button_name , void* userdata )
|
||||
|
||||
|
||||
CV_IMPL int cvCreateButton(const char* button_name,CvButtonCallback on_change, void* userdata , int button_type, bool initial_button_state )
|
||||
{
|
||||
QMetaObject::invokeMethod(&guiMainThread,
|
||||
"addButton",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QString, QString(window_name)),
|
||||
Q_ARG(QString, QString(bar_name)),
|
||||
Q_ARG(QString, QString(button_name)),
|
||||
Q_ARG(int, button_type),
|
||||
Q_ARG(bool, initial_button_state),
|
||||
Q_ARG(void*, (void*)on_change),
|
||||
Q_ARG(void*, userdata)
|
||||
);
|
||||
@ -734,11 +699,11 @@ void GuiReceiver::setPropWindow(QString name, double arg2 )
|
||||
switch(flags)
|
||||
{
|
||||
case CV_WINDOW_NORMAL:
|
||||
w->myLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
w->myGlobalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
w->param_flags = flags;
|
||||
break;
|
||||
case CV_WINDOW_AUTOSIZE:
|
||||
w->myLayout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
w->myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
w->param_flags = flags;
|
||||
break;
|
||||
default:;
|
||||
@ -900,46 +865,55 @@ void GuiReceiver::resizeWindow(QString name, int width, int height)
|
||||
w->resize(width, height);
|
||||
}
|
||||
|
||||
void GuiReceiver::addButton(QString window_name, QString bar_name, QString button_name, void* on_change, void* userdata)
|
||||
void GuiReceiver::addButton(QString button_name, int button_type, bool initial_button_state , void* on_change, void* userdata)
|
||||
{
|
||||
QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );
|
||||
|
||||
if (!w)
|
||||
if (!global_control_panel)
|
||||
return;
|
||||
|
||||
if (!on_change)
|
||||
CV_Error(CV_StsNullPtr, "Callback is NULL");
|
||||
QPointer<CvButtonbar> b;// = icvFindButtonbarByName( button_name.toLatin1().data(), global_control_panel->myLayout );
|
||||
|
||||
QPointer<CvButtonbar> b = icvFindButtonbarByName( bar_name.toLatin1().data() ,window_name.toLatin1().data() );
|
||||
//if (b)//button with this name already exist
|
||||
// return;
|
||||
|
||||
if (!b)//if the buttonbar does not exist, create it THEN, attached a new button
|
||||
b = w->createButtonbar(bar_name);
|
||||
CvBar* lastbar = (CvBar*) global_control_panel->myLayout->itemAt(global_control_panel->myLayout->count()-1);
|
||||
|
||||
if (b)
|
||||
b->addButton( button_name,(CvButtonCallback) on_change, userdata);
|
||||
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::addSlider(QString bar_name, QString window_name, void* value, int count, void* on_change)
|
||||
{
|
||||
QPointer<CvWindow> w = icvFindWindowByName( window_name.toLatin1().data() );
|
||||
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() );
|
||||
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" );
|
||||
|
||||
w->addSlider(bar_name,(int*)value,count,(CvTrackbarCallback) on_change);
|
||||
CvWindow::addSlider(w,bar_name,(int*)value,count,(CvTrackbarCallback) on_change);
|
||||
}
|
||||
|
||||
int GuiReceiver::start()
|
||||
@ -1052,7 +1026,7 @@ CvTrackbar::~CvTrackbar()
|
||||
|
||||
|
||||
//here CvButtonbar class
|
||||
CvButtonbar::CvButtonbar(CvWindow* arg, QString arg2)
|
||||
CvButtonbar::CvButtonbar(QWidget* arg, QString arg2)
|
||||
{
|
||||
type=type_CvButtonbar;
|
||||
myparent = arg;
|
||||
@ -1081,33 +1055,73 @@ void CvButtonbar::setLabel()
|
||||
label->setText(nameNormalized);
|
||||
}
|
||||
|
||||
void CvButtonbar::addButton( QString name, CvButtonCallback call, void* userdata)
|
||||
void CvButtonbar::addButton( QString name, CvButtonCallback call, void* userdata, int button_type, bool initial_button_state)
|
||||
{
|
||||
CvButton* button = new CvButton(this, name,call, userdata);
|
||||
QString button_name = name;
|
||||
|
||||
if (button_name == "")
|
||||
button_name = tr("button %1").arg(this->count());
|
||||
|
||||
button->setText(button_name);
|
||||
QObject::connect( button, SIGNAL( clicked() ),button, SLOT( callCallBack() ));
|
||||
QPointer<QAbstractButton> button;
|
||||
|
||||
this->addWidget(button,Qt::AlignCenter);
|
||||
if (button_type == CV_PUSH_BUTTON)
|
||||
//CvPushButton*
|
||||
button = (QAbstractButton*) new CvPushButton(this, button_name,call, userdata);
|
||||
|
||||
if (button_type == CV_CHECKBOX)
|
||||
//CvCheckButton*
|
||||
button = (QAbstractButton*) new CvCheckBox(this, button_name,call, userdata, initial_button_state);
|
||||
|
||||
if (button)
|
||||
{
|
||||
QObject::connect( button, SIGNAL( clicked() ),button, SLOT( callCallBack() ));
|
||||
addWidget(button,Qt::AlignCenter);
|
||||
}
|
||||
}
|
||||
|
||||
CvButton::CvButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4)
|
||||
|
||||
|
||||
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
void CvButton::callCallBack()
|
||||
void CvPushButton::callCallBack()
|
||||
{
|
||||
callback(userdata);
|
||||
callback(-1,userdata);
|
||||
}
|
||||
|
||||
CvCheckBox::CvCheckBox(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, bool 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);
|
||||
}
|
||||
|
||||
void CvCheckBox::callCallBack()
|
||||
{
|
||||
callback(this->isChecked(),userdata);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//here CvWinProperties class
|
||||
CvWinProperties::CvWinProperties(QString name_paraWindow, QWidget* parent)
|
||||
{
|
||||
@ -1190,10 +1204,6 @@ CvWindow::CvWindow(QString arg, int arg2)
|
||||
moveToThread(qApp->instance()->thread());
|
||||
param_name = arg;
|
||||
|
||||
//the first bit is for normal or autoresize
|
||||
//CV_WINDOW_NORMAL = 0x00000000 and CV_WINDOW_AUTOSIZE = 0x00000001
|
||||
//the secont bit is for the gui mode (normal or expanded)
|
||||
//CV_GUI_EXPANDED = 0x00000000 and CV_GUI_NORMAL = 0x00000010
|
||||
param_flags = arg2 & 0x0000000F;
|
||||
param_gui_mode = arg2 & 0x000000F0;
|
||||
|
||||
@ -1204,36 +1214,47 @@ CvWindow::CvWindow(QString arg, int arg2)
|
||||
|
||||
resize(400,300);
|
||||
|
||||
createLayout();
|
||||
//1: Layouts
|
||||
createBarLayout();
|
||||
createGlobalLayout();
|
||||
|
||||
//1: my view
|
||||
//2: my view
|
||||
int mode_display = CV_MODE_NORMAL;
|
||||
#if defined(OPENCV_GL)
|
||||
mode_display = CV_MODE_OPENGL;
|
||||
#endif
|
||||
createView(mode_display);
|
||||
|
||||
//2: shortcuts
|
||||
//3: shortcuts and actions
|
||||
createActions();
|
||||
createShortcuts();
|
||||
|
||||
//toolBar and statusbar
|
||||
//4: toolBar and statusbar
|
||||
if (param_gui_mode == CV_GUI_EXPANDED)
|
||||
{
|
||||
createToolBar();
|
||||
createStatusBar();
|
||||
createParameterWindow();
|
||||
}
|
||||
|
||||
//5: create control panel
|
||||
if (!global_control_panel)
|
||||
global_control_panel = createParameterWindow();
|
||||
|
||||
parameters_window = global_control_panel;
|
||||
|
||||
|
||||
//Now attach everything
|
||||
if (myToolBar)
|
||||
myLayout->addWidget(myToolBar,Qt::AlignCenter);
|
||||
myGlobalLayout->addWidget(myToolBar,Qt::AlignCenter);
|
||||
|
||||
myLayout->addWidget(myview,Qt::AlignCenter);
|
||||
myGlobalLayout->addWidget(myview,Qt::AlignCenter);
|
||||
|
||||
myGlobalLayout->addLayout(myBarLayout,Qt::AlignCenter);
|
||||
|
||||
if (myStatusBar)
|
||||
myLayout->addWidget(myStatusBar,Qt::AlignCenter);
|
||||
myGlobalLayout->addWidget(myStatusBar,Qt::AlignCenter);
|
||||
|
||||
setLayout(myLayout);
|
||||
setLayout(myGlobalLayout);
|
||||
show();
|
||||
}
|
||||
|
||||
@ -1241,14 +1262,23 @@ CvWindow::~CvWindow()
|
||||
{
|
||||
QLayoutItem *child;
|
||||
|
||||
if (myLayout)
|
||||
if (myGlobalLayout)
|
||||
{
|
||||
while ((child = myLayout->takeAt(0)) != 0)
|
||||
while ((child = myGlobalLayout->takeAt(0)) != 0)
|
||||
delete child;
|
||||
|
||||
delete myLayout;
|
||||
delete myGlobalLayout;
|
||||
}
|
||||
|
||||
if (myBarLayout)
|
||||
{
|
||||
while ((child = myBarLayout->takeAt(0)) != 0)
|
||||
delete child;
|
||||
|
||||
delete myBarLayout;
|
||||
}
|
||||
|
||||
|
||||
if (myStatusBar)
|
||||
{
|
||||
delete myStatusBar;
|
||||
@ -1267,28 +1297,21 @@ CvWindow::~CvWindow()
|
||||
delete vect_QShortcuts[i];
|
||||
}
|
||||
|
||||
|
||||
|
||||
CvButtonbar* CvWindow::createButtonbar(QString name_bar)
|
||||
{
|
||||
QPointer<CvButtonbar> t;
|
||||
|
||||
if (param_gui_mode == CV_GUI_EXPANDED)
|
||||
{
|
||||
t = new CvButtonbar(this,name_bar);
|
||||
QPointer<CvButtonbar> t = new CvButtonbar(global_control_panel,name_bar);
|
||||
t->setAlignment(Qt::AlignHCenter);
|
||||
|
||||
parameters_window->myLayout->insertLayout(parameters_window->myLayout->count(),t);
|
||||
}
|
||||
QPointer<QBoxLayout> myLayout = global_control_panel->myLayout;
|
||||
|
||||
myLayout->insertLayout(myLayout->count(),t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CvWinProperties* CvWindow::getWinProp()
|
||||
{
|
||||
return parameters_window;
|
||||
}
|
||||
|
||||
void CvWindow::hideTools()
|
||||
{
|
||||
if (myToolBar)
|
||||
@ -1313,10 +1336,12 @@ void CvWindow::showTools()
|
||||
// parameters_window->show();
|
||||
}
|
||||
|
||||
void CvWindow::createParameterWindow()
|
||||
CvWinProperties* CvWindow::createParameterWindow()
|
||||
{
|
||||
QString name_paraWindow=param_name+" window parameters";
|
||||
parameters_window = new CvWinProperties(name_paraWindow,this);
|
||||
QString name_paraWindow ="Global control panel";
|
||||
|
||||
CvWinProperties *result = new CvWinProperties(name_paraWindow,this);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CvWindow::displayPropertiesWin()
|
||||
@ -1327,56 +1352,62 @@ void CvWindow::displayPropertiesWin()
|
||||
parameters_window->hide();
|
||||
}
|
||||
|
||||
void CvWindow::createActions()
|
||||
{
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
QObject::connect( vect_QActions[3],SIGNAL(triggered()),myview, SLOT( siftWindowOnDown() ));
|
||||
|
||||
vect_QActions[4] = new QAction(QIcon(":/zoom_x1-icon"),"Zoom x1 (CTRL+P)",this);
|
||||
vect_QActions[4]->setIconVisibleInMenu(true);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
QObject::connect( vect_QActions[9],SIGNAL(triggered()),this, SLOT( displayPropertiesWin() ));
|
||||
}
|
||||
|
||||
void CvWindow::createToolBar()
|
||||
{
|
||||
myToolBar = new QToolBar;
|
||||
myToolBar->setFloatable(false);//is not a window
|
||||
myToolBar->setMaximumHeight(28);
|
||||
|
||||
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);
|
||||
QObject::connect( vect_QActions[0],SIGNAL(triggered()),myview, SLOT( siftWindowOnLeft() ));
|
||||
myToolBar->addAction(vect_QActions[0]);
|
||||
|
||||
vect_QActions[1] = new QAction(QIcon(":/right-icon"),"Panning right (CTRL+arrowRIGHT)",this);
|
||||
QObject::connect( vect_QActions[1],SIGNAL(triggered()),myview, SLOT( siftWindowOnRight() ));
|
||||
myToolBar->addAction(vect_QActions[1]);
|
||||
|
||||
vect_QActions[2] = new QAction(QIcon(":/up-icon"),"Panning up (CTRL+arrowUP)",this);
|
||||
QObject::connect( vect_QActions[2],SIGNAL(triggered()),myview, SLOT( siftWindowOnUp() ));
|
||||
myToolBar->addAction(vect_QActions[2]);
|
||||
|
||||
vect_QActions[3] = new QAction(QIcon(":/down-icon"),"Panning down (CTRL+arrowDOWN)",this);
|
||||
QObject::connect( vect_QActions[3],SIGNAL(triggered()),myview, SLOT( siftWindowOnDown() ));
|
||||
myToolBar->addAction(vect_QActions[3]);
|
||||
|
||||
vect_QActions[4] = new QAction(QIcon(":/zoom_x1-icon"),"Zoom x1 (CTRL+P)",this);
|
||||
QObject::connect( vect_QActions[4],SIGNAL(triggered()),myview, SLOT( resetZoom() ));
|
||||
myToolBar->addAction(vect_QActions[4]);
|
||||
|
||||
vect_QActions[5] = new QAction(QIcon(":/imgRegion-icon"),tr("Zoom x%1 (see label) (CTRL+X)")
|
||||
.arg(threshold_zoom_img_region)
|
||||
,this);
|
||||
QObject::connect( vect_QActions[5],SIGNAL(triggered()),myview, SLOT( imgRegion() ));
|
||||
myToolBar->addAction(vect_QActions[5]);
|
||||
|
||||
vect_QActions[6] = new QAction(QIcon(":/zoom_in-icon"),tr("Zoom in (CTRL++)"),this);
|
||||
QObject::connect( vect_QActions[6],SIGNAL(triggered()),myview, SLOT( ZoomIn() ));
|
||||
myToolBar->addAction(vect_QActions[6]);
|
||||
|
||||
vect_QActions[7] = new QAction(QIcon(":/zoom_out-icon"),tr("Zoom out (CTRL+-)"),this);
|
||||
QObject::connect( vect_QActions[7],SIGNAL(triggered()),myview, SLOT( ZoomOut() ));
|
||||
myToolBar->addAction(vect_QActions[7]);
|
||||
|
||||
vect_QActions[8] = new QAction(QIcon(":/save-icon"),tr("Save current image (CTRL+S)"),this);
|
||||
QObject::connect( vect_QActions[8],SIGNAL(triggered()),myview, SLOT( saveView() ));
|
||||
myToolBar->addAction(vect_QActions[8]);
|
||||
|
||||
vect_QActions[9] = new QAction(QIcon(":/properties-icon"),tr("Display properties window (CTRL+P)"),this);
|
||||
QObject::connect( vect_QActions[9],SIGNAL(triggered()),this, SLOT( displayPropertiesWin() ));
|
||||
myToolBar->addAction(vect_QActions[9]);
|
||||
foreach (QAction *a, vect_QActions)
|
||||
myToolBar->addAction(a);
|
||||
}
|
||||
|
||||
void CvWindow::createStatusBar()
|
||||
@ -1390,16 +1421,25 @@ void CvWindow::createStatusBar()
|
||||
myStatusBar->addWidget(myStatusBar_msg);
|
||||
}
|
||||
|
||||
void CvWindow::createLayout()
|
||||
void CvWindow::createGlobalLayout()
|
||||
{
|
||||
myLayout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
myLayout->setObjectName(QString::fromUtf8("boxLayout"));
|
||||
myLayout->setContentsMargins(0, 0, 0, 0);
|
||||
myLayout->setSpacing(0);
|
||||
myLayout->setMargin(0);
|
||||
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)
|
||||
myLayout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
myGlobalLayout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
}
|
||||
|
||||
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::createShortcuts()
|
||||
@ -1466,29 +1506,21 @@ void CvWindow::setMouseCallBack(CvMouseCallback m, void* param)
|
||||
myview->setMouseCallBack(m,param);
|
||||
}
|
||||
|
||||
void CvWindow::addSlider(QString name, int* value, int count,CvTrackbarCallback on_change)
|
||||
//addSlider is static
|
||||
void CvWindow::addSlider(CvWindow* w,QString name, int* value, int count,CvTrackbarCallback on_change)
|
||||
{
|
||||
QPointer<CvTrackbar> t = new CvTrackbar(this,name,value, count, on_change);
|
||||
QPointer<CvTrackbar> t = new CvTrackbar(w,name,value, count, on_change);
|
||||
t->setAlignment(Qt::AlignHCenter);
|
||||
|
||||
int position_insert;
|
||||
if (param_gui_mode == CV_GUI_NORMAL)
|
||||
{
|
||||
position_insert = myLayout->count();
|
||||
QPointer<QBoxLayout> myLayout;
|
||||
|
||||
if (myStatusBar)
|
||||
position_insert--;//max-1 means add trackbar between myview and statusbar
|
||||
if (w)
|
||||
myLayout = w->myBarLayout;
|
||||
else
|
||||
myLayout = global_control_panel->myLayout;
|
||||
|
||||
myLayout->insertLayout(position_insert,t);
|
||||
return;
|
||||
}
|
||||
myLayout->insertLayout( myLayout->count(),t);
|
||||
|
||||
if (param_gui_mode == CV_GUI_EXPANDED)
|
||||
{
|
||||
position_insert = parameters_window->myLayout->count();
|
||||
parameters_window->myLayout->insertLayout(position_insert,t);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1584,33 +1616,21 @@ void CvWindow::icvLoadTrackbars(QSettings *settings)
|
||||
{
|
||||
int size = settings->beginReadArray("trackbars");
|
||||
QPointer<CvTrackbar> t;
|
||||
//Warning ---- , asume the location 0 is toolbar, 1 is myview and max-1 the status bar
|
||||
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
||||
|
||||
|
||||
//trackbar are saved in the same order, so no need to use icvFindTrackbarByName
|
||||
|
||||
int start_index = 1;//index 0 is myview
|
||||
if (myToolBar)
|
||||
start_index ++;//index 0 is statusbar, 1 is myview
|
||||
|
||||
int stop_index = myLayout->layout()->count() - start_index ;
|
||||
if (myStatusBar)
|
||||
stop_index --;// index max-1 is the statusbar
|
||||
|
||||
//(in expended mode) nbTrackbar = count() - (toolbar + myview + statusbar) (3) = stop_index - start_index
|
||||
int start_index = 0;
|
||||
int stop_index = myBarLayout->layout()->count() ;
|
||||
|
||||
if (stop_index-start_index == size)//if not the same number, the window saved and loaded is not the same (nb trackbar not equal)
|
||||
for (int i = start_index; i < size+start_index; ++i)
|
||||
{
|
||||
settings->setArrayIndex(i-start_index);
|
||||
t = (CvTrackbar*) myLayout->layout()->itemAt(i);
|
||||
t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);
|
||||
|
||||
if (t->name_bar == settings->value("name").toString())
|
||||
//if (t->getName() == settings->value("name").toString())
|
||||
{
|
||||
t->slider->setValue(settings->value("value").toInt());
|
||||
}
|
||||
|
||||
}
|
||||
settings->endArray();
|
||||
|
||||
@ -1620,16 +1640,12 @@ void CvWindow::icvSaveTrackbars(QSettings *settings)
|
||||
{
|
||||
QPointer<CvTrackbar> t;
|
||||
|
||||
//Warning ---- , asume the location 0 is toolbar, 1 is myview and max-1 the status bar
|
||||
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
||||
settings->beginWriteArray("trackbars");
|
||||
|
||||
int start_index = 2;
|
||||
if (myToolBar)
|
||||
start_index=3;
|
||||
int start_index = 0;
|
||||
|
||||
for (int i = start_index; i < myLayout->layout()->count()-1; ++i) {
|
||||
t = (CvTrackbar*) myLayout->layout()->itemAt(i);
|
||||
for (int i = start_index; i < myBarLayout->layout()->count()-1; ++i) {
|
||||
t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);
|
||||
settings->setArrayIndex(i-start_index);
|
||||
settings->setValue("name", t->name_bar);
|
||||
//settings->setValue("name", t->getName());
|
||||
@ -1696,6 +1712,18 @@ ViewPort::~ViewPort()
|
||||
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()
|
||||
{
|
||||
|
@ -74,6 +74,9 @@
|
||||
#include <QFileDialog>
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QMenu>
|
||||
|
||||
//start private enum
|
||||
enum {CV_MODE_NORMAL= 0, CV_MODE_OPENGL = 1};
|
||||
@ -130,7 +133,7 @@ public slots:
|
||||
void loadWindowParameters(QString name);
|
||||
void setOpenGLCallback(QString window_name, void* callbackOpenGL, void* userdata);
|
||||
void putText(void* arg1, QString text, QPoint org, void* font);
|
||||
void addButton(QString window_name, QString bar_name, QString button_name, void* on_change, void* userdata);
|
||||
void addButton(QString button_name, int button_type, bool initial_button_state , void* on_change, void* userdata);
|
||||
|
||||
};
|
||||
|
||||
@ -140,7 +143,7 @@ class CvBar : public QHBoxLayout
|
||||
public:
|
||||
typeBar type;
|
||||
QString name_bar;
|
||||
QPointer<CvWindow> myparent;
|
||||
QPointer<QWidget> myparent;
|
||||
};
|
||||
|
||||
|
||||
@ -148,9 +151,9 @@ class CvButtonbar : public CvBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CvButtonbar(CvWindow* arg, QString bar_name);
|
||||
CvButtonbar(QWidget* arg, QString bar_name);
|
||||
~CvButtonbar();
|
||||
void addButton( QString button_name, CvButtonCallback call, void* userdata);
|
||||
void addButton( QString button_name, CvButtonCallback call, void* userdata, int button_type, bool initial_button_state);
|
||||
|
||||
private:
|
||||
void setLabel();
|
||||
@ -158,11 +161,12 @@ private:
|
||||
QPointer<QLabel> label;
|
||||
};
|
||||
|
||||
class CvButton : public QPushButton
|
||||
|
||||
class CvPushButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CvButton(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata);
|
||||
CvPushButton(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata);
|
||||
|
||||
private:
|
||||
CvButtonbar* myparent;
|
||||
@ -176,6 +180,23 @@ private slots:
|
||||
|
||||
|
||||
|
||||
class CvCheckBox : public QCheckBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CvCheckBox(CvButtonbar* par, QString button_name, CvButtonCallback call, void* userdata, bool initial_button_state);
|
||||
|
||||
private:
|
||||
CvButtonbar* myparent;
|
||||
QString button_name ;
|
||||
CvButtonCallback callback;
|
||||
void* userdata;
|
||||
|
||||
private slots:
|
||||
void callCallBack();
|
||||
};
|
||||
|
||||
|
||||
class CvTrackbar : public CvBar
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -219,7 +240,7 @@ class CvWindow : public QWidget
|
||||
public:
|
||||
CvWindow(QString arg2, int flag = CV_WINDOW_NORMAL);
|
||||
~CvWindow();
|
||||
void addSlider(QString name, int* value, int count, CvTrackbarCallback on_change = NULL);
|
||||
static void addSlider(CvWindow* w,QString name, int* value, int count, CvTrackbarCallback on_change CV_DEFAULT(NULL));
|
||||
void setMouseCallBack(CvMouseCallback m, void* param);
|
||||
void updateImage(void* arr);
|
||||
void displayInfo(QString text, int delayms );
|
||||
@ -229,42 +250,44 @@ public:
|
||||
void setOpenGLCallback(CvOpenGLCallback arg1,void* userdata);
|
||||
void hideTools();
|
||||
void showTools();
|
||||
CvButtonbar* createButtonbar(QString bar_name);
|
||||
static CvButtonbar* createButtonbar(QString bar_name);
|
||||
|
||||
|
||||
|
||||
ViewPort* getView();
|
||||
CvWinProperties* getWinProp();
|
||||
|
||||
QPointer<QBoxLayout> myLayout;
|
||||
QPointer<QBoxLayout> myGlobalLayout;//All the widget (toolbar, view, LayoutBar, ...) are attached to it
|
||||
QPointer<QBoxLayout> myBarLayout;
|
||||
QPointer<QStatusBar> myStatusBar;
|
||||
QPointer<QToolBar> myToolBar;
|
||||
QPointer<QLabel> myStatusBar_msg;
|
||||
|
||||
//parameters (will be save/load)
|
||||
QString param_name;
|
||||
QPointer<CvWinProperties> parameters_window ;
|
||||
int param_flags;
|
||||
int param_gui_mode;
|
||||
QVector<QAction*> vect_QActions;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
private:
|
||||
QPointer<CvWinProperties> parameters_window ;
|
||||
QPointer<ViewPort> myview;
|
||||
QVector<QAction*> vect_QActions;
|
||||
QVector<QShortcut*> vect_QShortcuts;
|
||||
|
||||
void icvLoadTrackbars(QSettings *settings);
|
||||
void icvSaveTrackbars(QSettings *settings);
|
||||
|
||||
void createShortcuts();
|
||||
void createActions();
|
||||
void createToolBar();
|
||||
void createView(int mode);
|
||||
void createStatusBar();
|
||||
void createLayout();
|
||||
void createParameterWindow();
|
||||
void createGlobalLayout();
|
||||
void createBarLayout();
|
||||
CvWinProperties* createParameterWindow();
|
||||
|
||||
private slots:
|
||||
void displayPropertiesWin();
|
||||
@ -323,6 +346,7 @@ public slots:
|
||||
void siftWindowOnDown();
|
||||
void resizeEvent ( QResizeEvent * );
|
||||
void saveView();
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user