Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef FUNCTION_SEGMENT_VIEWER_H
Toshihiro Shimizu 890ddd
#define FUNCTION_SEGMENT_VIEWER_H
Toshihiro Shimizu 890ddd
Tact Yoshida 1d7cf9
#include <array></array>
Toshihiro Shimizu 890ddd
#include <qlabel></qlabel>
Toshihiro Shimizu 890ddd
#include <qcombobox></qcombobox>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
shun-iwasawa e87e08
#include "tdoublekeyframe.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/lineedit.h"
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
class FunctionSegmentPage;
Toshihiro Shimizu 890ddd
class FunctionSheet;
Toshihiro Shimizu 890ddd
class TXsheetHandle;
Toshihiro Shimizu 890ddd
class KeyframeSetter;
Toshihiro Shimizu 890ddd
class FunctionPanel;
Toshihiro Shimizu 890ddd
class QPushButton;
Toshihiro Shimizu 890ddd
class QStackedWidget;
Shinya Kitaoka 120a6e
namespace DVGui {
Toshihiro Shimizu 890ddd
class MeasuredDoubleLineEdit;
Toshihiro Shimizu 890ddd
class ExpressionField;
shun-iwasawa e87e08
class FileField;
shun-iwasawa fe2893
}  // namespace DVGui
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FunctionSegmentViewer final : public QFrame, public TParamObserver {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDoubleParam *m_curve;
Shinya Kitaoka 120a6e
  int m_segmentIndex;
Shinya Kitaoka 120a6e
  int m_r0, m_r1;
Shinya Kitaoka 120a6e
  QWidget *m_topbar;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QLineEdit *m_fromFld;
Shinya Kitaoka 120a6e
  QLineEdit *m_toFld;
Shinya Kitaoka 120a6e
  QLabel *m_paramNameLabel;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QComboBox *m_typeCombo;
Shinya Kitaoka 120a6e
  DVGui::LineEdit *m_stepFld;
Shinya Kitaoka 120a6e
  QStackedWidget *m_parametersPanel;
Toshihiro Shimizu 890ddd
Tact Yoshida 1d7cf9
  std::array<functionsegmentpage *,="" 9=""> m_pages;</functionsegmentpage>
Tact Yoshida 1d7cf9
  std::array<int, 9=""> m_typeId;</int,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  FunctionSheet *m_sheet;
Shinya Kitaoka 120a6e
  TXsheetHandle *m_xshHandle;
Shinya Kitaoka 120a6e
  FunctionPanel *m_panel;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // buttons for move segments
Shinya Kitaoka 120a6e
  QPushButton *m_prevCurveButton;
Shinya Kitaoka 120a6e
  QPushButton *m_nextCurveButton;
Shinya Kitaoka 120a6e
  QPushButton *m_prevLinkButton;
Shinya Kitaoka 120a6e
  QPushButton *m_nextLinkButton;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionSegmentViewer(QWidget *parent, FunctionSheet *sheet = 0,
Shinya Kitaoka 120a6e
                        FunctionPanel *panel = 0);
Shinya Kitaoka 120a6e
  ~FunctionSegmentViewer();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDoubleParam *getCurve() const { return m_curve; }
Shinya Kitaoka 120a6e
  int getR0() const { return m_r0; }
Shinya Kitaoka 120a6e
  int getR1() const { return m_r1; }
Shinya Kitaoka 120a6e
  int getSegmentIndex() const { return m_segmentIndex; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void refresh();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // overriden from TDoubleParamObserver
Shinya Kitaoka 473e70
  void onChange(const TParamChange &) override { refresh(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setXsheetHandle(TXsheetHandle *xshHandle) { m_xshHandle = xshHandle; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool anyWidgetHasFocus();
Shinya Kitaoka 120a6e
  // in order to avoid FunctionViewer to get focus while editing the expression
Shinya Kitaoka 120a6e
  bool isExpressionPageActive();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  int typeToIndex(int type) const;
Shinya Kitaoka 120a6e
  int indexToType(int typeIndex) const { return m_typeId[typeIndex]; }
Shinya Kitaoka 120a6e
  bool segmentIsValid() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // for displaying the types of neighbor segments
Shinya Kitaoka 120a6e
  QString typeToString(int type) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private slots:
Shinya Kitaoka 120a6e
  void onSegmentTypeChanged(int type);
Shinya Kitaoka 120a6e
  void onCurveChanged();
Shinya Kitaoka 120a6e
  void onStepFieldChanged(const QString &);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void onApplyButtonPressed();
Shinya Kitaoka 120a6e
  void onPrevCurveButtonPressed();
Shinya Kitaoka 120a6e
  void onNextCurveButtonPressed();
Shinya Kitaoka 120a6e
  void onPrevLinkButtonPressed();
Shinya Kitaoka 120a6e
  void onNextLinkButtonPressed();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void setSegment(TDoubleParam *curve, int segmentIndex);
Shinya Kitaoka 120a6e
  void setSegmentByFrame(TDoubleParam *curve, int frame);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class FunctionSegmentPage : public QWidget {
Shinya Kitaoka 120a6e
  Q_OBJECT
Shinya Kitaoka 120a6e
  FunctionSegmentViewer *m_viewer;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionSegmentPage(FunctionSegmentViewer *parent);
Shinya Kitaoka 120a6e
  ~FunctionSegmentPage();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  FunctionSegmentViewer *getViewer() const { return m_viewer; }
Shinya Kitaoka 120a6e
  TDoubleParam *getCurve() const { return m_viewer->getCurve(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getR0() const { return m_viewer->getR0(); }
Shinya Kitaoka 120a6e
  int getR1() const { return m_viewer->getR1(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void refresh() = 0;
Shinya Kitaoka 120a6e
  virtual void apply()   = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void init(int segmentLength) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void onFieldChanged() { apply(); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class SpeedInOutSegmentPage final : public FunctionSegmentPage {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DVGui::LineEdit *m_speed0xFld;
Shinya Kitaoka 120a6e
  DVGui::MeasuredDoubleLineEdit *m_speed0yFld;
Shinya Kitaoka 120a6e
  DVGui::LineEdit *m_speed1xFld;
Shinya Kitaoka 120a6e
  DVGui::MeasuredDoubleLineEdit *m_speed1yFld;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DVGui::MeasuredDoubleLineEdit *m_firstSpeedFld;
Shinya Kitaoka 120a6e
  DVGui::MeasuredDoubleLineEdit *m_lastSpeedFld;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SpeedInOutSegmentPage(FunctionSegmentViewer *parent = 0);
Shinya Kitaoka 473e70
  void refresh() override;
Shinya Kitaoka 38fd86
  void apply() override{};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void getGuiValues(TPointD &speedIn, TPointD &speedOut);
Shinya Kitaoka 473e70
  void init(int segmentLength) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void onFirstHandleXChanged();
Shinya Kitaoka 120a6e
  void onFirstHandleYChanged();
Shinya Kitaoka 120a6e
  void onLastHandleXChanged();
Shinya Kitaoka 120a6e
  void onLastHandleYChanged();
Shinya Kitaoka 120a6e
  void onFirstSpeedChanged();
Shinya Kitaoka 120a6e
  void onLastSpeedChanged();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class EaseInOutSegmentPage final : public FunctionSegmentPage {
Shinya Kitaoka 120a6e
  Q_OBJECT
Shinya Kitaoka 120a6e
  DVGui::MeasuredDoubleLineEdit *m_ease0Fld, *m_ease1Fld;
Shinya Kitaoka 120a6e
  double m_fieldScale;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_isPercentage;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  EaseInOutSegmentPage(bool percentage, FunctionSegmentViewer *parent = 0);
Shinya Kitaoka 473e70
  void refresh() override;
Shinya Kitaoka 473e70
  void apply() override {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void getGuiValues(TPointD &easeIn, TPointD &easeOut);
Shinya Kitaoka 473e70
  void init(int segmentLength) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Shinya Kitaoka 120a6e
  void onEase0Changed();
Shinya Kitaoka 120a6e
  void onEase1Changed();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FunctionExpressionSegmentPage final : public FunctionSegmentPage {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DVGui::ExpressionField *m_expressionFld;
Shinya Kitaoka 120a6e
  DVGui::LineEdit *m_unitFld;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FunctionExpressionSegmentPage(FunctionSegmentViewer *parent = 0);
Shinya Kitaoka 473e70
  void refresh() override;
Shinya Kitaoka 473e70
  void apply() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // return false if a circular reference is occured
Shinya Kitaoka 120a6e
  bool getGuiValues(std::string &expressionText, std::string &unitName);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void init(int segmentLength) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class SimilarShapeSegmentPage final : public FunctionSegmentPage {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DVGui::ExpressionField *m_expressionFld;
Shinya Kitaoka 120a6e
  DVGui::LineEdit *m_offsetFld;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SimilarShapeSegmentPage(FunctionSegmentViewer *parent = 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void refresh() override;
Shinya Kitaoka 473e70
  void apply() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void init(int segmentLength) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void getGuiValues(std::string &expressionText, double &similarShapeOffset);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
shun-iwasawa e87e08
//-----------------------------------------------------------------------------
shun-iwasawa e87e08
shun-iwasawa e87e08
class FileSegmentPage final : public FunctionSegmentPage {
shun-iwasawa e87e08
  Q_OBJECT
shun-iwasawa e87e08
shun-iwasawa e87e08
  DVGui::FileField *m_fileFld;
shun-iwasawa e87e08
  DVGui::LineEdit *m_fieldIndexFld;
shun-iwasawa e87e08
  DVGui::LineEdit *m_measureFld;
shun-iwasawa e87e08
shun-iwasawa e87e08
public:
shun-iwasawa e87e08
  FileSegmentPage(FunctionSegmentViewer *parent = 0);
shun-iwasawa e87e08
  void refresh() override;
shun-iwasawa e87e08
  void init(int segmentLength) override;
shun-iwasawa e87e08
  void apply() override;
shun-iwasawa e87e08
  void getGuiValues(TDoubleKeyframe::FileParams &fileParam,
shun-iwasawa e87e08
                    std::string &unitName);
shun-iwasawa e87e08
};
shun-iwasawa e87e08
Toshihiro Shimizu 890ddd
#endif