1 #pragma once 2 3 #ifndef EXPORTSCENEPOPUP_H 4 #define EXPORTSCENEPOPUP_H 5 6 #include "toonzqt/dvdialog.h" 7 #include "toonzqt/lineedit.h" 8 #include "tfilepath.h" 9 #include "filebrowsermodel.h" 10 #include "dvdirtreeview.h" 11 12 #include <QTreeView> 13 #include <QItemDelegate> 14 15 // forward declaration 16 class QLabel; 17 class ExportSceneTreeView; 18 class QRadioButton; 19 20 //============================================================================= 21 // ExportSceneDvDirModelFileFolderNode 22 23 class ExportSceneDvDirModelFileFolderNode : public DvDirModelFileFolderNode { 24 public: ExportSceneDvDirModelFileFolderNode(DvDirModelNode * parent,std::wstring name,const TFilePath & path)25 ExportSceneDvDirModelFileFolderNode(DvDirModelNode *parent, std::wstring name, 26 const TFilePath &path) 27 : DvDirModelFileFolderNode(parent, name, path) {} ExportSceneDvDirModelFileFolderNode(DvDirModelNode * parent,const TFilePath & path)28 ExportSceneDvDirModelFileFolderNode(DvDirModelNode *parent, 29 const TFilePath &path) 30 : DvDirModelFileFolderNode(parent, path) {} 31 32 DvDirModelNode *makeChild(std::wstring name) override; 33 virtual DvDirModelFileFolderNode *createExposeSceneNode( 34 DvDirModelNode *parent, const TFilePath &path); 35 }; 36 37 //============================================================================= 38 // ExportSceneDvDirModelSpecialFileFolderNode 39 40 class ExportSceneDvDirModelSpecialFileFolderNode final 41 : public ExportSceneDvDirModelFileFolderNode { 42 QPixmap m_pixmap; 43 44 public: ExportSceneDvDirModelSpecialFileFolderNode(DvDirModelNode * parent,std::wstring name,const TFilePath & path)45 ExportSceneDvDirModelSpecialFileFolderNode(DvDirModelNode *parent, 46 std::wstring name, 47 const TFilePath &path) 48 : ExportSceneDvDirModelFileFolderNode(parent, name, path) {} getPixmap(bool isOpen)49 QPixmap getPixmap(bool isOpen) const override { return m_pixmap; } setPixmap(const QPixmap & pixmap)50 void setPixmap(const QPixmap &pixmap) { m_pixmap = pixmap; } 51 }; 52 53 //============================================================================= 54 // ExportSceneDvDirModelProjectNode 55 56 class ExportSceneDvDirModelProjectNode final 57 : public ExportSceneDvDirModelFileFolderNode { 58 public: ExportSceneDvDirModelProjectNode(DvDirModelNode * parent,const TFilePath & path)59 ExportSceneDvDirModelProjectNode(DvDirModelNode *parent, 60 const TFilePath &path) 61 : ExportSceneDvDirModelFileFolderNode(parent, path) {} makeCurrent()62 void makeCurrent() {} 63 bool isCurrent() const; 64 QPixmap getPixmap(bool isOpen) const override; 65 66 virtual DvDirModelFileFolderNode *createExposeSceneNode( 67 DvDirModelNode *parent, const TFilePath &path) override; 68 }; 69 70 //============================================================================= 71 // ExportSceneDvDirModelRootNode 72 73 class ExportSceneDvDirModelRootNode final : public DvDirModelNode { 74 std::vector<ExportSceneDvDirModelFileFolderNode *> m_projectRootNodes; 75 ExportSceneDvDirModelFileFolderNode *m_sandboxProjectNode; 76 void add(std::wstring name, const TFilePath &path); 77 78 public: 79 ExportSceneDvDirModelRootNode(); 80 81 void refreshChildren() override; 82 DvDirModelNode *getNodeByPath(const TFilePath &path) override; 83 }; 84 85 //============================================================================= 86 // ExportSceneDvDirModel 87 88 class ExportSceneDvDirModel final : public QAbstractItemModel { 89 DvDirModelNode *m_root; 90 91 public: 92 ExportSceneDvDirModel(); 93 ~ExportSceneDvDirModel(); 94 95 DvDirModelNode *getNode(const QModelIndex &index) const; 96 QModelIndex index(int row, int column, 97 const QModelIndex &parent) const override; 98 QModelIndex parent(const QModelIndex &index) const override; 99 QModelIndex childByName(const QModelIndex &parent, 100 const std::wstring &name) const; columnCount(const QModelIndex & parent)101 int columnCount(const QModelIndex &parent) const override { return 1; } 102 QVariant data(const QModelIndex &index, 103 int role = Qt::DisplayRole) const override; 104 Qt::ItemFlags flags(const QModelIndex &index) const override; 105 bool setData(const QModelIndex &index, const QVariant &value, 106 int role = Qt::EditRole) override; 107 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 108 bool hasChildren(const QModelIndex &parent) const override; 109 void refresh(const QModelIndex &index); 110 }; 111 112 //============================================================================= 113 // ExportSceneTreeViewDelegate 114 115 class ExportSceneTreeViewDelegate final : public QItemDelegate { 116 Q_OBJECT 117 ExportSceneTreeView *m_treeView; 118 119 public: 120 ExportSceneTreeViewDelegate(ExportSceneTreeView *parent); 121 ~ExportSceneTreeViewDelegate(); 122 void paint(QPainter *painter, const QStyleOptionViewItem &option, 123 const QModelIndex &index) const override; 124 QSize sizeHint(const QStyleOptionViewItem &option, 125 const QModelIndex &index) const override; 126 }; 127 128 //============================================================================= 129 // ExportSceneTreeView 130 131 class ExportSceneTreeView final : public StyledTreeView { 132 Q_OBJECT 133 ExportSceneDvDirModel *m_model; 134 135 public: 136 ExportSceneTreeView(QWidget *parent); 137 QSize sizeHint() const override; 138 DvDirModelNode *getCurrentNode() const; 139 140 protected: 141 void refresh(); 142 void showEvent(QShowEvent *) override; 143 void focusInEvent(QFocusEvent *event) override; 144 145 public slots: 146 void resizeToConts(); 147 148 signals: 149 void focusIn(); 150 }; 151 152 //============================================================================= 153 // ExportScenePopup 154 155 class ExportScenePopup final : public DVGui::Dialog { 156 Q_OBJECT 157 158 std::vector<TFilePath> m_scenes; 159 // QLabel* m_command; 160 QLabel *m_newProjectNameLabel; 161 DVGui::LineEdit *m_newProjectName; 162 ExportSceneTreeView *m_projectTreeView; 163 QRadioButton *m_newProjectButton; 164 QRadioButton *m_chooseProjectButton; 165 166 bool m_createNewProject; 167 168 public: 169 ExportScenePopup(std::vector<TFilePath> scenes); 170 setScenes(std::vector<TFilePath> scenes)171 void setScenes(std::vector<TFilePath> scenes) { 172 m_scenes = scenes; 173 // updateCommandLabel(); 174 } 175 176 protected slots: 177 void switchMode(int id); 178 void onProjectTreeViweFocusIn(); 179 void onProjectNameFocusIn(); 180 void onExport(); 181 182 protected: 183 //! Create new project and return new project path. 184 TFilePath createNewProject(); 185 // void updateCommandLabel(); 186 }; 187 188 #endif // EXPORTSCENEPOPUP_H 189