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