1 /***************************************************************************
2 parameterplotter.cpp - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "parameterplotter.h"
20 #include <KPlotObject>
21 #include <QMouseEvent>
25 ParameterPlotter::ParameterPlotter (QWidget *parent):KPlotWidget (parent){
26 setAntialiasing(true);
32 colors << Qt::white << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::gray << Qt::cyan;
36 void ParameterPlotter::setPointLists(const QList< QPair<QString, QMap< int , QVariant > > >& params,int startframe, int endframe){
38 QListIterator <QPair <QString, QMap< int , QVariant > > > nameit(params);
40 parameterNameList.clear();
43 while (nameit.hasNext() ){
44 KPlotObject *plot=new KPlotObject(colors[plotobjects.size()%colors.size()]);
45 plot->setShowLines(true);
46 QPair<QString, QMap< int , QVariant > > item=nameit.next();
47 parameterNameList << item.first;
49 QMapIterator <int,QVariant> pointit=item.second;
50 while (pointit.hasNext()){
52 plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1);
53 if (pointit.value().toInt() >maxy)
54 max_y=pointit.value().toInt();
56 plotobjects.append(plot);
60 setLimits(0,endframe,0,maxy+10);
61 addPlotObjects(plotobjects);
64 void ParameterPlotter::createParametersNew(){
65 QList< QPair<QString, QMap<int,QVariant> > > ret;
66 QList<KPlotObject*> plotobjs=plotObjects();
67 if (plotobjs.size() != parameterNameList.size() ){
68 kDebug() << "ERROR size not equal";
71 for (int i=0;i<parameterNameList.size() ;i++){
72 QList<KPlotPoint*> points=plotobjs[i]->points();
73 QMap<int,QVariant> vals;
74 foreach (KPlotPoint *o,points){
77 QPair<QString,QMap<int,QVariant> > pair("contrast",vals);
81 emit parameterChanged(ret);
86 void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
89 QList<KPlotPoint*> list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ;
91 foreach (KPlotObject *o, plotObjects() ){
92 QList<KPlotPoint*> points=o->points();
93 for(int p=0;p<points.size();p++){
94 if (points[p]==movepoint){
95 QPoint delta=event->pos()-oldmousepoint;
96 movepoint->setY(movepoint->y()-delta.y()*dataRect().height()/pixRect().height() );
97 if (p>0 && p<points.size()-1){
98 double newx=movepoint->x()+delta.x()*dataRect().width()/pixRect().width();
99 if ( newx>points[p-1]->x() && newx<points[p+1]->x() )
100 movepoint->setX(movepoint->x()+delta.x()*dataRect().width()/pixRect().width() );
102 replacePlotObject(i,o);
103 oldmousepoint=event->pos();
108 createParametersNew();
112 void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) {
113 QList<KPlotPoint*> list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ;
114 if (list.size() > 0){
116 oldmousepoint=event->pos();