Fixed bugs on Qt

pull/13383/head
Yannick Verdie 15 years ago
parent 49f1a9c3d5
commit e8aad75446
  1. 1
      modules/highgui/include/opencv2/highgui/highgui.hpp
  2. 2
      modules/highgui/include/opencv2/highgui/highgui_c.h
  3. 7
      modules/highgui/src/window.cpp
  4. 169
      modules/highgui/src/window_QT.cpp
  5. 4
      modules/highgui/src/window_QT.h

@ -66,6 +66,7 @@ CV_EXPORTS double getWindowProperty(const string& winname, int prop_id);//YV
//Only for Qt //Only for Qt
//------------------------ //------------------------
CV_EXPORTS CvFont fontQt(const string& nameFont, int pointSize CV_DEFAULT(-1), Scalar color CV_DEFAULT(Scalar::all(0)), int weight CV_DEFAULT(CV_FONT_NORMAL), int style CV_DEFAULT(CV_STYLE_NORMAL), int spacing CV_DEFAULT(0));
CV_EXPORTS void addText( const Mat& img, const char* text, Point org, CvFont font); CV_EXPORTS void addText( const Mat& img, const char* text, Point org, CvFont font);
CV_EXPORTS void displayOverlay(const string& winname, const string& text, int delayms); CV_EXPORTS void displayOverlay(const string& winname, const string& text, int delayms);

@ -74,7 +74,7 @@ enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal,
//for color cvScalar(blue_component, green_component, red\_component[, alpha_component]) //for color cvScalar(blue_component, green_component, red\_component[, alpha_component])
//and alpha= 0 <-> 0xFF (not transparent <-> transparent) //and alpha= 0 <-> 0xFF (not transparent <-> transparent)
CVAPI(CvFont) cvFont_Qt(const char* nameFont, int pointSize CV_DEFAULT(-1), CvScalar color CV_DEFAULT(cvScalarAll(0)), int weight CV_DEFAULT(CV_FONT_NORMAL), int style CV_DEFAULT(CV_STYLE_NORMAL), int spacing CV_DEFAULT(0)); CVAPI(CvFont) cvFontQt(const char* nameFont, int pointSize CV_DEFAULT(-1), CvScalar color CV_DEFAULT(cvScalarAll(0)), int weight CV_DEFAULT(CV_FONT_NORMAL), int style CV_DEFAULT(CV_STYLE_NORMAL), int spacing CV_DEFAULT(0));
CVAPI(void) cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont *arg2); CVAPI(void) cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont *arg2);

@ -190,10 +190,15 @@ int startWindowThread()
#if defined (HAVE_QT) #if defined (HAVE_QT)
CvFont fontQt(const string& nameFont, int pointSize, Scalar color, int weight, int style, int spacing)
{
return cvFontQt(nameFont.c_str(), pointSize,color,weight, style);
}
void addText( const Mat& img, const string& text, Point org, CvFont font) void addText( const Mat& img, const string& text, Point org, CvFont font)
{ {
CvMat _img = img; CvMat _img = img;
cvAddText( &_img, text.c_str(), CvPoint(org),&font); cvAddText( &_img, text.c_str(), org,&font);
} }
void displayStatusBar(const string& name, const string& text, int delayms) void displayStatusBar(const string& name, const string& text, int delayms)

@ -60,7 +60,7 @@ static CvWinProperties* global_control_panel = NULL;
CV_IMPL CvFont cvFont_Qt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing) CV_IMPL CvFont cvFontQt(const char* nameFont, int pointSize,CvScalar color,int weight,int style, int spacing)
{ {
/* /*
@ -441,10 +441,10 @@ int icvInitSystem()
new QApplication(parameterSystemC,parameterSystemV); new QApplication(parameterSystemC,parameterSystemV);
wasInitialized = 1; wasInitialized = 1;
qDebug()<<"init done"; //qDebug()<<"init done";
#if defined( HAVE_QT_OPENGL )//OK tested ! #if defined( HAVE_QT_OPENGL )//OK tested !
qDebug()<<"opengl support available"; //qDebug()<<"opengl support available";
#endif #endif
} }
@ -905,7 +905,7 @@ void GuiReceiver::showImage(QString name, void* arr)
} }
else else
{ {
qDebug()<<"Do nothing (Window or Image NULL)"<<endl; CV_Error(CV_StsNullPtr, "Do nothing (Window or Image NULL)");
} }
} }
@ -982,6 +982,11 @@ void GuiReceiver::addButton(QString button_name, int button_type, int initial_bu
//if (b)//button with this name already exist //if (b)//button with this name already exist
// return; // 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
}else{
CvBar* lastbar = (CvBar*) global_control_panel->myLayout->itemAt(global_control_panel->myLayout->count()-1); 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 if (lastbar->type == type_CvTrackbar)//if last bar is a trackbar, create a new buttonbar, else, attach to the current bar
@ -989,6 +994,8 @@ void GuiReceiver::addButton(QString button_name, int button_type, int initial_bu
else else
b = (CvButtonbar*) lastbar; b = (CvButtonbar*) lastbar;
}
b->addButton( button_name,(CvButtonCallback) on_change, userdata, button_type, initial_button_state); b->addButton( button_name,(CvButtonCallback) on_change, userdata, button_type, initial_button_state);
} }
@ -1713,6 +1720,8 @@ void CvWindow::readSettings()
//param_name = settings.value("name_window",param_name).toString(); //param_name = settings.value("name_window",param_name).toString();
param_flags = settings.value("mode_resize",param_flags).toInt(); param_flags = settings.value("mode_resize",param_flags).toInt();
param_gui_mode = settings.value("mode_gui",param_gui_mode).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(); myview->param_keepRatio = settings.value("view_aspectRatio",myview->param_keepRatio).toInt();
param_flags = settings.value("mode_resize",param_flags).toInt(); param_flags = settings.value("mode_resize",param_flags).toInt();
@ -1732,6 +1741,12 @@ void CvWindow::readSettings()
resize(size); resize(size);
move(pos); move(pos);
if (global_control_panel)
{
icvLoadControlPanel();
global_control_panel->move(settings.value("posPanel", global_control_panel->pos()).toPoint());
}
} }
void CvWindow::writeSettings() void CvWindow::writeSettings()
@ -1743,6 +1758,8 @@ void CvWindow::writeSettings()
settings.setValue("size", size()); settings.setValue("size", size());
settings.setValue("mode_resize",param_flags); settings.setValue("mode_resize",param_flags);
settings.setValue("mode_gui",param_gui_mode); settings.setValue("mode_gui",param_gui_mode);
settings.setValue("param_ratio_mode",param_ratio_mode);
settings.setValue("view_aspectRatio",myview->param_keepRatio); settings.setValue("view_aspectRatio",myview->param_keepRatio);
settings.setValue("matrix_view.m11",myview->param_matrixWorld.m11()); settings.setValue("matrix_view.m11",myview->param_matrixWorld.m11());
@ -1756,8 +1773,134 @@ void CvWindow::writeSettings()
settings.setValue("matrix_view.m33",myview->param_matrixWorld.m33()); settings.setValue("matrix_view.m33",myview->param_matrixWorld.m33());
icvSaveTrackbars(&settings); 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) void CvWindow::icvLoadTrackbars(QSettings *settings)
{ {
int size = settings->beginReadArray("trackbars"); int size = settings->beginReadArray("trackbars");
@ -1765,13 +1908,10 @@ void CvWindow::icvLoadTrackbars(QSettings *settings)
//trackbar are saved in the same order, so no need to use icvFindTrackbarByName //trackbar are saved in the same order, so no need to use icvFindTrackbarByName
int start_index = 0; if (myBarLayout->layout()->count() == size)//if not the same number, the window saved and loaded is not the same (nb trackbar not equal)
int stop_index = myBarLayout->layout()->count() ; for (int i = 0; i < size; ++i)
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); settings->setArrayIndex(i);
t = (CvTrackbar*) myBarLayout->layout()->itemAt(i); t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);
if (t->name_bar == settings->value("name").toString()) if (t->name_bar == settings->value("name").toString())
@ -1788,13 +1928,10 @@ void CvWindow::icvSaveTrackbars(QSettings *settings)
settings->beginWriteArray("trackbars"); settings->beginWriteArray("trackbars");
int start_index = 0; for (int i = 0; i < myBarLayout->layout()->count(); ++i) {
for (int i = start_index; i < myBarLayout->layout()->count()-1; ++i) {
t = (CvTrackbar*) myBarLayout->layout()->itemAt(i); t = (CvTrackbar*) myBarLayout->layout()->itemAt(i);
settings->setArrayIndex(i-start_index); settings->setArrayIndex(i);
settings->setValue("name", t->name_bar); settings->setValue("name", t->name_bar);
//settings->setValue("name", t->getName());
settings->setValue("value", t->slider->value()); settings->setValue("value", t->slider->value());
} }
settings->endArray(); settings->endArray();
@ -1920,7 +2057,7 @@ void ViewPort::saveView()
return; return;
} }
qDebug()<<"file extension not recognized, please choose between JPG, JPEG, BMP or PNG"; CV_Error(CV_StsNullPtr, "file extension not recognized, please choose between JPG, JPEG, BMP or PNG");
} }
} }

@ -304,6 +304,10 @@ private:
void icvLoadTrackbars(QSettings *settings); void icvLoadTrackbars(QSettings *settings);
void icvSaveTrackbars(QSettings *settings); void icvSaveTrackbars(QSettings *settings);
void icvLoadControlPanel();
void icvSaveControlPanel();
void icvLoadButtonbar(CvButtonbar* t,QSettings *settings);
void icvSaveButtonbar(CvButtonbar* t,QSettings *settings);
void createShortcuts(); void createShortcuts();
void createActions(); void createActions();

Loading…
Cancel
Save