changeset 211:fbd4905ada5e

add plotter
author benoitrigolleau
date Fri, 01 Feb 2008 15:46:16 +0000
parents bf1d6386eb4b
children 40689f0e8a02
files widgets/Plotter.cpp widgets/Plotter.h widgets/svwidgets.vcproj
diffstat 3 files changed, 273 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/Plotter.cpp	Fri Feb 01 15:46:16 2008 +0000
@@ -0,0 +1,179 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*	Sound Access	
+		EASAIER client application.	
+		Silogic 2007. Benoit Rigolleau. 
+	
+	This program 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.  See the file    
+	COPYING included with this distribution for more information.
+*/
+
+#include  "Plotter.h"  
+#include <QtGui>
+
+Plotter::Plotter(QWidget *parent):
+m_signalWidth(400),
+m_signalHeight(180),
+m_margin(5),
+m_curveMaskActive(false)
+{
+	m_curveMask = new int[m_signalWidth];
+	for(int i = 0 ; i < m_signalWidth ; i++){
+		m_curveMask[i] = 0;
+	}
+
+
+	m_curve.push_back(QPoint(399,179));
+	m_curve.push_back(QPoint(300,20));
+	m_curve.push_back(QPoint(60,150));
+	m_curve.push_back(QPoint(10,30));
+	m_curve.push_back(QPoint(0,0));
+
+
+	refreshPixmap();
+
+}
+
+void Plotter::setCurveData(const QVector<QPoint> &data){
+	m_curve = data;
+	refreshPixmap();
+}
+
+void Plotter::clearCurve(){
+	m_curve.clear();
+	refreshPixmap();
+}
+
+void Plotter::paintEvent(QPaintEvent *event){
+	QStylePainter painter(this);
+    painter.drawPixmap(0, 0, m_pixmap);
+}
+
+void Plotter::resizeEvent(QResizeEvent *event){
+	refreshPixmap();
+}
+
+void Plotter::mousePressEvent(QMouseEvent *event){
+	QRect rect(m_margin, m_margin,
+               m_signalWidth + m_margin, m_signalHeight + m_margin);
+
+    if (event->button() == Qt::LeftButton) {
+        if (rect.contains(event->pos())) {
+            m_curveMaskActive = true;
+			int x = event->pos().x()- m_margin;
+			int y = event->pos().y()- m_margin;
+			m_curveMask[x] = y;
+			m_lastPoint.setX(x);
+			m_lastPoint.setY(y);
+            setCursor(Qt::CrossCursor);
+			refreshPixmap();
+        }
+    }
+}
+
+void Plotter::mouseMoveEvent(QMouseEvent *event){
+	QRect rect(m_margin, m_margin,
+               m_signalWidth + m_margin , m_signalHeight + m_margin);
+
+	if(m_curveMaskActive && rect.contains(event->pos())){
+		int x = event->pos().x() - m_margin;
+		int y = event->pos().y() - m_margin;
+		if(y>m_signalHeight-1)
+			y= m_signalHeight-1;
+		int xlast = m_lastPoint.x();
+		int ylast = m_lastPoint.y();
+
+		//regul mask curve
+		int minx, maxx, miny, maxy;
+		if(x>xlast){
+			minx = xlast;
+			maxx = x;
+		}else{
+			minx = x;
+			maxx = xlast;
+		}
+		if(y>ylast){
+			miny = ylast;
+			maxy = y;
+		}else{
+			miny = y;
+			maxy = ylast;
+		}
+
+		if((maxx - minx)>1){
+			double incr = (double)(maxy - miny)/(double)(maxx - minx);
+			if(x>xlast){
+				for (int i = xlast + 1 ; i < x ; i++){
+					if(ylast > y){
+						m_curveMask[i] = ylast - (i-xlast)*incr;
+					}else{
+						m_curveMask[i] = ylast + (i-xlast)*incr;
+					}
+				}
+			}else{
+				for (int i = xlast - 1 ; i > x ; i--){
+					if(ylast > y){
+						m_curveMask[i] = ylast + (i-xlast)*incr;
+					}else{
+						m_curveMask[i] = ylast - (i-xlast)*incr;
+					}
+				}
+			}
+		}
+		m_curveMask[x] = y;
+		m_lastPoint.setX(x);
+		m_lastPoint.setY(y);
+		refreshPixmap();
+	}
+}
+
+void Plotter::mouseReleaseEvent(QMouseEvent *event){
+	 if ((event->button() == Qt::LeftButton) && m_curveMaskActive) {
+        m_curveMaskActive = false;
+        unsetCursor();
+	 }
+}
+
+void Plotter::drawGrid(QPainter *painter){
+	QPixmap pm(":icons/grid.png");
+	painter->drawPixmap(0,0,pm);
+}
+
+void Plotter::drawCurve(QPainter *painter){
+	QPolygonF polyline(m_signalWidth);
+	for(int i = 0 ; i < m_curve.count() ; i++){
+		polyline[i] = QPoint(m_curve.at(i).x()+m_margin, m_curve.at(i).y()+m_margin);
+	}
+	painter->setPen(Qt::green);
+    painter->drawPolyline(polyline);
+}
+
+void Plotter::drawMaskCurve(QPainter *painter){
+
+	QPolygonF polyline(m_signalWidth);
+
+	for(int i = 0 ; i < m_signalWidth ; i++){
+		polyline[i] = QPoint(i+m_margin, m_curveMask[i]+m_margin);
+	}
+	painter->setPen(Qt::red);
+    painter->drawPolyline(polyline);
+}
+
+void Plotter::refreshPixmap(){
+    m_pixmap = QPixmap(size());
+    m_pixmap.fill(this, 0, 0);
+
+    QPainter painter(&m_pixmap);
+    painter.initFrom(this);
+    drawGrid(&painter);
+    drawCurve(&painter);
+	drawMaskCurve(&painter);
+    update();
+}
+
+void Plotter::setMargin(int margin){
+	m_margin = margin;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/Plotter.h	Fri Feb 01 15:46:16 2008 +0000
@@ -0,0 +1,60 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*	Sound Access	
+		EASAIER client application.	
+		Silogic 2007. Benoit Rigolleau. 
+	
+	This program 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.  See the file    
+	COPYING included with this distribution for more information.
+*/
+
+
+#ifndef PLOTTER_H
+#define PLOTTER_H
+
+#include <QMap>
+#include <QPixmap>
+#include <QVector>
+#include <QWidget>
+
+
+class Plotter : public QWidget
+{
+    Q_OBJECT
+
+public:
+    Plotter(QWidget *parent = 0);
+
+    void setCurveData(const QVector<QPoint> &data);
+    void clearCurve();
+	void setSignalSize(int m_signalWidth, int m_signalHeight);
+	void setMargin(int margin);
+
+protected:
+    void paintEvent(QPaintEvent *event);
+    void resizeEvent(QResizeEvent *event);
+    void mousePressEvent(QMouseEvent *event);
+    void mouseMoveEvent(QMouseEvent *event);
+    void mouseReleaseEvent(QMouseEvent *event);
+
+private:
+	void refreshPixmap();
+    void drawGrid(QPainter *painter);
+    void drawCurve(QPainter *painter);
+	void drawMaskCurve(QPainter *painter);
+	QVector<QPoint> m_curve;
+	int *m_curveMask;
+    QPixmap m_pixmap;
+	int m_signalHeight;
+	int m_signalWidth;
+	int m_margin;
+	bool m_curveMaskActive;
+	QPoint m_lastPoint;
+};
+
+
+#endif
+
--- a/widgets/svwidgets.vcproj	Thu Jan 31 13:51:37 2008 +0000
+++ b/widgets/svwidgets.vcproj	Fri Feb 01 15:46:16 2008 +0000
@@ -352,6 +352,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Plotter.cpp"
+				>
+			</File>
+			<File
 				RelativePath="PluginParameterBox.cpp"
 				>
 			</File>
@@ -1377,6 +1381,32 @@
 					</FileConfiguration>
 				</File>
 				<File
+					RelativePath=".\Plotter.h"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+							Description="MOC $(InputFileName)"
+							CommandLine="$(QTDIR)\bin\moc.exe -DNDEBUG -DBUILD_RELEASE -DUSE_VC -D_WINDOWS -DUNICODE -DQT_LARGEFILE_SUPPORT -DWIN32 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DHAVE_BZ2 -DHAVE_PORTAUDIO -DHAVE_PORTAUDIO_V18 -DHAVE_OGGZ -DHAVE_FISHSOUND -DHAVE_FFTW3F -DHAVE_VAMP -DHAVE_VAMP_HOSTSDK -DHAVE_SNDFILE -DHAVE_SAMPLERATE -DQT_THREAD_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB  -I &quot;$(QTDIR)\include\QtCore&quot; -I &quot;$(QTDIR)\include\QtCore&quot; -I &quot;$(QTDIR)\include\QtGui&quot; -I &quot;$(QTDIR)\include\QtGui&quot; -I &quot;$(QTDIR)\include\QtXml&quot; -I &quot;$(QTDIR)\include\QtXml&quot; -I &quot;$(QTDIR)\include&quot; -I &quot;.&quot; -I &quot;..&quot; -I &quot;$(QTDIR)\include\ActiveQt&quot; -I &quot;tmp_moc&quot; -I &quot;.&quot; -I&quot;$(QTDIR)\mkspecs\win32-msvc2005&quot; $(InputPath) -o tmp_moc\moc_$(InputName).cpp"
+							AdditionalDependencies="$(QTDIR)\bin\moc.exe"
+							Outputs="tmp_moc\moc_$(InputName).cpp"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+							Description="MOC $(InputFileName)"
+							CommandLine="$(QTDIR)\bin\moc.exe -DBUILD_DEBUG -DUSE_VC -D_WINDOWS -DUNICODE -DQT_LARGEFILE_SUPPORT -DWIN32 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DHAVE_BZ2 -DHAVE_PORTAUDIO -DHAVE_PORTAUDIO_V18 -DHAVE_OGGZ -DHAVE_FISHSOUND -DHAVE_FFTW3F -DHAVE_VAMP -DHAVE_VAMP_HOSTSDK -DHAVE_SNDFILE -DHAVE_SAMPLERATE -DQT_THREAD_SUPPORT -DQT_DLL -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB  -I &quot;$(QTDIR)\include\QtCore&quot; -I &quot;$(QTDIR)\include\QtCore&quot; -I &quot;$(QTDIR)\include\QtGui&quot; -I &quot;$(QTDIR)\include\QtGui&quot; -I &quot;$(QTDIR)\include\QtXml&quot; -I &quot;$(QTDIR)\include\QtXml&quot; -I &quot;$(QTDIR)\include&quot; -I &quot;.&quot; -I &quot;..&quot; -I &quot;$(QTDIR)\include\ActiveQt&quot; -I &quot;tmp_moc&quot; -I &quot;.&quot; -I&quot;$(QTDIR)\mkspecs\win32-msvc2005&quot; $(InputPath) -o tmp_moc\moc_$(InputName).cpp"
+							AdditionalDependencies="$(QTDIR)\bin\moc.exe"
+							Outputs="tmp_moc\moc_$(InputName).cpp"
+						/>
+					</FileConfiguration>
+				</File>
+				<File
 					RelativePath="PluginParameterBox.h"
 					>
 					<FileConfiguration
@@ -2321,6 +2351,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\tmp_moc\moc_Plotter.cpp"
+				>
+			</File>
+			<File
 				RelativePath="tmp_moc\moc_PluginParameterBox.cpp"
 				>
 			</File>