QT new functions:

- add CV_RADIOBOX with exclusive mode
pull/13383/head
Yannick Verdie 15 years ago
parent 2c923c7eba
commit f572047496
  1. 2
      modules/highgui/include/opencv2/highgui/highgui_c.h
  2. 105
      modules/highgui/src/window_QT.cpp
  3. 20
      modules/highgui/src/window_QT.h

@ -95,7 +95,7 @@ CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* a
CVAPI(void) cvStopLoop();
typedef void (CV_CDECL *CvButtonCallback)(int state, void* userdata);
enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1};
enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1, CV_RADIOBOX = 2};
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));
//----------------------

@ -1028,55 +1028,65 @@ CvTrackbar::~CvTrackbar()
//here CvButtonbar class
CvButtonbar::CvButtonbar(QWidget* arg, QString arg2)
{
type=type_CvButtonbar;
myparent = arg;
name_bar = arg2;
setObjectName(name_bar);
type=type_CvButtonbar;
myparent = arg;
name_bar = arg2;
setObjectName(name_bar);
/*
label = new QLabel;
setLabel();
addWidget(label,Qt::AlignLeft );
*/
group_button = new QButtonGroup;
/*
label = new QLabel;
setLabel();
addWidget(label,Qt::AlignLeft );
*/
}
CvButtonbar::~CvButtonbar()
{
QLayoutItem *child;
QLayoutItem *child;
while ((child = takeAt(0)) != 0)
delete child;
while ((child = takeAt(0)) != 0)
delete child;
delete group_button;
}
void CvButtonbar::setLabel()
{
QString nameNormalized = name_bar.leftJustified( 10, ' ', true );
label->setText(nameNormalized);
QString nameNormalized = name_bar.leftJustified( 10, ' ', true );
label->setText(nameNormalized);
}
void CvButtonbar::addButton( QString name, CvButtonCallback call, void* userdata, int button_type, bool initial_button_state)
{
QString button_name = name;
QString button_name = name;
if (button_name == "")
button_name = tr("button %1").arg(this->count());
if (button_name == "")
button_name = tr("button %1").arg(this->count());
QPointer<QAbstractButton> button;
QPointer<QAbstractButton> button;
if (button_type == CV_PUSH_BUTTON)
//CvPushButton*
button = (QAbstractButton*) new CvPushButton(this, button_name,call, userdata);
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_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);
}
if (button_type == CV_RADIOBOX)
{
//CvCheckButton*
button = (QAbstractButton*) new CvRadioButton(this, button_name,call, userdata, initial_button_state);
group_button->addButton(button);
}
if (button)
{
QObject::connect( button, SIGNAL( clicked() ),button, SLOT( callCallBack() ));
addWidget(button,Qt::AlignCenter);
}
}
@ -1086,21 +1096,38 @@ void CvButtonbar::addButton( QString name, CvButtonCallback call, void* userdata
//buttons here
CvPushButton::CvPushButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4)
{
myparent = arg1;
button_name = arg2;
callback = arg3;
userdata=arg4;
myparent = arg1;
button_name = arg2;
callback = arg3;
userdata=arg4;
setObjectName(button_name);
setText(button_name);
setObjectName(button_name);
setText(button_name);
}
void CvPushButton::callCallBack()
{
callback(-1,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);
}
CvRadioButton::CvRadioButton(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, void* arg4, bool initial_button_state)
{
myparent = arg1;
button_name = arg2;
@ -1108,11 +1135,11 @@ CvCheckBox::CvCheckBox(CvButtonbar* arg1, QString arg2, CvButtonCallback arg3, v
userdata=arg4;
setObjectName(button_name);
setCheckState((initial_button_state == 1?Qt::Checked:Qt::Unchecked));
setChecked(initial_button_state);
setText(button_name);
}
void CvCheckBox::callCallBack()
void CvRadioButton::callCallBack()
{
callback(this->isChecked(),userdata);
}
@ -1120,8 +1147,6 @@ void CvCheckBox::callCallBack()
//here CvWinProperties class
CvWinProperties::CvWinProperties(QString name_paraWindow, QWidget* parent)
{

@ -76,6 +76,8 @@
#include <QAction>
#include <QPushButton>
#include <QCheckBox>
#include <QRadioButton>
#include <QButtonGroup>
#include <QMenu>
//start private enum
@ -159,6 +161,7 @@ private:
void setLabel();
QPointer<QLabel> label;
QPointer<QButtonGroup> group_button;
};
@ -196,6 +199,23 @@ private slots:
void callCallBack();
};
class CvRadioButton : public QRadioButton
{
Q_OBJECT
public:
CvRadioButton(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
{

Loading…
Cancel
Save