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;
41 void ParameterPlotter::setPointLists(const QList< QPair<QString, QMap< int , QVariant > > >& params,int startframe, int endframe){
43 QListIterator <QPair <QString, QMap< int , QVariant > > > nameit(params);
45 parameterNameList.clear();
48 while (nameit.hasNext() ){
49 KPlotObject *plot=new KPlotObject(colors[plotobjects.size()%colors.size()]);
50 plot->setShowLines(true);
51 QPair<QString, QMap< int , QVariant > > item=nameit.next();
52 parameterNameList << item.first;
54 QMapIterator <int,QVariant> pointit=item.second;
55 while (pointit.hasNext()){
57 plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1);
58 if (pointit.value().toInt() >maxy)
59 max_y=pointit.value().toInt();
61 plotobjects.append(plot);
65 setLimits(0,endframe,0,maxy+10);
66 addPlotObjects(plotobjects);
70 void ParameterPlotter::createParametersNew(){
71 QList< QPair<QString, QMap<int,QVariant> > > ret;
72 QList<KPlotObject*> plotobjs=plotObjects();
73 if (plotobjs.size() != parameterNameList.size() ){
74 kDebug() << "ERROR size not equal";
77 for (int i=0;i<parameterNameList.size() ;i++){
78 QList<KPlotPoint*> points=plotobjs[i]->points();
79 QMap<int,QVariant> vals;
80 foreach (KPlotPoint *o,points){
83 QPair<QString,QMap<int,QVariant> > pair("contrast",vals);
87 emit parameterChanged(ret);
92 void ParameterPlotter::mouseMoveEvent ( QMouseEvent * event ) {
95 QList<KPlotPoint*> list= pointsUnderPoint (event->pos()-QPoint(leftPadding(), topPadding() ) ) ;
97 foreach (KPlotObject *o, plotObjects() ){
98 QList<KPlotPoint*> points=o->points();
99 for(int p=0;p<points.size();p++){
100 if (points[p]==movepoint){
101 QPoint delta=event->pos()-oldmousepoint;
103 movepoint->setY(movepoint->y()-delta.y()*dataRect().height()/pixRect().height() );
104 if (p>0 && p<points.size()-1){
105 double newx=movepoint->x()+delta.x()*dataRect().width()/pixRect().width();
106 if ( newx>points[p-1]->x() && newx<points[p+1]->x() && m_moveX)
107 movepoint->setX(movepoint->x()+delta.x()*dataRect().width()/pixRect().width() );
109 if (m_moveTimeline && (m_moveX|| m_moveY) )
111 replacePlotObject(i,o);
112 oldmousepoint=event->pos();
117 createParametersNew();
121 void ParameterPlotter::replot(const QString & name){
122 //removeAllPlotObjects();
124 bool drawAll=name.isEmpty() || name=="all";
126 foreach (KPlotObject* p,plotObjects() ){
127 p->setShowPoints(drawAll || parameterNameList[i]==name);
128 p->setShowLines(drawAll || parameterNameList[i]==name);
129 if ( parameterNameList[i]==name )
131 replacePlotObject(i++,p);
135 void ParameterPlotter::mousePressEvent ( QMouseEvent * event ) {
136 //topPadding and other padding can be wrong and this (i hope) will be correctet in newer kde versions
137 QPoint inPlot=event->pos()-QPoint(leftPadding(), topPadding() );
138 QList<KPlotPoint*> list= pointsUnderPoint (inPlot ) ;
139 if (list.size() > 0){
141 oldmousepoint=event->pos();
143 if (m_newPoints && activeIndexPlot>=0){
145 KPlotObject* p=plotObjects()[activeIndexPlot];
146 QList<KPlotPoint*> points=p->points();
147 QList<QPointF> newpoints;
149 double newx=inPlot.x()*dataRect().width()/pixRect().width();
150 double newy=(height()-inPlot.y()-bottomPadding()-topPadding() )*dataRect().height()/pixRect().height();
152 foreach (KPlotPoint* pt,points){
153 if (pt->x() >newx && !inserted){
154 newpoints.append(QPointF(newx,newy));
157 newpoints.append(QPointF(pt->x(),pt->y()));
160 foreach (QPointF qf, newpoints ){
163 replacePlotObject(activeIndexPlot,p);
169 void ParameterPlotter::setMoveX(bool b){
173 void ParameterPlotter::setMoveY(bool b){
177 void ParameterPlotter::setMoveTimeLine(bool b){
181 void ParameterPlotter::setNewPoints(bool b){
185 bool ParameterPlotter::isMoveX(){
189 bool ParameterPlotter::isMoveY(){
193 bool ParameterPlotter::isMoveTimeline(){
194 return m_moveTimeline;
197 bool ParameterPlotter::isNewPoints(){