1 #pragma once
2 
3 #ifndef FXSETTINGS_H
4 #define FXSETTINGS_H
5 
6 #ifdef _MSC_VER
7 #pragma warning(disable : 4251)
8 #endif
9 
10 #include <QSplitter>
11 #include <QToolBar>
12 #include <QStackedWidget>
13 #include <QScrollArea>
14 #include <QMap>
15 #include <QGroupBox>
16 
17 #include "tcommon.h"
18 #include "tfx.h"
19 #include "tabbar.h"
20 #include "gutil.h"
21 
22 #include "toonzqt/framenavigator.h"
23 #include "toonzqt/paramfield.h"
24 #include "toonzqt/swatchviewer.h"
25 #include "toonzqt/fxhistogramrender.h"
26 
27 #undef DVAPI
28 #undef DVVAR
29 #ifdef TOONZQT_EXPORTS
30 #define DVAPI DV_EXPORT_API
31 #define DVVAR DV_EXPORT_VAR
32 #else
33 #define DVAPI DV_IMPORT_API
34 #define DVVAR DV_IMPORT_VAR
35 #endif
36 
37 // forward declaration
38 class QToolBar;
39 class QStackedWidget;
40 class QVBoxLayout;
41 class QGridLayout;
42 class QPushButton;
43 class FxKeyframeNavigator;
44 class ParamViewer;
45 class TFxHandle;
46 class TFrameHandle;
47 class TXsheetHandle;
48 class TSceneHandle;
49 class TXshLevelHandle;
50 class TObjectHandle;
51 class ToonzScene;
52 
53 //=============================================================================
54 /*! \brief ParamsPage. View a page with fx params.
55 
56                 Inherits \b QWidget.
57 */
58 class DVAPI ParamsPage final : public QFrame {
59   Q_OBJECT
60 
61   QColor m_textColor; /*-- 文字の色 デフォルト黒 --*/
62   Q_PROPERTY(QColor TextColor READ getTextColor WRITE setTextColor)
63 
64   QGridLayout *m_mainLayout;
65   QHBoxLayout *m_horizontalLayout;
66   QGridLayout *m_groupLayout;
67 
68   friend class ParamViewer;
69   QVector<ParamField *> m_fields;
70   /*! To menage eventually histogram in page. */
71   FxHistogramRender *m_fxHistogramRender;
72 
73   ParamViewer *m_paramViewer;
74 
75 public:
76   ParamsPage(QWidget *parent = 0, ParamViewer *paramViewer = 0);
77   ~ParamsPage();
78 
setPage(TIStream & is,const TFxP & fx)79   void setPage(TIStream &is, const TFxP &fx) {
80     setPageField(is, fx);
81     setPageSpace();
82   }
83 
84   void setFx(const TFxP &currentFx, const TFxP &actualFx, int frame);
85 
86   void update(int frame);
87   void setPointValue(int index, const TPointD &p);
88 
getFxHistogramRender()89   FxHistogramRender *getFxHistogramRender() const {
90     return m_fxHistogramRender;
91   }
92 
93   /*- 現在のページの最適なサイズを返す -*/
94   QSize getPreferredSize();
95 
setTextColor(const QColor & color)96   void setTextColor(const QColor &color) { m_textColor = color; }
getTextColor()97   QColor getTextColor() const { return m_textColor; }
98 
99 protected:
100   void setPageField(TIStream &is, const TFxP &fx, bool isVertical = true);
101 
102 public:
103   void setPageSpace();
104   void beginGroup(const char *name);
105   void endGroup();
106 
107   void addWidget(QWidget *, bool isVertical = true);
108 
109 #define TOONZ_DECLARE_NEW_COMPONENT(NAME)                                      \
110   QWidget *NAME(TFx *fx, const char *name)
111 
112   TOONZ_DECLARE_NEW_COMPONENT(newParamField);
113   TOONZ_DECLARE_NEW_COMPONENT(newLineEdit);
114   TOONZ_DECLARE_NEW_COMPONENT(newSlider);
115   TOONZ_DECLARE_NEW_COMPONENT(newSpinBox);
116   TOONZ_DECLARE_NEW_COMPONENT(newCheckBox);
117   TOONZ_DECLARE_NEW_COMPONENT(newRadioButton);
118   TOONZ_DECLARE_NEW_COMPONENT(newComboBox);
119 
120 #undef TOONZ_DECLARE_NEW_COMPONENT
121 
122   // make ParamsPageSet to re-compute preferred size.
123   // currently emitted only from ToneCurveParamField
124 signals:
125   void preferredPageSizeChanged();
126 };
127 
128 //=============================================================================
129 /*! \brief ParamsPageSet. Contains a stack of page \b ParamsPage with relative
130    tab.
131 
132                 Inherits \b QWidget.
133 */
134 class DVAPI ParamsPageSet final : public QWidget {
135   Q_OBJECT
136 
137   TabBarContainter *m_tabBarContainer;
138   DVGui::TabBar *m_tabBar;
139   QStackedWidget *m_pagesList;
140 
141   ParamViewer *m_parent;
142 
143   //! Allows to map page and index, useful to display a macro.
144   QMap<ParamsPage *, int> m_pageFxIndexTable;
145 
146   QSize m_preferredSize;
147   /*-- ヘルプのファイルパス(もしあれば)---*/
148   std::string m_helpFilePath;
149   /*-- pdfファイルのページ指定など、引数が必要な場合の追加引数 --*/
150   std::string m_helpCommand;
151   /*-- ヘルプボタンで開くURL --*/
152   std::string m_helpUrl;
153   QPushButton *m_helpButton;
154 
155 public:
156 #if QT_VERSION >= 0x050500
157   ParamsPageSet(QWidget *parent = 0, Qt::WindowFlags flags = 0);
158 #else
159   ParamsPageSet(QWidget *parent = 0, Qt::WFlags flags = 0);
160 #endif
161   ~ParamsPageSet();
162 
163   void setFx(const TFxP &currentFx, const TFxP &actualFx, int frame);
164   void setScene(ToonzScene *scene);
165   void setIsCameraViewMode(bool isCameraViewMode);
166 
167   void updatePage(int frame, bool onlyParam);
168   /*! Create a page reading xml file relating to \b fx. */
169   void createControls(const TFxP &fx, int index = -1);
170 
171   ParamsPage *getCurrentParamsPage() const;
172   ParamsPage *getParamsPage(int index) const;
getParamsPageCount()173   int getParamsPageCount() const { return (int)m_pagesList->count(); };
174 
175   ParamsPage *createParamsPage();
176   void addParamsPage(ParamsPage *page, const char *name);
177 
getPreferredSize()178   QSize getPreferredSize() { return m_preferredSize; }
179 
180 protected:
181   void createPage(TIStream &is, const TFxP &fx, int index);
182 
183 protected slots:
184   void setPage(int);
185   void openHelpFile();
186   void openHelpUrl();
187   void recomputePreferredSize();
188 };
189 
190 //=============================================================================
191 /*! \brief ParamViewer. Contains a stack of \b ParamsPageSet.
192 
193                 Inherits \b QWidget.
194 */
195 class DVAPI ParamViewer final : public QFrame {
196   Q_OBJECT
197 
198   TFxP m_fx;
199   TFxP m_actualFx;
200 
201   QStackedWidget *m_tablePageSet;
202   QMap<std::string, int> m_tableFxIndex;
203 
204 public:
205 #if QT_VERSION >= 0x050500
206   ParamViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0);
207 #else
208   ParamViewer(QWidget *parent = 0, Qt::WFlags flags = 0);
209 #endif
210   ~ParamViewer();
211 
212   void setFx(const TFxP &currentFx, const TFxP &actualFx, int frame,
213              ToonzScene *scene);
214   void setScene(ToonzScene *scene);
215   void setIsCameraViewMode(bool isCameraViewMode);
216   /*! If onlyParam is true don't invalidate raster of associated histogram. */
217   void update(int frame, bool onlyParam);
218 
219   void setPointValue(int index, const TPointD &p);
220 
notifyPreferredSizeChanged(QSize size)221   void notifyPreferredSizeChanged(QSize size) {
222     emit preferredSizeChanged(size);
223   }
224 
225 protected:
226   ParamsPageSet *getCurrentPageSet() const;
227 
228 signals:
229   void currentFxParamChanged();
230   void actualFxParamChanged();
231   void paramKeyChanged();
232 
233   void preferredSizeChanged(QSize);
234   void showSwatchButtonToggled(bool);
235 };
236 
237 //=============================================================================
238 /*! \brief FxSettings.
239 
240                 Inherits \b QWidget.
241 */
242 
243 class QActionGroup;
244 class DVAPI FxSettings final : public QSplitter {
245   Q_OBJECT
246 
247   QToolBar *m_toolBar;
248   QAction *m_checkboardBg;
249   ParamViewer *m_paramViewer;
250   SwatchViewer *m_viewer;
251 
252   TFxHandle *m_fxHandle;
253   TXsheetHandle *m_xsheetHandle;
254   TSceneHandle *m_sceneHandle;
255   TXshLevelHandle *m_levelHandle;
256   TFrameHandle *m_frameHandle;
257   TObjectHandle *m_objectHandle;
258 
259   FxKeyframeNavigator *m_keyframeNavigator;
260   FrameNavigator *m_frameNavigator;
261 
262   TPixel32 m_checkCol1, m_checkCol2;
263 
264   bool m_isCameraModeView;
265 
266   int m_container_height;
267   int m_container_width;
268 
269 public:
270   FxSettings(QWidget *parent, const TPixel32 &checkCol1,
271              const TPixel32 &checkCol2);
272   ~FxSettings();
273 
274   // Devono essere settati!
275   void setFxHandle(TFxHandle *fxHandle);
getFxHandle()276   TFxHandle *getFxHandle() const { return m_fxHandle; }
277   void setFrameHandle(TFrameHandle *frameHandle);
getFrameHandle()278   TFrameHandle *getFrameHandle() const { return m_frameHandle; }
279   void setXsheetHandle(TXsheetHandle *XsheetHandle);
getXsheetHandle()280   TXsheetHandle *getXsheetHandle() const { return m_xsheetHandle; }
281   void setSceneHandle(TSceneHandle *sceneHandle);
getSceneHandle()282   TSceneHandle *getSceneHandle() const { return m_sceneHandle; }
283   void setLevelHandle(TXshLevelHandle *levelHandle);
getLevelHandle()284   TXshLevelHandle *getLevelHandle() const { return m_levelHandle; }
285   void setObjectHandle(TObjectHandle *objectHandle);
getObjectHandle()286   TObjectHandle *getObjectHandle() const { return m_objectHandle; }
287 
288 public slots:
289   void setCurrentFrame();
290   void setCurrentFx();
291   void setCurrentScene();
292   void notifySceneChanged();
293 
294 protected:
295   /*! \b currentFx is fx with parent, \b actualFx is simple fx. */
296   void setFx(const TFxP &currentFx, const TFxP &actualFx);
297 
298   void createToolBar();
299   void showEvent(QShowEvent *) override;
300   void hideEvent(QHideEvent *) override;
301   void setCheckboardColors(const TPixel32 &col1, const TPixel32 &col2);
302 
303   void changeTitleBar(TFx *fx);
304 
305 protected slots:
306   void updateViewer();
307   void updateParamViewer();
308   void onPointChanged(int index, const TPointD &p);
309   void onViewModeChanged(QAction *);
310 
311   void setWhiteBg();
312   void setBlackBg();
313   void setCheckboardBg();
314 
315   void onPreferredSizeChanged(QSize);
316   void onShowSwatchButtonToggled(bool);
317 };
318 
319 #endif  // FXSETTINGS_H
320