1 #pragma once
2 
3 #ifndef BOARDSETTINGSPOPUP_H
4 #define BOARDSETTINGSPOPUP_H
5 
6 #include "toonzqt/dvdialog.h"
7 #include "tpixel.h"
8 #include "filebrowserpopup.h"
9 #include <QWidget>
10 #include <QStackedWidget>
11 
12 class TOutputProperties;
13 class QLineEdit;
14 class QTextEdit;
15 class QComboBox;
16 class QFontComboBox;
17 class QListWidget;
18 class BoardItem;
19 
20 namespace DVGui {
21 class FileField;
22 class ColorField;
23 class IntLineEdit;
24 }  // namespace DVGui
25 
26 //=============================================================================
27 
28 class BoardView : public QWidget {
29   Q_OBJECT
30 
31   enum DragItem {
32     None = 0,
33     Translate,
34     TopLeftCorner,
35     TopRightCorner,
36     BottomRightCorner,
37     BottomLeftCorner,
38     TopEdge,
39     RightEdge,
40     BottomEdge,
41     LeftEdge
42   } m_dragItem = None;
43 
44   QImage m_boardImg;
45   bool m_valid = false;
46 
47   QRectF m_boardImgRect;
48 
49   QRectF m_dragStartItemRect;
50   QPointF m_dragStartPos;
51 
52 public:
53   BoardView(QWidget* parent = nullptr);
invalidate()54   void invalidate() { m_valid = false; }
55 
56 protected:
57   void paintEvent(QPaintEvent* event) override;
58   void resizeEvent(QResizeEvent* event) override;
59 
60   void mouseMoveEvent(QMouseEvent* event) override;
61   void mousePressEvent(QMouseEvent* event) override;
62   void mouseReleaseEvent(QMouseEvent* event) override;
63 };
64 
65 //=============================================================================
66 
67 class ItemInfoView : public QStackedWidget {
68   Q_OBJECT
69 
70   QLineEdit* m_nameEdit;
71   DVGui::IntLineEdit* m_maxFontSizeEdit;
72   QComboBox* m_typeCombo;
73   QTextEdit* m_textEdit;
74   DVGui::FileField* m_imgPathField;
75   QFontComboBox* m_fontCombo;
76   QPushButton *m_boldButton, *m_italicButton;
77   DVGui::ColorField* m_fontColorField;
78   QComboBox* m_imgARModeCombo;
79 
80   QWidget *m_fontPropBox, *m_imgPropBox;
81 
82 public:
83   ItemInfoView(QWidget* parent = nullptr);
84   void setCurrentItem(int index);
85 
86 protected slots:
87   void onNameEdited();
88   void onMaxFontSizeEdited();
89   void onTypeComboActivated(int);
90   void onFreeTextChanged();
91   void onImgPathChanged();
92   void onFontComboChanged(const QFont&);
93   void onBoldButtonClicked(bool);
94   void onItalicButtonClicked(bool);
95   void onFontColorChanged(const TPixel32&, bool);
96   void onImgARModeComboActivated();
97 
98 signals:
99   // if updateListView is true then update the list view as well
100   void itemPropertyChanged(bool updateListView);
101 };
102 
103 //=============================================================================
104 
105 class ItemListView : public QWidget {
106   Q_OBJECT
107   QListWidget* m_list;
108   QPushButton *m_deleteItemBtn, *m_moveUpBtn, *m_moveDownBtn;
109 
110 public:
111   ItemListView(QWidget* parent = nullptr);
112   void initialize();
113   void updateCurrentItem();
114 protected slots:
115   void onCurrentItemSwitched(int);
116   void onNewItemButtonClicked();
117   void onDeleteItemButtonClicked();
118   void onMoveUpButtonClicked();
119   void onMoveDownButtonClicked();
120 signals:
121   void currentItemSwitched(int);
122   void itemAddedOrDeleted();
123 };
124 
125 //=============================================================================
126 
127 class BoardSettingsPopup : public DVGui::Dialog {
128   Q_OBJECT
129 
130   BoardView* m_boardView;
131   ItemInfoView* m_itemInfoView;
132   ItemListView* m_itemListView;
133 
134   DVGui::IntLineEdit* m_durationEdit;
135 
136   void initialize();
137   void initializeItemTypeString();  // call once on the first launch
138 public:
139   static BoardItem* currentBoardItem;
140 
141   BoardSettingsPopup(QWidget* parent = nullptr);
142 
143 protected:
showEvent(QShowEvent *)144   void showEvent(QShowEvent*) override { initialize(); }
145   void hideEvent(QHideEvent*) override;
146 protected slots:
147   void onCurrentItemSwitched(int);
148   void onItemAddedOrDeleted();
149   void onItemPropertyChanged(bool updateListView);
150   void onDurationEdited();
151   void onLoadPreset();
152   void onSavePreset();
153 };
154 
155 //=============================================================================
156 
157 class SaveBoardPresetFilePopup final : public GenericSaveFilePopup {
158   Q_OBJECT
159 public:
160   SaveBoardPresetFilePopup();
161 
162 protected:
163   void showEvent(QShowEvent*) override;
164 };
165 
166 //=============================================================================
167 
168 class LoadBoardPresetFilePopup final : public GenericLoadFilePopup {
169   Q_OBJECT
170 public:
171   LoadBoardPresetFilePopup();
172 
173 protected:
174   void showEvent(QShowEvent*) override;
175 };
176 
177 #endif
178