From aab627accb4b57166259f0128cc16b88b4c1dc25 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 29 Jul 2011 16:38:51 +0200 Subject: Ported threshold to canvastool. --- dgedit/Makefile.am | 2 + dgedit/canvas.cc | 52 +------------------- dgedit/canvas.h | 7 --- dgedit/canvastoolthreshold.cc | 108 ++++++++++++++++++++++++++++++++++++++++++ dgedit/canvastoolthreshold.h | 56 ++++++++++++++++++++++ 5 files changed, 168 insertions(+), 57 deletions(-) create mode 100644 dgedit/canvastoolthreshold.cc create mode 100644 dgedit/canvastoolthreshold.h (limited to 'dgedit') diff --git a/dgedit/Makefile.am b/dgedit/Makefile.am index a29a9b8..01187f1 100644 --- a/dgedit/Makefile.am +++ b/dgedit/Makefile.am @@ -11,6 +11,7 @@ dgedit_SOURCES = $(shell ../tools/MocList cc ) \ canvas.cc \ canvastool.cc \ canvastoolselections.cc \ + canvastoolthreshold.cc \ filelist.cc \ itemeditor.cc \ mainwindow.cc \ @@ -24,6 +25,7 @@ EXTRA_DIST = \ canvas.h \ canvastool.h \ canvastoolselections.h \ + canvastoolthreshold.h \ filelist.h \ itemeditor.h \ mainwindow.h \ diff --git a/dgedit/canvas.cc b/dgedit/canvas.cc index 70ac219..8249dd2 100644 --- a/dgedit/canvas.cc +++ b/dgedit/canvas.cc @@ -35,6 +35,7 @@ #include #include "canvastoolselections.h" +#include "canvastoolthreshold.h" #define DEFYSCALE 200 @@ -55,22 +56,18 @@ Canvas::Canvas(QWidget *parent) xoffset = 0.0; yoffset = 0.5; - threshold = 0.5; - threshold_is_moving = false; - colBg = QColor(180, 200, 180); colSec = QColor(160, 180, 160); colWavMax = QColor(100, 100, 100); colWavAvg = QColor(0, 0, 0); colMax = QColor(127, 127, 255); colHalf = QColor(180, 180, 255); - colThreshold = QColor(255, 127, 127); - colThresholdMoving = QColor(180, 0, 0); setCursor(Qt::ArrowCursor); wav = QImage(width(), height(), QImage::Format_RGB32); + tools.push_back(new CanvasToolThreshold(this)); tools.push_back(new CanvasToolSelections(this)); } @@ -146,24 +143,6 @@ float Canvas::unmapY(float y) void Canvas::mouseMoveEvent(QMouseEvent *event) { - if(threshold_is_moving) { - float val = unmapY(event->y()); - if(fabs(val) > 1.0) val = 1.0; - threshold = fabs(val); - update(); - return; - } - - if(event->button() != Qt::LeftButton) { - if(abs(event->y() - mapY(threshold)) < 2 || - abs(event->y() - mapY(-threshold)) < 2 ) { - setCursor(Qt::SplitVCursor); - return; - } else { - setCursor(Qt::ArrowCursor); - } - } - for(int i = 0; i < tools.size(); i++) { if(tools[i]->mouseMoveEvent(event)) return; } @@ -171,17 +150,6 @@ void Canvas::mouseMoveEvent(QMouseEvent *event) void Canvas::mousePressEvent(QMouseEvent *event) { - 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; - update(); - return; - } - } - for(int i = 0; i < tools.size(); i++) { if(tools[i]->mousePressEvent(event)) return; } @@ -189,15 +157,6 @@ void Canvas::mousePressEvent(QMouseEvent *event) void Canvas::mouseReleaseEvent(QMouseEvent *event) { - if(event->button() == Qt::LeftButton) { - if(threshold_is_moving) { - threshold_is_moving = false; - setCursor(Qt::ArrowCursor); - update(); - return; - } - } - for(int i = 0; i < tools.size(); i++) { if(tools[i]->mouseReleaseEvent(event)) return; } @@ -282,13 +241,6 @@ void Canvas::paintEvent(QPaintEvent *event) painter.drawImage(event->rect(),wav,event->rect()); - 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)); - for(int i = 0; i < tools.size(); i++) { tools[i]->paintEvent(event, painter); } diff --git a/dgedit/canvas.h b/dgedit/canvas.h index b0ff552..3c268ed 100644 --- a/dgedit/canvas.h +++ b/dgedit/canvas.h @@ -81,19 +81,12 @@ private: float xoffset; float yoffset; - float threshold; - bool threshold_is_moving; - QColor colBg; QColor colSec; QColor colMax; QColor colHalf; QColor colWavMax; QColor colWavAvg; - QColor colThreshold; - QColor colThresholdMoving; - - QVector tools; }; diff --git a/dgedit/canvastoolthreshold.cc b/dgedit/canvastoolthreshold.cc new file mode 100644 index 0000000..6fa1b2e --- /dev/null +++ b/dgedit/canvastoolthreshold.cc @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * canvastoolthreshold.cc + * + * Fri Jul 29 16:27:00 CEST 2011 + * Copyright 2011 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "canvastoolthreshold.h" + +#include + +#define mapX(x) canvas->mapX(x) +#define mapY(x) canvas->mapY(x) +#define unmapX(x) canvas->unmapX(x) +#define unmapY(x) canvas->unmapY(x) + +CanvasToolThreshold::CanvasToolThreshold(Canvas *c) +{ + canvas = c; + threshold = 0.5; + threshold_is_moving = false; + + colThreshold = QColor(255, 127, 127); + colThresholdMoving = QColor(180, 0, 0); +} + +bool CanvasToolThreshold::mouseMoveEvent(QMouseEvent *event) +{ + if(event->button() != Qt::LeftButton) { + if(abs(event->y() - mapY(threshold)) < 2 || + abs(event->y() - mapY(-threshold)) < 2 ) { + canvas->setCursor(Qt::SplitVCursor); + return true; + } else { + canvas->setCursor(Qt::ArrowCursor); + } + } + + if(threshold_is_moving) { + float val = unmapY(event->y()); + if(fabs(val) > 1.0) val = 1.0; + threshold = fabs(val); + canvas->update(); + return true; + } + + return false; +} + +bool CanvasToolThreshold::mousePressEvent(QMouseEvent *event) +{ + 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) +{ + if(event->button() == Qt::LeftButton) { + if(threshold_is_moving) { + threshold_is_moving = false; + canvas->setCursor(Qt::ArrowCursor); + canvas->update(); + return true; + } + } + + return false; +} + +void CanvasToolThreshold::paintEvent(QPaintEvent *event, QPainter &painter) +{ + 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)); +} + diff --git a/dgedit/canvastoolthreshold.h b/dgedit/canvastoolthreshold.h new file mode 100644 index 0000000..b19bf01 --- /dev/null +++ b/dgedit/canvastoolthreshold.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * canvastoolthreshold.h + * + * Fri Jul 29 16:27:00 CEST 2011 + * Copyright 2011 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __DRUMGIZMO_CANVASTOOLTHRESHOLD_H__ +#define __DRUMGIZMO_CANVASTOOLTHRESHOLD_H__ + +#include "canvastool.h" + +#include + +#include "canvas.h" + +class CanvasToolThreshold : public CanvasTool { +Q_OBJECT +public: + CanvasToolThreshold(Canvas *canvas); + + bool mouseMoveEvent(QMouseEvent *event); + bool mousePressEvent(QMouseEvent *event); + bool mouseReleaseEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event, QPainter &painter); + +private: + float threshold; + bool threshold_is_moving; + + Canvas *canvas; + + QColor colThreshold; + QColor colThresholdMoving; +}; + +#endif/*__DRUMGIZMO_CANVASTOOLTHRESHOLD_H__*/ -- cgit v1.2.3