Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef FUNCTIONSELECTION_H
Toshihiro Shimizu 890ddd
#define FUNCTIONSELECTION_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include "functiontreeviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/selection.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvmimedata.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tdoublekeyframe.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qwidget></qwidget>
Toshihiro Shimizu 890ddd
#include <qlist></qlist>
Toshihiro Shimizu 890ddd
#include <qset></qset>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TOONZQT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
class TDoubleParam;
Toshihiro Shimizu 890ddd
class TFrameHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class ColumnToCurveMapper {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual TDoubleParam *getCurve(int columnIndex) const = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FunctionSelection final : public QObject, public TSelection {
Shinya Kitaoka 120a6e
  Q_OBJECT
Shinya Kitaoka 120a6e
  QRect m_selectedCells;  // yrange = rowrange of the selected keyframes;
Shinya Kitaoka 120a6e
                          // xrange = columnrange (functionsheet only)
Shinya Kitaoka 120a6e
  QList<qpair<tdoubleparam *,="" qset<int="">>> m_selectedKeyframes;</qpair<tdoubleparam>
Shinya Kitaoka 120a6e
  // first = curve, second = set of selected keyframes index
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_selectedSegment;  // index of the first keyframe of the segment; -1 if
Shinya Kitaoka 120a6e
                          // no segment selected
Shinya Kitaoka 120a6e
                          // (functionpanel only)
Shinya Kitaoka 120a6e
  // assert(m_selectedSegment<0 || m_selectedKeyframes.size()==1)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFrameHandle *m_frameHandle;
Shinya Kitaoka 120a6e
  ColumnToCurveMapper *m_columnToCurveMapper;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getCurveIndex(TDoubleParam *curve) const;
Shinya Kitaoka 120a6e
  // finds i : m_selectedKeyframes[i].first == curve
Shinya Kitaoka 120a6e
  //-1 if curve not found
Shinya Kitaoka 120a6e
  int touchCurveIndex(TDoubleParam *curve);
Shinya Kitaoka 120a6e
  // as getCurve(); if curve not found then add it
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionSelection();
Shinya Kitaoka 120a6e
  ~FunctionSelection();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setFrameHandle(TFrameHandle *frameHandle) {
Shinya Kitaoka 120a6e
    m_frameHandle = frameHandle;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // function graph
Shinya Kitaoka 120a6e
  void selectCurve(TDoubleParam *curve);
Shinya Kitaoka 120a6e
  void deselectAllKeyframes();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // function sheet
Shinya Kitaoka 120a6e
  QRect getSelectedCells() const { return m_selectedCells; }
Shinya Kitaoka 120a6e
  void selectCells(const QRect &selectedCells,
Shinya Kitaoka 120a6e
                   const QList<tdoubleparam *=""> &curves);</tdoubleparam>
Shinya Kitaoka 120a6e
  void selectCells(const QRect &selectedCells);
Shinya Kitaoka 120a6e
  void deselectAllCells();
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  bool isEmpty() const override { return m_selectedKeyframes.empty(); }
Shinya Kitaoka 473e70
  void selectNone() override;
Shinya Kitaoka 120a6e
  void select(TDoubleParam *curve, int k);
Shinya Kitaoka 120a6e
  bool isSelected(TDoubleParam *curve, int k) const;
Shinya Kitaoka 120a6e
  void selectSegment(TDoubleParam *, int k,
Shinya Kitaoka 120a6e
                     QRect selectedCells = QRect());  // note: if a segment is
Shinya Kitaoka 120a6e
                                                      // selected then also the
Shinya Kitaoka 120a6e
                                                      // segment ends are
Shinya Kitaoka 120a6e
                                                      // selected
Shinya Kitaoka 120a6e
  int getSelectedKeyframeCount() const;
Shinya Kitaoka 120a6e
  QPair<tdoubleparam *,="" int=""> getSelectedKeyframe(int index)</tdoubleparam>
Shinya Kitaoka 120a6e
      const;  // if index<0 || index>=getSelectedKeyframeCount() returns (0,-1)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPair<tdoubleparam *,="" int=""> getSelectedSegment()</tdoubleparam>
Shinya Kitaoka 120a6e
      const;  // if no segment is selected returns (0,-1)
Shinya Kitaoka 120a6e
  bool isSegmentSelected(TDoubleParam *, int k) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setColumnToCurveMapper(ColumnToCurveMapper *mapper);  // gets ownership
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParam *getCurveFromColumn(int columnIndex) const {
Shinya Kitaoka 120a6e
    return m_columnToCurveMapper ? m_columnToCurveMapper->getCurve(columnIndex)
Shinya Kitaoka 120a6e
                                 : 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void enableCommands() override;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void doCopy();
Shinya Kitaoka 120a6e
  void doPaste();
Shinya Kitaoka 120a6e
  void doCut();
Shinya Kitaoka 120a6e
  void doDelete();
Shinya Kitaoka 120a6e
  void insertCells();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void selectionChanged();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FunctionKeyframesData final : public DvMimeData {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionKeyframesData();
Shinya Kitaoka 120a6e
  ~FunctionKeyframesData();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  typedef std::vector<tdoublekeyframe> Keyframes;</tdoublekeyframe>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setColumnCount(int columnCount);
Shinya Kitaoka 120a6e
  int getColumnCount() const { return (int)m_keyframes.size(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getRowCount() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void getData(int columnIndex, TDoubleParam *curve, double frame,
Shinya Kitaoka 120a6e
               const QSet<int> &kIndices);</int>
Shinya Kitaoka 120a6e
  void setData(int columnIndex, TDoubleParam *curve, double frame) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const Keyframes &getKeyframes(int columnIndex) const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  DvMimeData *clone() const override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isCircularReferenceFree(int columnIndex, TDoubleParam *curve) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  std::vector<keyframes> m_keyframes;</keyframes>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif