summaryrefslogtreecommitdiffstats
path: root/clients
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-13 17:55:12 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-13 17:55:12 -0500
commit11d6b6dded9a6820438ef5b018d76e7ae88349b2 (patch)
treedb9a137deb0b6da8151f12cd9f3382947f31933b /clients
parent34a27d54d6f62d4ea6753667ed78bf5ad4b9db62 (diff)
downloadulab-11d6b6dded9a6820438ef5b018d76e7ae88349b2.tar.gz
ulab-11d6b6dded9a6820438ef5b018d76e7ae88349b2.zip
Add zoom box pan ability
Diffstat (limited to 'clients')
-rw-r--r--clients/tde/src/widgets/tracewidget.cpp199
-rw-r--r--clients/tde/src/widgets/tracewidget.h6
2 files changed, 199 insertions, 6 deletions
diff --git a/clients/tde/src/widgets/tracewidget.cpp b/clients/tde/src/widgets/tracewidget.cpp
index 5cec9eb..9902a57 100644
--- a/clients/tde/src/widgets/tracewidget.cpp
+++ b/clients/tde/src/widgets/tracewidget.cpp
@@ -370,7 +370,9 @@ void CursorData::moveNegMultiTicks() {
GraticuleWidget::GraticuleWidget(TraceWidget* parent, const char* name) : TQWidget(parent, name),
m_base(parent),
- m_graticulePixmap(0) {
+ m_graticulePixmap(0),
+ leftMouseDown(false),
+ middleMouseDown(false) {
setBackgroundMode(NoBackground);
setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding));
@@ -453,12 +455,64 @@ void GraticuleWidget::resizeEvent(TQResizeEvent *) {
updateGraticule();
}
-void GraticuleWidget::mousePressEvent(TQMouseEvent *) {
- //
+void GraticuleWidget::mousePressEvent(TQMouseEvent *e) {
+ if ((e->button() == TQt::LeftButton) && (!leftMouseDown) && (!middleMouseDown)) {
+ m_prevCursorRect = m_base->zoomCursorBox();
+ if (m_base->m_zoomBoxEnabled) {
+ leftMouseDown = true;
+ m_prevDownPos = e->pos();
+ }
+ }
+ else if ((e->button() == TQt::MidButton) && (!leftMouseDown) && (!middleMouseDown)) {
+ m_prevCursorRect = m_base->zoomCursorBox();
+ if (m_base->m_zoomBoxEnabled) {
+ middleMouseDown = true;
+ m_prevDownPos = e->pos();
+ }
+ }
}
-void GraticuleWidget::mouseReleaseEvent(TQMouseEvent *) {
- //
+void GraticuleWidget::mouseReleaseEvent(TQMouseEvent *e) {
+ if (leftMouseDown) {
+ if (e->button() == TQt::LeftButton) {
+ leftMouseDown = false;
+
+ double x1 = m_prevDownPos.x();
+ double y1 = m_prevDownPos.y();
+ double x2 = e->x();
+ double y2 = e->y();
+ if ((x1 < width()) && (y1 < height()) && (x2 < width()) && (y2 < height()) && (x1 > 0) && (y1 > 0) && (x2 > 0) && (y2 > 0)) {
+ x1 = ((x1/width())*100.0);
+ y1 = ((y1/height())*100.0);
+ x2 = ((x2/width())*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 if (middleMouseDown) {
+ if (e->button() == TQt::MidButton) {
+ middleMouseDown = false;
+
+ double x1 = m_prevDownPos.x();
+ double y1 = m_prevDownPos.y();
+ double x2 = e->x();
+ double y2 = e->y();
+ if ((x1 < width()) && (y1 < height()) && (x2 < width()) && (y2 < height()) && (x1 > 0) && (y1 > 0) && (x2 > 0) && (y2 > 0)) {
+ TQPoint diff = e->pos() - m_prevDownPos;
+ diff = TQPoint(diff.x()*(100.0/width()), diff.y()*(100.0/height()));
+ m_base->setZoomCursorBox(TQRectF(m_prevCursorRect.x()+diff.x(), m_prevCursorRect.y()+diff.y(), m_prevCursorRect.width()+diff.x(), m_prevCursorRect.height()+diff.y()));
+ }
+ else {
+ // Reset original zoom box
+ m_base->setZoomCursorBox(m_prevCursorRect);
+ }
+ }
+ }
}
void GraticuleWidget::mouseDoubleClickEvent(TQMouseEvent *) {
@@ -486,6 +540,25 @@ void GraticuleWidget::mouseMoveEvent(TQMouseEvent *e) {
m_base->m_traceArray[trace]->graphStatusLabelInner->setText(m_base->m_traceArray[trace]->graphStatusLabel->text());
}
}
+
+ if (leftMouseDown) {
+ double x1 = m_prevDownPos.x();
+ double y1 = m_prevDownPos.y();
+ double x2 = e->x();
+ double y2 = e->y();
+ if ((x1 < width()) && (y1 < height()) && (x2 < width()) && (y2 < height()) && (x1 > 0) && (y1 > 0) && (x2 > 0) && (y2 > 0)) {
+ x1 = ((x1/width())*100.0);
+ y1 = ((y1/height())*100.0);
+ x2 = ((x2/width())*100.0);
+ y2 = ((y2/height())*100.0);
+ m_base->setZoomCursorBox(TQRectF(x1, y1, x2, y2));
+ }
+ }
+ else if (middleMouseDown) {
+ TQPoint diff = e->pos() - m_prevDownPos;
+ diff = TQPoint(diff.x()*(100.0/width()), diff.y()*(100.0/height()));
+ m_base->setZoomCursorBox(TQRectF(m_prevCursorRect.x()+diff.x(), m_prevCursorRect.y()+diff.y(), m_prevCursorRect.width()+diff.x(), m_prevCursorRect.height()+diff.y()));
+ }
}
void GraticuleWidget::enterEvent(TQEvent *) {
@@ -602,7 +675,7 @@ void TraceWidget::updateTraceText() {
offsetText = TQString(" +%1").arg(prettyFormat(fabs(offset), vertical_range, m_traceArray[trace]->verticalUnits));
}
}
- m_traceArray[trace]->paramLabel->setText(TQString("<qt><nobr>%1%2<br>%3/div%4/div<br>%5,%6<br>%7,%8</qt>").arg(m_traceArray[trace]->traceName).arg(offsetText).arg(prettyFormat(horizontal_units_per_division, horizontal_range, m_traceArray[trace]->horizontalUnits)).arg(prettyFormat(vertical_units_per_division, vertical_range, m_traceArray[trace]->verticalUnits)).arg(prettyFormat(m_traceArray[trace]->leftEdge, horizontal_range, m_traceArray[trace]->horizontalUnits)).arg(prettyFormat(m_traceArray[trace]->topEdge, vertical_range, m_traceArray[trace]->verticalUnits)).arg(prettyFormat(m_traceArray[trace]->rightEdge, horizontal_range, m_traceArray[trace]->horizontalUnits)).arg(prettyFormat(m_traceArray[trace]->bottomEdge, vertical_range, m_traceArray[trace]->verticalUnits)));
+ m_traceArray[trace]->paramLabel->setText(TQString("<qt><nobr>%1%2<br>%3/div,%4/div<br>%5,%6<br>%7,%8</qt>").arg(m_traceArray[trace]->traceName).arg(offsetText).arg(prettyFormat(horizontal_units_per_division, horizontal_range, m_traceArray[trace]->horizontalUnits)).arg(prettyFormat(vertical_units_per_division, vertical_range, m_traceArray[trace]->verticalUnits)).arg(prettyFormat(m_traceArray[trace]->leftEdge, horizontal_range, m_traceArray[trace]->horizontalUnits)).arg(prettyFormat(m_traceArray[trace]->topEdge, vertical_range, m_traceArray[trace]->verticalUnits)).arg(prettyFormat(m_traceArray[trace]->rightEdge, horizontal_range, m_traceArray[trace]->horizontalUnits)).arg(prettyFormat(m_traceArray[trace]->bottomEdge, vertical_range, m_traceArray[trace]->verticalUnits)));
}
}
@@ -765,6 +838,8 @@ void TraceWidget::setCursorPosition(uint cursorNumber, double position) {
m_cursorArray[cursorNumber]->position = position;
updateCursorText();
+ m_graticuleWidget->updateGraticule();
+ m_graticuleWidget->repaint(true);
}
bool TraceWidget::cursorEnabled(uint cursorNumber) {
@@ -885,6 +960,118 @@ TQRectF TraceWidget::zoomBox() {
}
}
+TQRectF TraceWidget::zoomCursorBox() {
+ uint i;
+
+ if ((m_cursorArray.count() < 4) || (!m_zoomBoxEnabled)) {
+ return TQRectF();
+ }
+ else {
+ // Find the first two horizontal and first two vertical cursors
+ // If two of each cannot be found, return TQRectF()
+ double horiz[2];
+ double vert[2];
+ int j = 0;
+ int k = 0;
+ for (i=0;i<m_cursorArray.count(); i++) {
+ if (m_cursorArray[i]->orientation == TQt::Horizontal) {
+ if (j<2) {
+ vert[j] = m_cursorArray[i]->position;
+ j++;
+ }
+ }
+ else {
+ if (k<2) {
+ horiz[k] = m_cursorArray[i]->position;
+ k++;
+ }
+ }
+ if ((j>1) && (k>1)) {
+ break;
+ }
+ }
+ if ((j>1) && (k>1)) {
+ return TQRectF(horiz[0], vert[0], horiz[1], vert[1]);
+ }
+ else {
+ return TQRectF();
+ }
+ }
+}
+
+void TraceWidget::setZoomCursorBox(const TQRectF rect) {
+ uint i;
+
+ TQRectF boundedRect = rect;
+
+ if (boundedRect.x() < 0.0) {
+ boundedRect.setX(0.0);
+ }
+ if (boundedRect.x() > 100.0) {
+ boundedRect.setX(100.0);
+ }
+ if (boundedRect.y() < 0.0) {
+ boundedRect.setY(0.0);
+ }
+ if (boundedRect.y() > 100.0) {
+ boundedRect.setY(100.0);
+ }
+ if (boundedRect.width() < 0.0) {
+ boundedRect.setWidth(0.0);
+ }
+ if (boundedRect.width() > 100.0) {
+ boundedRect.setWidth(100.0);
+ }
+ if (boundedRect.height() < 0.0) {
+ boundedRect.setHeight(0.0);
+ }
+ if (boundedRect.height() > 100.0) {
+ boundedRect.setHeight(100.0);
+ }
+
+ if ((m_cursorArray.count() < 4) || (!m_zoomBoxEnabled)) {
+ return;
+ }
+ else {
+ // Find the first two horizontal and first two vertical cursors
+ // If two of each cannot be found, return TQRectF()
+ CursorData* horiz[2];
+ CursorData* vert[2];
+ int j = 0;
+ int k = 0;
+ for (i=0;i<m_cursorArray.count(); i++) {
+ if (m_cursorArray[i]->orientation == TQt::Horizontal) {
+ if (j<2) {
+ vert[j] = m_cursorArray[i];
+ j++;
+ }
+ }
+ else {
+ if (k<2) {
+ horiz[k] = m_cursorArray[i];
+ k++;
+ }
+ }
+ if ((j>1) && (k>1)) {
+ break;
+ }
+ }
+ if ((j>1) && (k>1)) {
+ // Set cursors...
+ vert[0]->position = boundedRect.y();
+ vert[1]->position = boundedRect.height();
+ horiz[0]->position = boundedRect.x();
+ horiz[1]->position = boundedRect.width();
+
+ updateCursorText();
+ m_graticuleWidget->updateGraticule();
+ m_graticuleWidget->repaint(true);
+
+ return;
+ }
+ }
+}
+
void TraceWidget::setZoomBoxEnabled(bool enabled) {
m_zoomBoxEnabled = enabled;
m_graticuleWidget->updateGraticule();
diff --git a/clients/tde/src/widgets/tracewidget.h b/clients/tde/src/widgets/tracewidget.h
index 71f883c..c8789ee 100644
--- a/clients/tde/src/widgets/tracewidget.h
+++ b/clients/tde/src/widgets/tracewidget.h
@@ -144,6 +144,10 @@ class GraticuleWidget : public TQWidget
private:
TraceWidget* m_base;
TQPixmap* m_graticulePixmap;
+ bool leftMouseDown;
+ bool middleMouseDown;
+ TQPoint m_prevDownPos;
+ TQRectF m_prevCursorRect;
friend class TraceWidget;
friend class TraceData;
@@ -192,6 +196,8 @@ class TraceWidget : public TQWidget
TQRectF zoomBox();
void setZoomBoxEnabled(bool enabled);
+ TQRectF zoomCursorBox();
+ void setZoomCursorBox(const TQRectF rect);
static TQString prettyFormat(double value, double rangeDetectValue, TQString baseUnits, unsigned int precision=3);