From f5720474963dd9e4f1e7edee12ee789754e1bf6e Mon Sep 17 00:00:00 2001 From: Yannick Verdie Date: Thu, 22 Jul 2010 21:46:27 +0000 Subject: [PATCH] QT new functions: - add CV_RADIOBOX with exclusive mode --- .../highgui/include/opencv2/highgui/highgui_c.h | 2 +- modules/highgui/src/window_QT.cpp | 105 +++++++++++++-------- modules/highgui/src/window_QT.h | 20 ++++ 3 files changed, 86 insertions(+), 41 deletions(-) diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index 9aa06e0..cd62639 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.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)); //---------------------- diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index b1200d5..0fea7bc 100755 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -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 button; + QPointer 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,33 +1096,50 @@ 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; callback = arg3; 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) { diff --git a/modules/highgui/src/window_QT.h b/modules/highgui/src/window_QT.h index 13fb539..40f195d 100644 --- a/modules/highgui/src/window_QT.h +++ b/modules/highgui/src/window_QT.h @@ -76,6 +76,8 @@ #include #include #include +#include +#include #include //start private enum @@ -159,6 +161,7 @@ private: void setLabel(); QPointer label; + QPointer 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 { -- 2.7.4