From 637fba85d3f8392a76cdc3980c5d2d25ecd01518 Mon Sep 17 00:00:00 2001 From: MPIBR-kretschmerf Date: Thu, 2 Feb 2017 10:56:11 +0100 Subject: [PATCH] Added size check on uiInitialize to avoid unneccesarry actions when size stays the same --- TrackerPlugin_EyeTracker.cpp | 42 +++++++++++++++++++----------------- TrackerPlugin_EyeTracker.h | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/TrackerPlugin_EyeTracker.cpp b/TrackerPlugin_EyeTracker.cpp index d846366..a7507fe 100644 --- a/TrackerPlugin_EyeTracker.cpp +++ b/TrackerPlugin_EyeTracker.cpp @@ -161,26 +161,28 @@ QObject *TrackerPlugin_EyeTracker::worker() void TrackerPlugin_EyeTracker::initializeUI(QLayout *layout, QGraphicsScene *cameraScene, QSize cameraResolution) { - this->cameraResolution = cameraResolution; - layout->addWidget(this); - this->cameraScene = cameraScene; - - for(int i=0;icameraScene->addItem(rectItems.at(i)); - } - - /*Resize rectangles according to the correct size*/ - if(cameraResolution.width()>cameraResolution.height()){ - this->maxRectWidth = cameraResolution.height()/2; - }else{ - this->maxRectWidth = cameraResolution.width()/2; - } - qDebug()<setRect(QRect(0,0,maxRectWidth,maxRectWidth)); - emit(thresholdChanged(i, uiSliders.at(i)->value())); - emit(sizeChanged(i, QSize(rectItems.at(i)->rect().width(), rectItems.at(i)->rect().height()))); - emit(posChanged(i, QPoint(rectItems.at(i)->pos().rx(),rectItems.at(i)->pos().ry()))); + /*Keep rectangles unchanged if the resolution didn't change*/ + if(this->cameraResolution!=cameraResolution){ + this->cameraResolution = cameraResolution; + layout->addWidget(this); + this->cameraScene = cameraScene; + + for(int i=0;icameraScene->addItem(rectItems.at(i)); + } + + /*Resize rectangles according to the correct size*/ + if(cameraResolution.width()>cameraResolution.height()){ + this->maxRectWidth = cameraResolution.height()/2; + }else{ + this->maxRectWidth = cameraResolution.width()/2; + } + for(int i=0;isetRect(QRect(0,0,maxRectWidth,maxRectWidth)); + emit(thresholdChanged(i, uiSliders.at(i)->value())); + emit(sizeChanged(i, QSize(rectItems.at(i)->rect().width(), rectItems.at(i)->rect().height()))); + emit(posChanged(i, QPoint(rectItems.at(i)->pos().rx(),rectItems.at(i)->pos().ry()))); + } } } diff --git a/TrackerPlugin_EyeTracker.h b/TrackerPlugin_EyeTracker.h index 037bb9a..37b351b 100644 --- a/TrackerPlugin_EyeTracker.h +++ b/TrackerPlugin_EyeTracker.h @@ -38,7 +38,7 @@ class TrackerPlugin_EyeTracker : public QWidget, public TrackerInterface QObject *worker(); void initializeUI(QLayout* guiTargetLayout, QGraphicsScene* cameraScene, QSize cameraResolution); TrackerWorker* trackerWorker; - QSize cameraResolution; + QSize cameraResolution = QSize(0,0); private: Ui::TrackerPlugin_EyeTracker *ui;