//    tonalisa - software to look at overtone-structures
//    Copyright (C) 2016  Dominik Schmidt-Philipp
//
//    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 3 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, see <http://www.gnu.org/licenses/>.
//
#ifndef FREQUENCYVIEW_H
#define FREQUENCYVIEW_H

#include <QtQuick/QQuickPaintedItem>

class FrequencyView : public QQuickPaintedItem
{
  Q_OBJECT
  Q_PROPERTY(bool paintAxes READ paintAxes WRITE setPaintAxes)
  Q_PROPERTY(bool paintGrid READ paintGrid WRITE setPaintGrid)
  Q_PROPERTY(bool paintFFT READ paintFFT WRITE setPaintFFT)
  Q_PROPERTY(bool paintPeaks READ paintPeaks WRITE setPaintPeaks)

  Q_PROPERTY(QList<double> fftData READ fftData WRITE setFftData)
  Q_PROPERTY(double sampleRate READ sampleRate WRITE setSampleRate NOTIFY sampleRateChanged)
  Q_PROPERTY(QList<double> peaks READ peaks WRITE setPeaks)
  Q_PROPERTY(QList<double> grid READ grid WRITE setGrid NOTIFY gridChanged)
  Q_PROPERTY(int gridTunedStep READ gridTunedStep WRITE setGridTunedStep)
  Q_PROPERTY(double gridPitch READ gridPitch WRITE setGridPitch NOTIFY gridPitchChanged)
  Q_PROPERTY(double gridLowest READ gridLowest WRITE setGridLowest)
  Q_PROPERTY(double gridHighest READ gridHighest WRITE setGridHighest)
  Q_PROPERTY(double pointerFreq READ pointerFreq WRITE setPointerFreq NOTIFY pointerFreqChanged)
  Q_PROPERTY(double pointerAmp READ pointerAmp WRITE setPointerAmp NOTIFY pointerAmpChanged)
  Q_PROPERTY(QPointF pointerPos READ pointerPos NOTIFY pointerPosChanged)

 public:
  FrequencyView(QQuickItem *parent = 0);

  // Getter Functions for properties:
  bool paintAxes();
  bool paintGrid();
  bool paintFFT();
  bool paintPeaks();
  QList<double> fftData();
  double sampleRate() const;
  QList<double> peaks();
  QList<double> grid();
  int gridTunedStep() const;
  double gridPitch() const;
  double gridLowest() const;
  double gridHighest() const;
  double pointerFreq() const;
  double pointerAmp() const;
  QPointF pointerPos();
  
  
  // Setter Functions for properties:
  void setPaintAxes(const bool &paint);
  void setPaintGrid(const bool &paint);
  void setPaintFFT(const bool &paint);
  void setSampleRate(const double &sampleRate);
  void setPaintPeaks(const bool &paint);
  void setFftData(const QList<double> &fftData);
  void setPeaks(const QList<double> &peaks);
  virtual void setGrid(const QList<double> &grid);
  void setGridTunedStep(const int &gridTunedStep);
  void setGridPitch(const double &gridPitch);
  void setGridLowest(const double &gridLowest);
  void setGridHighest(const double &gridHighest);
  virtual void setPointerFreq(const double &pointerFreq);
  virtual void setPointerAmp(const double &pointerAmp);
  virtual void calculateGrid();
  //
  void paint(QPainter *painter);

 signals:
  void pointerFreqChanged();
  void pointerAmpChanged();
  void pointerPosChanged();
  void gridChanged();
  void gridPitchChanged();
  void sampleRateChanged();
  
 protected:
  bool paint_coord;
  bool paint_grid;
  bool paint_fft;
  bool paint_peaks;
  QList<double> m_fftData;
  double m_sampleRate;
  double m_fftSize;
  QList<double> m_peaks;
  QList<double> m_grid;
  int m_gridTunedStep;
  double m_gridPitch;
  double m_gridLowest;
  double m_gridHighest;
  double m_pointerFreq;
  double m_pointerAmp;
  QPointF m_pointerPos;
};
#endif // FREQUENCYVIEW_H
