/***************************************************************************
 *   Copyright (C) 2004 by Armando Navarro-Vazquez                         *
 *   qoajnv@usc.es                                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef QUANTUMPLOT_H
#define QUANTUMPLOT_H

#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
/**
A derived QwtPlot class which plots markers on all optimization points and emits a signal with the number of the step clicked


@author Armando Navarro-Vazquez
*/
//Added by qt3to4:
#include <QMouseEvent>

class QuantumPlot : public QwtPlot
{
    Q_OBJECT

  public:
    QuantumPlot ( QWidget* parent );

    ~QuantumPlot();

    void setupStepMarkers();
    void ChangeLimits(int first, int last, double ymin,double ymax);
  signals:
    void selectedPoint ( int );
  public slots:
    void OnSelectedPoint ( int point );
  protected:
    void mousePressEvent ( QMouseEvent* e );
    void mouseMoveEvent( QMouseEvent* e );

  class QuantumMarker : public QwtPlotMarker
    {
      public:
        QuantumMarker ( QwtPlot* parent ) : QwtPlotMarker() {};
        void setStep ( int step ) { m_step=step; };
        int step() const { return m_step; }
      private:
        int m_step;
    };


    QSize sizeHint() const { return QSize ( 250,200 ); }
//associate a step number with the key
    //bool setMarkerStep ( long key,int step );
    int m_point;
public:
    QuantumMarker* closestQuantumMarker ( const QPoint& pos, int distance );
};

class QuantumCurve : public QwtPlotCurve
{
  public:
    QuantumCurve ( QwtPlot* parent, const QString& title=QString::null )
        : QwtPlotCurve ( title ) , m_label(QString::null) {};
    void setExtraData ( double* z ) { m_extradata=z; }
    double z ( int i ) { return m_extradata[i]; }
    void setExtraLabel ( const QString& label ) { m_label=label; }
    const QString& extraLabel() const { return m_label; }
    virtual QString strData ( int i )
    {
      QString str;
      str.sprintf ( "%.6f",y ( i ) );
      str=extraLabel() +"=" + str;
      return str;
    };
  private:
    double* m_extradata;
    QString m_label;

};

class EnergyCurve :  public QuantumCurve
{
  public:
    EnergyCurve ( QwtPlot* parent, const QString& title=QString::null )
        : QuantumCurve ( parent,title ) {};
    QString strData ( int i )
    {
      QString str;
      str.sprintf ( "%.5f\nS2=%.3f",y ( i ),z ( i ) );
      str=extraLabel()  + "=" +str;
      return str;
    }
};



#endif
