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