Branch: master

63b68e2d 2014-03-04 21:45:57 Timothy Pearson
Add ability to set digital trace viewer cursors with the mouse
Fix oversized cursor control buttons
M clients/tde/src/part/logicanalyzer/part.cpp
M clients/tde/src/widgets/tracewidget.cpp
M clients/tde/src/widgets/tracewidget.h
diff --git a/clients/tde/src/part/logicanalyzer/part.cpp b/clients/tde/src/part/logicanalyzer/part.cpp
index fbece40..e3a9675 100644
--- a/clients/tde/src/part/logicanalyzer/part.cpp
+++ b/clients/tde/src/part/logicanalyzer/part.cpp
@@ -130,18 +130,24 @@
 	m_traceWidget->setLeftTraceInfoAreaFitSpacing(10);
 	m_traceWidget->showLeftCursorTraceInfoArea(true);
 	m_traceWidget->setMinimumPixelsPerHorizDiv(30);
-	m_traceWidget->setNumberOfCursors(2);
-	m_traceWidget->setTraceInfoCursor(1);
+	m_traceWidget->setNumberOfCursors(3);
+	m_traceWidget->setTraceInfoCursor(2);
+	m_traceWidget->setHoverCursor(2);
 	m_traceWidget->setCursorColor(0, TQColor(0, 255, 0));
 	m_traceWidget->setCursorColor(1, TQColor(0, 255, 0));
+	m_traceWidget->setCursorColor(2, TQColor(255, 255, 0));
 	m_traceWidget->setCursorHighlightColor(0, TQColor(192, 255, 192));
 	m_traceWidget->setCursorHighlightColor(1, TQColor(192, 255, 192));
+	m_traceWidget->setCursorHighlightColor(2, TQColor(255, 255, 192));
 	m_traceWidget->setCursorOrientation(0, TQt::Vertical);
 	m_traceWidget->setCursorOrientation(1, TQt::Vertical);
+	m_traceWidget->setCursorOrientation(2, TQt::Vertical);
 	m_traceWidget->setCursorEnabled(0, true);
 	m_traceWidget->setCursorEnabled(1, true);
+	m_traceWidget->setCursorEnabled(2, true);
 	m_traceWidget->setCursorName(0, "Cursor V1");
 	m_traceWidget->setCursorName(1, "Cursor V2");
+	m_traceWidget->setCursorName(2, "Cursor VH");
 	m_traceWidget->setCursorPosition(0, 25);
 	m_traceWidget->setCursorPosition(1, 75);
 	TraceNumberList activeTraces;
@@ -150,7 +156,9 @@
 	}
 	m_traceWidget->setCursorActiveTraceList(0, activeTraces);
 	m_traceWidget->setCursorActiveTraceList(1, activeTraces);
+	m_traceWidget->setCursorActiveTraceList(2, activeTraces);
 	m_traceWidget->setZoomBoxEnabled(false);
+	m_traceWidget->setHorizCursorDirectClickEnabled(true);
 
 	connect(m_base->acqStart, SIGNAL(clicked()), this, SLOT(startDAQ()));
 	connect(m_base->acqStop, SIGNAL(clicked()), this, SLOT(stopDAQ()));
diff --git a/clients/tde/src/widgets/tracewidget.cpp b/clients/tde/src/widgets/tracewidget.cpp
index 60bc7ce..c0527c4 100644
--- a/clients/tde/src/widgets/tracewidget.cpp
+++ b/clients/tde/src/widgets/tracewidget.cpp
@@ -7,10 +7,12 @@
 #include <cmath>
 #include <float.h>
 
+#include <tqstyle.h>
 #include <tqpixmap.h>
 #include <tqpainter.h>
 #include <tqpushbutton.h>
 #include <tqtoolbutton.h>
+#include <tqapplication.h>
 
 #include <tqlabel.h>
 #include <tqlayout.h>
@@ -94,6 +96,64 @@
 
 bool TQRectF::operator!=(const TQRectF &r1) {
 	return !operator==(r1);
+}
+
+TraceWidgetPushButton::TraceWidgetPushButton(TQWidget *parent, const char* name) : TQPushButton(parent, name) {
+	//
+}
+
+TraceWidgetPushButton::TraceWidgetPushButton(const TQString &text, TQWidget *parent, const char* name) : TQPushButton(text, parent, name) {
+	//
+}
+
+TraceWidgetPushButton::TraceWidgetPushButton(const TQIconSet& icon, const TQString &text, TQWidget *parent, const char* name) : TQPushButton(icon, text, parent, name) {
+	//
+}
+
+TraceWidgetPushButton::~TraceWidgetPushButton() {
+	//
+}
+
+// Largely taken from TQPushButton::sizeHint()
+TQSize TraceWidgetPushButton::sizeHint() const {
+	constPolish();
+	
+	int w = 0, h = 0;
+	
+	// calculate contents size...
+	if (iconSet() && !iconSet()->isNull()) {
+		int iw = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).width() + 4;
+		int ih = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).height();
+		w += iw;
+		h = TQMAX(h, ih);
+	}
+
+	if (isMenuButton()) {
+		w += style().pixelMetric(TQStyle::PM_MenuButtonIndicator, this);
+	}
+	
+	if (pixmap()) {
+		TQPixmap *pm = (TQPixmap *)pixmap();
+		w += pm->width();
+		h += pm->height();
+	}
+	else {
+		TQString s(text());
+		bool empty = s.isEmpty();
+		if (empty) {
+			s = TQString::fromLatin1("XXXX");
+		}
+		TQFontMetrics fm = fontMetrics();
+		TQSize sz = fm.size(ShowPrefix, s);
+		if (!empty || !w) {
+			w += sz.width();
+		}
+		if (!empty || !h) {
+			h = TQMAX(h, sz.height());
+		}
+	}
+	
+	return (TQSize(w, h).expandedTo(TQApplication::globalStrut()).expandedTo(TQSize(20, 20)));
 }
 
 class TraceLabelLayout : public TQLayout
@@ -639,7 +699,7 @@
 				// Draw fill areas
 				if ((sampleArray[n] != 0) && (sampleArray[n+1] != 0)) {
 					p->save();
-					p->fillRect(x+1, y+1, x2-x, baseline-y-1, TQBrush(color.dark(400)));
+					p->fillRect(x+1, y+1, x2-x, baseline-y, TQBrush(color.dark(400)));
 					p->restore();
 				}
 				else if ((sampleArray[n] != 0) && (sampleArray[n+1] == 0)) {
@@ -649,7 +709,7 @@
 					p->drawLine(x2-3, y+1, x2-1, y2-1);
 					p->drawLine(x2-2, y+1, x2, y2-1);
 					// Fill rectangle under trace
-					p->fillRect(x+2, y+1, (x2-1)-(x+1)-1, baseline-y-1, TQBrush(color.dark(400)));
+					p->fillRect(x+2, y+1, (x2-1)-(x+1)-1, baseline-y, TQBrush(color.dark(400)));
 					p->restore();
 				}
 				else if ((sampleArray[n] == 0) && (sampleArray[n+1] != 0)) {
@@ -761,10 +821,10 @@
 		font.setPointSize(font.pointSize()-1);
 		paramLabel->setFont(font);
 		paramLabel->hide();
-		singleIncrBtn = new TQPushButton(labelParent);
-		singleDecrBtn = new TQPushButton(labelParent);
-		multiIncrBtn = new TQPushButton(labelParent);
-		multiDecrBtn = new TQPushButton(labelParent);
+		singleIncrBtn = new TraceWidgetPushButton(labelParent);
+		singleDecrBtn = new TraceWidgetPushButton(labelParent);
+		multiIncrBtn = new TraceWidgetPushButton(labelParent);
+		multiDecrBtn = new TraceWidgetPushButton(labelParent);
 		font = singleIncrBtn->font();
 		font.setPointSize(font.pointSize()-1);
 		singleIncrBtn->setFont(font);
@@ -1100,7 +1160,7 @@
 		}
 		else {
 			m_prevCursorRect = m_base->zoomCursorBox();
-			if (m_base->m_zoomBoxEnabled) {
+			if (m_base->m_zoomBoxEnabled || m_base->m_horizCursorDirectClickEnabled) {
 				m_leftMouseDown = true;
 				m_prevDownPos = e->pos();
 			}
@@ -1149,16 +1209,25 @@
 				double y2 = e->y();
 				double pixelDiffX = fabs(x1-x2);
 				double pixelDiffY = fabs(y1-y2);
-				if ((x1 < virtualWidth()) && (y1 < height()) && (x2 < virtualWidth()) && (y2 < height()) && (x1 > 0) && (y1 > 0) && (x2 > 0) && (y2 > 0) && (pixelDiffX>0) && (pixelDiffY>0)) {
-					x1 = ((x1/virtualWidth())*100.0);
-					y1 = ((y1/height())*100.0);
-					x2 = ((x2/virtualWidth())*100.0);
-					y2 = ((y2/height())*100.0);
-					m_base->setZoomCursorBox(TQRectF(x1, y1, x2, y2));
+				if (m_base->m_zoomBoxEnabled) {
+					if ((x1 < virtualWidth()) && (y1 < height()) && (x2 < virtualWidth()) && (y2 < height()) && (x1 > 0) && (y1 > 0) && (x2 > 0) && (y2 > 0) && (pixelDiffX>0) && (pixelDiffY>0)) {
+						x1 = ((x1/virtualWidth())*100.0);
+						y1 = ((y1/height())*100.0);
+						x2 = ((x2/virtualWidth())*100.0);
+						y2 = ((y2/height())*100.0);
+						m_base->setZoomCursorBox(TQRectF(x1, y1, x2, y2));
+					}
+					else {
+						// Reset original zoom box
+						m_base->setZoomCursorBox(m_prevCursorRect);
+					}
 				}
-				else {
-					// Reset original zoom box
-					m_base->setZoomCursorBox(m_prevCursorRect);
+				else if (m_base->m_horizCursorDirectClickEnabled) {
+					// Allow the first two cursors to be set via click+drag
+					x1 = ((x1/virtualWidth())*100.0);
+					x2 = ((x2/virtualWidth())*100.0);
+					m_base->setCursorPosition(0, x1);
+					m_base->setCursorPosition(1, x2);
 				}
 			}
 		}
@@ -1201,6 +1270,10 @@
 	m_closestCursorDistance = -1;
 	if ((!m_leftMouseDown) && (!m_middleMouseDown) && (m_movingCursor < 0)) {
 		for (uint cursor=0;cursor<m_base->m_cursorArray.count();cursor++) {
+			if ((int)cursor == m_base->m_hoverCursor) {
+				continue;
+			}
+
 			double scaledYPos = (e->y()*100.0)/height();
 			double scaledXPos = ((e->x()+m_base->horizScrollOffset())*100.0)/virtualWidth();
 			unsigned int pixelDistance;
@@ -1282,11 +1355,20 @@
 		double x2 = e->x();
 		double y2 = e->y();
 		if ((x1 < virtualWidth()) && (y1 < height()) && (x2 < virtualWidth()) && (y2 < height()) && (x1 > 0) && (y1 > 0) && (x2 > 0) && (y2 > 0)) {
-			x1 = ((x1/virtualWidth())*100.0);
-			y1 = ((y1/height())*100.0);
-			x2 = ((x2/virtualWidth())*100.0);
-			y2 = ((y2/height())*100.0);
-			m_base->setZoomCursorBox(TQRectF(x1, y1, x2, y2));
+			if (m_base->m_zoomBoxEnabled) {
+				x1 = ((x1/virtualWidth())*100.0);
+				y1 = ((y1/height())*100.0);
+				x2 = ((x2/virtualWidth())*100.0);
+				y2 = ((y2/height())*100.0);
+				m_base->setZoomCursorBox(TQRectF(x1, y1, x2, y2));
+			}
+			else if (m_base->m_horizCursorDirectClickEnabled) {
+				// Allow the first two cursors to be set via click+drag
+				x1 = ((x1/virtualWidth())*100.0);
+				x2 = ((x2/virtualWidth())*100.0);
+				m_base->setCursorPosition(0, x1);
+				m_base->setCursorPosition(1, x2);
+			}
 		}
 	}
 	else if ((m_leftMouseDown) && (m_movingCursor >= 0)) {
@@ -1317,6 +1399,22 @@
 		m_base->setZoomCursorBox(TQRectF(m_prevCursorRect.x()+dx, m_prevCursorRect.y()+dy, m_prevCursorRect.width()+dx, m_prevCursorRect.height()+dy));
 	}
 
+	if (m_base->m_hoverCursor >= 0) {
+		if (m_base->m_cursorArray[m_base->m_hoverCursor]->enabled) {
+			double scaledXPos = ((e->x()+m_base->horizScrollOffset())*100.0)/virtualWidth();
+			if (scaledXPos < 0.0) {
+				scaledXPos = 0.0;
+			}
+			if (scaledXPos > 100.0) {
+				scaledXPos = 100.0;
+			}
 ** Diff limit reached (max: 250 lines) **