1 #ifndef SHINY_EDITOR_MAINWINDOW_HPP
2 #define SHINY_EDITOR_MAINWINDOW_HPP
3 
4 #include <QMainWindow>
5 
6 #include <QSortFilterProxyModel>
7 #include <QStandardItemModel>
8 #include <QStringListModel>
9 
10 #include <queue>
11 
12 #include "Actions.hpp"
13 #include "Query.hpp"
14 
15 #include "PropertySortModel.hpp"
16 
17 namespace Ui {
18 class MainWindow;
19 }
20 
21 namespace sh
22 {
23 
24 struct SynchronizationState;
25 
26 
27 /**
28  * @brief A snapshot of the material system's state. Lock the mUpdateMutex before accessing.
29  */
30 struct MaterialSystemState
31 {
32 	std::vector<std::string> mMaterialList;
33 
34 	std::map<std::string, std::string> mGlobalSettingsMap;
35 
36 	std::vector<std::string> mConfigurationList;
37 
38 	std::vector<std::string> mMaterialFiles;
39 	std::vector<std::string> mConfigurationFiles;
40 
41 	std::vector<std::string> mShaderSets;
42 
43 	std::string mErrors;
44 };
45 
46 class MainWindow : public QMainWindow
47 {
48     Q_OBJECT
49 
50 public:
51     explicit MainWindow(QWidget *parent = 0);
52     ~MainWindow();
53 
54 	// really should be an std::atomic
55 	volatile bool mRequestShowWindow;
56 	// dito
57 	volatile bool mRequestExit;
58 
59 	SynchronizationState* mSync;
60 
61 	/// \todo Is there a better way to ignore manual model changes?
62 	bool mIgnoreGlobalSettingChange;
63 	bool mIgnoreConfigurationChange;
64 	bool mIgnoreMaterialChange;
65 	bool mIgnoreMaterialPropertyChange;
66 
67 	std::queue<Action*> mActionQueue;
68 	std::vector<Query*> mQueries;
69 
70 	MaterialSystemState mState;
71 
72 private:
73 	Ui::MainWindow *ui;
74 
75 	// material tab
76 	QStringListModel* mMaterialModel;
77 	QSortFilterProxyModel* mMaterialProxyModel;
78 
79 	QStandardItemModel* mMaterialPropertyModel;
80 	PropertySortModel* mMaterialSortModel;
81 
82 	// global settings tab
83 	QStandardItemModel* mGlobalSettingsModel;
84 
85 	// configuration tab
86 	QStandardItemModel* mConfigurationModel;
87 
88 	void queueAction(Action* action);
89 	void requestQuery(Query* query);
90 
91 	void buildMaterialModel (MaterialQuery* data);
92 	void buildConfigurationModel (ConfigurationQuery* data);
93 
94 	QString getSelectedMaterial();
95 
96 	/// get the context of an index in the material property model
97 	void getContext(QModelIndex index, int* passIndex, int* textureIndex, bool* isInPass=NULL, bool* isInTextureUnit=NULL);
98 
99 	std::string getPropertyKey(QModelIndex index);
100 	std::string getPropertyValue(QModelIndex index);
101 
102 	void addProperty (QStandardItem* parent, const std::string& key, MaterialProperty value, bool scrollTo=false);
103 
104 protected:
105 	void closeEvent(QCloseEvent *event);
106 
107 public slots:
108 	void onIdle();
109 
110 	void onMaterialSelectionChanged (const QModelIndex & current, const QModelIndex & previous);
111 	void onConfigurationSelectionChanged (const QString& current);
112 
113 	void onGlobalSettingChanged (QStandardItem* item);
114 	void onConfigurationChanged (QStandardItem* item);
115 	void onMaterialPropertyChanged (QStandardItem* item);
116 
117 	void onContextMenuRequested(const QPoint& point);
118 
119 private slots:
120 	void on_lineEdit_textEdited(const QString &arg1);
121 	void on_actionSave_triggered();
122 	void on_actionNewMaterial_triggered();
123 	void on_actionDeleteMaterial_triggered();
124 	void on_actionQuit_triggered();
125 	void on_actionNewConfiguration_triggered();
126 	void on_actionDeleteConfiguration_triggered();
127 	void on_actionDeleteConfigurationProperty_triggered();
128 	void on_actionCloneMaterial_triggered();
129 	void on_actionCreatePass_triggered();
130 	void on_actionDeleteProperty_triggered();
131 	void on_actionNewProperty_triggered();
132 	void on_actionCreateTextureUnit_triggered();
133 	void on_clearButton_clicked();
134 	void on_tabWidget_currentChanged(int index);
135 };
136 
137 }
138 
139 #endif // MAINWINDOW_HPP
140