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;
39 void ParameterPlotter::setPointLists(const QList< QPair<QString, QMap< int , QVariant > > >& params,int startframe, int endframe){
41 QListIterator <QPair <QString, QMap< int , QVariant > > > nameit(params);
43 parameterNameList.clear();
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;
52 QMapIterator <int,QVariant> pointit=item.second;
53 while (pointit.hasNext()){
55 plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1);
56 if (pointit.value().toInt() >maxy)
57 max_y=pointit.value().toInt();
59 plotobjects.append(plot);
63 setLimits(0,endframe,0,maxy+10);
64 addPlotObjects(plotobjects);
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";
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){
80 QPair<QString,QMap<int,QVariant> > pair("contrast",vals);
84 emit parameterChanged(ret);
89 void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
92 QList<KPlotPoint*> list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ;
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;
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() );
106 replacePlotObject(i,o);
107 oldmousepoint=event->pos();
112 createParametersNew();
116 void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) {
117 QList<KPlotPoint*> list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ;
118 if (list.size() > 0){
120 oldmousepoint=event->pos();
125 void ParameterPlotter::setMoveX(bool b){
129 void ParameterPlotter::setMoveY(bool b){
133 void ParameterPlotter::setMoveTimeLine(bool b){
137 bool ParameterPlotter::isMoveX(){
141 bool ParameterPlotter::isMoveY(){
145 bool ParameterPlotter::isMoveTimeline(){
146 return m_moveTimeline;