fluidvis
SXEditor.h
1 #ifndef _SX_SXEDITOR_H_
2 #define _SX_SXEDITOR_H_
3 
8 #include <export/Export.h>
9 #include <QWidget>
10 #include <QSplitter>
11 #include <QTabWidget>
12 #include <QToolButton>
13 #include <QLabel>
14 #include <QStackedWidget>
15 #include <QLayout>
16 #include <sx/SXWidget.h>
17 #include <QLineEdit>
18 #include <QDialog>
19 #include <QGraphicsScene>
20 #include <QCompleter>
21 #include <string>
22 #include <boost/unordered_map.hpp>
23 using namespace boost;
24 using namespace std;
25 
26 namespace sx {
27 
28  enum LayoutExpansion {
29  EXPAND_VERTICALLY,
30  EXPAND_HORIZONTALLY
31  };
32 
33  class SequenceLayout: public QLayout
34  {
35  Q_OBJECT
36  private:
37  QList<QLayoutItem *> items;
38  LayoutExpansion expansion;
39  int margin_bottom;
40  int margin_top;
41  int margin_left;
42  int margin_right;
43 
45  SequenceLayout &operator = (const SequenceLayout &);
46  public:
47  SequenceLayout(LayoutExpansion expansion);
48 
49  void setMargin(int margin_bottom, int margin_top, int margin_left, int margin_right);
50  void setMargin(int margin);
51 
52  void addItem(QLayoutItem *);
53  int count() const;
54  QLayoutItem *itemAt(int index) const;
55  QLayoutItem *takeAt(int index);
56  void setGeometry(const QRect &);
57  QSize sizeHint() const;
58  QSize minimumSize() const;
59  bool hasHeightForWidth() const;
60  int heightForWidth(int) const;
61  };
62 
63  class ClickableLabel: public QLabel {
64  Q_OBJECT
65  private:
67  ClickableLabel &operator = (const ClickableLabel &);
68  protected:
69  void mousePressEvent(QMouseEvent *ev);
70  public:
71  ClickableLabel(QWidget * parent = 0, Qt::WindowFlags f = 0);
72  ClickableLabel(const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0);
73  signals:
74  void clicked();
75  };
76 
77  class Warning: public QDialog {
78  Q_OBJECT
79  private:
80  void initGui(const QString &msg);
81 
82  Warning(const Warning &);
83  Warning &operator = (const Warning &);
84  public:
85  Warning(const QString &title, const QString &text, QWidget *w);
86  };
87 
88  struct SXLogicObject {
89  string ID;
90  unordered_map<int,unordered_map<int,int> > guiParts;
91  };
92 
93  struct SXLogicPass: public SXLogicObject {
94  };
95 
96  struct SXLogicObjects {
97  private:
98  static unordered_map<int,int> nextIDs;
99  public:
100  static unordered_map<string,SXLogicObject *> objects;
101  static unordered_map<string,unordered_map<int,int> > effects;
102  static unordered_map<string,SXLogicPass *> passes;
103  static unordered_map<string,unordered_map<int,int> > renderobjects;
104  static unordered_map<string,unordered_map<int,int> > meshes;
105  static unordered_map<string,unordered_map<int,int> > shaders;
106  static unordered_map<string,unordered_map<int,int> > rendertargets;
107  static unordered_map<string,unordered_map<int,int> > textures;
108  static unordered_map<string,unordered_map<int,int> > matrices;
109  static unordered_map<string,unordered_map<int,int> > vectors;
110  static unordered_map<string,unordered_map<int,int> > floats;
111 
112  static bool checkAddPass(const string &ID);
113  static void addPass(const string &ID, int diagramID, int guiID);
114  static void changePass(const string &oldID, const string &newID, int diagramID, int guiID);
115  static void removePass(const string &ID, int diagramID, int guiID);
116 
117  static void updateNextID(int diagramID, int existingID);
118  static int getNextID(int diagramID);
119  };
120 
121  class GraphEditPane;
122 
123  struct ConfigParts {
124  int ID;
125  QWidget *tools;
126  GraphEditPane *graphEdit;
127  QWidget *detailEdit;
128  QToolButton *closeDetailButton;
129  QWidget *detailEditPane;
130  };
131 
132  enum EditMode {
133  MODE_NONE,
134  MODE_ADDPASS,
135 
136  MODE_EDITPASS,
137 
138  MODE_MOVE,
139  };
140 
141  class ChooseIDDialog: public QDialog {
142  Q_OBJECT
143  private:
144  EditMode editMode;
145  QLineEdit *input;
146  QCompleter *completer;
147  QString ID;
148 
149  void initGui();
151  ChooseIDDialog &operator = (const ChooseIDDialog &);
152  private slots:
153  void choose();
154  public:
155  ChooseIDDialog(EditMode mode, QWidget *w = 0);
156  const QString getID() const;
157  };
158 
159  class ChangeIDInput: public QWidget {
160  Q_OBJECT
161  private:
162  GraphEditPane *scene;
163  EditMode editMode;
164  ClickableLabel *label;
165  QDialog *inputWidget;
166  QLineEdit *input;
167  QCompleter *completer;
168  QString ID;
169  int diagramID;
170  int guiID;
171 
172  void initGui();
173  ChangeIDInput(const ChangeIDInput &);
174  ChangeIDInput &operator = (const ChangeIDInput &);
175  private slots:
176  void awaitInput();
177  void takeInput();
178  void discardInput();
179  public:
180  ChangeIDInput(EditMode mode, const QString &ID, int diagramID, int guiID, GraphEditPane *scene = 0);
181  void setID(const QString &ID);
182  const QString getID() const;
183  public slots:
184  void showLabel();
185  void showInput();
186  signals:
187  void changedGui();
188  };
189 
190  class ChangeUniformInput: public QWidget {
191  Q_OBJECT
192  private:
193  GraphEditPane *scene;
194  EditMode editMode;
195  ClickableLabel *label;
196  QDialog *inputWidget;
197  QLineEdit *input;
198  QLabel *assignmentLabel;
199  QLineEdit *valueInput;
200  QToolButton *addValueButton;
201  QToolButton *removeValueButton;
202  QCompleter *completer;
203  QCompleter *valueCompleter;
204  QString ID;
205  int diagramID;
206  int guiID;
207 
208  void initGui();
210  ChangeUniformInput &operator = (const ChangeUniformInput &);
211  private slots:
212  void awaitInput();
213  void takeInput();
214  void discardInput();
215  public:
216  ChangeUniformInput(EditMode mode, const QString &ID, int diagramID, int guiID, GraphEditPane *scene = 0);
217  void setID(const QString &ID);
218  const QString getID() const;
219  public slots:
220  void showLabel();
221  void showInput();
222  signals:
223  void changedGui();
224  };
225 
226  class GraphicWidget: public QWidget {
227  Q_OBJECT
228  protected:
229  int guiID;
230  GraphEditPane *scene;
231 
232  GraphicWidget(int guiID, GraphEditPane *scene, QWidget *parent = 0);
233  protected slots:
234  void startMove();
235  private:
236  GraphicWidget(const GraphicWidget &);
237  GraphicWidget &operator = (const GraphicWidget &);
238  public:
239  virtual void setID(const QString &ID) = 0;
240  virtual const QString getID() const = 0;
241  int getGuiID() const;
242  public slots:
243  void pack();
244  virtual void removeDiagramItem() = 0;
245  };
246 
247  class PassWidget: public GraphicWidget {
248  Q_OBJECT
249  private:
250  ClickableLabel *titleLabel;
251  ChangeIDInput *IDgui;
252 
253  void initGui();
254  PassWidget(int guiID, const PassWidget &);
255  PassWidget &operator = (const PassWidget &);
256  public:
257  PassWidget(const QString &ID, int guiID, GraphEditPane *scene, QWidget *parent = 0);
258  void setID(const QString &ID);
259  const QString getID() const;
260  protected:
261  void paintEvent(QPaintEvent *);
262  public slots:
263  void removeDiagramItem();
264  };
265 
266  class GraphEditPane: public QGraphicsScene {
267  Q_OBJECT
268  private:
269  int diagramID;
270  unordered_map<int,GraphicWidget *> nodes;
271  QWidget *parentWidget;
272  QGraphicsView *view;
273  QString nextID;
274  EditMode editMode;
275  QPointF movePoint;
276 
277  GraphEditPane(const GraphEditPane &);
278  GraphEditPane &operator = (const GraphEditPane &);
279  public:
280  GraphEditPane(int diagramID, const QSize &size,QWidget *parent = 0);
281  int getDiagramID() const;
282  void setNextID(const QString &ID);
283  void setEditMode(EditMode mode);
284  void addPass(const QPointF &point, const QString &ID, int guiID);
285  void addNode(GraphicWidget &node);
286  void removeNode(int guiID);
287  void setGraphicsView(QGraphicsView *view);
288  QGraphicsView *getGraphicsView();
289  protected:
290  void mousePressEvent(QGraphicsSceneMouseEvent *event);
291  void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
292  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
293  void keyPressEvent(QKeyEvent *keyEvent);
294  public slots:
295  void removeDiagramItems();
296  signals:
297  void removingDiagramItems();
298  };
299 
300  class SXEditor: public QWidget {
301  Q_OBJECT
302  private:
303  QStackedWidget *mainGuis;
304 
305  QWidget *start;
306 
307  QSplitter *splitter;
308  int nextConfigID;
309  QTabWidget *configurations;
310  QVector<ConfigParts> configParts;
311  QAction *addPassAction;
312  SXWidget *renderer;
313 
314  SXEditor(const SXEditor &);
315  SXEditor &operator = (const SXEditor &);
316  void initGui();
317  private slots:
318  void createDialog();
319  void openDialog();
320  void setAddPass();
321  public:
322  SXEditor();
323  ~SXEditor();
324  void addConfiguration(const QString &path = "", bool load = false);
325  QSize sizeHint() const;
326  ConfigParts &currentConfig();
327  public slots:
328  void removeConfiguration(int index);
329  };
330 
331  class CreateConfigDialog: public QDialog {
332  Q_OBJECT
333  private:
334  QLineEdit *input;
335 
336  void initGui();
338  CreateConfigDialog &operator = (const CreateConfigDialog &);
339  private slots:
340  void create();
341  public:
342  CreateConfigDialog(QWidget *w);
343  const QString getText() const;
344  };
345 
346 }
347 
348 #endif
Definition: SXEditor.h:226
Definition: SXEditor.h:300
Definition: SXEditor.h:159
Definition: SXEditor.h:33
Definition: SXEditor.h:141
Definition: SXEditor.h:266
Definition: SXEditor.h:331
Definition: SXWidget.h:112
Definition: SXEditor.h:247
Definition: SXEditor.h:77
Definition: SXEditor.h:96
Definition: SXEditor.h:190
Definition: SXEditor.h:63
Definition: SXEditor.h:123
Definition: SXEditor.h:88
Definition: SXEditor.h:93
Definition: Exception.h:13