diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-16 21:59:38 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-16 21:59:38 -0500 |
commit | 9c5e2aa99427fe125c631d4753b1f944992d8c03 (patch) | |
tree | 61840d3ba80140ba31daa54bd86b0c472cd8bd51 /clients/tde/src/widgets/tracewidget.cpp | |
parent | e7ef2071e5f64e1a34201961592750a410060f1f (diff) | |
download | ulab-9c5e2aa99427fe125c631d4753b1f944992d8c03.tar.gz ulab-9c5e2aa99427fe125c631d4753b1f944992d8c03.zip |
Fix trace widget
Diffstat (limited to 'clients/tde/src/widgets/tracewidget.cpp')
-rw-r--r-- | clients/tde/src/widgets/tracewidget.cpp | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/clients/tde/src/widgets/tracewidget.cpp b/clients/tde/src/widgets/tracewidget.cpp index 1f7c576..e3803ed 100644 --- a/clients/tde/src/widgets/tracewidget.cpp +++ b/clients/tde/src/widgets/tracewidget.cpp @@ -97,6 +97,8 @@ bool TQRectF::operator!=(const TQRectF &r1) { TraceData::TraceData(TraceWidget* parent, TQWidget* labelParent) : TQObject(), parentWidget(parent) { color = TQColor(0, 255, 0); numberOfSamples = 0; + leftEdgeIndex = -1; + rightEdgeIndex = -1; offset = 0.0; leftEdge = 0; rightEdge = 0; @@ -178,21 +180,45 @@ void TraceData::drawTrace(TQPainter* p, int graticule_width, int graticule_heigh if ((bottomEdge != topEdge) && (enabled) && (positionArray.count() >= numberOfSamples) && (sampleArray.count() >= numberOfSamples) && (numberOfSamples > 0)) { // Draw the points unsigned int n; + unsigned int incr; + unsigned int activeSamples; int x,y,x2,y2; - for (n=0; n<numberOfSamples-1; n++) { + // Determine how many samples are actually being displayed + if ((leftEdgeIndex < 0) || (rightEdgeIndex < 0)) { + for (n=0; n<numberOfSamples; n++) { + x = (((positionArray[n]-leftEdge)/(rightEdge-leftEdge))*(graticule_width)); + if (leftEdgeIndex < 0) { + if (x >= 0) { + leftEdgeIndex = n; + } + } + else { + if (x >= graticule_width) { + rightEdgeIndex = n; + break; + } + } + } + if (rightEdgeIndex < 0) { + rightEdgeIndex = numberOfSamples-1; + } + } + activeSamples = abs(rightEdgeIndex-leftEdgeIndex); + incr = (activeSamples/graticule_width)+1; + for (n=leftEdgeIndex; n<numberOfSamples-incr; n=n+incr) { x = (((positionArray[n]-leftEdge)/(rightEdge-leftEdge))*(graticule_width)); y = ((((sampleArray[n]+offset)-topEdge)/(bottomEdge-topEdge))*(graticule_height)); - x2 = (((positionArray[n+1]-leftEdge)/(rightEdge-leftEdge))*(graticule_width)); - y2 = ((((sampleArray[n+1]+offset)-topEdge)/(bottomEdge-topEdge))*(graticule_height)); + x2 = (((positionArray[n+incr]-leftEdge)/(rightEdge-leftEdge))*(graticule_width)); + y2 = ((((sampleArray[n+incr]+offset)-topEdge)/(bottomEdge-topEdge))*(graticule_height)); if (x < 0) x = 0; if (x > graticule_width) x = graticule_width; if (y < 0) y = 0; - if (y > graticule_width) y = graticule_height; + if (y > graticule_height) y = graticule_height; if (x2 < 0) x2 = 0; if (x2 > graticule_width) x2 = graticule_width; if (y2 < 0) y2 = 0; - if (y2 > graticule_width) y2 = graticule_height; + if (y2 > graticule_height) y2 = graticule_height; p->drawLine(x, y, x2, y2); } @@ -535,6 +561,7 @@ void GraticuleWidget::mousePressEvent(TQMouseEvent *e) { if (m_base->m_zoomBoxEnabled) { m_middleMouseDown = true; m_prevDownPos = e->pos(); + setCursor(tqsizeAllCursor); } } } @@ -545,7 +572,24 @@ void GraticuleWidget::mouseReleaseEvent(TQMouseEvent *e) { m_leftMouseDown = false; if (m_movingCursor >= 0) { + TQPoint diff = e->pos() - m_prevDownPos; + double dx = diff.x()*(100.0/width()); + double dy = diff.y()*(100.0/height()); + if (m_base->m_cursorArray[m_movingCursor]->orientation == TQt::Horizontal) { + m_base->m_cursorArray[m_movingCursor]->position = m_prevCursorPos+dy; + } + else { + m_base->m_cursorArray[m_movingCursor]->position = m_prevCursorPos+dx; + } + if (m_base->m_cursorArray[m_movingCursor]->position < 0.0) { + m_base->m_cursorArray[m_movingCursor]->position = 0.0; + } + if (m_base->m_cursorArray[m_movingCursor]->position > 100.0) { + m_base->m_cursorArray[m_movingCursor]->position = 100.0; + } m_movingCursor = -1; + updateGraticule(); + repaint(false); } else { double x1 = m_prevDownPos.x(); @@ -578,13 +622,15 @@ void GraticuleWidget::mouseReleaseEvent(TQMouseEvent *e) { double y2 = e->y(); if ((x1 < width()) && (y1 < height()) && (x2 < width()) && (y2 < height()) && (x1 > 0) && (y1 > 0) && (x2 > 0) && (y2 > 0)) { TQPoint diff = e->pos() - m_prevDownPos; - diff = TQPoint(diff.x()*(100.0/width()), diff.y()*(100.0/height())); - m_base->setZoomCursorBox(TQRectF(m_prevCursorRect.x()+diff.x(), m_prevCursorRect.y()+diff.y(), m_prevCursorRect.width()+diff.x(), m_prevCursorRect.height()+diff.y())); + double dx = diff.x()*(100.0/width()); + double dy = diff.y()*(100.0/height()); + m_base->setZoomCursorBox(TQRectF(m_prevCursorRect.x()+dx, m_prevCursorRect.y()+dy, m_prevCursorRect.width()+dx, m_prevCursorRect.height()+dy)); } else { // Reset original zoom box m_base->setZoomCursorBox(m_prevCursorRect); } + setCursor(tqcrossCursor); } } @@ -694,12 +740,13 @@ void GraticuleWidget::mouseMoveEvent(TQMouseEvent *e) { } else if ((m_leftMouseDown) && (m_movingCursor >= 0)) { TQPoint diff = e->pos() - m_prevDownPos; - diff = TQPoint(diff.x()*(100.0/width()), diff.y()*(100.0/height())); + double dx = diff.x()*(100.0/width()); + double dy = diff.y()*(100.0/height()); if (m_base->m_cursorArray[m_movingCursor]->orientation == TQt::Horizontal) { - m_base->m_cursorArray[m_movingCursor]->position = m_prevCursorPos+diff.y(); + m_base->m_cursorArray[m_movingCursor]->position = m_prevCursorPos+dy; } else { - m_base->m_cursorArray[m_movingCursor]->position = m_prevCursorPos+diff.x(); + m_base->m_cursorArray[m_movingCursor]->position = m_prevCursorPos+dx; } if (m_base->m_cursorArray[m_movingCursor]->position < 0.0) { m_base->m_cursorArray[m_movingCursor]->position = 0.0; @@ -713,8 +760,9 @@ void GraticuleWidget::mouseMoveEvent(TQMouseEvent *e) { } else if (m_middleMouseDown) { TQPoint diff = e->pos() - m_prevDownPos; - diff = TQPoint(diff.x()*(100.0/width()), diff.y()*(100.0/height())); - m_base->setZoomCursorBox(TQRectF(m_prevCursorRect.x()+diff.x(), m_prevCursorRect.y()+diff.y(), m_prevCursorRect.width()+diff.x(), m_prevCursorRect.height()+diff.y())); + double dx = diff.x()*(100.0/width()); + double dy = diff.y()*(100.0/height()); + m_base->setZoomCursorBox(TQRectF(m_prevCursorRect.x()+dx, m_prevCursorRect.y()+dy, m_prevCursorRect.width()+dx, m_prevCursorRect.height()+dy)); } m_base->updateCursorText(); @@ -805,6 +853,8 @@ void TraceWidget::setNumberOfSamples(uint traceNumber, unsigned int samples) { m_traceArray[traceNumber]->numberOfSamples = samples; m_traceArray[traceNumber]->sampleArray.resize(samples); m_traceArray[traceNumber]->positionArray.resize(samples); + m_traceArray[traceNumber]->leftEdgeIndex = -1; + m_traceArray[traceNumber]->rightEdgeIndex = -1; m_graticuleWidget->updateGraticule(); updateTraceText(); @@ -831,6 +881,8 @@ void TraceWidget::setDisplayLimits(uint traceNumber, TQRectF limits) { m_traceArray[traceNumber]->rightEdge = limits.width(); m_traceArray[traceNumber]->topEdge = limits.y(); m_traceArray[traceNumber]->bottomEdge = limits.height(); + m_traceArray[traceNumber]->leftEdgeIndex = -1; + m_traceArray[traceNumber]->rightEdgeIndex = -1; m_graticuleWidget->updateGraticule(); m_graticuleWidget->repaint(false); @@ -958,6 +1010,8 @@ void TraceWidget::setPositions(uint traceNumber, TQDoubleArray& tqda) { m_traceArray[traceNumber]->positionArray = tqda; m_traceArray[traceNumber]->numberOfSamples = tqda.size(); + m_traceArray[traceNumber]->leftEdgeIndex = -1; + m_traceArray[traceNumber]->rightEdgeIndex = -1; m_graticuleWidget->repaint(false); } |