Branch: master

83cee4e3 2015-09-11 13:46:34 Timothy Pearson
Move seven segment display widget to common widget directory
A clients/tde/src/widgets/sevensegment.cpp
A clients/tde/src/widgets/sevensegment.h
M clients/tde/src/part/fpgaview/Makefile.am
M clients/tde/src/part/fpgaview/layout.ui
M clients/tde/src/part/fpgaview/part.cpp
M clients/tde/src/part/fpgaview/part.h
M clients/tde/src/widgets/Makefile.am
M clients/tde/src/widgets/floatspinbox.cpp
M clients/tde/src/widgets/tracewidget.cpp
M clients/tde/src/widgets/tracewidget.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 @@
 
 # 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 @@
 														<property name="margin">
 															<number>2</number>
 														</property>
-														<widget class="FPGA7Segment" row="0" column="0">
+														<widget class="Display7Segment" row="0" column="0">
 															<property name="name">
 																<cstring>LEDOutputDisplayDigit0</cstring>
 															</property>
@@ -463,7 +463,7 @@
 																</size>
 															</property>
 														</widget>
-														<widget class="FPGA7Segment" row="0" column="1">
+														<widget class="Display7Segment" row="0" column="1">
 															<property name="name">
 																<cstring>LEDOutputDisplayDigit1</cstring>
 															</property>
@@ -474,7 +474,7 @@
 																</size>
 															</property>
 														</widget>
-														<widget class="FPGA7Segment" row="0" column="2">
+														<widget class="Display7Segment" row="0" column="2">
 															<property name="name">
 																<cstring>LEDOutputDisplayDigit2</cstring>
 															</property>
@@ -485,7 +485,7 @@
 																</size>
 															</property>
 														</widget>
-														<widget class="FPGA7Segment" row="0" column="3">
+														<widget class="Display7Segment" row="0" column="3">
 															<property name="name">
 																<cstring>LEDOutputDisplayDigit3</cstring>
 															</property>
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 @@
 	}
 }
 
-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<nErases; j++ ) {
-			if ( segs[i] == updates[j][1] ) {	// Same segment ?
-// FIXME
-// Always redraw segments for now, as dragging windows in front of the LED display currently erases the occluded portion(s) of the display!
-#if 0
-				updates[j][0] = leaveAlone;	// yes, already on screen
-				break;
-#endif
-			}
-		}
-		if ( j == nErases ) {				// If not already on screen
-			updates[nUpdates][0] = draw;
-			updates[nUpdates][1] = segs[i];
-			nUpdates++;
-		}
-	}
-	for ( i=0; i<nUpdates; i++ ) {
-		if ( updates[i][0] == draw ) {
-			drawSegment( pos, updates[i][1], p, segLen );
-		}
-		if (updates[i][0] == erase) {
-			drawSegment( pos, updates[i][1], p, segLen, TRUE );
-		}
-	}
-
-	memcpy(m_prevSegments, newSegs, sizeof(char)*9);
-}
-
-void FPGA7Segment::drawSegment(const TQPoint &pos, char segmentNo, TQPainter &p, int segLen, bool erase) {
-	TQPoint pt = pos;
-	int width = segLen/5;
-
-	const TQColorGroup & g = colorGroup();
-	TQColor lightColor,darkColor,fgColor;
-	if (erase) {
-		lightColor = backgroundColor();
-		darkColor  = lightColor;
-		fgColor    = lightColor;
-	}
-	else {
-		lightColor = g.light();
-		darkColor  = g.dark();
-		fgColor    = g.foreground();
-	}
-
-#define LINETO(X,Y) addPoint( a, TQPoint(pt.x() + (X),pt.y() + (Y)))
-#define LIGHT
-#define DARK
-
-	if ( fill ) {
-		TQPointArray a(0);
-	
-		//The following is an exact copy of the switch below.
-		//don't make any changes here
-		switch ( segmentNo ) {
-			case 0 :
-				p.moveTo(pt);
-				LIGHT;
-				LINETO(segLen - 1,0);
-				DARK;
-				LINETO(segLen - width - 1,width);
-				LINETO(width,width);
-				LINETO(0,0);
-				break;
-			case 1 :
-				pt += TQPoint(0 , 1);
-				p.moveTo(pt);
-				LIGHT;
-				LINETO(width,width);
-				DARK;
-				LINETO(width,segLen - width/2 - 2);
-				LINETO(0,segLen - 2);
-				LIGHT;
-				LINETO(0,0);
-				break;
-			case 2 :
-				pt += TQPoint(segLen - 1 , 1);
-				p.moveTo(pt);
 ** Diff limit reached (max: 250 lines) **