]> git.sesse.net Git - kdenlive/blob - src/parameterplotter.cpp
multiparamter setup
[kdenlive] / src / parameterplotter.cpp
1 /***************************************************************************
2                           parameterplotter.cpp  -  description
3                              -------------------
4     begin                : Feb 15 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "parameterplotter.h"
19 #include <QVariant>
20 #include <KPlotObject>
21 #include <QMouseEvent>
22 #include <KDebug>
23 #include <KPlotPoint>
24
25 ParameterPlotter::ParameterPlotter (QWidget *parent):KPlotWidget (parent){
26         setAntialiasing(true);
27         setLeftPadding(20);
28         setRightPadding(10);
29         setTopPadding(10);
30         setBottomPadding(20);
31         movepoint=NULL;
32         colors << Qt::white << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::gray << Qt::cyan;
33         maxy=0;
34 }
35
36 void ParameterPlotter::setPointLists(const QList< QPair<QString, QMap< int , QVariant > > >& params,int startframe, int endframe){
37         
38         QListIterator <QPair <QString, QMap< int , QVariant > > > nameit(params);
39         int max_y=0;
40         parameterNameList.clear();
41         
42         
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;
48
49                 QMapIterator <int,QVariant> pointit=item.second;
50                 while (pointit.hasNext()){
51                         pointit.next();
52                         plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1);
53                         if (pointit.value().toInt() >maxy)
54                                 max_y=pointit.value().toInt();
55                 }
56                 plotobjects.append(plot);
57         }
58         maxx=endframe;
59         maxy=max_y;
60         setLimits(0,endframe,0,maxy+10);
61         addPlotObjects(plotobjects);
62 }
63
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";
69         }
70         
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){
75                         vals[o->x()]=o->y();
76                 }
77                 QPair<QString,QMap<int,QVariant> > pair("contrast",vals);
78                 ret.append(pair);
79         }
80         
81         emit parameterChanged(ret);
82         
83 }
84
85
86 void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
87         
88         if (movepoint!=NULL){
89                 QList<KPlotPoint*> list=   pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() )  ) ;
90                 int i=0,j=-1;
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() );
101                                         }
102                                         replacePlotObject(i,o);
103                                         oldmousepoint=event->pos();
104                                 }
105                         }
106                         i++;
107                 }
108                 createParametersNew();
109         }
110 }
111
112 void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) {
113         QList<KPlotPoint*> list=   pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() )  ) ;
114         if (list.size() > 0){
115                 movepoint=list[0];
116                 oldmousepoint=event->pos();
117         }else
118                 movepoint=NULL;
119 }