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;
40 void ParameterPlotter::setPointLists(const QList< QPair<QString, QMap< int , QVariant > > >& params,int startframe, int endframe){
42 QListIterator <QPair <QString, QMap< int , QVariant > > > nameit(params);
44 parameterNameList.clear();
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;
53 QMapIterator <int,QVariant> pointit=item.second;
54 while (pointit.hasNext()){
56 plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1);
57 if (pointit.value().toInt() >maxy)
58 max_y=pointit.value().toInt();
60 plotobjects.append(plot);
64 setLimits(0,endframe,0,maxy+10);
65 addPlotObjects(plotobjects);
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";
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){
81 QPair<QString,QMap<int,QVariant> > pair("contrast",vals);
85 emit parameterChanged(ret);
90 void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
93 QList<KPlotPoint*> list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ;
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;
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() );
107 replacePlotObject(i,o);
108 oldmousepoint=event->pos();
113 createParametersNew();
117 void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) {
118 QList<KPlotPoint*> list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ;
119 if (list.size() > 0){
121 oldmousepoint=event->pos();
126 void ParameterPlotter::setMoveX(bool b){
130 void ParameterPlotter::setMoveY(bool b){
134 void ParameterPlotter::setMoveTimeLine(bool b){
138 void ParameterPlotter::setNewPoints(bool b){
142 bool ParameterPlotter::isMoveX(){
146 bool ParameterPlotter::isMoveY(){
150 bool ParameterPlotter::isMoveTimeline(){
151 return m_moveTimeline;
154 bool ParameterPlotter::isNewPoints(){