|
|
|
@@ -42,7 +42,6 @@
|
|
|
|
|
#ifdef HAVE_QT
|
|
|
|
|
|
|
|
|
|
#include <window_QT.h>
|
|
|
|
|
#include <QVarLengthArray>
|
|
|
|
|
|
|
|
|
|
//Static and global first
|
|
|
|
|
static GuiReceiver guiMainThread;
|
|
|
|
@@ -132,6 +131,22 @@ CV_IMPL void cvDisplayOverlay(const char* name, const char* text, int delayms)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CV_IMPL void cvSaveWindowParameters(const char* name)
|
|
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
|
"saveWindowParameters",
|
|
|
|
|
Qt::AutoConnection,
|
|
|
|
|
Q_ARG(QString, QString(name)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CV_IMPL void cvLoadWindowParameters(const char* name)
|
|
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(&guiMainThread,
|
|
|
|
|
"loadWindowParameters",
|
|
|
|
|
Qt::AutoConnection,
|
|
|
|
|
Q_ARG(QString, QString(name)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CV_IMPL void cvDisplayStatusBar(const char* name, const char* text, int delayms)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@@ -235,7 +250,7 @@ CV_IMPL CvWindow* icvFindWindowByName( const char* arg )
|
|
|
|
|
foreach (QWidget *widget, QApplication::topLevelWidgets())
|
|
|
|
|
{
|
|
|
|
|
w = (CvWindow*) widget;
|
|
|
|
|
if (w->name==name)
|
|
|
|
|
if (w->param_name==name)
|
|
|
|
|
{
|
|
|
|
|
window = w;
|
|
|
|
|
break;
|
|
|
|
@@ -259,7 +274,8 @@ CvTrackbar* icvFindTrackbarByName( const char* name_trackbar, const char* name_w
|
|
|
|
|
QPointer<CvTrackbar> t;
|
|
|
|
|
|
|
|
|
|
//Warning ---- , asume the location 0 is myview and max-1 the status bar
|
|
|
|
|
for (int i = 1; i < w->layout->layout()->count()-2; ++i)
|
|
|
|
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
|
|
|
|
for (int i = 1; i < w->layout->layout()->count()-1; ++i)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
t = (CvTrackbar*) w->layout->layout()->itemAt(i);
|
|
|
|
@@ -467,6 +483,22 @@ GuiReceiver::GuiReceiver() : _bTimeOut(false)
|
|
|
|
|
qApp->setQuitOnLastWindowClosed ( false );//maybe the user would like to access this setting
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GuiReceiver::saveWindowParameters(QString name)
|
|
|
|
|
{
|
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
|
|
if (w)
|
|
|
|
|
w->writeSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GuiReceiver::loadWindowParameters(QString name)
|
|
|
|
|
{
|
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
|
|
|
|
|
|
if (w)
|
|
|
|
|
w->readSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double GuiReceiver::getRatioWindow(QString name)
|
|
|
|
|
{
|
|
|
|
|
QPointer<CvWindow> w = icvFindWindowByName( name.toLatin1().data() );
|
|
|
|
@@ -504,7 +536,7 @@ double GuiReceiver::getPropWindow(QString name)
|
|
|
|
|
if (!w)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return (double)w->flags;
|
|
|
|
|
return (double)w->param_flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GuiReceiver::setPropWindow(QString name, double arg2 )
|
|
|
|
@@ -516,7 +548,7 @@ void GuiReceiver::setPropWindow(QString name, double arg2 )
|
|
|
|
|
|
|
|
|
|
int flags = (int) arg2;
|
|
|
|
|
|
|
|
|
|
if (w->flags == flags)//nothing to do
|
|
|
|
|
if (w->param_flags == flags)//nothing to do
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -524,11 +556,11 @@ void GuiReceiver::setPropWindow(QString name, double arg2 )
|
|
|
|
|
{
|
|
|
|
|
case CV_WINDOW_NORMAL:
|
|
|
|
|
w->layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
|
|
|
|
w->flags = flags;
|
|
|
|
|
w->param_flags = flags;
|
|
|
|
|
break;
|
|
|
|
|
case CV_WINDOW_AUTOSIZE:
|
|
|
|
|
w->layout->setSizeConstraint(QLayout::SetFixedSize);
|
|
|
|
|
w->flags = flags;
|
|
|
|
|
w->param_flags = flags;
|
|
|
|
|
break;
|
|
|
|
|
default:;
|
|
|
|
|
}
|
|
|
|
@@ -796,13 +828,13 @@ CvTrackbar::~CvTrackbar()
|
|
|
|
|
CvWindow::CvWindow(QString arg, int arg2)
|
|
|
|
|
{
|
|
|
|
|
moveToThread(qApp->instance()->thread());
|
|
|
|
|
name = arg;
|
|
|
|
|
flags = arg2;
|
|
|
|
|
param_name = arg;
|
|
|
|
|
param_flags = arg2;
|
|
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);//in other case, does not release memory
|
|
|
|
|
setContentsMargins(0,0,0,0);
|
|
|
|
|
setWindowTitle(name);
|
|
|
|
|
setObjectName(name);
|
|
|
|
|
setWindowTitle(param_name);
|
|
|
|
|
setObjectName(param_name);
|
|
|
|
|
|
|
|
|
|
resize(400,300);
|
|
|
|
|
|
|
|
|
@@ -811,22 +843,20 @@ CvWindow::CvWindow(QString arg, int arg2)
|
|
|
|
|
myview->setAlignment(Qt::AlignHCenter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shortcut_r_Zoom = new QShortcut(Qt::CTRL + Qt::Key_P, this);
|
|
|
|
|
QObject::connect( shortcut_r_Zoom, SIGNAL( activated ()),myview, SLOT( resetZoom( ) ));
|
|
|
|
|
shortcut_imgRegion = new QShortcut(Qt::CTRL + Qt::Key_O, this);
|
|
|
|
|
QObject::connect( shortcut_imgRegion, SIGNAL( activated ()),myview, SLOT( imgRegion( ) ));
|
|
|
|
|
shortcut_Plus = new QShortcut(QKeySequence(QKeySequence::ZoomIn), this);
|
|
|
|
|
QObject::connect( shortcut_Plus, SIGNAL( activated ()),myview, SLOT( ZoomIn() ));
|
|
|
|
|
shortcut_Minus = new QShortcut(QKeySequence(QKeySequence::ZoomOut), this);
|
|
|
|
|
QObject::connect(shortcut_Minus, SIGNAL( activated ()),myview, SLOT( ZoomOut() ));
|
|
|
|
|
shortcut_Left = new QShortcut(Qt::CTRL + Qt::Key_Left, this);
|
|
|
|
|
QObject::connect( shortcut_Left, SIGNAL( activated ()),myview, SLOT( siftWindowOnLeft() ));
|
|
|
|
|
shortcut_Right = new QShortcut(Qt::CTRL + Qt::Key_Right, this);
|
|
|
|
|
QObject::connect( shortcut_Right, SIGNAL( activated ()),myview, SLOT( siftWindowOnRight() ));
|
|
|
|
|
shortcut_Up = new QShortcut(Qt::CTRL + Qt::Key_Up, this);
|
|
|
|
|
QObject::connect(shortcut_Up, SIGNAL( activated ()),myview, SLOT( siftWindowOnUp() ));
|
|
|
|
|
shortcut_Down = new QShortcut(Qt::CTRL + Qt::Key_Down, this);
|
|
|
|
|
QObject::connect(shortcut_Down, SIGNAL( activated ()),myview, SLOT( siftWindowOnDown() ));
|
|
|
|
|
shortcutZ = new QShortcut(Qt::CTRL + Qt::Key_P, this);
|
|
|
|
|
QObject::connect( shortcutZ, SIGNAL( activated ()),myview, SLOT( resetZoom( ) ));
|
|
|
|
|
shortcutPlus = new QShortcut(QKeySequence(QKeySequence::ZoomIn), this);
|
|
|
|
|
QObject::connect( shortcutPlus, SIGNAL( activated ()),myview, SLOT( ZoomIn() ));
|
|
|
|
|
shortcutMinus = new QShortcut(QKeySequence(QKeySequence::ZoomOut), this);
|
|
|
|
|
QObject::connect(shortcutMinus, SIGNAL( activated ()),myview, SLOT( ZoomOut() ));
|
|
|
|
|
shortcutLeft = new QShortcut(Qt::CTRL + Qt::Key_Left, this);
|
|
|
|
|
QObject::connect( shortcutLeft, SIGNAL( activated ()),myview, SLOT( siftWindowOnLeft() ));
|
|
|
|
|
shortcutRight = new QShortcut(Qt::CTRL + Qt::Key_Right, this);
|
|
|
|
|
QObject::connect( shortcutRight, SIGNAL( activated ()),myview, SLOT( siftWindowOnRight() ));
|
|
|
|
|
shortcutUp = new QShortcut(Qt::CTRL + Qt::Key_Up, this);
|
|
|
|
|
QObject::connect(shortcutUp, SIGNAL( activated ()),myview, SLOT( siftWindowOnUp() ));
|
|
|
|
|
shortcutDown = new QShortcut(Qt::CTRL + Qt::Key_Down, this);
|
|
|
|
|
QObject::connect(shortcutDown, SIGNAL( activated ()),myview, SLOT( siftWindowOnDown() ));
|
|
|
|
|
|
|
|
|
|
layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
|
//layout = new CustomLayout;
|
|
|
|
@@ -837,7 +867,7 @@ CvWindow::CvWindow(QString arg, int arg2)
|
|
|
|
|
layout->addWidget(myview,Qt::AlignCenter);
|
|
|
|
|
//layout->addStretch(0);
|
|
|
|
|
|
|
|
|
|
if (flags == CV_WINDOW_AUTOSIZE)
|
|
|
|
|
if (param_flags == CV_WINDOW_AUTOSIZE)
|
|
|
|
|
layout->setSizeConstraint(QLayout::SetFixedSize);
|
|
|
|
|
|
|
|
|
|
//now status bar
|
|
|
|
@@ -874,14 +904,13 @@ CvWindow::~CvWindow()
|
|
|
|
|
delete myBar_msg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete shortcut_r_Zoom;
|
|
|
|
|
delete shortcut_imgRegion;
|
|
|
|
|
delete shortcut_Plus;
|
|
|
|
|
delete shortcut_Minus;
|
|
|
|
|
delete shortcut_Left;
|
|
|
|
|
delete shortcut_Right;
|
|
|
|
|
delete shortcut_Up;
|
|
|
|
|
delete shortcut_Down;
|
|
|
|
|
delete shortcutZ;
|
|
|
|
|
delete shortcutPlus;
|
|
|
|
|
delete shortcutMinus;
|
|
|
|
|
delete shortcutLeft;
|
|
|
|
|
delete shortcutRight;
|
|
|
|
|
delete shortcutUp;
|
|
|
|
|
delete shortcutDown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewPort* CvWindow::getView()
|
|
|
|
@@ -950,28 +979,103 @@ void CvWindow::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CvWindow::readSettings()//not tested
|
|
|
|
|
void CvWindow::readSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings settings("Trolltech", "Application Example");
|
|
|
|
|
//organisation and application's name
|
|
|
|
|
QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
|
|
|
|
|
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
|
|
|
|
|
QSize size = settings.value("size", QSize(400, 400)).toSize();
|
|
|
|
|
param_name = settings.value("name_window",param_name).toString();
|
|
|
|
|
|
|
|
|
|
param_flags = settings.value("mode_resize",param_flags).toInt();
|
|
|
|
|
qreal m11 = settings.value("matrix_view.m11",myview->param_matrixWorld.m11()).toReal();
|
|
|
|
|
qreal m12 = settings.value("matrix_view.m12",myview->param_matrixWorld.m12()).toReal();
|
|
|
|
|
qreal m13 = settings.value("matrix_view.m13",myview->param_matrixWorld.m13()).toReal();
|
|
|
|
|
qreal m21 = settings.value("matrix_view.m21",myview->param_matrixWorld.m21()).toReal();
|
|
|
|
|
qreal m22 = settings.value("matrix_view.m22",myview->param_matrixWorld.m22()).toReal();
|
|
|
|
|
qreal m23 = settings.value("matrix_view.m23",myview->param_matrixWorld.m23()).toReal();
|
|
|
|
|
qreal m31 = settings.value("matrix_view.m31",myview->param_matrixWorld.m31()).toReal();
|
|
|
|
|
qreal m32 = settings.value("matrix_view.m32",myview->param_matrixWorld.m32()).toReal();
|
|
|
|
|
qreal m33 = settings.value("matrix_view.m33",myview->param_matrixWorld.m33()).toReal();
|
|
|
|
|
myview->param_matrixWorld = QTransform(m11,m12,m13,m21,m22,m23,m31,m32,m33);
|
|
|
|
|
|
|
|
|
|
//trackbar here
|
|
|
|
|
icvLoadTrackbars(&settings);
|
|
|
|
|
|
|
|
|
|
resize(size);
|
|
|
|
|
move(pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CvWindow::writeSettings()//not tested
|
|
|
|
|
void CvWindow::writeSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings settings("Trolltech", "Application Example");
|
|
|
|
|
//organisation and application's name
|
|
|
|
|
QSettings settings("OpenCV2", QFileInfo(QApplication::applicationFilePath()).fileName());
|
|
|
|
|
settings.setValue("name_window",param_name);
|
|
|
|
|
settings.setValue("pos", pos());
|
|
|
|
|
settings.setValue("size", size());
|
|
|
|
|
settings.setValue("mode_resize",param_flags);
|
|
|
|
|
settings.setValue("view_aspectRatio",myview->param_keepRatio);
|
|
|
|
|
|
|
|
|
|
settings.setValue("matrix_view.m11",myview->param_matrixWorld.m11());
|
|
|
|
|
settings.setValue("matrix_view.m12",myview->param_matrixWorld.m12());
|
|
|
|
|
settings.setValue("matrix_view.m13",myview->param_matrixWorld.m13());
|
|
|
|
|
settings.setValue("matrix_view.m21",myview->param_matrixWorld.m21());
|
|
|
|
|
settings.setValue("matrix_view.m22",myview->param_matrixWorld.m22());
|
|
|
|
|
settings.setValue("matrix_view.m23",myview->param_matrixWorld.m23());
|
|
|
|
|
settings.setValue("matrix_view.m31",myview->param_matrixWorld.m31());
|
|
|
|
|
settings.setValue("matrix_view.m32",myview->param_matrixWorld.m32());
|
|
|
|
|
settings.setValue("matrix_view.m33",myview->param_matrixWorld.m33());
|
|
|
|
|
|
|
|
|
|
icvSaveTrackbars(&settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CvWindow::icvLoadTrackbars(QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
int size = settings->beginReadArray("trackbars");
|
|
|
|
|
QPointer<CvTrackbar> t;
|
|
|
|
|
//Warning ---- , asume the location 0 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
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
settings->setArrayIndex(i);
|
|
|
|
|
t = (CvTrackbar*) layout->layout()->itemAt(i+1);//+1 because index 0 is myview (see Warning)
|
|
|
|
|
|
|
|
|
|
if (t->trackbar_name == settings->value("name").toString())
|
|
|
|
|
{
|
|
|
|
|
t->slider->setValue(settings->value("value").toInt());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
settings->endArray();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CvWindow::icvSaveTrackbars(QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
QPointer<CvTrackbar> t;
|
|
|
|
|
|
|
|
|
|
//Warning ---- , asume the location 0 is myview and max-1 the status bar
|
|
|
|
|
//done three times in the code, in loadtrackbars, savetrackbar and in findtrackbar
|
|
|
|
|
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)
|
|
|
|
|
settings->setArrayIndex(i);
|
|
|
|
|
settings->setValue("name", t->trackbar_name);
|
|
|
|
|
settings->setValue("value", t->slider->value());
|
|
|
|
|
}
|
|
|
|
|
settings->endArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Here is ViewPort
|
|
|
|
|
ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
|
|
|
|
{
|
|
|
|
|
centralWidget = arg,
|
|
|
|
|
mode = arg2;
|
|
|
|
|
keepRatio = arg3;
|
|
|
|
|
mode_display = arg2;
|
|
|
|
|
param_keepRatio = arg3;
|
|
|
|
|
|
|
|
|
|
setupViewport(centralWidget);
|
|
|
|
|
setContentsMargins(0,0,0,0);
|
|
|
|
@@ -988,7 +1092,7 @@ ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(OPENCV_GL)
|
|
|
|
|
if (mode == CV_MODE_OPENGL)
|
|
|
|
|
if ( mode_display == CV_MODE_OPENGL)
|
|
|
|
|
{
|
|
|
|
|
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
|
|
|
|
initGL();
|
|
|
|
@@ -1013,62 +1117,57 @@ ViewPort::~ViewPort()
|
|
|
|
|
|
|
|
|
|
void ViewPort::setRatio(int flags)
|
|
|
|
|
{
|
|
|
|
|
keepRatio = flags;
|
|
|
|
|
param_keepRatio = flags;
|
|
|
|
|
updateGeometry();
|
|
|
|
|
viewport()->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ViewPort::getRatio()
|
|
|
|
|
{
|
|
|
|
|
return keepRatio;
|
|
|
|
|
return param_keepRatio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ViewPort::resetZoom()
|
|
|
|
|
{
|
|
|
|
|
matrixWorld.reset();
|
|
|
|
|
param_matrixWorld.reset();
|
|
|
|
|
controlImagePosition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ViewPort::imgRegion( )
|
|
|
|
|
{
|
|
|
|
|
scaleView(threshold_zoom_img_region/matrixWorld.m11(), QPointF(size().width()/2,size().height()/2),false);//false = do not process the 1st param
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ViewPort::ZoomIn()
|
|
|
|
|
{
|
|
|
|
|
scaleView( 0.5,QPointF(size().width()/2,size().height()/2),true);
|
|
|
|
|
scaleView( 0.5,QPointF(size().width()/2,size().height()/2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ViewPort::ZoomOut()
|
|
|
|
|
{
|
|
|
|
|
scaleView( -0.5,QPointF(size().width()/2,size().height()/2),true);
|
|
|
|
|
scaleView( -0.5,QPointF(size().width()/2,size().height()/2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
|
void ViewPort::siftWindowOnLeft()
|
|
|
|
|
{
|
|
|
|
|
float delta = 2*width()/(100.0*matrixWorld.m11());
|
|
|
|
|
float delta = 2*width()/(100.0*param_matrixWorld.m11());
|
|
|
|
|
moveView(QPointF(delta,0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
|
void ViewPort::siftWindowOnRight()
|
|
|
|
|
{
|
|
|
|
|
float delta = -2*width()/(100.0*matrixWorld.m11());
|
|
|
|
|
float delta = -2*width()/(100.0*param_matrixWorld.m11());
|
|
|
|
|
moveView(QPointF(delta,0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
|
void ViewPort::siftWindowOnUp()
|
|
|
|
|
{
|
|
|
|
|
float delta = 2*height()/(100.0*matrixWorld.m11());
|
|
|
|
|
float delta = 2*height()/(100.0*param_matrixWorld.m11());
|
|
|
|
|
moveView(QPointF(0,delta));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Note: move 2 percent of the window
|
|
|
|
|
void ViewPort::siftWindowOnDown()
|
|
|
|
|
{
|
|
|
|
|
float delta = -2*height()/(100.0*matrixWorld.m11());
|
|
|
|
|
float delta = -2*height()/(100.0*param_matrixWorld.m11());
|
|
|
|
|
moveView(QPointF(0,delta));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1125,30 +1224,30 @@ void ViewPort::controlImagePosition()
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
|
|
|
|
|
|
//after check top-left, bottom right corner to avoid getting "out" during zoom/panning
|
|
|
|
|
matrixWorld.map(0,0,&left,&top);
|
|
|
|
|
param_matrixWorld.map(0,0,&left,&top);
|
|
|
|
|
|
|
|
|
|
if (left > 0)
|
|
|
|
|
{
|
|
|
|
|
matrixWorld.translate(-left,0);
|
|
|
|
|
param_matrixWorld.translate(-left,0);
|
|
|
|
|
left = 0;
|
|
|
|
|
}
|
|
|
|
|
if (top > 0)
|
|
|
|
|
{
|
|
|
|
|
matrixWorld.translate(0,-top);
|
|
|
|
|
param_matrixWorld.translate(0,-top);
|
|
|
|
|
top = 0;
|
|
|
|
|
}
|
|
|
|
|
//-------
|
|
|
|
|
|
|
|
|
|
QSize sizeImage = size();
|
|
|
|
|
matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
|
|
|
|
|
param_matrixWorld.map(sizeImage.width(),sizeImage.height(),&right,&bottom);
|
|
|
|
|
if (right < sizeImage.width())
|
|
|
|
|
{
|
|
|
|
|
matrixWorld.translate(sizeImage.width()-right,0);
|
|
|
|
|
param_matrixWorld.translate(sizeImage.width()-right,0);
|
|
|
|
|
right = sizeImage.width();
|
|
|
|
|
}
|
|
|
|
|
if (bottom < sizeImage.height())
|
|
|
|
|
{
|
|
|
|
|
matrixWorld.translate(0,sizeImage.height()-bottom);
|
|
|
|
|
param_matrixWorld.translate(0,sizeImage.height()-bottom);
|
|
|
|
|
bottom = sizeImage.height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1156,51 +1255,48 @@ void ViewPort::controlImagePosition()
|
|
|
|
|
positionCorners.setTopLeft(QPoint(left,top));
|
|
|
|
|
positionCorners.setBottomRight(QPoint(right,bottom));
|
|
|
|
|
//save also the inv matrix
|
|
|
|
|
matrixWorld_inv = matrixWorld.inverted();
|
|
|
|
|
matrixWorld_inv = param_matrixWorld.inverted();
|
|
|
|
|
|
|
|
|
|
viewport()->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ViewPort::moveView(QPointF delta)
|
|
|
|
|
{
|
|
|
|
|
matrixWorld.translate(delta.x(),delta.y());
|
|
|
|
|
param_matrixWorld.translate(delta.x(),delta.y());
|
|
|
|
|
controlImagePosition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//factor is -0.5 (zoom out) or 0.5 (zoom in)
|
|
|
|
|
void ViewPort::scaleView(qreal factor,QPointF center,bool process_factor)
|
|
|
|
|
{
|
|
|
|
|
if (process_factor)
|
|
|
|
|
void ViewPort::scaleView(qreal factor,QPointF center)
|
|
|
|
|
{
|
|
|
|
|
factor/=5;//-0.1 <-> 0.1
|
|
|
|
|
factor+=1;//0.9 <-> 1.1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//limit zoom out ---
|
|
|
|
|
if (matrixWorld.m11()==1 && factor < 1)
|
|
|
|
|
if (param_matrixWorld.m11()==1 && factor < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (matrixWorld.m11()*factor<1)
|
|
|
|
|
factor = 1/matrixWorld.m11();
|
|
|
|
|
if (param_matrixWorld.m11()*factor<1)
|
|
|
|
|
factor = 1/param_matrixWorld.m11();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//limit zoom int ---
|
|
|
|
|
if (matrixWorld.m11()>100 && factor > 1)
|
|
|
|
|
if (param_matrixWorld.m11()>100 && factor > 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//inverse the transform
|
|
|
|
|
int a, b;
|
|
|
|
|
matrixWorld_inv.map(center.x(),center.y(),&a,&b);
|
|
|
|
|
|
|
|
|
|
matrixWorld.translate(a-factor*a,b-factor*b);
|
|
|
|
|
matrixWorld.scale(factor,factor);
|
|
|
|
|
param_matrixWorld.translate(a-factor*a,b-factor*b);
|
|
|
|
|
param_matrixWorld.scale(factor,factor);
|
|
|
|
|
|
|
|
|
|
controlImagePosition();
|
|
|
|
|
|
|
|
|
|
//display new zoom
|
|
|
|
|
centralWidget->displayStatusBar(tr("Zoom: %1%").arg(matrixWorld.m11()*100),1000);
|
|
|
|
|
centralWidget->displayStatusBar(tr("Zoom: %1%").arg(param_matrixWorld.m11()*100),1000);
|
|
|
|
|
|
|
|
|
|
if (matrixWorld.m11()>1)
|
|
|
|
|
if (param_matrixWorld.m11()>1)
|
|
|
|
|
setCursor(Qt::OpenHandCursor);
|
|
|
|
|
else
|
|
|
|
|
unsetCursor();
|
|
|
|
@@ -1208,7 +1304,7 @@ void ViewPort::scaleView(qreal factor,QPointF center,bool process_factor)
|
|
|
|
|
|
|
|
|
|
void ViewPort::wheelEvent(QWheelEvent *event)
|
|
|
|
|
{
|
|
|
|
|
scaleView( -event->delta() / 240.0,event->pos(),true);//true means process the 1st parameter
|
|
|
|
|
scaleView( -event->delta() / 240.0,event->pos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ViewPort::mousePressEvent(QMouseEvent *event)
|
|
|
|
@@ -1220,7 +1316,7 @@ void ViewPort::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
icvmouseHandler(event, mouse_down, cv_event, flags);
|
|
|
|
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
|
|
|
|
|
|
|
|
|
if (matrixWorld.m11()>1)
|
|
|
|
|
if (param_matrixWorld.m11()>1)
|
|
|
|
|
{
|
|
|
|
|
setCursor(Qt::ClosedHandCursor);
|
|
|
|
|
positionGrabbing = event->pos();
|
|
|
|
@@ -1239,7 +1335,7 @@ void ViewPort::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
icvmouseHandler(event, mouse_up, cv_event, flags);
|
|
|
|
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
|
|
|
|
|
|
|
|
|
if (matrixWorld.m11()>1)
|
|
|
|
|
if (param_matrixWorld.m11()>1)
|
|
|
|
|
setCursor(Qt::OpenHandCursor);
|
|
|
|
|
|
|
|
|
|
QWidget::mouseReleaseEvent(event);
|
|
|
|
@@ -1267,9 +1363,9 @@ void ViewPort::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (matrixWorld.m11()>1 && event->buttons() == Qt::LeftButton)
|
|
|
|
|
if (param_matrixWorld.m11()>1 && event->buttons() == Qt::LeftButton)
|
|
|
|
|
{
|
|
|
|
|
QPointF dxy = (pt - positionGrabbing)/matrixWorld.m11();
|
|
|
|
|
QPointF dxy = (pt - positionGrabbing)/param_matrixWorld.m11();
|
|
|
|
|
|
|
|
|
|
positionGrabbing = event->pos();
|
|
|
|
|
|
|
|
|
@@ -1357,7 +1453,7 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
|
|
|
|
|
ratioX=width()/float(image2Draw_ipl->width);
|
|
|
|
|
ratioY=height()/float(image2Draw_ipl->height);
|
|
|
|
|
|
|
|
|
|
if(keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
|
|
|
|
|
if(param_keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
|
|
|
|
|
{
|
|
|
|
|
QSize newSize = QSize(image2Draw_ipl->width,image2Draw_ipl->height);
|
|
|
|
|
newSize.scale(event->size(),Qt::KeepAspectRatio);
|
|
|
|
@@ -1382,13 +1478,13 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
|
|
|
|
|
void ViewPort::paintEvent(QPaintEvent* event)
|
|
|
|
|
{
|
|
|
|
|
QPainter myPainter(viewport());
|
|
|
|
|
myPainter.setWorldTransform(matrixWorld);
|
|
|
|
|
myPainter.setWorldTransform(param_matrixWorld);
|
|
|
|
|
|
|
|
|
|
draw2D(&myPainter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(OPENCV_GL)
|
|
|
|
|
if (mode == CV_MODE_OPENGL && false)//disable it for now
|
|
|
|
|
if ( mode_display == CV_MODE_OPENGL && false)//disable it for now
|
|
|
|
|
{
|
|
|
|
|
setGL(this->width(),this->height());
|
|
|
|
|
draw3D();
|
|
|
|
@@ -1397,12 +1493,12 @@ void ViewPort::paintEvent(QPaintEvent* event)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//in mode zoom/panning
|
|
|
|
|
if (matrixWorld.m11()>1)
|
|
|
|
|
if (param_matrixWorld.m11()>1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
myPainter.setWorldMatrixEnabled (false );
|
|
|
|
|
|
|
|
|
|
if (matrixWorld.m11()>=threshold_zoom_img_region)
|
|
|
|
|
if (param_matrixWorld.m11()>=threshold_zoom_img_region)
|
|
|
|
|
drawImgRegion(&myPainter);
|
|
|
|
|
|
|
|
|
|
drawViewOverview(&myPainter);
|
|
|
|
@@ -1463,23 +1559,23 @@ void ViewPort::drawStatusBar()
|
|
|
|
|
|
|
|
|
|
void ViewPort::drawImgRegion(QPainter *painter)
|
|
|
|
|
{
|
|
|
|
|
qreal offsetX = matrixWorld.dx()/matrixWorld.m11();
|
|
|
|
|
qreal offsetX = param_matrixWorld.dx()/param_matrixWorld.m11();
|
|
|
|
|
offsetX = offsetX - floor(offsetX);
|
|
|
|
|
qreal offsetY = matrixWorld.dy()/matrixWorld.m11();
|
|
|
|
|
qreal offsetY = param_matrixWorld.dy()/param_matrixWorld.m11();
|
|
|
|
|
offsetY = offsetY - floor(offsetY);
|
|
|
|
|
|
|
|
|
|
QSize view = size();
|
|
|
|
|
QVarLengthArray<QLineF, 30> linesX;
|
|
|
|
|
for (qreal x = offsetX*matrixWorld.m11(); x < view.width(); x += matrixWorld.m11() )
|
|
|
|
|
for (qreal x = offsetX*param_matrixWorld.m11(); x < view.width(); x += param_matrixWorld.m11() )
|
|
|
|
|
linesX.append(QLineF(x, 0, x, view.height()));
|
|
|
|
|
|
|
|
|
|
QVarLengthArray<QLineF, 30> linesY;
|
|
|
|
|
for (qreal y = offsetY*matrixWorld.m11(); y < view.height(); y += matrixWorld.m11() )
|
|
|
|
|
for (qreal y = offsetY*param_matrixWorld.m11(); y < view.height(); y += param_matrixWorld.m11() )
|
|
|
|
|
linesY.append(QLineF(0, y, view.width(), y));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFont f = painter->font();
|
|
|
|
|
f.setPointSize(threshold_zoom_img_region/3+(matrixWorld.m11()-threshold_zoom_img_region)/6);
|
|
|
|
|
f.setPixelSize(6+(param_matrixWorld.m11()-threshold_zoom_img_region)/5);
|
|
|
|
|
//f.setStretch(0);
|
|
|
|
|
painter->setFont(f);
|
|
|
|
|
QString val;
|
|
|
|
@@ -1489,11 +1585,11 @@ void ViewPort::drawImgRegion(QPainter *painter)
|
|
|
|
|
QPointF point2;//idem
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int j=-1;j<view.height()/matrixWorld.m11();j++)
|
|
|
|
|
for (int i=-1;i<view.width()/matrixWorld.m11();i++)
|
|
|
|
|
for (int j=-1;j<view.height()/param_matrixWorld.m11();j++)
|
|
|
|
|
for (int i=-1;i<view.width()/param_matrixWorld.m11();i++)
|
|
|
|
|
{
|
|
|
|
|
point1.setX((i+offsetX)*matrixWorld.m11());
|
|
|
|
|
point1.setY((j+offsetY)*matrixWorld.m11());
|
|
|
|
|
point1.setX((i+offsetX)*param_matrixWorld.m11());
|
|
|
|
|
point1.setY((j+offsetY)*param_matrixWorld.m11());
|
|
|
|
|
|
|
|
|
|
matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry());
|
|
|
|
|
|
|
|
|
@@ -1502,22 +1598,21 @@ void ViewPort::drawImgRegion(QPainter *painter)
|
|
|
|
|
else
|
|
|
|
|
rgbValue = qRgb(0,0,0);
|
|
|
|
|
|
|
|
|
|
const int margin = 1;
|
|
|
|
|
if (nbChannelOriginImage==3)
|
|
|
|
|
{
|
|
|
|
|
val = tr("%1").arg(qRed(rgbValue));
|
|
|
|
|
painter->setPen(QPen(Qt::red, 1));
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y()+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
|
|
|
|
Qt::AlignCenter, val);
|
|
|
|
|
|
|
|
|
|
val = tr("%1").arg(qGreen(rgbValue));
|
|
|
|
|
painter->setPen(QPen(Qt::green, 1));
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y()+matrixWorld.m11()/3+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y()+param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
|
|
|
|
Qt::AlignCenter, val);
|
|
|
|
|
|
|
|
|
|
val = tr("%1").arg(qBlue(rgbValue));
|
|
|
|
|
painter->setPen(QPen(Qt::blue, 1));
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y()+2*matrixWorld.m11()/3+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y()+2*param_matrixWorld.m11()/3,param_matrixWorld.m11(),param_matrixWorld.m11()/3),
|
|
|
|
|
Qt::AlignCenter, val);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@@ -1525,7 +1620,7 @@ void ViewPort::drawImgRegion(QPainter *painter)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
val = tr("%1").arg(qRed(rgbValue));
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y(),matrixWorld.m11(),matrixWorld.m11()),
|
|
|
|
|
painter->drawText(QRect(point1.x(),point1.y(),param_matrixWorld.m11(),param_matrixWorld.m11()),
|
|
|
|
|
Qt::AlignCenter, val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -1549,7 +1644,7 @@ void ViewPort::drawViewOverview(QPainter *painter)
|
|
|
|
|
painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
|
|
|
|
|
|
|
|
|
|
//daw the view's location inside the image
|
|
|
|
|
qreal ratioSize = 1/matrixWorld.m11();
|
|
|
|
|
qreal ratioSize = 1/param_matrixWorld.m11();
|
|
|
|
|
qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
|
|
|
|
|
painter->setPen(Qt::darkBlue);
|
|
|
|
|
painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
|
|
|
|
|