QT new functions:

- Add toolbar
 - Clean the code
 - Window properties in progress
This commit is contained in:
Yannick Verdie 2010-07-16 09:12:15 +00:00
parent b8535d1726
commit ddc29e08be
5 changed files with 499 additions and 398 deletions

View File

@ -78,11 +78,14 @@ if (HAVE_QT)
endif() endif()
INCLUDE(${QT_USE_FILE}) INCLUDE(${QT_USE_FILE})
SET(_RCCS_FILES src/window_QT.qrc)
QT4_ADD_RESOURCES(_RCC_OUTFILES ${_RCCS_FILES})
SET(_MOC_HEADERS src/window_QT.h ) SET(_MOC_HEADERS src/window_QT.h )
QT4_WRAP_CPP(_MOC_OUTFILES ${_MOC_HEADERS}) QT4_WRAP_CPP(_MOC_OUTFILES ${_MOC_HEADERS})
set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} ${QT_LIBRARIES}) set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} ${QT_LIBRARIES})
set(highgui_srcs ${highgui_srcs} src/window_QT.cpp ${_MOC_OUTFILES}) set(highgui_srcs ${highgui_srcs} src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES} )
endif() endif()
if(WIN32) if(WIN32)

View File

@ -72,6 +72,11 @@ enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal,
}; };
/* ---------*/ /* ---------*/
//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 extended)
enum {CV_GUI_EXTENDED = 0x00000000, CV_GUI_NORMAL = 0x00000010};
//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) 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));
@ -96,23 +101,26 @@ CVAPI(int) cvInitSystem( int argc, char** argv );
CVAPI(int) cvStartWindowThread(); CVAPI(int) cvStartWindowThread();
enum { CV_WINDOW_AUTOSIZE = 1 };
/* create window */
CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
// --------- YV --------- // --------- YV ---------
enum enum
{ {
CV_WND_PROP_FULLSCREEN = 0, //These 3 flags are used by cvSet/GetWindowProperty
CV_WND_PROP_AUTOSIZE = 1, CV_WND_PROP_FULLSCREEN = 0,//to change/get window's fullscreen property
CV_WND_PROP_ASPECTRATIO= 2, CV_WND_PROP_AUTOSIZE = 1,//to change/get window's autosize property
CV_WINDOW_NORMAL = 0, CV_WND_PROP_ASPECTRATIO= 2,//to change/get window's aspectratio property
CV_WINDOW_FULLSCREEN = 1, //
CV_WINDOW_FREERATIO = 0, //These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty
CV_WINDOW_KEEPRATIO = 1 CV_WINDOW_NORMAL = 0,//the user can resize the window (no constraint)
CV_WINDOW_AUTOSIZE = 1,//the user cannot resize the window, the size is constrainted by the image displayed
//
//These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty
CV_WINDOW_FULLSCREEN = 1,//change the window to fullscreen
CV_WINDOW_FREERATIO = 0,//the image expends as much as it can (no ratio constraint)
CV_WINDOW_KEEPRATIO = 1//the ration image is respected.
}; };
/* create window */
CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
/* Set and Get Property of the window */ /* Set and Get Property of the window */
CVAPI(void) cvSetWindowProperty(const char* name, int prop_id, double prop_value); CVAPI(void) cvSetWindowProperty(const char* name, int prop_id, double prop_value);

View File

@ -51,7 +51,10 @@ static bool multiThreads = false;
static int last_key = -1; static int last_key = -1;
QWaitCondition key_pressed; QWaitCondition key_pressed;
QMutex mutexKey; QMutex mutexKey;
static const unsigned int threshold_zoom_img_region = 15;//the minimum zoom value to start displaying the values' grid 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
//end static and global //end static and global
@ -287,9 +290,7 @@ CV_IMPL void cvStopLoop()
{ {
qApp->exit(); qApp->exit();
} }
CvWindow* icvFindWindowByName( const char* arg )
CV_IMPL CvWindow* icvFindWindowByName( const char* arg )
{ {
QPointer<CvWindow> window = NULL; QPointer<CvWindow> window = NULL;
@ -300,6 +301,8 @@ CV_IMPL CvWindow* icvFindWindowByName( const char* arg )
QString name(arg); QString name(arg);
QPointer<CvWindow> w; QPointer<CvWindow> w;
foreach (QWidget *widget, QApplication::topLevelWidgets()) foreach (QWidget *widget, QApplication::topLevelWidgets())
{
if (widget->isWindow() && !widget->parentWidget ())//is a window without parent
{ {
w = (CvWindow*) widget; w = (CvWindow*) widget;
if (w->param_name==name) if (w->param_name==name)
@ -308,6 +311,7 @@ CV_IMPL CvWindow* icvFindWindowByName( const char* arg )
break; break;
} }
} }
}
return window; return window;
} }
@ -325,11 +329,13 @@ CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_w
QString nameQt = QString(name_trackbar); QString nameQt = QString(name_trackbar);
QPointer<CvTrackbar> t; QPointer<CvTrackbar> t;
//Warning ---- , asume the location 0 is myview and max-1 the status bar int 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 //done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
for (int i = 1; i < w->layout->layout()->count()-1; ++i) for (int i = start_index; i < w->layout->layout()->count()-1; ++i)
{ {
t = (CvTrackbar*) w->layout->layout()->itemAt(i); t = (CvTrackbar*) w->layout->layout()->itemAt(i);
if (t->trackbar_name==nameQt) if (t->trackbar_name==nameQt)
{ {
@ -546,7 +552,7 @@ GuiReceiver::GuiReceiver() : _bTimeOut(false)
void GuiReceiver::putText(void* arg1, QString text, QPoint org, void* arg2) void GuiReceiver::putText(void* arg1, QString text, QPoint org, void* arg2)
{ {
CV_Assert(arg1); CV_Assert(arg1)
IplImage* img = (IplImage*)arg1; IplImage* img = (IplImage*)arg1;
@ -843,14 +849,14 @@ CvTrackbar::CvTrackbar(CvWindow* arg, QString name, int* value, int count, CvTra
//Change style of the Slider //Change style of the Slider
slider->setStyleSheet(str_Trackbar_css); //slider->setStyleSheet(str_Trackbar_css);
//QFile qss(PATH_QSLIDERCSS); QFile qss(":/stylesheet-trackbar");
//if (qss.open(QFile::ReadOnly)) if (qss.open(QFile::ReadOnly))
//{ {
// slider->setStyleSheet(QLatin1String(qss.readAll())); slider->setStyleSheet(QLatin1String(qss.readAll()));
// qss.close(); qss.close();
//} }
//this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?) //this next line does not work if we change the style with a stylesheet, why ? (bug in QT ?)
@ -925,14 +931,18 @@ CvTrackbar::~CvTrackbar()
} }
//Here CvWindow class //Here CvWindow class
CvWindow::CvWindow(QString arg, int arg2) CvWindow::CvWindow(QString arg, int arg2)
{ {
moveToThread(qApp->instance()->thread()); moveToThread(qApp->instance()->thread());
param_name = arg; param_name = arg;
param_flags = arg2;
//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 extended)
//CV_GUI_EXTENDED = 0x00000000 and CV_GUI_NORMAL = 0x00000010
param_flags = arg2 & 0x0000000F;
param_gui_mode = arg2 & 0x000000F0;
setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory
setContentsMargins(0,0,0,0); setContentsMargins(0,0,0,0);
@ -941,58 +951,33 @@ CvWindow::CvWindow(QString arg, int arg2)
resize(400,300); resize(400,300);
createLayout();
//1: my view
int mode_display = CV_MODE_NORMAL; int mode_display = CV_MODE_NORMAL;
#if defined(OPENCV_GL)
#if defined(OPENCV_GL)
mode_display = CV_MODE_OPENGL; mode_display = CV_MODE_OPENGL;
#endif #endif
createView(mode_display);
//CV_MODE_NORMAL or CV_MODE_OPENGL //2: shortcuts
myview = new ViewPort(this, mode_display,CV_WINDOW_KEEPRATIO);//parent, mode_display, keep_aspect_ratio createShortcuts();
myview->setAlignment(Qt::AlignHCenter);
//toolBar and statusbar
if (param_gui_mode == CV_GUI_EXTENDED)
{
createToolBar();
createStatusBar();
}
shortcut_Z = new QShortcut(shortcut_zoom_normal, this); //Now attach everything
QObject::connect( shortcut_Z, SIGNAL( activated ()),myview, SLOT( resetZoom( ) )); if (myToolBar)
shortcut_S = new QShortcut(shortcut_save_img, this); layout->addWidget(myToolBar,Qt::AlignCenter);
QObject::connect( shortcut_S, SIGNAL( activated ()),myview, SLOT( saveView( ) ));
shortcut_P = new QShortcut(shortcut_properties_win, this);
//QObject::connect( shortcut_P, SIGNAL( activated ()),myview, SLOT( callPropertiesWin( ) ));
shortcut_X = new QShortcut(shortcut_zoom_imgRegion, this);
QObject::connect( shortcut_X, SIGNAL( activated ()),myview, SLOT( imgRegion( ) ));
shortcut_Plus = new QShortcut(shortcut_zoom_in, this);
QObject::connect( shortcut_Plus, SIGNAL( activated ()),myview, SLOT( ZoomIn() ));
shortcut_Minus = new QShortcut(shortcut_zoom_out, this);
QObject::connect(shortcut_Minus, SIGNAL( activated ()),myview, SLOT( ZoomOut() ));
shortcut_Left = new QShortcut(shortcut_panning_left, this);
QObject::connect( shortcut_Left, SIGNAL( activated ()),myview, SLOT( siftWindowOnLeft() ));
shortcut_Right = new QShortcut(shortcut_panning_right, this);
QObject::connect( shortcut_Right, SIGNAL( activated ()),myview, SLOT( siftWindowOnRight() ));
shortcut_Up = new QShortcut(shortcut_panning_up, this);
QObject::connect(shortcut_Up, SIGNAL( activated ()),myview, SLOT( siftWindowOnUp() ));
shortcut_Down = new QShortcut(shortcut_panning_down, this);
QObject::connect(shortcut_Down, SIGNAL( activated ()),myview, SLOT( siftWindowOnDown() ));
layout = new QBoxLayout(QBoxLayout::TopToBottom);
layout->setObjectName(QString::fromUtf8("boxLayout"));
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setMargin(0);
layout->addWidget(myview,Qt::AlignCenter); layout->addWidget(myview,Qt::AlignCenter);
if (param_flags == CV_WINDOW_AUTOSIZE) if (myStatusBar)
layout->setSizeConstraint(QLayout::SetFixedSize); layout->addWidget(myStatusBar,Qt::AlignCenter);
//now status bar
myBar = new QStatusBar;
myBar->setSizeGripEnabled(false);
myBar->setMaximumHeight(20);
myBar_msg = new QLabel;
myBar_msg->setFrameStyle(QFrame::Raised);
myBar_msg->setAlignment(Qt::AlignHCenter);
myBar->addWidget(myBar_msg);
layout->addWidget(myBar,Qt::AlignCenter);
setLayout(layout); setLayout(layout);
show(); show();
@ -1010,26 +995,131 @@ CvWindow::~CvWindow()
delete layout; delete layout;
} }
delete myBar; delete myStatusBar;
delete myBar_msg; delete myStatusBar_msg;
delete shortcut_Z; for (int i=0;i<vect_QShortcuts.count();i++)
delete shortcut_S; delete vect_QShortcuts[i];
delete shortcut_P;
delete shortcut_X; for (int i=0;i<vect_QActions.count();i++)
delete shortcut_Plus; delete vect_QActions[i];
delete shortcut_Minus;
delete shortcut_Left;
delete shortcut_Right;
delete shortcut_Up;
delete shortcut_Down;
} }
void CvWindow::setOpenGLCallback(CvOpenGLCallback func,void* userdata) 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()),myview, SLOT( displayPropertiesWin() ));
myToolBar->addAction(vect_QActions[9]);
}
void CvWindow::createStatusBar()
{
myStatusBar = new QStatusBar;
myStatusBar->setSizeGripEnabled(false);
myStatusBar->setMaximumHeight(20);
myStatusBar_msg = new QLabel;
myStatusBar_msg->setFrameStyle(QFrame::Raised);
myStatusBar_msg->setAlignment(Qt::AlignHCenter);
myStatusBar->addWidget(myStatusBar_msg);
}
void CvWindow::createLayout()
{
layout = new QBoxLayout(QBoxLayout::TopToBottom);
layout->setObjectName(QString::fromUtf8("boxLayout"));
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setMargin(0);
if (param_flags == CV_WINDOW_AUTOSIZE)
layout->setSizeConstraint(QLayout::SetFixedSize);
}
void CvWindow::createShortcuts()
{
vect_QShortcuts.resize(10);
vect_QShortcuts[0] = new QShortcut(shortcut_panning_left, this);
QObject::connect( vect_QShortcuts[0], SIGNAL( activated ()),myview, SLOT( siftWindowOnLeft() ));
vect_QShortcuts[1] = new QShortcut(shortcut_panning_right, this);
QObject::connect( vect_QShortcuts[1], SIGNAL( activated ()),myview, SLOT( siftWindowOnRight() ));
vect_QShortcuts[2] = new QShortcut(shortcut_panning_up, this);
QObject::connect(vect_QShortcuts[2], SIGNAL( activated ()),myview, SLOT( siftWindowOnUp() ));
vect_QShortcuts[3] = new QShortcut(shortcut_panning_down, this);
QObject::connect(vect_QShortcuts[3], SIGNAL( activated ()),myview, SLOT( siftWindowOnDown() ));
vect_QShortcuts[4] = new QShortcut(shortcut_zoom_normal, this);
QObject::connect( vect_QShortcuts[4], SIGNAL( activated ()),myview, SLOT( resetZoom( ) ));
vect_QShortcuts[5] = new QShortcut(shortcut_zoom_imgRegion, this);
QObject::connect( vect_QShortcuts[5], SIGNAL( activated ()),myview, SLOT( imgRegion( ) ));
vect_QShortcuts[6] = new QShortcut(shortcut_zoom_in, this);
QObject::connect( vect_QShortcuts[6], SIGNAL( activated ()),myview, SLOT( ZoomIn() ));
vect_QShortcuts[7] = new QShortcut(shortcut_zoom_out, this);
QObject::connect(vect_QShortcuts[7], SIGNAL( activated ()),myview, SLOT( ZoomOut() ));
vect_QShortcuts[8] = new QShortcut(shortcut_save_img, this);
QObject::connect( vect_QShortcuts[8], SIGNAL( activated ()),myview, SLOT( saveView( ) ));
vect_QShortcuts[9] = new QShortcut(shortcut_properties_win, this);
QObject::connect( vect_QShortcuts[9], SIGNAL( activated ()),myview, SLOT( displayPropertiesWin() ));
}
void CvWindow::createView(int mode)
{
//mode = CV_MODE_NORMAL or CV_MODE_OPENGL
myview = new ViewPort(this, mode,CV_WINDOW_KEEPRATIO);//parent, mode_display, keep_aspect_ratio
myview->setAlignment(Qt::AlignHCenter);
}
void CvWindow::setOpenGLCallback(CvOpenGLCallback func,void* userdata)
{
myview->setOpenGLCallback(func,userdata); myview->setOpenGLCallback(func,userdata);
} }
ViewPort* CvWindow::getView() ViewPort* CvWindow::getView()
{ {
@ -1043,7 +1133,7 @@ void CvWindow::displayInfo(QString text,int delayms)
void CvWindow::displayStatusBar(QString text,int delayms) void CvWindow::displayStatusBar(QString text,int delayms)
{ {
myBar->showMessage(text,delayms); myStatusBar->showMessage(text,delayms);
} }
void CvWindow::updateImage(void* arr) void CvWindow::updateImage(void* arr)
@ -1060,7 +1150,12 @@ void CvWindow::addSlider(QString name, int* value, int count,CvTrackbarCallback
{ {
QPointer<CvTrackbar> t = new CvTrackbar(this,name,value, count, on_change); QPointer<CvTrackbar> t = new CvTrackbar(this,name,value, count, on_change);
t->setAlignment(Qt::AlignHCenter); t->setAlignment(Qt::AlignHCenter);
layout->insertLayout(layout->count()-1,t);//max-1 means add trackbar between myview and statusbar int position_insert = layout->count();
if (myStatusBar)
position_insert--;//max-1 means add trackbar between myview and statusbar
layout->insertLayout(position_insert,t);
} }
//Need more test here ! //Need more test here !
@ -1152,15 +1247,27 @@ void CvWindow::icvLoadTrackbars(QSettings *settings)
{ {
int size = settings->beginReadArray("trackbars"); int size = settings->beginReadArray("trackbars");
QPointer<CvTrackbar> t; QPointer<CvTrackbar> t;
//Warning ---- , asume the location 0 is myview and max-1 the status bar //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 //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 //trackbar are saved in the same order, so no need to use icvFindTrackbarByName
if (layout->layout()->count()-2 == size)//if not the same number, the window saved and loaded is not the same (nb trackbar not equal)
for (int i = 0; i < size; ++i) int start_index = 1;//index 0 is myview
if (myToolBar)
start_index ++;//index 0 is statusbar, 1 is myview
int stop_index = layout->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
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); settings->setArrayIndex(i-start_index);
t = (CvTrackbar*) layout->layout()->itemAt(i+1);//+1 because index 0 is myview (see Warning) t = (CvTrackbar*) layout->layout()->itemAt(i);
if (t->trackbar_name == settings->value("name").toString()) if (t->trackbar_name == settings->value("name").toString())
{ {
@ -1175,12 +1282,17 @@ void CvWindow::icvSaveTrackbars(QSettings *settings)
{ {
QPointer<CvTrackbar> t; QPointer<CvTrackbar> t;
//Warning ---- , asume the location 0 is myview and max-1 the status bar //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 //done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
settings->beginWriteArray("trackbars"); settings->beginWriteArray("trackbars");
for (int i = 0; i < layout->layout()->count()-2; ++i) {
t = (CvTrackbar*) layout->layout()->itemAt(i+1);//+1 because index 0 is myview (see Warning) int start_index = 2;
settings->setArrayIndex(i); if (myToolBar)
start_index=3;
for (int i = start_index; i < layout->layout()->count()-1; ++i) {
t = (CvTrackbar*) layout->layout()->itemAt(i);
settings->setArrayIndex(i-start_index);
settings->setValue("name", t->trackbar_name); settings->setValue("name", t->trackbar_name);
settings->setValue("value", t->slider->value()); settings->setValue("value", t->slider->value());
} }
@ -1197,6 +1309,7 @@ void CvWindow::icvSaveTrackbars(QSettings *settings)
ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3) ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
{ {
centralWidget = arg, centralWidget = arg,
setParent(centralWidget);
mode_display = arg2; mode_display = arg2;
param_keepRatio = arg3; param_keepRatio = arg3;
@ -1288,6 +1401,11 @@ void ViewPort::saveView()
} }
} }
void ViewPort::displayPropertiesWin()
{
}
void ViewPort::setRatio(int flags) void ViewPort::setRatio(int flags)
{ {
param_keepRatio = flags; param_keepRatio = flags;
@ -1405,7 +1523,7 @@ void ViewPort::setOpenGLCallback(CvOpenGLCallback func,void* userdata)
{ {
on_openGL_draw3D = func; on_openGL_draw3D = func;
on_openGL_param = userdata; on_openGL_param = userdata;
} }
void ViewPort::controlImagePosition() void ViewPort::controlImagePosition()
{ {
@ -1482,6 +1600,7 @@ void ViewPort::scaleView(qreal factor,QPointF center)
controlImagePosition(); controlImagePosition();
//display new zoom //display new zoom
if (centralWidget->myStatusBar)
centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000); centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);
if (param_matrixWorld.m11()>1) if (param_matrixWorld.m11()>1)
@ -1560,6 +1679,7 @@ void ViewPort::mouseMoveEvent(QMouseEvent *event)
//I update the statusbar here because if the user does a cvWaitkey(0) (like with inpaint.cpp) //I update the statusbar here because if the user does a cvWaitkey(0) (like with inpaint.cpp)
//the status bar will only be repaint when a click occurs. //the status bar will only be repaint when a click occurs.
if (centralWidget->myStatusBar)
viewport()->update(); viewport()->update();
QWidget::mouseMoveEvent(event); QWidget::mouseMoveEvent(event);
@ -1653,6 +1773,11 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
//move to the middle //move to the middle
//newSize get the delta offset to place the picture in the middle of its parent //newSize get the delta offset to place the picture in the middle of its parent
newSize= (event->size()-newSize)/2; newSize= (event->size()-newSize)/2;
//if the toolbar is displayed, avoid drawing myview on top of it
if (centralWidget->myToolBar)
newSize +=QSize(0,centralWidget->myToolBar->height());
move(newSize.width(),newSize.height()); move(newSize.width(),newSize.height());
} }
} }
@ -1709,6 +1834,7 @@ void ViewPort::paintEvent(QPaintEvent* event)
//end display //end display
//for statusbar //for statusbar
if (centralWidget->myStatusBar)
drawStatusBar(); drawStatusBar();
QGraphicsView::paintEvent(event); QGraphicsView::paintEvent(event);
@ -1730,7 +1856,7 @@ void ViewPort::drawStatusBar()
if (nbChannelOriginImage==3) if (nbChannelOriginImage==3)
{ {
centralWidget->myBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>") centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
.arg(mouseCoordinate.x()) .arg(mouseCoordinate.x())
.arg(mouseCoordinate.y())+ .arg(mouseCoordinate.y())+
tr("<font color='red'>R:%3 </font>").arg(qRed(rgbValue))+//.arg(value.val[0])+ tr("<font color='red'>R:%3 </font>").arg(qRed(rgbValue))+//.arg(value.val[0])+
@ -1739,7 +1865,7 @@ void ViewPort::drawStatusBar()
); );
}else{ }else{
//all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed //all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed
centralWidget->myBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>") centralWidget->myStatusBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
.arg(mouseCoordinate.x()) .arg(mouseCoordinate.x())
.arg(mouseCoordinate.y())+ .arg(mouseCoordinate.y())+
tr("<font color='grey'>grey:%3 </font>").arg(qRed(rgbValue)) tr("<font color='grey'>grey:%3 </font>").arg(qRed(rgbValue))
@ -1766,8 +1892,10 @@ void ViewPort::drawImgRegion(QPainter *painter)
QFont f = painter->font(); QFont f = painter->font();
int original_font_size = f.pointSize();
//change font size
//f.setPointSize(4+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
f.setPixelSize(6+(param_matrixWorld.m11()-threshold_zoom_img_region)/5); f.setPixelSize(6+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
//f.setStretch(0);
painter->setFont(f); painter->setFont(f);
QString val; QString val;
QRgb rgbValue; QRgb rgbValue;
@ -1820,6 +1948,10 @@ void ViewPort::drawImgRegion(QPainter *painter)
painter->drawLines(linesX.data(), linesX.size()); painter->drawLines(linesX.data(), linesX.size());
painter->drawLines(linesY.data(), linesY.size()); painter->drawLines(linesY.data(), linesY.size());
//restore font size
f.setPointSize(original_font_size);
painter->setFont(f);
} }
void ViewPort::drawViewOverview(QPainter *painter) void ViewPort::drawViewOverview(QPainter *painter)
@ -1858,6 +1990,7 @@ void ViewPort::drawInstructions(QPainter *painter)
painter->setPen(Qt::white); painter->setPen(Qt::white);
painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border), painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
QColor(0, 0, 0, 127)); QColor(0, 0, 0, 127));
painter->drawText((width() - rect.width())/2, border, painter->drawText((width() - rect.width())/2, border,
rect.width(), rect.height(), rect.width(), rect.height(),
Qt::AlignCenter | Qt::TextWordWrap, infoText); Qt::AlignCenter | Qt::TextWordWrap, infoText);

View File

@ -72,8 +72,10 @@
#include <QFileInfo> #include <QFileInfo>
#include <QDate> #include <QDate>
#include <QFileDialog> #include <QFileDialog>
#include <QToolBar>
#include <QAction>
//start enum //start private enum
enum {CV_MODE_NORMAL= 0, CV_MODE_OPENGL = 1}; enum {CV_MODE_NORMAL= 0, CV_MODE_OPENGL = 1};
//we can change the keyboard shortcuts from here ! //we can change the keyboard shortcuts from here !
@ -155,6 +157,7 @@ private:
}; };
class CvWindow : public QWidget class CvWindow : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -172,12 +175,14 @@ public:
ViewPort* getView(); ViewPort* getView();
QPointer<QBoxLayout> layout; QPointer<QBoxLayout> layout;
QPointer<QStatusBar> myBar; QPointer<QStatusBar> myStatusBar;
QPointer<QLabel> myBar_msg; QPointer<QToolBar> myToolBar;
QPointer<QLabel> myStatusBar_msg;
//parameters (will be save/load) //parameters (will be save/load)
QString param_name; QString param_name;
int param_flags; int param_flags;
int param_gui_mode;
protected: protected:
@ -185,19 +190,17 @@ protected:
private: private:
QPointer<ViewPort> myview; QPointer<ViewPort> myview;
QPointer<QShortcut> shortcut_Z; QVector<QAction*> vect_QActions;
QPointer<QShortcut> shortcut_S; QVector<QShortcut*> vect_QShortcuts;
QPointer<QShortcut> shortcut_P;
QPointer<QShortcut> shortcut_X;
QPointer<QShortcut> shortcut_Plus;
QPointer<QShortcut> shortcut_Minus;
QPointer<QShortcut> shortcut_Left;
QPointer<QShortcut> shortcut_Right;
QPointer<QShortcut> shortcut_Up;
QPointer<QShortcut> shortcut_Down;
void icvLoadTrackbars(QSettings *settings); void icvLoadTrackbars(QSettings *settings);
void icvSaveTrackbars(QSettings *settings); void icvSaveTrackbars(QSettings *settings);
void createShortcuts();
void createToolBar();
void createView(int mode);
void createStatusBar();
void createLayout();
}; };
@ -253,6 +256,7 @@ public slots:
void siftWindowOnDown(); void siftWindowOnDown();
void resizeEvent ( QResizeEvent * ); void resizeEvent ( QResizeEvent * );
void saveView(); void saveView();
void displayPropertiesWin();
private: private:
QPoint mouseCoordinate; QPoint mouseCoordinate;
@ -304,66 +308,4 @@ private slots:
void stopDisplayInfo(); void stopDisplayInfo();
}; };
//here css for trackbar
/* from http://thesmithfam.org/blog/2010/03/10/fancy-qslider-stylesheet */
static const QString str_Trackbar_css = QString("")
+ "QSlider::groove:horizontal {"
+ "border: 1px solid #bbb;"
+ "background: white;"
+ "height: 10px;"
+ "border-radius: 4px;"
+ "}"
+ "QSlider::sub-page:horizontal {"
+ "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
+ "stop: 0 #66e, stop: 1 #bbf);"
+ "background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,"
+ "stop: 0 #bbf, stop: 1 #55f);"
+ "border: 1px solid #777;"
+ "height: 10px;"
+ "border-radius: 4px;"
+ "}"
+ "QSlider::add-page:horizontal {"
+ "background: #fff;"
+ "border: 1px solid #777;"
+ "height: 10px;"
+ "border-radius: 4px;"
+ "}"
+ "QSlider::handle:horizontal {"
+ "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
+ "stop:0 #eee, stop:1 #ccc);"
+ "border: 1px solid #777;"
+ "width: 13px;"
+ "margin-top: -2px;"
+ "margin-bottom: -2px;"
+ "border-radius: 4px;"
+ "}"
+ "QSlider::handle:horizontal:hover {"
+ "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
+ "stop:0 #fff, stop:1 #ddd);"
+ "border: 1px solid #444;"
+ "border-radius: 4px;"
+ "}"
+ "QSlider::sub-page:horizontal:disabled {"
+ "background: #bbb;"
+ "border-color: #999;"
+ "}"
+ "QSlider::add-page:horizontal:disabled {"
+ "background: #eee;"
+ "border-color: #999;"
+ "}"
+ "QSlider::handle:horizontal:disabled {"
+ "background: #eee;"
+ "border: 1px solid #aaa;"
+ "border-radius: 4px;"
+ "}";
#endif #endif

View File

@ -0,0 +1,15 @@
<RCC>
<qresource prefix="/">
<file alias="left-icon">files_Qt/Milky/48/28.png</file>
<file alias="right-icon">files_Qt/Milky/48/23.png</file>
<file alias="up-icon">files_Qt/Milky/48/19.png</file>
<file alias="down-icon">files_Qt/Milky/48/24.png</file>
<file alias="zoom_x1-icon">files_Qt/Milky/48/27.png</file>
<file alias="imgRegion-icon">files_Qt/Milky/48/61.png</file>
<file alias="zoom_in-icon">files_Qt/Milky/48/106.png</file>
<file alias="zoom_out-icon">files_Qt/Milky/48/107.png</file>
<file alias="save-icon">files_Qt/Milky/48/7.png</file>
<file alias="properties-icon">files_Qt/Milky/48/38.png</file>
<file alias="stylesheet-trackbar">files_Qt/stylesheet_trackbar.qss</file>
</qresource>
</RCC>