summaryrefslogtreecommitdiffstats
path: root/clients/tde/src/widgets/tracewidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clients/tde/src/widgets/tracewidget.cpp')
-rw-r--r--clients/tde/src/widgets/tracewidget.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/clients/tde/src/widgets/tracewidget.cpp b/clients/tde/src/widgets/tracewidget.cpp
new file mode 100644
index 0000000..9b771bc
--- /dev/null
+++ b/clients/tde/src/widgets/tracewidget.cpp
@@ -0,0 +1,124 @@
+//Author: Timothy Pearson <kb9vqf@pearsoncomputing.net>, (C) 2012
+//Copyright: See COPYING file that comes with this distribution
+
+#include "tracewidget.h"
+
+#include <stdlib.h>
+
+#include <tqpixmap.h>
+#include <tqpainter.h>
+
+TraceWidget::TraceWidget(TQWidget* parent, const char* name) : TQWidget(parent, name),
+ m_samples(0),
+ m_horizDivs(0),
+ m_vertDivs(0),
+ m_leftEdge(0),
+ m_rightEdge(0),
+ m_topEdge(0),
+ m_bottomEdge(0),
+ m_sampleArray(0),
+ m_graticulePixmap(0) {
+ setBackgroundMode(NoBackground);
+
+ setPaletteBackgroundColor(TQt::black);
+ setPaletteForegroundColor(TQColor(0,128,0));
+}
+
+TraceWidget::~TraceWidget() {
+ //
+}
+
+void TraceWidget::setNumberOfSamples(unsigned int samples) {
+ m_samples = samples;
+ if (m_sampleArray) {
+ delete [] m_sampleArray;
+ }
+ m_sampleArray = new double[m_samples];
+
+ updateGraticule();
+}
+
+void TraceWidget::setNumberOfHorizontalDivisions(unsigned int divisions) {
+ m_horizDivs = divisions;
+ updateGraticule();
+}
+
+void TraceWidget::setNumberOfVerticalDivisions(unsigned int divisions) {
+ m_vertDivs = divisions;
+ updateGraticule();
+}
+
+void TraceWidget::setDisplayLimits(double x, double y, double w, double h) {
+ m_leftEdge = x;
+ m_rightEdge = w;
+ m_topEdge = y;
+ m_bottomEdge = h;
+}
+
+double* TraceWidget::samples() {
+ return m_sampleArray;
+}
+
+void TraceWidget::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_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());
+
+ // Repaint the widget
+ repaint();
+}
+
+void TraceWidget::paintEvent(TQPaintEvent*) {
+ TQPainter p(this);
+ p.setPen(foregroundColor().light(150));
+
+ if ((m_graticulePixmap) && (m_bottomEdge != m_topEdge)) {
+ // Draw the graticule pixmap to erase the widget
+ p.drawPixmap(0, 0, *m_graticulePixmap);
+
+ // Draw the points
+ unsigned int n;
+ int x,y,x2,y2;
+ for (n=0; n<m_samples-1; n++) {
+ x = abs(((n*1.0)/(m_samples-1))*(m_graticulePixmap->width()));
+ y = abs(((m_sampleArray[n]-m_topEdge)/(m_bottomEdge-m_topEdge))*(m_graticulePixmap->height()));
+ x2 = abs(((n+1*1.0)/(m_samples-1))*(m_graticulePixmap->width()));
+ y2 = abs(((m_sampleArray[n+1]-m_topEdge)/(m_bottomEdge-m_topEdge))*(m_graticulePixmap->height()));
+ p.drawLine(x, y, x2, y2);
+ }
+ }
+ else {
+ p.fillRect(x(), y(), width(), height(), backgroundColor());
+ }
+}
+
+void TraceWidget::resizeEvent(TQResizeEvent *) {
+ updateGraticule();
+} \ No newline at end of file