diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-09-14 17:24:04 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-09-14 17:24:04 +0200 |
commit | fbca62b8ef01796127999405b76bbd918c76c69e (patch) | |
tree | 0b722e6dd0dc0edde2c4490977a739d2f3798a12 | |
parent | cf5a0fb030e44f616475b9c85115f0eafeecde70 (diff) |
throttle QFunctionConfigurator updates
Don't consume whole CPU time when the spline editor control points are
being dragged.
-rw-r--r-- | qfunctionconfigurator/qfunctionconfigurator.cpp | 60 | ||||
-rw-r--r-- | qfunctionconfigurator/qfunctionconfigurator.h | 2 |
2 files changed, 32 insertions, 30 deletions
diff --git a/qfunctionconfigurator/qfunctionconfigurator.cpp b/qfunctionconfigurator/qfunctionconfigurator.cpp index 418d46c8..76245de4 100644 --- a/qfunctionconfigurator/qfunctionconfigurator.cpp +++ b/qfunctionconfigurator/qfunctionconfigurator.cpp @@ -136,10 +136,8 @@ void QFunctionConfigurator::saveSettings(QString settingsFile) { // void QFunctionConfigurator::drawBackground(const QRectF &fullRect) { -int i; -QRect scale; - - qDebug() << "QFunctionConfigurator::drawBackground."; + int i; + QRect scale; _background = QPixmap(fullRect.width(), fullRect.height()); QPainter painter(&_background); @@ -393,6 +391,7 @@ void QFunctionConfigurator::mousePressEvent(QMouseEvent *e) if ( markContains( graphicalizePoint( points[i] ), e->pos() ) ) { bTouchingPoint = true; movingPoint = i; + timer.restart(); break; } } @@ -450,40 +449,40 @@ void QFunctionConfigurator::mouseMoveEvent(QMouseEvent *e) QList<QPointF> points = _config->getPoints(); if (movingPoint >= 0 && movingPoint < points.size()) { - setCursor(Qt::ClosedHandCursor); - // - // Change the currently moving Point. - // - QPointF new_pt = normalizePoint(e->pos()); - points[movingPoint] = new_pt; - _config->movePoint(movingPoint, new_pt); - _draw_function = _draw_background = true; - update(); + if (timer.isValid() && timer.elapsed() > 100) + { + timer.restart(); + QPointF new_pt = normalizePoint(e->pos()); + points[movingPoint] = new_pt; + _config->movePoint(movingPoint, new_pt); + _draw_function = _draw_background = true; + update(); + } } else { - - // - // Check to see if the cursor is touching one of the points. - // - bool bTouchingPoint = false; - if (_config) { - - for (int i = 0; i < points.size(); i++) { - if ( markContains( graphicalizePoint( points[i] ), e->pos() ) ) { - bTouchingPoint = true; + if (withinRect(e->pos(), rect())) + { + // + // Check to see if the cursor is touching one of the points. + // + bool bTouchingPoint = false; + if (_config) { + for (int i = 0; i < points.size(); i++) { + if ( markContains( graphicalizePoint( points[i] ), e->pos() ) ) { + bTouchingPoint = true; + } } } - } - if ( bTouchingPoint ) { - setCursor(Qt::OpenHandCursor); - } - else { - setCursor(Qt::ArrowCursor); + if ( bTouchingPoint ) { + setCursor(Qt::OpenHandCursor); + } + else { + setCursor(Qt::ArrowCursor); + } } - } } @@ -492,6 +491,7 @@ void QFunctionConfigurator::mouseReleaseEvent(QMouseEvent *e) QList<QPointF> points = _config->getPoints(); if (e->button() == Qt::LeftButton) { + timer.invalidate(); //qDebug()<<"releasing"; if (movingPoint >= 0 && movingPoint < points.size()) { emit CurveChanged( true ); diff --git a/qfunctionconfigurator/qfunctionconfigurator.h b/qfunctionconfigurator/qfunctionconfigurator.h index d2714ced..fc2a1957 100644 --- a/qfunctionconfigurator/qfunctionconfigurator.h +++ b/qfunctionconfigurator/qfunctionconfigurator.h @@ -39,6 +39,7 @@ #include <QtGui> #include <QtDesigner/QDesignerExportWidget> #include <QPointF> +#include <QElapsedTimer> #include "qfunctionconfigurator/functionconfig.h" #include "ftnoir_tracker_base/ftnoir_tracker_base.h" @@ -171,6 +172,7 @@ private: QPointF graphicalizePoint (QPointF point) const; // Convert the Point to a graphical Point int movingPoint; + QElapsedTimer timer; int MaxInput; // Maximum input limit int MaxOutput; // Maximum output limit |