1 #pragma once
2 
3 #ifndef TXSHCOLUMN_INCLUDED
4 #define TXSHCOLUMN_INCLUDED
5 
6 #include "tcolumnset.h"
7 #include "tpersist.h"
8 #include "traster.h"
9 
10 #include <QPair>
11 #include <QString>
12 
13 #undef DVAPI
14 #undef DVVAR
15 #ifdef TOONZLIB_EXPORTS
16 #define DVAPI DV_EXPORT_API
17 #define DVVAR DV_EXPORT_VAR
18 #else
19 #define DVAPI DV_IMPORT_API
20 #define DVVAR DV_IMPORT_VAR
21 #endif
22 
23 //=============================================================================
24 // forward declarations
25 class TXshLevelColumn;
26 class TXshSoundColumn;
27 class TXshSoundTextColumn;
28 class TXshCellColumn;
29 class TXshPaletteColumn;
30 class TXshZeraryFxColumn;
31 class TXshMeshColumn;
32 class TXsheet;
33 class TXshCell;
34 class TFx;
35 
36 //=============================================================================
37 //! The TXshColumn class is the base class of column managers in xsheet.
38 /*!Inherits \b TColumnHeader and \b TPersist.
39 \n This is an abstract base class inherited by the concrete classes
40    \b TXshCellColumn, \b TXshSoundColumn and TXshPaletteColumn.
41 
42    The class contains all features about a generic xsheet column and gives
43    all methods to access to these informations.
44 
45    The createEmpty() static method creates an new empty column.
46 
47    The getXsheet() function return xsheet to which column belongs, xsheet can be
48    changed using the setXsheet().
49 
50    The getIcon() function return column icon.
51 
52    TXshColumn allows to manage generic column status getStatusWord() and
53 setStatusWord.
54    Particularly it's possible to know if column is a mask isMask(), is lock
55 isLocked(),
56    or if it's view is in modality preview or camera stand, isCamstandVisible()
57 and
58    isPreviewVisible(). It's besides possible ot change this settings using
59 setMask(),
60    lock(), setCamstandVisible() and setPreviewVisible().
61 */
62 //=============================================================================
63 
64 class DVAPI TXshColumn : public TColumnHeader, public TPersist {
65   int m_status;
66   TXsheet *m_xsheet;
67   int m_colorTag;  // Usato solo in tabkids
68   UCHAR m_opacity;
69 
70 public:
71   enum FilterColor {
72     FilterNone = 0,
73     FilterRed,
74     FilterGreen,
75     FilterBlue,
76     FilterDarkYellow,
77     FilterDarkCyan,
78     FilterDarkMagenta,
79     FilterAmount
80   };
81 
82 private:
83   FilterColor m_filterColorId;
84 
85 protected:
86   enum {
87     eCamstandVisible       = 0x1,
88     ePreviewVisible        = 0x2,
89     eLocked                = 0x8,
90     eMasked                = 0x10,
91     eCamstandTransparent43 = 0x20  // obsoleto, solo per retrocompatibilita'
92   };
93 
94   TRaster32P m_icon;
95 
96   /*!
97 Set \b m_status to \b status.
98 \sa getStatusWord()
99 */
100   void setStatusWord(int status);
101   /*!
102 Return \b m_status.
103 \sa setStatusWord()
104 */
getStatusWord()105   int getStatusWord() const { return m_status; };
106 
107 public:
108   /*!
109 Constructs a TXshColumn with default value.
110 */
TXshColumn()111   TXshColumn()
112       : m_status(0)
113       , m_xsheet(0)
114       , m_colorTag(0)
115       , m_opacity(255)
116       , m_filterColorId(FilterNone) {}
117 
118   enum ColumnType {
119     eLevelType = 0,
120     eSoundType,
121     eSoundTextType,
122     eZeraryFxType,
123     ePaletteType,
124     eMeshType
125   };
126 
127   virtual ColumnType getColumnType() const = 0;
128 
129   //! Returns the column type used to store levels of the specified type.
130   static ColumnType toColumnType(int levelType);
131 
132   //! Creates an empty TXshColumn of the specified column type.
133   static TXshColumn *createEmpty(int colType);
134 
getLevelColumn()135   virtual TXshLevelColumn *getLevelColumn() { return 0; }
getSoundColumn()136   virtual TXshSoundColumn *getSoundColumn() { return 0; }
getSoundTextColumn()137   virtual TXshSoundTextColumn *getSoundTextColumn() { return 0; }
getCellColumn()138   virtual TXshCellColumn *getCellColumn() { return 0; }
getPaletteColumn()139   virtual TXshPaletteColumn *getPaletteColumn() { return 0; }
getZeraryFxColumn()140   virtual TXshZeraryFxColumn *getZeraryFxColumn() { return 0; }
getMeshColumn()141   virtual TXshMeshColumn *getMeshColumn() { return 0; }
142 
143   virtual int getMaxFrame() const = 0;
144 
145   virtual TXshColumn *clone() const = 0;
146 
147   /*!
148 Return true if camera stand is visible.
149 \sa setCamstandVisible()
150 */
151   bool isCamstandVisible() const;
152   /*!
153 Set column status camera stand visibility to \b on.
154 \sa isCamstandVisible()
155 */
156   void setCamstandVisible(bool on);
157 
158   /*!
159 Return true if camera stand is transparent.notice: this value is not relevant if
160 camerastandVisible is off.
161 \sa setCamstandTransparent()
162 */
getOpacity()163   UCHAR getOpacity() const { return m_opacity; }
164   /*!
165 Set column status camera stand transparent to \b on. notice: this value is not
166 relevant if camerastandVisible is off.
167 \sa isCamstandTransparent()
168 */
setOpacity(UCHAR val)169   void setOpacity(UCHAR val) { m_opacity = val; }
170 
171   // switch to next camera stand state. It's a 3-state-toggle: notvisible ->
172   // visible+nottransparent -> visible+transparent
173   // void setCamstandNextState();
174   /*!
175 Return true if preview is visible.
176 \sa setPreviewVisible()
177 */
178   bool isPreviewVisible() const;
179   /*!
180 Set column status preview to \b on.
181 \sa isPreviewVisible()
182 */
183   void setPreviewVisible(bool on);
184 
185   /*!
186 Return true if column is locked.
187 \sa lock()
188 */
189   bool isLocked() const;
190   /*!
191 Set column status look to \b on.
192 \sa isLocked()
193 */
194   void lock(bool on);
195 
196   /*!
197 Return true if column is a mask.
198 \sa setMask()
199 */
200   bool isMask() const;
201   /*!
202 Set column status mask to \b on.
203 \sa isMask()
204 */
205   void setIsMask(bool on);
206 
isEmpty()207   virtual bool isEmpty() const { return true; }
208 
209   /*!
210 Return \b m_icon.
211 */
getIcon()212   virtual TRaster32P getIcon() { return m_icon; }
213 
214   virtual bool isCellEmpty(int row) const = 0;
215 
216   /*!
217 If r0=r1=row return false.
218 */
219   virtual bool getLevelRange(int row, int &r0, int &r1) const = 0;
220 
getRange(int & r0,int & r1)221   virtual int getRange(int &r0, int &r1) const {
222     r0 = 0;
223     r1 = -1;
224     return 0;
225   }
226 
227   /*!
228 Set \b m_xsheet to \b xsheet.
229 \sa getXsheet()
230 */
setXsheet(TXsheet * xsheet)231   virtual void setXsheet(TXsheet *xsheet) { m_xsheet = xsheet; }
232   /*!
233 Return \b m_xsheet.
234 \sa setXsheet()
235 */
getXsheet()236   TXsheet *getXsheet() const { return m_xsheet; }
237 
getFx()238   virtual TFx *getFx() const { return 0; }
239 
240   /*!
241 Return true if column affects the final render
242 */
243   virtual bool isRendered() const;
244 
245   /*!
246 Return true if column is control.
247 */
248   virtual bool isControl() const;
249 
250   /*!
251 Return column color tag.
252 \sa setColorTag()
253 */
getColorTag()254   int getColorTag() const { return m_colorTag; }  // Usato solo in tabkids
255   /*!
256 Set column color tag to \b colorTag.
257 \sa getColorTag()
258 */
setColorTag(int colorTag)259   void setColorTag(int colorTag) {
260     m_colorTag = colorTag;
261   }  // Usato solo in tabkids
262 
getFilterColorId()263   FilterColor getFilterColorId() const { return m_filterColorId; }
setFilterColorId(FilterColor id)264   void setFilterColorId(FilterColor id) { m_filterColorId = id; }
265   TPixel32 getFilterColor();
266   static QPair<QString, TPixel32> getFilterInfo(FilterColor key);
267   static void initColorFilters();
268 
269   void resetColumnProperties();
270 };
271 
272 #ifdef _WIN32
273 template class DV_EXPORT_API TSmartPointerT<TXshColumn>;
274 #endif
275 typedef TSmartPointerT<TXshColumn> TXshColumnP;
276 
277 //=============================================================================
278 //! The TXshCellColumn class is the base class of column cell managers in
279 //! xsheet.
280 /*!Inherits \b TXshColumn.
281 \n This is an abstract base class inherited by the concrete classes
282    \b TXshLevelColumn and \b TXshZeraryFxColumn.
283 
284    The class defines column by cells getCellColumn(). TXshCellColumn is an
285 object
286    composed of a \b TXshCell vector and of an integer to memorize first not
287 empty cell.
288 
289    Class allows to manage cells in a column.
290    It's possible to know if cell is empty isCellEmpty(), if column is empty
291    isEmpty(), to know column range getRange(), row count getRowCount(), last and
292 first
293    not empty frame getMaxFrame(), getFirstRow().
294    Specally class allows to change cells, getCells(), setCells(), or
295 individually cell,
296    getCell(), setCell(); allows to insert insertEmptyCells(), remove
297 removeCells(),
298    clear clearCells() and move moveCells() cells in a column of xsheet.
299 */
300 //=============================================================================
301 
302 class DVAPI TXshCellColumn : public TXshColumn {
303 protected:
304   std::vector<TXshCell> m_cells;
305   int m_first;
306 
307 public:
308   /*!
309 Constructs a TXshCellColumn with default value.
310 */
311   TXshCellColumn();
312   /*!
313 Destroys the TXshCellColumn object.
314 */
315   ~TXshCellColumn();
316 
317   /*!
318 Return \b TXshCellColumn.
319 */
getCellColumn()320   TXshCellColumn *getCellColumn() override { return this; }
321 
322   virtual bool canSetCell(const TXshCell &cell) const = 0;
323 
324   /*!
325 Return not empty cell range. Set \b r0 and \b r1 to first
326 and last row with not empty cell.
327 \sa isEmpty() and getRowCount()
328 */
329   int getRange(int &r0, int &r1) const override;
330   /*!
331 Return row count.
332 \sa isEmpty() and getRange()
333 */
334   virtual int getRowCount() const;
335   /*!
336 Return true if row count is null.
337 \sa isCellEmpty(), getRowCount(), getRange()
338 */
isEmpty()339   bool isEmpty() const override { return getRowCount() == 0; }
340 
341   /*!
342 Return true if cell in \b row is empty.
343 \sa isEmpty()
344 */
345   bool isCellEmpty(int row) const override;
346 
347   /*!
348 Return cell in \b row.
349 \sa getCells and setCell()
350 */
351   virtual const TXshCell &getCell(int row) const;
352   /*!
353 Set cell in \b row to \b TXshCell \b cell.
354 \sa setCells() and getCell(); return false if cannot set cells.
355 */
356   virtual bool setCell(int row, const TXshCell &cell);
357 
358   /*!
359 Set \b cells[] from \b row to \b row + \b rowCount to column cells.
360 \sa getCell and setCells()
361 */
362   virtual void getCells(int row, int rowCount, TXshCell cells[]);
363   /*!
364 Set column cells from \b row to \b row + \b rowCount to cells[].
365 \sa setCell() and getCell(); return false if cannot set cells[].
366 */
367   virtual bool setCells(int row, int rowCount, const TXshCell cells[]);
368 
369   /*!
370 Insert \b rowCount empty cells from line \b row.
371 */
372   virtual void insertEmptyCells(int row, int rowCount = 1);
373   /*!
374 Remove \b rowCount cells from line \b row, with shift.
375 */
376   virtual void removeCells(int row, int rowCount = 1);
377   /*!
378 Clear \b rowCount cells from line \b row, without shift.
379 */
380   virtual void clearCells(int row, int rowCount = 1);
381 
382   /*!
383 Return last row with not empty cell.
384 */
385   int getMaxFrame() const override;
386 
387   /*!
388 Return first not empty row.
389 */
390   virtual int getFirstRow() const;
391   // debug only
392   virtual void checkColumn() const;
393 
394   /*!
395 Return true if cell in row is not empty. Set \b r0 and \b r1 to first and
396 last row with not empty cell of same level.
397 */
398   bool getLevelRange(int row, int &r0, int &r1) const override;
399 
400   // virtual void updateIcon() = 0;
401 };
402 
403 #endif
404