| #pragma once |
| |
| #ifndef FUNCTIONTREEMODEL_H |
| #define FUNCTIONTREEMODEL_H |
| |
| |
| #include "tcommon.h" |
| #include "tdoubleparam.h" |
| |
| |
| #include "treemodel.h" |
| |
| |
| #include <QScrollBar> |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TOONZQT_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| |
| |
| |
| class TStageObject; |
| class TFx; |
| class TDoubleParam; |
| class TXsheet; |
| class TParamContainer; |
| class TFxHandle; |
| class TObjectHandle; |
| |
| class FunctionTreeView; |
| class FunctionViewer; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class FunctionTreeModel final : public TreeModel, public TParamObserver { |
| Q_OBJECT |
| |
| public: |
| |
| |
| |
| |
| |
| class Item : public TreeModel::Item { |
| public: |
| Item() {} |
| |
| virtual bool isActive() const = 0; |
| virtual bool isAnimated() const = 0; |
| }; |
| |
| |
| |
| |
| class ChannelGroup : public Item { |
| public: |
| enum ShowFilter { ShowAllChannels, ShowAnimatedChannels }; |
| |
| private: |
| QString m_name; |
| ShowFilter m_showFilter; |
| |
| public: |
| ChannelGroup(const QString &name = ""); |
| ~ChannelGroup(); |
| |
| bool isActive() const override; |
| bool isAnimated() const override; |
| |
| virtual QString getShortName() const { return m_name; } |
| virtual QString getLongName() const { return m_name; } |
| |
| virtual QString getIdName() const; |
| |
| void setShowFilter(ShowFilter showFilter); |
| ShowFilter getShowFilter() const { return m_showFilter; } |
| |
| void applyShowFilter(); |
| |
| QVariant data(int role) const override; |
| |
| |
| void setChildrenAllActive(bool active); |
| |
| void displayAnimatedChannels(); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class ParamWrapper { |
| protected: |
| TParamP m_param; |
| std::wstring m_fxId; |
| |
| public: |
| ParamWrapper(const TParamP ¶m, const std::wstring &fxId) |
| : m_param(param), m_fxId(fxId) {} |
| virtual ~ParamWrapper() {} |
| |
| const std::wstring &getFxId() const { return m_fxId; } |
| |
| TParamP getParam() const { return m_param; } |
| virtual void setParam(const TParamP ¶m) { m_param = param; } |
| }; |
| |
| |
| |
| |
| class Channel final : public ParamWrapper, |
| public Item, |
| public TParamObserver { |
| FunctionTreeModel *m_model; |
| ChannelGroup |
| *m_group; |
| |
| std::string m_paramNamePref; |
| |
| bool m_isActive; |
| |
| public: |
| Channel(FunctionTreeModel *model, TDoubleParam *param, |
| std::string paramNamePrefix = "", std::wstring fxId = L""); |
| ~Channel(); |
| |
| TDoubleParam *getParam() const { |
| return (TDoubleParam *)m_param.getPointer(); |
| } |
| void setParam(const TParamP ¶m) override; |
| |
| QString getShortName() const; |
| QString getLongName() const; |
| |
| |
| QString getExprRefName() const; |
| |
| ChannelGroup *getChannelGroup() const { return m_group; } |
| void setChannelGroup(ChannelGroup *group) { m_group = group; } |
| |
| QVariant data(int role) const override; |
| |
| bool isActive() const override { return m_isActive; } |
| void setIsActive(bool active); |
| |
| bool isAnimated() const override; |
| |
| bool isCurrent() const; |
| void setIsCurrent(bool current); |
| |
| bool isHidden() const; |
| |
| void onChange(const TParamChange &) override; |
| |
| void *getInternalPointer() const override; |
| }; |
| |
| private: |
| ChannelGroup |
| *m_stageObjects, |
| *m_fxs; |
| |
| std::vector<Channel *> m_activeChannels; |
| |
| Channel *m_currentChannel; |
| TStageObject |
| *m_currentStageObject; |
| TFx *m_currentFx; |
| |
| bool m_paramsChanged; |
| |
| TFxHandle *m_fxHandle; |
| TObjectHandle *m_objectHandle; |
| |
| public: |
| FunctionTreeModel( |
| FunctionTreeView *parent = 0); |
| ~FunctionTreeModel(); |
| |
| Channel *getCurrentChannel() const { return m_currentChannel; } |
| |
| Channel *getActiveChannel(int index) const; |
| int getActiveChannelCount() const { return m_activeChannels.size(); } |
| |
| int getColumnIndexByCurve(TDoubleParam *param) const; |
| |
| double getValue(Channel *channel, double frame) const; |
| int getClosestKeyframe(Channel *channel, |
| double frame) const; |
| Channel *getClosestChannel(double frame, double value) const; |
| |
| void refreshActiveChannels(); |
| void refreshData( |
| TXsheet *xsh); |
| |
| void resetAll(); |
| |
| void applyShowFilters(); |
| |
| void setCurrentStageObject(TStageObject *obj) { m_currentStageObject = obj; } |
| TStageObject *getCurrentStageObject() const { return m_currentStageObject; } |
| |
| void setCurrentFx(TFx *fx); |
| TFx *getCurrentFx() const { return m_currentFx; } |
| |
| void addParameter( |
| TParam *parameter, |
| const TFilePath |
| &folder); |
| |
| TFxHandle *getFxHandle() { return m_fxHandle; } |
| void setFxHandle(TFxHandle *fxHandle) { m_fxHandle = fxHandle; } |
| |
| TObjectHandle *getObjectHandle() { return m_objectHandle; } |
| void setObjectHandle(TObjectHandle *objectHandle) { |
| m_objectHandle = objectHandle; |
| } |
| |
| signals: |
| |
| void activeChannelsChanged(); |
| void curveSelected(TDoubleParam *); |
| void curveChanged(bool isDragging); |
| void currentChannelChanged(FunctionTreeModel::Channel *); |
| |
| private: |
| void addParameter(ChannelGroup *group, const std::string &prefixString, |
| const std::wstring &fxId, TParam *param); |
| |
| |
| void onChannelDestroyed(Channel *channel); |
| |
| |
| void emitDataChanged(Channel *channel) { |
| QModelIndex index = channel->createIndex(); |
| emit dataChanged(index, index); |
| emit activeChannelsChanged(); |
| } |
| |
| void emitCurveSelected(TDoubleParam *curve) { emit curveSelected(curve); } |
| |
| void emitCurrentChannelChanged(FunctionTreeModel::Channel *channel) { |
| emit currentChannelChanged(channel); |
| } |
| |
| void addChannels(TFx *fx, ChannelGroup *fxItem, TParamContainer *params); |
| |
| |
| |
| void onChange( |
| const TParamChange &) override; |
| void onParamChange(bool isDragging); |
| |
| |
| |
| void refreshStageObjects(TXsheet *xsh); |
| void refreshFxs(TXsheet *xsh); |
| void refreshPlasticDeformations(); |
| void addActiveChannels(TreeModel::Item *item); |
| |
| public: |
| ChannelGroup *getStageObjectChannel(int index) const; |
| ChannelGroup *getFxChannel(int index) const; |
| int getStageObjectsChannelCount() const { |
| return m_stageObjects->getChildCount(); |
| } |
| int getFxsChannelCount() const { return m_fxs->getChildCount(); } |
| }; |
| |
| |
| |
| class FxChannelGroup final : public FunctionTreeModel::ChannelGroup { |
| public: |
| TFx *m_fx; |
| |
| public: |
| FxChannelGroup(TFx *fx); |
| ~FxChannelGroup(); |
| |
| QString getShortName() const override; |
| QString getLongName() const override; |
| |
| QString getIdName() const override; |
| |
| void *getInternalPointer() const override { |
| return static_cast<void *>(m_fx); |
| } |
| TFx *getFx() const { return m_fx; } |
| QVariant data(int role) const override; |
| |
| void refresh() override; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class FunctionTreeView final : public TreeView { |
| Q_OBJECT |
| |
| TFilePath m_scenePath; |
| FunctionTreeModel::Channel *m_clickedItem; |
| |
| FunctionTreeModel::Channel *m_draggingChannel; |
| QPoint m_dragStartPosition; |
| |
| |
| |
| QColor m_textColor; |
| QColor m_currentTextColor; |
| Q_PROPERTY(QColor TextColor READ getTextColor WRITE setTextColor) |
| Q_PROPERTY(QColor CurrentTextColor READ getCurrentTextColor WRITE |
| setCurrentTextColor) |
| |
| public: |
| FunctionTreeView(FunctionViewer *parent); |
| |
| void setCurrentScenePath(TFilePath scenePath) { m_scenePath = scenePath; } |
| |
| void openContextMenu(TreeModel::Item *item, const QPoint &globalPos) override; |
| |
| void setTextColor(const QColor &color) { m_textColor = color; } |
| QColor getTextColor() const { return m_textColor; } |
| void setCurrentTextColor(const QColor &color) { m_currentTextColor = color; } |
| QColor getCurrentTextColor() const { return m_currentTextColor; } |
| |
| protected: |
| void onClick(TreeModel::Item *item, const QPoint &itemPos, |
| QMouseEvent *e) override; |
| |
| void onMidClick(TreeModel::Item *item, const QPoint &itemPos, |
| QMouseEvent *e) override; |
| |
| void onDrag(TreeModel::Item *item, const QPoint &itemPos, |
| QMouseEvent *e) override; |
| void onRelease() override; |
| |
| void openContextMenu(FunctionTreeModel::Channel *channel, |
| const QPoint &globalPos); |
| void openContextMenu(FunctionTreeModel::ChannelGroup *group, |
| const QPoint &globalPos); |
| |
| public slots: |
| |
| void onActivated(const QModelIndex &index); |
| void updateAll(); |
| |
| |
| void displayAnimatedChannels(); |
| |
| signals: |
| |
| void switchCurrentObject(TStageObject *obj); |
| void switchCurrentFx(TFx *fx); |
| }; |
| |
| #endif |