From 83cee4e365992ae1eb83900a1e02b5dbc80e9ecb Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 11 Sep 2015 13:46:34 -0500 Subject: [PATCH] Move seven segment display widget to common widget directory --- clients/tde/src/part/fpgaview/Makefile.am | 2 +- clients/tde/src/part/fpgaview/layout.ui | 8 +- clients/tde/src/part/fpgaview/part.cpp | 427 -------------------- clients/tde/src/part/fpgaview/part.h | 43 +- clients/tde/src/widgets/Makefile.am | 5 +- clients/tde/src/widgets/floatspinbox.cpp | 4 +- clients/tde/src/widgets/sevensegment.cpp | 456 ++++++++++++++++++++++ clients/tde/src/widgets/sevensegment.h | 68 ++++ clients/tde/src/widgets/tracewidget.cpp | 2 + clients/tde/src/widgets/tracewidget.h | 9 +- 10 files changed, 546 insertions(+), 478 deletions(-) create mode 100644 clients/tde/src/widgets/sevensegment.cpp create mode 100644 clients/tde/src/widgets/sevensegment.h diff --git a/clients/tde/src/part/fpgaview/Makefile.am b/clients/tde/src/part/fpgaview/Makefile.am index a3f4d3c..f1efd6a 100644 --- a/clients/tde/src/part/fpgaview/Makefile.am +++ b/clients/tde/src/part/fpgaview/Makefile.am @@ -6,6 +6,6 @@ KDE_ICON = libremotelab_fpgaviewer # Part kde_module_LTLIBRARIES = libremotelab_fpgaviewer.la -libremotelab_fpgaviewer_la_LIBADD = ../../widgets/libtracewidget.la ../../widgets/libfloatspinbox.la $(LIB_KFILE) $(LIB_TDEPARTS) $(LIB_TDEUI) $(LIB_QT) -ltdekrbsocket -ltqtrla +libremotelab_fpgaviewer_la_LIBADD = ../../widgets/libtracewidget.la ../../widgets/libfloatspinbox.la ../../widgets/libsevensegment.la $(LIB_KFILE) $(LIB_TDEPARTS) $(LIB_TDEUI) $(LIB_QT) -ltdekrbsocket -ltqtrla libremotelab_fpgaviewer_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) $(LIB_TDECORE) $(LIB_TDEUI) -ltdeio -ltdefx -ltdemdi libremotelab_fpgaviewer_la_SOURCES = part.cpp layout.ui diff --git a/clients/tde/src/part/fpgaview/layout.ui b/clients/tde/src/part/fpgaview/layout.ui index 95328ab..058f33b 100644 --- a/clients/tde/src/part/fpgaview/layout.ui +++ b/clients/tde/src/part/fpgaview/layout.ui @@ -452,7 +452,7 @@ 2 - + LEDOutputDisplayDigit0 @@ -463,7 +463,7 @@ - + LEDOutputDisplayDigit1 @@ -474,7 +474,7 @@ - + LEDOutputDisplayDigit2 @@ -485,7 +485,7 @@ - + LEDOutputDisplayDigit3 diff --git a/clients/tde/src/part/fpgaview/part.cpp b/clients/tde/src/part/fpgaview/part.cpp index 2e2a615..fd7aec9 100644 --- a/clients/tde/src/part/fpgaview/part.cpp +++ b/clients/tde/src/part/fpgaview/part.cpp @@ -128,433 +128,6 @@ void FPGAPushButton::leaveEvent(TQEvent *e) { } } -FPGA7Segment::FPGA7Segment( TQWidget *parent, const char *name ) - : TQFrame( parent, name ) -{ - init(); -} - -FPGA7Segment::~FPGA7Segment() { - free(m_prevSegments); - free(m_currentSegments); -} - -void FPGA7Segment::init() { - setFrameStyle(TQFrame::Box | TQFrame::Raised); - prevSegments = 0; - val = 0; - smallPoint = TRUE; - setSegmentStyle(Flat); - m_prevSegments = (char*)malloc(sizeof(char)*9); - m_currentSegments = (char*)malloc(sizeof(char)*9); - m_prevSegments[0] = 99; - m_currentSegments[0] = 99; - setSizePolicy(TQSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Minimum)); -} - -void FPGA7Segment::setLitSegments(unsigned char segs) { - // This produces an array of up to 10 chars, with each char being the number of a lit segment, and the list being terminated with the number 99 - // The bit input in segs is active high - // The bit sequence, MSB to LSB, is dp a b c d e f g - // Segment letters are taken from ug130.pdf - - if (prevSegments != segs) { - int i = 0; - if (segs & 0x80) { m_currentSegments[i] = 7; i++; } - if (segs & 0x40) { m_currentSegments[i] = 0; i++; } - if (segs & 0x20) { m_currentSegments[i] = 2; i++; } - if (segs & 0x10) { m_currentSegments[i] = 5; i++; } - if (segs & 0x08) { m_currentSegments[i] = 6; i++; } - if (segs & 0x04) { m_currentSegments[i] = 4; i++; } - if (segs & 0x02) { m_currentSegments[i] = 1; i++; } - if (segs & 0x01) { m_currentSegments[i] = 3; i++; } - - m_currentSegments[i] = 99; - - update(); - } - - prevSegments = segs; -} - -void FPGA7Segment::drawContents( TQPainter *p ) -{ - // Draw all segments - TQPoint pos; - int digitSpace = smallPoint ? 2 : 1; - int xSegLen = width()*5/(1*(5 + digitSpace) + digitSpace); - int ySegLen = height()*5/12; - int segLen = ySegLen > xSegLen ? xSegLen : ySegLen; - int xAdvance = segLen*( 5 + 1 )/5; - int xOffset = ( width() - xAdvance + segLen/5 )/2; - int yOffset = ( height() - segLen*2 )/2; - - pos = TQPoint(xOffset, yOffset); - drawDigit(pos, *p, segLen, m_currentSegments); -} - -TQSize FPGA7Segment::sizeHint() const { - return TQSize(10 + 9 * (1 + (smallPoint ? 0 : 1)), 23); -} - -void FPGA7Segment::setSegmentStyle( SegmentStyle s ) { - fill = (s == Flat || s == Filled); - shadow = (s == Outline || s == Filled); - update(); -} - -FPGA7Segment::SegmentStyle FPGA7Segment::segmentStyle() const { - Q_ASSERT(fill || shadow); - if (!fill && shadow) { - return Outline; - } - if (fill && shadow) { - return Filled; - } - return Flat; -} - -static void addPoint( TQPointArray &a, const TQPoint &p ) { - uint n = a.size(); - a.resize(n + 1); - a.setPoint(n, p); -} - -void FPGA7Segment::drawDigit(const TQPoint &pos, TQPainter &p, int segLen, const char *newSegs) { - char updates[20][2]; // Can hold 2 times number of segments, only - // first 10 used if segment table is correct - int nErases; - int nUpdates; - const char *segs; - int i,j; - - const char erase = 0; - const char draw = 1; -// const char leaveAlone = 2; - - segs = m_prevSegments; - for ( nErases=0; segs[nErases] != 99; nErases++ ) { - updates[nErases][0] = erase; // Get segments to erase to - updates[nErases][1] = segs[nErases]; // remove old char - } - nUpdates = nErases; - segs = newSegs; - for(i = 0 ; segs[i] != 99 ; i++) { - for ( j=0; j #include -#include #include #include @@ -41,6 +40,8 @@ #include +#include + class TDEAboutData; using KParts::StatusBarExtension; class TraceWidget; @@ -90,46 +91,6 @@ class FPGAPushButton : public KLed bool mouseDown; }; -class FPGA7SegmentPrivate; - -class TQ_EXPORT FPGA7Segment : public TQFrame -{ - Q_OBJECT - TQ_ENUMS(SegmentStyle) - TQ_PROPERTY(SegmentStyle segmentStyle READ segmentStyle WRITE setSegmentStyle) - - public: - FPGA7Segment(TQWidget* parent=0, const char* name=0); - ~FPGA7Segment(); - - enum SegmentStyle { Outline, Filled, Flat }; - - SegmentStyle segmentStyle() const; - virtual void setSegmentStyle(SegmentStyle); - - void setLitSegments(unsigned char); - - TQSize sizeHint() const; - - protected: - void drawContents(TQPainter *); - - private: - void init(); - void drawSegment(const TQPoint &, char, TQPainter &, int, bool = FALSE); - void drawDigit(const TQPoint &, TQPainter &, int, const char *); - - char* m_prevSegments; - char* m_currentSegments; - - unsigned int prevSegments; - double val; - uint smallPoint : 1; - uint fill : 1; - uint shadow : 1; - FPGA7SegmentPrivate *d; -}; - class ImageViewerWindow : public KMdiChildView { Q_OBJECT diff --git a/clients/tde/src/widgets/Makefile.am b/clients/tde/src/widgets/Makefile.am index fac5e76..47f84e0 100644 --- a/clients/tde/src/widgets/Makefile.am +++ b/clients/tde/src/widgets/Makefile.am @@ -1,6 +1,7 @@ INCLUDES = $(all_includes) $(KDE_INCLUDES)/tde METASOURCES = AUTO -noinst_LTLIBRARIES = libtracewidget.la libfloatspinbox.la +noinst_LTLIBRARIES = libtracewidget.la libfloatspinbox.la libsevensegment.la libtracewidget_la_SOURCES = tracewidget.cpp libtracewidget_la_LDFLAGS = $(all_libraries) -ltqtrla -libfloatspinbox_la_SOURCES = floatspinbox.cpp \ No newline at end of file +libfloatspinbox_la_SOURCES = floatspinbox.cpp +libsevensegment_la_SOURCES = sevensegment.cpp \ No newline at end of file diff --git a/clients/tde/src/widgets/floatspinbox.cpp b/clients/tde/src/widgets/floatspinbox.cpp index caf0d31..9592968 100644 --- a/clients/tde/src/widgets/floatspinbox.cpp +++ b/clients/tde/src/widgets/floatspinbox.cpp @@ -108,4 +108,6 @@ void FloatSpinBox::acceptValueChanged(int ival) { FloatSpinBox::~FloatSpinBox() { // -} \ No newline at end of file +} + +#include "floatspinbox.moc" \ No newline at end of file diff --git a/clients/tde/src/widgets/sevensegment.cpp b/clients/tde/src/widgets/sevensegment.cpp new file mode 100644 index 0000000..f97c428 --- /dev/null +++ b/clients/tde/src/widgets/sevensegment.cpp @@ -0,0 +1,456 @@ +/* + * Remote Laboratory Seven Segment Display Widget + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2012 - 2015 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include + +#include + +#include "sevensegment.h" + +Display7Segment::Display7Segment( TQWidget *parent, const char *name ) + : TQFrame( parent, name ) +{ + init(); +} + +Display7Segment::~Display7Segment() { + free(m_prevSegments); + free(m_currentSegments); +} + +void Display7Segment::init() { + setFrameStyle(TQFrame::Box | TQFrame::Raised); + prevSegments = 0; + val = 0; + smallPoint = TRUE; + setSegmentStyle(Flat); + m_prevSegments = (char*)malloc(sizeof(char)*9); + m_currentSegments = (char*)malloc(sizeof(char)*9); + m_prevSegments[0] = 99; + m_currentSegments[0] = 99; + setSizePolicy(TQSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Minimum)); +} + +void Display7Segment::setLitSegments(unsigned char segs) { + // This produces an array of up to 10 chars, with each char being the number of a lit segment, and the list being terminated with the number 99 + // The bit input in segs is active high + // The bit sequence, MSB to LSB, is dp a b c d e f g + // Segment letters are taken from ug130.pdf + + if (prevSegments != segs) { + int i = 0; + if (segs & 0x80) { m_currentSegments[i] = 7; i++; } + if (segs & 0x40) { m_currentSegments[i] = 0; i++; } + if (segs & 0x20) { m_currentSegments[i] = 2; i++; } + if (segs & 0x10) { m_currentSegments[i] = 5; i++; } + if (segs & 0x08) { m_currentSegments[i] = 6; i++; } + if (segs & 0x04) { m_currentSegments[i] = 4; i++; } + if (segs & 0x02) { m_currentSegments[i] = 1; i++; } + if (segs & 0x01) { m_currentSegments[i] = 3; i++; } + + m_currentSegments[i] = 99; + + update(); + } + + prevSegments = segs; +} + +void Display7Segment::drawContents( TQPainter *p ) +{ + // Draw all segments + TQPoint pos; + int digitSpace = smallPoint ? 2 : 1; + int xSegLen = width()*5/(1*(5 + digitSpace) + digitSpace); + int ySegLen = height()*5/12; + int segLen = ySegLen > xSegLen ? xSegLen : ySegLen; + int xAdvance = segLen*( 5 + 1 )/5; + int xOffset = ( width() - xAdvance + segLen/5 )/2; + int yOffset = ( height() - segLen*2 )/2; + + pos = TQPoint(xOffset, yOffset); + drawDigit(pos, *p, segLen, m_currentSegments); +} + +TQSize Display7Segment::sizeHint() const { + return TQSize(10 + 9 * (1 + (smallPoint ? 0 : 1)), 23); +} + +void Display7Segment::setSegmentStyle( SegmentStyle s ) { + fill = (s == Flat || s == Filled); + shadow = (s == Outline || s == Filled); + update(); +} + +Display7Segment::SegmentStyle Display7Segment::segmentStyle() const { + Q_ASSERT(fill || shadow); + if (!fill && shadow) { + return Outline; + } + if (fill && shadow) { + return Filled; + } + return Flat; +} + +static void addPoint( TQPointArray &a, const TQPoint &p ) { + uint n = a.size(); + a.resize(n + 1); + a.setPoint(n, p); +} + +void Display7Segment::drawDigit(const TQPoint &pos, TQPainter &p, int segLen, const char *newSegs) { + char updates[20][2]; // Can hold 2 times number of segments, only + // first 10 used if segment table is correct + int nErases; + int nUpdates; + const char *segs; + int i,j; + + const char erase = 0; + const char draw = 1; +// const char leaveAlone = 2; + + segs = m_prevSegments; + for ( nErases=0; segs[nErases] != 99; nErases++ ) { + updates[nErases][0] = erase; // Get segments to erase to + updates[nErases][1] = segs[nErases]; // remove old char + } + nUpdates = nErases; + segs = newSegs; + for(i = 0 ; segs[i] != 99 ; i++) { + for ( j=0; j + +class Display7SegmentPrivate; + +class TQ_EXPORT Display7Segment : public TQFrame +{ + Q_OBJECT + TQ_ENUMS(SegmentStyle) + TQ_PROPERTY(SegmentStyle segmentStyle READ segmentStyle WRITE setSegmentStyle) + + public: + Display7Segment(TQWidget* parent=0, const char* name=0); + ~Display7Segment(); + + enum SegmentStyle { Outline, Filled, Flat }; + + SegmentStyle segmentStyle() const; + virtual void setSegmentStyle(SegmentStyle); + + void setLitSegments(unsigned char); + + TQSize sizeHint() const; + + protected: + void drawContents(TQPainter *); + + private: + void init(); + void drawSegment(const TQPoint &, char, TQPainter &, int, bool = FALSE); + void drawDigit(const TQPoint &, TQPainter &, int, const char *); + + char* m_prevSegments; + char* m_currentSegments; + + unsigned int prevSegments; + double val; + uint smallPoint : 1; + uint fill : 1; + uint shadow : 1; + Display7SegmentPrivate *d; +}; + +#endif \ No newline at end of file diff --git a/clients/tde/src/widgets/tracewidget.cpp b/clients/tde/src/widgets/tracewidget.cpp index 5aec418..08cfe42 100644 --- a/clients/tde/src/widgets/tracewidget.cpp +++ b/clients/tde/src/widgets/tracewidget.cpp @@ -2652,3 +2652,5 @@ void TraceScrollWidget::setVScrollBarMode(TQScrollView::ScrollBarMode sm) { TraceWidget* TraceScrollWidget::traceWidget() { return m_traceScrollView->m_traceWidget; } + +#include "tracewidget.moc" \ No newline at end of file diff --git a/clients/tde/src/widgets/tracewidget.h b/clients/tde/src/widgets/tracewidget.h index 389c7c0..e4cf255 100644 --- a/clients/tde/src/widgets/tracewidget.h +++ b/clients/tde/src/widgets/tracewidget.h @@ -15,11 +15,14 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * (c) 2012-2014 Timothy Pearson + * (c) 2012-2015 Timothy Pearson * Raptor Engineering * http://www.raptorengineeringinc.com */ +#ifndef REMOTELAB_TRACEWIDGET_H +#define REMOTELAB_TRACEWIDGET_H + #include #include #include @@ -426,4 +429,6 @@ class TraceScrollWidget : public TQVBox TraceScrollView* m_traceScrollView; TQScrollBar* m_horizScrollBar; TQScrollView::ScrollBarMode m_horizScrollBarMode; -}; \ No newline at end of file +}; + +#endif \ No newline at end of file