summaryrefslogtreecommitdiff
path: root/src/canvastoolthreshold.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/canvastoolthreshold.cc')
-rw-r--r--src/canvastoolthreshold.cc167
1 files changed, 97 insertions, 70 deletions
diff --git a/src/canvastoolthreshold.cc b/src/canvastoolthreshold.cc
index a321ff2..bafee70 100644
--- a/src/canvastoolthreshold.cc
+++ b/src/canvastoolthreshold.cc
@@ -33,88 +33,115 @@
#define unmapX(x) canvas->unmapX(x)
#define unmapY(x) canvas->unmapY(x)
-CanvasToolThreshold::CanvasToolThreshold(Canvas *c)
+CanvasToolThreshold::CanvasToolThreshold(Canvas* c)
{
- canvas = c;
- threshold = 0.5;
- threshold_is_moving = false;
+ canvas = c;
+ threshold = 0.5;
+ threshold_is_moving = false;
- colThreshold = QColor(255, 127, 127);
- colThresholdMoving = QColor(180, 0, 0);
+ colThreshold = QColor(255, 127, 127);
+ colThresholdMoving = QColor(180, 0, 0);
}
-bool CanvasToolThreshold::mouseMoveEvent(QMouseEvent *event)
+bool CanvasToolThreshold::mouseMoveEvent(QMouseEvent* event)
{
- if(!isActive()) return false;
-
- if(event->button() != Qt::LeftButton) {
- if(abs(event->y() - mapY(threshold)) < 2 ||
- abs(event->y() - mapY(-threshold)) < 2 ) {
- canvas->setCursor(Qt::SplitVCursor);
- return true;
- }
- }
-
- if(threshold_is_moving) {
- float val = unmapY(event->y());
- if(fabs(val) > 1.0) val = 1.0;
- threshold = fabs(val);
- canvas->update();
-
- emit thresholdChanging(threshold);
-
- return true;
- }
-
- return false;
+ if(!isActive())
+ {
+ return false;
+ }
+
+ if(event->button() != Qt::LeftButton)
+ {
+ if(abs(event->y() - mapY(threshold)) < 2 ||
+ abs(event->y() - mapY(-threshold)) < 2 )
+ {
+
+ canvas->setCursor(Qt::SplitVCursor);
+ return true;
+ }
+ }
+
+ if(threshold_is_moving)
+ {
+ float val = unmapY(event->y());
+ if(fabs(val) > 1.0)
+ {
+ val = 1.0;
+ }
+ threshold = fabs(val);
+ canvas->update();
+
+ emit thresholdChanging(threshold);
+
+ return true;
+ }
+
+ return false;
}
-bool CanvasToolThreshold::mousePressEvent(QMouseEvent *event)
+bool CanvasToolThreshold::mousePressEvent(QMouseEvent* event)
{
- if(!isActive()) return false;
-
- if(event->button() == Qt::LeftButton) {
-
- // Check if threshold is being dragged.
- if(abs(event->y() - mapY(threshold)) < 2 ||
- abs(event->y() - mapY(-threshold)) < 2 ) {
- threshold_is_moving = true;
- canvas->update();
- return true;
- }
- }
-
- return false;
+ if(!isActive())
+ {
+ return false;
+ }
+
+ if(event->button() == Qt::LeftButton)
+ {
+ // Check if threshold is being dragged.
+ if(abs(event->y() - mapY(threshold)) < 2 ||
+ abs(event->y() - mapY(-threshold)) < 2)
+ {
+ threshold_is_moving = true;
+ canvas->update();
+ return true;
+ }
+ }
+
+ return false;
}
-bool CanvasToolThreshold::mouseReleaseEvent(QMouseEvent *event)
+bool CanvasToolThreshold::mouseReleaseEvent(QMouseEvent* event)
{
- if(!isActive()) return false;
-
- if(event->button() == Qt::LeftButton) {
- if(threshold_is_moving) {
- threshold_is_moving = false;
- canvas->setCursor(Qt::ArrowCursor);
- canvas->update();
-
- emit thresholdChanged(threshold);
-
- return true;
- }
- }
-
- return false;
+ if(!isActive())
+ {
+ return false;
+ }
+
+ if(event->button() == Qt::LeftButton)
+ {
+ if(threshold_is_moving)
+ {
+ threshold_is_moving = false;
+ canvas->setCursor(Qt::ArrowCursor);
+ canvas->update();
+
+ emit thresholdChanged(threshold);
+
+ return true;
+ }
+ }
+
+ return false;
}
-void CanvasToolThreshold::paintEvent(QPaintEvent *event, QPainter &painter)
+void CanvasToolThreshold::paintEvent(QPaintEvent* event, QPainter& painter)
{
- if(!isActive()) return;
-
- if(threshold_is_moving) painter.setPen(colThresholdMoving);
- else painter.setPen(colThreshold);
- painter.drawLine(event->rect().x(), mapY(threshold),
- event->rect().x() + event->rect().width(), mapY(threshold));
- painter.drawLine(event->rect().x(), mapY(-threshold),
- event->rect().x() + event->rect().width(), mapY(-threshold));
+ if(!isActive())
+ {
+ return;
+ }
+
+ if(threshold_is_moving)
+ {
+ painter.setPen(colThresholdMoving);
+ }
+ else
+ {
+ painter.setPen(colThreshold);
+ }
+ painter.drawLine(event->rect().x(), mapY(threshold),
+ event->rect().x() + event->rect().width(), mapY(threshold));
+ painter.drawLine(event->rect().x(), mapY(-threshold),
+ event->rect().x() + event->rect().width(), mapY(-threshold));
}
-