Add trace zero indicators

Save and restore offsets
master
Timothy Pearson 11 years ago
parent 1219c9b7a4
commit 7d92c9326f

@ -1344,6 +1344,7 @@ void ScopePart::saveWaveforms() {
ds << m_samplesInTrace[traceno];
ds << m_voltsDiv[traceno];
ds << m_secsDiv[traceno];
ds << m_base->traceZoomWidget->traceOffset(traceno-1);
ds << m_traceWidget->samples(traceno-1);
ds << m_traceWidget->positions(traceno-1);
}
@ -1375,14 +1376,18 @@ void ScopePart::recallWaveforms() {
ds >> m_samplesInTrace[traceno];
ds >> m_voltsDiv[traceno];
ds >> m_secsDiv[traceno];
double offset;
TQDoubleArray values;
TQDoubleArray positions;
ds >> offset;
ds >> values;
ds >> positions;
m_traceWidget->setSamples(traceno-1, values);
m_traceWidget->setPositions(traceno-1, positions);
m_traceWidget->setTraceOffset(traceno-1, offset);
m_base->traceZoomWidget->setSamples(traceno-1, values);
m_base->traceZoomWidget->setPositions(traceno-1, positions);
m_base->traceZoomWidget->setTraceOffset(traceno-1, offset);
}
for (int cursorno=0; cursorno<5; cursorno++) {
double cursorPos;

@ -15,6 +15,7 @@
#include <tqlayout.h>
#include <klocale.h>
#include <kinputdialog.h>
#define VERIFY_TRACE_ARRAY_SIZE if (traceNumber >= m_traceArray.count()) resizeTraceArray(traceNumber+1);
#define VERIFY_CURSOR_ARRAY_SIZE if (cursorNumber >= m_cursorArray.count()) resizeCursorArray(cursorNumber+1);
@ -141,27 +142,36 @@ TraceData::TraceData(TraceWidget* parent, TQWidget* labelParent) : TQObject(), p
singleDecrBtn = new TQToolButton(TQt::DownArrow, labelParent);
posResetBtn = new TQToolButton(labelParent);
posResetBtn->setText("0");
posSetBtn = new TQToolButton(labelParent);
posSetBtn->setText("M");
singleIncrBtn->setFixedSize(16,16);
singleDecrBtn->setFixedSize(16,16);
posResetBtn->setFixedSize(16,16);
posSetBtn->setFixedSize(16,16);
singleIncrBtn->setAutoRepeat(true);
singleDecrBtn->setAutoRepeat(true);
posResetBtn->setAutoRepeat(false);
posSetBtn->setAutoRepeat(false);
singleIncrBtn->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed));
singleDecrBtn->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed));
posResetBtn->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed));
posSetBtn->setSizePolicy(TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed));
singleIncrBtn->setPaletteBackgroundColor(labelParent->paletteBackgroundColor());
singleIncrBtn->setPaletteForegroundColor(color);
singleDecrBtn->setPaletteBackgroundColor(labelParent->paletteBackgroundColor());
singleDecrBtn->setPaletteForegroundColor(color);
posResetBtn->setPaletteBackgroundColor(labelParent->paletteBackgroundColor());
posResetBtn->setPaletteForegroundColor(color);
posSetBtn->setPaletteBackgroundColor(labelParent->paletteBackgroundColor());
posSetBtn->setPaletteForegroundColor(color);
singleIncrBtn->hide();
singleDecrBtn->hide();
posResetBtn->hide();
posSetBtn->hide();
connect(singleIncrBtn, SIGNAL(clicked()), this, SLOT(movePosOneTick()));
connect(singleDecrBtn, SIGNAL(clicked()), this, SLOT(moveNegOneTick()));
connect(posResetBtn, SIGNAL(clicked()), this, SLOT(resetVPosition()));
connect(posSetBtn, SIGNAL(clicked()), this, SLOT(setVPosition()));
}
else {
paramLabel = NULL;
@ -170,6 +180,7 @@ TraceData::TraceData(TraceWidget* parent, TQWidget* labelParent) : TQObject(), p
singleIncrBtn = NULL;
singleDecrBtn = NULL;
posResetBtn = NULL;
posSetBtn = NULL;
}
}
@ -178,6 +189,7 @@ TraceData::~TraceData() {
}
void TraceData::drawTrace(TQPainter* p, int graticule_width, int graticule_height) {
p->save();
p->setPen(color);
if ((bottomEdge != topEdge) && (enabled) && (positionArray.count() >= numberOfSamples) && (sampleArray.count() >= numberOfSamples) && (numberOfSamples > 0)) {
@ -225,7 +237,34 @@ void TraceData::drawTrace(TQPainter* p, int graticule_width, int graticule_heigh
p->drawLine(x, y, x2, y2);
}
// Draw the zero level indicator
int pixel_size = 20;
TQFont painterFont = p->font();
painterFont.setFamily("Monospace");
painterFont.setPixelSize(pixel_size);
p->setFont(painterFont);
int font_vertical_offset = pixel_size/5;
int font_height = p->fontMetrics().boundingRect("").height();
x = 0;
y = (((offset-topEdge)/(bottomEdge-topEdge))*(graticule_height))+(font_height/2)-(font_vertical_offset/2);
if (y > graticule_height) {
font_height = p->fontMetrics().boundingRect("").height();
y = graticule_height-font_vertical_offset;
p->drawText(x, y, trUtf8(""));
}
else if (y < 0) {
font_height = p->fontMetrics().boundingRect("").height();
y = font_height-font_vertical_offset;
p->drawText(x, y, trUtf8(""));
}
else {
p->drawText(x, y, trUtf8(""));
}
}
p->restore();
}
void TraceData::movePosOneTick() {
@ -259,6 +298,22 @@ void TraceData::resetVPosition() {
parentWidget->m_graticuleWidget->repaint(false);
}
void TraceData::setVPosition() {
bool ok;
double newoffset;
ok = false;
newoffset = KInputDialog::getDouble(i18n("Set Trace Offset"), i18n("New offset for %1 (%2):").arg(traceName).arg(verticalUnits), offset, (double)-2147483647, (double)2147483647, 0.1, 1, &ok, parentWidget);
if (ok) {
offset = newoffset;
emit(offsetChanged(offset));
parentWidget->updateTraceText();
parentWidget->updateCursorText();
parentWidget->m_graticuleWidget->repaint(false);
}
}
CursorData::CursorData(TraceWidget* parent, TQWidget* labelParent) : TQObject(), parentWidget(parent) {
color = TQColor(0, 255, 0);
highlightColor = TQColor(192, 255, 192);
@ -869,6 +924,7 @@ void TraceWidget::setBackgroundColor(const TQColor color) {
m_traceArray[trace]->singleIncrBtn->setPaletteBackgroundColor(color);
m_traceArray[trace]->singleDecrBtn->setPaletteBackgroundColor(color);
m_traceArray[trace]->posResetBtn->setPaletteBackgroundColor(color);
m_traceArray[trace]->posSetBtn->setPaletteBackgroundColor(color);
}
for (uint cursor=0;cursor<m_cursorArray.count();cursor++) {
m_cursorArray[cursor]->paramLabel->setPaletteBackgroundColor(color);
@ -1087,6 +1143,7 @@ void TraceWidget::setTraceEnabled(uint traceNumber, bool enabled, bool showText)
m_traceArray[traceNumber]->singleIncrBtn->show();
m_traceArray[traceNumber]->singleDecrBtn->show();
m_traceArray[traceNumber]->posResetBtn->show();
m_traceArray[traceNumber]->posSetBtn->show();
}
else {
m_traceArray[traceNumber]->paramLabel->hide();
@ -1095,6 +1152,7 @@ void TraceWidget::setTraceEnabled(uint traceNumber, bool enabled, bool showText)
m_traceArray[traceNumber]->singleIncrBtn->hide();
m_traceArray[traceNumber]->singleDecrBtn->hide();
m_traceArray[traceNumber]->posResetBtn->hide();
m_traceArray[traceNumber]->posSetBtn->hide();
}
}
else {
@ -1104,6 +1162,7 @@ void TraceWidget::setTraceEnabled(uint traceNumber, bool enabled, bool showText)
m_traceArray[traceNumber]->singleIncrBtn->hide();
m_traceArray[traceNumber]->singleDecrBtn->hide();
m_traceArray[traceNumber]->posResetBtn->hide();
m_traceArray[traceNumber]->posSetBtn->hide();
}
m_graticuleWidget->updateGraticule();
@ -1525,6 +1584,12 @@ TQString TraceWidget::prettyFormat(double value, double rangeDetectValue, TQStri
return result;
}
double TraceWidget::traceOffset(uint traceNumber) {
VERIFY_TRACE_ARRAY_SIZE
return m_traceArray[traceNumber]->offset;
}
void TraceWidget::setTraceOffset(uint traceNumber, double offset) {
VERIFY_TRACE_ARRAY_SIZE
@ -1582,7 +1647,8 @@ void TraceWidget::resizeTraceArray(uint newsize) {
m_traceLabelLayout->addMultiCellWidget(m_traceArray[i]->paramLabel, 0, 2, i*2, i*2);
m_traceLabelLayout->addWidget(m_traceArray[i]->singleIncrBtn, 0, (i*2)+1);
m_traceLabelLayout->addWidget(m_traceArray[i]->posResetBtn, 1, (i*2)+1);
m_traceLabelLayout->addWidget(m_traceArray[i]->singleDecrBtn, 2, (i*2)+1);
m_traceLabelLayout->addWidget(m_traceArray[i]->posSetBtn, 2, (i*2)+1);
m_traceLabelLayout->addWidget(m_traceArray[i]->singleDecrBtn, 3, (i*2)+1);
m_statusLabelLayout->insertWidget(i, m_traceArray[i]->graphStatusLabel, TQt::AlignTop);
m_statusLabelLayoutInner->insertWidget(i, m_traceArray[i]->graphStatusLabelInner);
}
@ -1595,6 +1661,7 @@ void TraceWidget::resizeTraceArray(uint newsize) {
m_traceLabelLayout->remove(m_traceArray[i]->paramLabel);
m_traceLabelLayout->remove(m_traceArray[i]->singleIncrBtn);
m_traceLabelLayout->remove(m_traceArray[i]->posResetBtn);
m_traceLabelLayout->remove(m_traceArray[i]->posSetBtn);
m_traceLabelLayout->remove(m_traceArray[i]->singleDecrBtn);
m_statusLabelLayout->remove(m_traceArray[i]->graphStatusLabel);
m_statusLabelLayoutInner->remove(m_traceArray[i]->graphStatusLabelInner);

@ -57,6 +57,7 @@ class TraceData : public TQObject
void movePosOneTick();
void moveNegOneTick();
void resetVPosition();
void setVPosition();
signals:
void offsetChanged(double offset);
@ -83,6 +84,7 @@ class TraceData : public TQObject
TQToolButton* singleIncrBtn;
TQToolButton* singleDecrBtn;
TQToolButton* posResetBtn;
TQToolButton* posSetBtn;
TraceWidget* parentWidget;
friend class TraceWidget;
@ -233,6 +235,8 @@ class TraceWidget : public TQWidget
unsigned int zoomCursorStartIndex();
void setZoomCursorStartIndex(unsigned int index);
double traceOffset(uint traceNumber);
static TQString prettyFormat(double value, double rangeDetectValue, TQString baseUnits, unsigned int precision=3);
public slots:

Loading…
Cancel
Save