Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef FUNCTIONPANEL_H
Toshihiro Shimizu 890ddd
#define FUNCTIONPANEL_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include "functiontreeviewer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qdialog></qdialog>
Toshihiro Shimizu 890ddd
#include <set></set>
Keisuke Ogaki e76b22
#include <cmath></cmath>
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 TDoubleKeyframe;
Toshihiro Shimizu 890ddd
class TFrameHandle;
Toshihiro Shimizu 890ddd
class FunctionSelection;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! Channel edit panel (numcols + graph popup)
Shinya Kitaoka d1f6c4
class FunctionPanel final : public QDialog {
Shinya Kitaoka 120a6e
  Q_OBJECT
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QColor m_bgColor;
Shinya Kitaoka 120a6e
  QColor m_valueLineColor;
Shinya Kitaoka 120a6e
  QColor m_frameLineColor;
Shinya Kitaoka 120a6e
  QColor m_otherCurvesColor;
Shinya Kitaoka 120a6e
  QColor m_rulerBackground;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Q_PROPERTY(QColor BGColor READ getBGColor WRITE setBGColor)
Shinya Kitaoka 120a6e
  Q_PROPERTY(
Shinya Kitaoka 120a6e
      QColor ValueLineColor READ getValueLineColor WRITE setValueLineColor)
Shinya Kitaoka 120a6e
  Q_PROPERTY(
Shinya Kitaoka 120a6e
      QColor FrameLineColor READ getFrameLineColor WRITE setFrameLineColor)
Shinya Kitaoka 120a6e
  Q_PROPERTY(QColor OtherCurvesColor READ getOtherCurvesColor WRITE
Shinya Kitaoka 120a6e
                 setOtherCurvesColor)
Shinya Kitaoka 120a6e
  Q_PROPERTY(
Shinya Kitaoka 120a6e
      QColor RulerBackground READ getRulerBackground WRITE setRulerBackground)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QColor m_textColor;      // black
Shinya Kitaoka 120a6e
  QColor m_subColor;       // white
Shinya Kitaoka 120a6e
  QColor m_selectedColor;  // blue
Shinya Kitaoka 120a6e
  Q_PROPERTY(QColor TextColor READ getTextColor WRITE setTextColor)
Shinya Kitaoka 120a6e
  Q_PROPERTY(QColor SubColor READ getSubColor WRITE setSubColor)
Shinya Kitaoka 120a6e
  Q_PROPERTY(QColor SelectedColor READ getSelectedColor WRITE setSelectedColor)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class DragTool;
Shinya Kitaoka 120a6e
  enum Handle {
Shinya Kitaoka 120a6e
    None,
Shinya Kitaoka 120a6e
    Curve,
Shinya Kitaoka 120a6e
    Point,
Shinya Kitaoka 120a6e
    SpeedIn,
Shinya Kitaoka 120a6e
    SpeedOut,
Shinya Kitaoka 120a6e
    EaseIn,
Shinya Kitaoka 120a6e
    EaseOut,
Shinya Kitaoka 120a6e
    EaseInPercentage,
Shinya Kitaoka 120a6e
    EaseOutPercentage
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  QTransform m_viewTransform;  // world -> window
Shinya Kitaoka 120a6e
  int m_valueAxisX, m_frameAxisY, m_graphViewportY;
Shinya Kitaoka 120a6e
  QPoint m_origin;              // axes origin (window coords)
Shinya Kitaoka 120a6e
  QPoint m_startPos, m_oldPos;  // mouse click position, last mouse click/drag
Shinya Kitaoka 120a6e
                                // position (window coords)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  struct Gadget {
Shinya Kitaoka 120a6e
    Handle m_handle;
Shinya Kitaoka 120a6e
    int m_kIndex;
Shinya Kitaoka 120a6e
    QRect m_hitRegion;
Shinya Kitaoka 120a6e
    QPointF m_pos, m_pointPos;
Shinya Kitaoka 120a6e
    double m_keyframePosition;
Shinya Kitaoka 120a6e
    FunctionTreeModel::Channel *m_channel;
Shinya Kitaoka 120a6e
    Gadget(Handle handle, int kIndex, const QPointF &p, int rx, int ry,
Shinya Kitaoka 120a6e
           const QPointF &pointPos = QPointF());
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  QList<gadget> m_gadgets;</gadget>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  DragTool *m_dragTool;
Shinya Kitaoka 120a6e
  FunctionSelection *m_selection;
Shinya Kitaoka 120a6e
  TFrameHandle *m_frameHandle;
Shinya Kitaoka 120a6e
  FunctionTreeModel *m_functionTreeModel;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int m_currentFrameStatus;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  struct Highlighted {
Shinya Kitaoka 120a6e
    Handle handle;
Shinya Kitaoka 120a6e
    int gIndex;
Shinya Kitaoka 120a6e
  } m_highlighted;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  struct {
Shinya Kitaoka 120a6e
    bool visible;
Shinya Kitaoka 120a6e
    double frame, value;
Shinya Kitaoka 120a6e
  } m_cursor;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  struct {
Shinya Kitaoka 120a6e
    QPoint curvePos, labelPos;
Shinya Kitaoka 120a6e
    std::string text;
Shinya Kitaoka 120a6e
    TDoubleParam *curve;
Shinya Kitaoka 120a6e
  } m_curveLabel;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enum CURVE_SHAPE {
Shinya Kitaoka 120a6e
    SMOOTH = 0,
Shinya Kitaoka 120a6e
    FRAME_BASED  // curves with the connected polylines of integer frames
Shinya Kitaoka 120a6e
  } m_curveShape;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionPanel(QWidget *parent);
Shinya Kitaoka 120a6e
  ~FunctionPanel();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setModel(FunctionTreeModel *model) { m_functionTreeModel = model; };
Shinya Kitaoka 120a6e
  FunctionTreeModel *getModel() const { return m_functionTreeModel; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FunctionSelection *getSelection() const { return m_selection; }
Shinya Kitaoka 120a6e
  void setSelection(FunctionSelection *selection) {
Shinya Kitaoka 120a6e
    m_selection = selection;
Shinya Kitaoka 120a6e
  }  // does NOT get ownership
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setFrameHandle(TFrameHandle *frameHandle);
Shinya Kitaoka 120a6e
  TFrameHandle *getFrameHandle() const { return m_frameHandle; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QTransform getViewTransform() const { return m_viewTransform; }
Shinya Kitaoka 120a6e
  void setViewTransform(const QTransform &viewTransform) {
Shinya Kitaoka 120a6e
    m_viewTransform = viewTransform;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // frame pixel size / value pixel size
Shinya Kitaoka 120a6e
  double getPixelRatio(TDoubleParam *curve) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double xToFrame(double x) const;
Shinya Kitaoka 120a6e
  double frameToX(double frame) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // note: the y-unit depends on the unit (e.g. degress, inches,..) and
Shinya Kitaoka 120a6e
  // therefore on the curve
Shinya Kitaoka 120a6e
  double valueToY(TDoubleParam *curve, double value) const;
Shinya Kitaoka 120a6e
  double yToValue(TDoubleParam *curve, double y) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void pan(int dx, int dy);
Shinya Kitaoka 120a6e
  void pan(const QPoint &delta) { pan(delta.x(), delta.y()); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void zoom(double sx, double sy, const QPoint ¢er);
Shinya Kitaoka 120a6e
  void fitSelectedPoints();
Shinya Kitaoka 120a6e
  void fitCurve();
Shinya Kitaoka 120a6e
  void fitGraphToWindow(bool currentCurveOnly = false);
Shinya Kitaoka 120a6e
  void fitRegion(double f0, double v0, double f1, double v1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPointF getWinPos(TDoubleParam *curve, double frame, double value) const;
Shinya Kitaoka 120a6e
  QPointF getWinPos(TDoubleParam *curve, const TPointD &frameValuePos) const {
Shinya Kitaoka 120a6e
    return getWinPos(curve, frameValuePos.x, frameValuePos.y);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  QPointF getWinPos(TDoubleParam *curve, double frame) const;
Shinya Kitaoka 120a6e
  QPointF getWinPos(TDoubleParam *curve, const TDoubleKeyframe &kf) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getCurveDistance(TDoubleParam *curve, const QPoint &winPos);
Shinya Kitaoka 120a6e
  TDoubleParam *findClosestCurve(const QPoint &winPos, int maxWinDistance);
Shinya Kitaoka 120a6e
  FunctionTreeModel::Channel *findClosestChannel(const QPoint &winPos,
Shinya Kitaoka 120a6e
                                                 int maxWinDistance);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // returns the keyframe index (-1 if no keyframe found)
Shinya Kitaoka 120a6e
  // int findClosestKeyframe(TDoubleParam* curve, const QPoint &winPos, Handle
Shinya Kitaoka 120a6e
  // &handle, int maxWinDistance);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int findClosestGadget(const QPoint &winPos, Handle &handle,
Shinya Kitaoka 120a6e
                        int maxWinDistance);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // creates a QPainterPath representing a curve segment, limited in [x0,x1]
Shinya Kitaoka 120a6e
  // segmentIndex = -1 => ]-inf,first keyframe]
Shinya Kitaoka 120a6e
  // segmentIndex = segmentCount => [last keyframe, inf[
Shinya Kitaoka 120a6e
  QPainterPath getSegmentPainterPath(TDoubleParam *curve, int segmentIndex,
Shinya Kitaoka 120a6e
                                     int x0, int x1);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParam *getCurrentCurve() const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void emitKeyframeSelected(double frame) { emit keyframeSelected(frame); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setBGColor(const QColor &color) { m_bgColor = color; }
Shinya Kitaoka 120a6e
  QColor getBGColor() const { return m_bgColor; }
Shinya Kitaoka 120a6e
  void setValueLineColor(const QColor &color) { m_valueLineColor = color; }
Shinya Kitaoka 120a6e
  QColor getValueLineColor() const { return m_valueLineColor; }
Shinya Kitaoka 120a6e
  void setFrameLineColor(const QColor &color) { m_frameLineColor = color; }
Shinya Kitaoka 120a6e
  QColor getFrameLineColor() const { return m_frameLineColor; }
Shinya Kitaoka 120a6e
  void setOtherCurvesColor(const QColor &color) { m_otherCurvesColor = color; }
Shinya Kitaoka 120a6e
  QColor getOtherCurvesColor() const { return m_otherCurvesColor; }
Shinya Kitaoka 120a6e
  void setRulerBackground(const QColor &color) { m_rulerBackground = color; }
Shinya Kitaoka 120a6e
  QColor getRulerBackground() const { return m_rulerBackground; }
Shinya Kitaoka 120a6e
  void setTextColor(const QColor &color) { m_textColor = color; }
Shinya Kitaoka 120a6e
  QColor getTextColor() const { return m_textColor; }
Shinya Kitaoka 120a6e
  void setSubColor(const QColor &color) { m_subColor = color; }
Shinya Kitaoka 120a6e
  QColor getSubColor() const { return m_subColor; }
Shinya Kitaoka 120a6e
  void setSelectedColor(const QColor &color) { m_selectedColor = color; }
Shinya Kitaoka 120a6e
  QColor getSelectedColor() const { return m_selectedColor; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  void updateGadgets(TDoubleParam *curve);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void drawCurrentFrame(QPainter &);
Shinya Kitaoka 120a6e
  void drawFrameGrid(QPainter &);
Shinya Kitaoka 120a6e
  void drawValueGrid(QPainter &);
Shinya Kitaoka 120a6e
  void drawOtherCurves(QPainter &);
Shinya Kitaoka 120a6e
  void drawCurrentCurve(QPainter &);
Shinya Kitaoka 120a6e
  void drawGroupKeyframes(QPainter &);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *e) override;
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *e) override;
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QMouseEvent *e) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *e) override;
Shinya Kitaoka 473e70
  void wheelEvent(QWheelEvent *e) override;
Shinya Kitaoka 120a6e
  void openContextMenu(QMouseEvent *e);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void keyPressEvent(QKeyEvent *e) override;
Shinya Kitaoka 473e70
  void enterEvent(QEvent *) override;
Shinya Kitaoka 473e70
  void leaveEvent(QEvent *) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void showEvent(QShowEvent *) override;
Shinya Kitaoka 473e70
  void hideEvent(QHideEvent *) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void onFrameSwitched();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  // void segmentSelected(TDoubleParam *curve, int segmentIndex);
Shinya Kitaoka 120a6e
  void keyframeSelected(double frame);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif