]> git.sesse.net Git - kdenlive/blob - src/parameterplotter.cpp
parameter adjustable
[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         plot=new KPlotObject();
33         plot->setShowLines(true);
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 maxy=0;
40         while (nameit.hasNext() ){
41         
42                 QPair<QString, QMap< int , QVariant > > item=nameit.next();
43                 QString name(item.first);
44                 QMapIterator <int,QVariant> pointit=item.second;
45                 while (pointit.hasNext()){
46                         pointit.next();
47                         plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),"",1);
48                         if (pointit.value().toInt() >maxy)
49                                 maxy=pointit.value().toInt();
50                 }
51                 addPlotObject(plot);
52         }
53         
54         setLimits(0,endframe,0,maxy);
55         
56 }
57
58 QList< QPair<QString, QMap<int,QVariant> > > ParameterPlotter::getPointLists(){
59         return pointlists;
60 }
61
62 void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
63         
64         if (movepoint!=NULL){
65                 QList<KPlotPoint*> list=   pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() )  ) ;
66                 int i=0,j=-1;
67                 foreach (KPlotObject *o, plotObjects() ){
68                         foreach (KPlotPoint* p, o->points()){
69                                 if (p==movepoint){
70                                         QPoint delta=event->pos()-oldmousepoint;
71                                         movepoint->setY(movepoint->y()-delta.y()*dataRect().height()/pixRect().height() );
72                                         
73                                         movepoint->setX(movepoint->x()+delta.x()*dataRect().width()/pixRect().width() );
74                                         replacePlotObject(i,o);
75                                         oldmousepoint=event->pos();
76                                 }
77                         }
78                         i++;
79                 }
80         }
81 }
82
83 void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) {
84         QList<KPlotPoint*> list=   pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() )  ) ;
85         if (list.size() > 0){
86                 movepoint=list[0];
87                 oldmousepoint=event->pos();
88         }else
89                 movepoint=NULL;
90 }