]> git.sesse.net Git - kdenlive/blob - src/parameterplotter.cpp
effectstack can add self effects
[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         m_moveX=false;
35         m_moveY=true;
36         m_moveTimeline=true;
37         m_newPoints=false;
38 }
39
40 void ParameterPlotter::setPointLists(const QList< QPair<QString, QMap< int , QVariant > > >& params,int startframe, int endframe){
41         
42         QListIterator <QPair <QString, QMap< int , QVariant > > > nameit(params);
43         int max_y=0;
44         parameterNameList.clear();
45         
46         
47         while (nameit.hasNext() ){      
48                 KPlotObject *plot=new KPlotObject(colors[plotobjects.size()%colors.size()]);
49                 plot->setShowLines(true);
50                 QPair<QString, QMap< int , QVariant > > item=nameit.next();
51                 parameterNameList << item.first;
52
53                 QMapIterator <int,QVariant> pointit=item.second;
54                 while (pointit.hasNext()){
55                         pointit.next();
56                         plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1);
57                         if (pointit.value().toInt() >maxy)
58                                 max_y=pointit.value().toInt();
59                 }
60                 plotobjects.append(plot);
61         }
62         maxx=endframe;
63         maxy=max_y;
64         setLimits(0,endframe,0,maxy+10);
65         addPlotObjects(plotobjects);
66 }
67
68 void ParameterPlotter::createParametersNew(){
69         QList< QPair<QString, QMap<int,QVariant> > > ret;
70         QList<KPlotObject*> plotobjs=plotObjects();
71         if (plotobjs.size() != parameterNameList.size() ){
72                 kDebug() << "ERROR size not equal";
73         }
74         
75         for (int i=0;i<parameterNameList.size() ;i++){
76                 QList<KPlotPoint*> points=plotobjs[i]->points();
77                 QMap<int,QVariant> vals;
78                 foreach (KPlotPoint *o,points){
79                         vals[o->x()]=o->y();
80                 }
81                 QPair<QString,QMap<int,QVariant> > pair("contrast",vals);
82                 ret.append(pair);
83         }
84         
85         emit parameterChanged(ret);
86         
87 }
88
89
90 void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
91         
92         if (movepoint!=NULL){
93                 QList<KPlotPoint*> list=   pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() )  ) ;
94                 int i=0,j=-1;
95                 foreach (KPlotObject *o, plotObjects() ){
96                         QList<KPlotPoint*> points=o->points();
97                         for(int p=0;p<points.size();p++){
98                                 if (points[p]==movepoint){
99                                         QPoint delta=event->pos()-oldmousepoint;
100                                         if (m_moveY)
101                                         movepoint->setY(movepoint->y()-delta.y()*dataRect().height()/pixRect().height() );
102                                         if (p>0 && p<points.size()-1){
103                                                 double newx=movepoint->x()+delta.x()*dataRect().width()/pixRect().width();
104                                                 if ( newx>points[p-1]->x() && newx<points[p+1]->x() && m_moveX)
105                                                         movepoint->setX(movepoint->x()+delta.x()*dataRect().width()/pixRect().width() );
106                                         }
107                                         if (m_moveTimeline && (m_moveX|| m_moveY) )
108                                                 emit updateFrame(0);
109                                         replacePlotObject(i,o);
110                                         oldmousepoint=event->pos();
111                                 }
112                         }
113                         i++;
114                 }
115                 createParametersNew();
116         }
117 }
118
119 void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) {
120         QList<KPlotPoint*> list=   pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() )  ) ;
121         if (list.size() > 0){
122                 movepoint=list[0];
123                 oldmousepoint=event->pos();
124         }else{
125                 if (m_newPoints){
126                         //setup new points
127                 }
128                 movepoint=NULL;
129         }
130 }
131
132 void ParameterPlotter::setMoveX(bool b){
133         m_moveX=b;
134 }
135
136 void ParameterPlotter::setMoveY(bool b){
137         m_moveY=b;
138 }
139
140 void ParameterPlotter::setMoveTimeLine(bool b){
141         m_moveTimeline=b;
142 }
143
144 void ParameterPlotter::setNewPoints(bool b){
145         m_newPoints=b;
146 }
147
148 bool ParameterPlotter::isMoveX(){
149         return m_moveX;
150 }
151
152 bool ParameterPlotter::isMoveY(){
153         return m_moveY;
154 }
155
156 bool ParameterPlotter::isMoveTimeline(){
157         return m_moveTimeline;
158 }
159
160 bool ParameterPlotter::isNewPoints(){
161         return m_newPoints;
162 }