diff options
Diffstat (limited to 'clients/tde/src/widgets/tracewidget.cpp')
-rw-r--r-- | clients/tde/src/widgets/tracewidget.cpp | 290 |
1 files changed, 218 insertions, 72 deletions
diff --git a/clients/tde/src/widgets/tracewidget.cpp b/clients/tde/src/widgets/tracewidget.cpp index 2444bc7..1fe3ff4 100644 --- a/clients/tde/src/widgets/tracewidget.cpp +++ b/clients/tde/src/widgets/tracewidget.cpp @@ -4,22 +4,55 @@ #include "tracewidget.h" #include <stdlib.h> +#include <cmath> #include <tqpixmap.h> #include <tqpainter.h> +#include <tqlabel.h> +#include <tqlayout.h> + +#include <klocale.h> + #define VERIFY_TRACE_ARRAY_SIZE if (traceNumber >= m_traceArray.count()) resizeTraceArray(traceNumber+1); -TraceData::TraceData() { +TraceData::TraceData(TQWidget* labelParent) { color = TQColor(0, 255, 0); numberOfSamples = 0; leftEdge = 0; rightEdge = 0; topEdge = 0; bottomEdge = 0; + traceName = i18n("Unknown"); + horizontalUnits = i18n("Units"); + verticalUnits = i18n("Units"); enabled = false; + + if (labelParent) { + infoLabel = new TQLabel(labelParent); + infoLabel->setPaletteBackgroundColor(labelParent->paletteBackgroundColor()); + infoLabel->setPaletteForegroundColor(color); + infoLabel->setAlignment(TQt::AlignHCenter|TQt::AlignVCenter|TQt::SingleLine); + infoLabel->hide(); + } + else { + infoLabel = NULL; + } } +TraceData::~TraceData() { + // +} + +// RAJA FIXME +// Add cursor support + +// RAJA FIXME +// Add offset (x and y) support + +// RAJA FIXME +// Add scaling support + void TraceData::drawTrace(TQPainter* p, int graticule_width, int graticule_height) { p->setPen(color); @@ -28,55 +61,159 @@ void TraceData::drawTrace(TQPainter* p, int graticule_width, int graticule_heigh unsigned int n; int x,y,x2,y2; for (n=0; n<numberOfSamples-1; n++) { - x = abs(((n*1.0)/(numberOfSamples-1))*(graticule_width)); + x = abs(((positionArray[n]-leftEdge)/(rightEdge-leftEdge))*(graticule_width)); y = abs(((sampleArray[n]-topEdge)/(bottomEdge-topEdge))*(graticule_height)); - x2 = abs(((n+1*1.0)/(numberOfSamples-1))*(graticule_width)); + x2 = abs(((positionArray[n+1]-leftEdge)/(rightEdge-leftEdge))*(graticule_width)); y2 = abs(((sampleArray[n+1]-topEdge)/(bottomEdge-topEdge))*(graticule_height)); p->drawLine(x, y, x2, y2); } } } +GraticuleWidget::GraticuleWidget(TraceWidget* parent, const char* name) : TQWidget(parent, name), + m_base(parent), + m_graticulePixmap(0) { + setBackgroundMode(NoBackground); + setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding)); + + setPaletteBackgroundColor(TQt::black); + setPaletteForegroundColor(TQColor(0,128,0)); +} + +GraticuleWidget::~GraticuleWidget() { + // +} + +void GraticuleWidget::updateGraticule() { + unsigned int d,s,x,y; + + if (m_graticulePixmap) { + delete m_graticulePixmap; + } + m_graticulePixmap = new TQPixmap(width(), height()); + + // Draw the graticule into the pixmap + TQPainter p(m_graticulePixmap); + p.setPen(TQPen(foregroundColor(), 1, TQt::SolidLine)); + p.fillRect(0, 0, m_graticulePixmap->width(), m_graticulePixmap->height(), backgroundColor()); + p.setPen(TQPen(foregroundColor(), 1, TQt::DotLine)); + if (m_base->m_vertDivs > 0) { + s = m_graticulePixmap->width() / m_base->m_vertDivs; + x = 0; + for (d=0; d<m_base->m_vertDivs; d++) { + p.drawLine(x, 0, x, m_graticulePixmap->height()); + x += s; + } + } + if (m_base->m_horizDivs > 0) { + s = m_graticulePixmap->height() / m_base->m_horizDivs; + y = 0; + for (d=0; d<m_base->m_horizDivs; d++) { + p.drawLine(0, y, m_graticulePixmap->width(), y); + y += s; + } + } + p.setPen(TQPen(foregroundColor(), 1, TQt::SolidLine)); + p.drawRect(0, 0, m_graticulePixmap->width(), m_graticulePixmap->height()); + + // Repaint the widget + repaint(); +} + +void GraticuleWidget::paintEvent(TQPaintEvent*) { + TQPainter p(this); + + if (m_graticulePixmap) { + // Draw the graticule pixmap to erase the widget + p.drawPixmap(0, 0, *m_graticulePixmap); + + // Draw the traces + for (uint trace=0;trace<m_base->m_traceArray.count();trace++) { + m_base->m_traceArray[trace]->drawTrace(&p, m_graticulePixmap->width(), m_graticulePixmap->height()); + } + } + else { + p.fillRect(x(), y(), width(), height(), backgroundColor()); + } +} + +void GraticuleWidget::resizeEvent(TQResizeEvent *) { + updateGraticule(); +} + TraceWidget::TraceWidget(TQWidget* parent, const char* name) : TQWidget(parent, name), m_horizDivs(0), - m_vertDivs(0), - m_graticulePixmap(0) { + m_vertDivs(0) { setBackgroundMode(NoBackground); + m_primaryLayout = new TQVBoxLayout(this); + m_graticuleWidget = new GraticuleWidget(this); + m_primaryLayout->addWidget(m_graticuleWidget); + m_traceLabelLayout = new TQGridLayout(m_primaryLayout); + m_traceLabelLayout->addItem(new TQSpacerItem(0, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum), 0, 255); + setPaletteBackgroundColor(TQt::black); setPaletteForegroundColor(TQColor(0,128,0)); } TraceWidget::~TraceWidget() { - resizeTraceArray(0); + for (uint i=0;i<m_traceArray.count();i++) { + delete m_traceArray[i]; + } } -void TraceWidget::setNumberOfSamples(unsigned int samples, uint traceNumber) { +void TraceWidget::setNumberOfSamples(uint traceNumber, unsigned int samples) { VERIFY_TRACE_ARRAY_SIZE m_traceArray[traceNumber]->numberOfSamples = samples; m_traceArray[traceNumber]->sampleArray.resize(samples); + m_traceArray[traceNumber]->positionArray.resize(samples); - updateGraticule(); + m_graticuleWidget->updateGraticule(); + updateTraceText(); } void TraceWidget::setNumberOfHorizontalDivisions(unsigned int divisions) { m_horizDivs = divisions; - updateGraticule(); + m_graticuleWidget->updateGraticule(); + updateTraceText(); } void TraceWidget::setNumberOfVerticalDivisions(unsigned int divisions) { m_vertDivs = divisions; - updateGraticule(); + m_graticuleWidget->updateGraticule(); + updateTraceText(); } -void TraceWidget::setDisplayLimits(double x, double y, double w, double h, uint traceNumber) { +void TraceWidget::setDisplayLimits(uint traceNumber, double x, double y, double w, double h) { VERIFY_TRACE_ARRAY_SIZE m_traceArray[traceNumber]->leftEdge = x; m_traceArray[traceNumber]->rightEdge = w; m_traceArray[traceNumber]->topEdge = y; m_traceArray[traceNumber]->bottomEdge = h; + + updateTraceText(); +} + +void TraceWidget::updateTraceText() { + // RAJA FIXME + // Display current scaling and offset values for all traces + + // RAJA FIXME + // Display upper/lower/left/right boundary values, + // possibly in a different routine + + for (uint trace=0;trace<m_traceArray.count();trace++) { + double horizontal_units_per_division; + double vertical_units_per_division; + + horizontal_units_per_division = fabs(m_traceArray[trace]->rightEdge-m_traceArray[trace]->leftEdge)/m_horizDivs; + vertical_units_per_division = fabs(m_traceArray[trace]->topEdge-m_traceArray[trace]->bottomEdge)/m_vertDivs; + m_traceArray[trace]->infoLabel->setPaletteBackgroundColor(paletteBackgroundColor()); + m_traceArray[trace]->infoLabel->setPaletteForegroundColor(m_traceArray[trace]->color); + m_traceArray[trace]->infoLabel->setText(TQString("<qt>%1<br>%2 %3/div<br>%4 %5/div</qt>").arg(m_traceArray[trace]->traceName).arg(horizontal_units_per_division).arg(m_traceArray[trace]->horizontalUnits).arg(vertical_units_per_division).arg(m_traceArray[trace]->verticalUnits)); + } } TQDoubleArray& TraceWidget::samples(uint traceNumber) { @@ -85,23 +222,39 @@ TQDoubleArray& TraceWidget::samples(uint traceNumber) { return m_traceArray[traceNumber]->sampleArray; } -void TraceWidget::setSamples(TQDoubleArray& tqda, uint traceNumber) { +void TraceWidget::setSamples(uint traceNumber, TQDoubleArray& tqda) { VERIFY_TRACE_ARRAY_SIZE m_traceArray[traceNumber]->sampleArray = tqda; m_traceArray[traceNumber]->numberOfSamples = tqda.size(); } +TQDoubleArray& TraceWidget::positions(uint traceNumber) { + VERIFY_TRACE_ARRAY_SIZE + + return m_traceArray[traceNumber]->positionArray; +} + +void TraceWidget::setPositions(uint traceNumber, TQDoubleArray& tqda) { + VERIFY_TRACE_ARRAY_SIZE + + m_traceArray[traceNumber]->positionArray = tqda; + m_traceArray[traceNumber]->numberOfSamples = tqda.size(); +} + TQColor& TraceWidget::traceColor(uint traceNumber) { VERIFY_TRACE_ARRAY_SIZE return m_traceArray[traceNumber]->color; } -void TraceWidget::setTraceColor(TQColor& color, uint traceNumber) { +void TraceWidget::setTraceColor(uint traceNumber, TQColor& color) { VERIFY_TRACE_ARRAY_SIZE m_traceArray[traceNumber]->color = color; + + m_graticuleWidget->updateGraticule(); + updateTraceText(); } bool TraceWidget::traceEnabled(uint traceNumber) { @@ -110,82 +263,75 @@ bool TraceWidget::traceEnabled(uint traceNumber) { return m_traceArray[traceNumber]->enabled; } -void TraceWidget::setTraceEnabled(bool enabled, uint traceNumber) { +void TraceWidget::setTraceEnabled(uint traceNumber, bool enabled) { VERIFY_TRACE_ARRAY_SIZE m_traceArray[traceNumber]->enabled = enabled; -} - -void TraceWidget::resizeTraceArray(uint newsize) { - uint oldcount = m_traceArray.count(); - - if (newsize > oldcount) { - m_traceArray.resize(newsize); - for (uint i=oldcount;i<newsize;i++) { - m_traceArray[i] = new TraceData; - } + if (enabled) { + m_traceArray[traceNumber]->infoLabel->show(); } else { - m_traceArray.resize(newsize); - for (uint i=newsize;i<oldcount;i++) { - delete m_traceArray[i]; - } + m_traceArray[traceNumber]->infoLabel->hide(); } + + m_graticuleWidget->updateGraticule(); + updateTraceText(); } -void TraceWidget::updateGraticule() { - unsigned int d,s,x,y; +TQString TraceWidget::traceName(uint traceNumber) { + VERIFY_TRACE_ARRAY_SIZE - if (m_graticulePixmap) { - delete m_graticulePixmap; - } - m_graticulePixmap = new TQPixmap(width(), height()); + return m_traceArray[traceNumber]->traceName; +} - // Draw the graticule into the pixmap - TQPainter p(m_graticulePixmap); - p.setPen(TQPen(foregroundColor(), 1, TQt::SolidLine)); - p.fillRect(0, 0, m_graticulePixmap->width(), m_graticulePixmap->height(), backgroundColor()); - p.setPen(TQPen(foregroundColor(), 1, TQt::DotLine)); - if (m_vertDivs > 0) { - s = m_graticulePixmap->width() / m_vertDivs; - x = 0; - for (d=0; d<m_vertDivs; d++) { - p.drawLine(x, 0, x, m_graticulePixmap->height()); - x += s; - } - } - if (m_horizDivs > 0) { - s = m_graticulePixmap->height() / m_horizDivs; - y = 0; - for (d=0; d<m_horizDivs; d++) { - p.drawLine(0, y, m_graticulePixmap->width(), y); - y += s; - } - } - p.setPen(TQPen(foregroundColor(), 1, TQt::SolidLine)); - p.drawRect(0, 0, m_graticulePixmap->width(), m_graticulePixmap->height()); +void TraceWidget::setTraceName(uint traceNumber, TQString name) { + VERIFY_TRACE_ARRAY_SIZE - // Repaint the widget - repaint(); + m_traceArray[traceNumber]->traceName = name; + updateTraceText(); } -void TraceWidget::paintEvent(TQPaintEvent*) { - TQPainter p(this); +TQString TraceWidget::traceHorizontalUnits(uint traceNumber) { + VERIFY_TRACE_ARRAY_SIZE - if (m_graticulePixmap) { - // Draw the graticule pixmap to erase the widget - p.drawPixmap(0, 0, *m_graticulePixmap); + return m_traceArray[traceNumber]->horizontalUnits; +} - // Draw the traces - for (uint trace=0;trace<m_traceArray.count();trace++) { - m_traceArray[trace]->drawTrace(&p, m_graticulePixmap->width(), m_graticulePixmap->height()); +void TraceWidget::setTraceHorizontalUnits(uint traceNumber, TQString units) { + VERIFY_TRACE_ARRAY_SIZE + + m_traceArray[traceNumber]->horizontalUnits = units; + updateTraceText(); +} + +TQString TraceWidget::traceVerticalUnits(uint traceNumber) { + VERIFY_TRACE_ARRAY_SIZE + + return m_traceArray[traceNumber]->verticalUnits; +} + +void TraceWidget::setTraceVerticalUnits(uint traceNumber, TQString units) { + VERIFY_TRACE_ARRAY_SIZE + + m_traceArray[traceNumber]->verticalUnits = units; + updateTraceText(); +} + +void TraceWidget::resizeTraceArray(uint newsize) { + uint oldcount = m_traceArray.count(); + + if (newsize > oldcount) { + m_traceArray.resize(newsize); + for (uint i=oldcount;i<newsize;i++) { + m_traceArray[i] = new TraceData(this); + m_traceLabelLayout->addWidget(m_traceArray[i]->infoLabel, 0, i); } } else { - p.fillRect(x(), y(), width(), height(), backgroundColor()); + m_traceArray.resize(newsize); + for (uint i=newsize;i<oldcount;i++) { + m_traceLabelLayout->remove(m_traceArray[i]->infoLabel); + delete m_traceArray[i]; + } } -} - -void TraceWidget::resizeEvent(TQResizeEvent *) { - updateGraticule(); }
\ No newline at end of file |