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