/***************************************************************************
 *   Copyright (C) 2005 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 SPECTRALWIDGET_H
#define SPECTRALWIDGET_H

/**
A widget for drawing spectra
 
@author Armando Navarro Vazquez
*/
#include <qwidget.h>
//Added by qt3to4:
#include <QResizeEvent>
#include <QMouseEvent>
#include <Q3PopupMenu>
#include <QPaintEvent>


class SpectrumParser;
class KUrl;
class QwtScaleDraw;
class QwtLinearScaleEngine;
class QPalette;
class QRectTracker;
class QLineTracker;
class Spectrum;
class Q3PopupMenu;
class PeakPicker;
class Integrator;
class QRubberBand;
class SpectralWidget : public QWidget
{
  Q_OBJECT

  enum mouseaction { NONE, ZOOM, INFO, PHASE, INTEGRAL, PEAKPICKING, REFERENCE };

public:
  SpectralWidget(QWidget* parent=0 ,const char* name=0);

  ~SpectralWidget();
  void OpenFile(QString file);
  void GetImage(QImage& img, int width, int height);
signals:
  void info(const QString& );
  void ft(bool );
public slots:
  void OnPrint();
  void OnExport(const QString& file);
  void OnZoom(bool b);
  void OnPhase(bool b);
  void OnPeakPicking(bool b);
  void OnFull();
  /** Move spectrum up*/
  void OnUp();
  /** Move spectrum down*/
  void OnDown();
  /** Move spectrum to the left*/
  void OnLeft();
  /** Move spectrum to the right*/
  void OnRight();
  /** Increase spectrum scale*/
  void OnPlus();
  /** Decrease spectrum scale*/
  void OnMinus();
  /** info mode*/
  void OnInfo(bool b);
  /** Integration mode*/
  void OnIntegral(bool b);
  /** Do Fourier Transform*/
  void OnFT();
  /** Do WlT transform*/
 // void OnWLT();
  /** Clear Peak Picking*/
  void OnClearPeaks();
  /** Show Peaks on Screen*/
  void OnShowPeaks();
  /** Remove Solvent*/
 // void OnRemoveSolvent();
 // void OnCorrectBaseline();
   void OnZeroFill(int n);
private slots: 
  void OnZeroFillDialog();
  /** Do a full update of drawing points*/
  void OnFullUpdate();
protected:
  void paintEvent(QPaintEvent* e);
  void resizeEvent(QResizeEvent* e);
  void mousePressEvent(QMouseEvent* e);
  void mouseMoveEvent(QMouseEvent* e);
  void mouseReleaseEvent(QMouseEvent* e);
private: //private methods
  void Draw(QPainter* p, const QRect& rect,bool bprint=false);
  void SetCursor();
  void InitMenus();
  void DrawPivot(QPainter* p);
  void UpdateDrawingRect(const QRect& rect, bool autoscale=false);
private:
  Spectrum* m_spectrum;
//  SpectrumParser* m_parser;
  QwtScaleDraw* m_scale;
  QwtLinearScaleEngine* m_scaleengine;
  QPalette* m_scalepalette;
  mouseaction m_mouseaction;
  QRubberBand* m_recttracker;
  QRubberBand* m_linetracker;
  bool m_lgrabbed;
  bool m_rgrabbed;
  Q3PopupMenu* m_fidmenu;
  Q3PopupMenu* m_spectrummenu;
  Q3PopupMenu* m_peakpickingmenu;
  SpectrumParser* m_parser;
  QPoint m_lastpoint;
  PeakPicker* m_peakpicker;
  Integrator* m_integrator;
  bool m_bshowpeaks;

};

#endif
