From 57f4d38841c40cad3c206abdd16eebaed753aa1c Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 18 Mar 2018 18:18:57 +0100 Subject: Update all fiels to adhere to style-guide --- src/canvastoolthreshold.cc | 167 ++++++++++++++++++++++++++------------------- 1 file changed, 97 insertions(+), 70 deletions(-) (limited to 'src/canvastoolthreshold.cc') 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)); } - -- cgit v1.2.3