1 #pragma once
2 
3 #ifndef IMAGEUTILS_H
4 #define IMAGEUTILS_H
5 
6 // TnzBase includes
7 #include "trasterfx.h"
8 
9 // TnzCore includes
10 #include "tregion.h"
11 #include "tvectorimage.h"
12 
13 // Qt includes
14 #include <QWidget>
15 #include <QKeyEvent>
16 
17 #undef DVAPI
18 #undef DVVAR
19 #ifdef TOONZQT_EXPORTS
20 #define DVAPI DV_EXPORT_API
21 #define DVVAR DV_EXPORT_VAR
22 #else
23 #define DVAPI DV_IMPORT_API
24 #define DVVAR DV_IMPORT_VAR
25 #endif
26 
27 //=============================================================================
28 
29 //    Forward declarations
30 
31 class TFilePath;
32 class TPropertyGroup;
33 // enum TRenderSettings::ResampleQuality;
34 
35 class QHBoxLayout;
36 
37 //=============================================================================
38 
39 namespace ImageUtils {
40 
41 /*!
42   \brief    Notify that a task on a single frame is completed.
43 */
44 class DVAPI FrameTaskNotifier final : public QObject {
45   Q_OBJECT
46 
47   int m_errorCount, m_warningCount;
48   bool m_abort;
49 
50 public:
FrameTaskNotifier()51   FrameTaskNotifier() : m_errorCount(0), m_warningCount(0), m_abort(false) {}
~FrameTaskNotifier()52   ~FrameTaskNotifier() {}
53 
notifyFrameCompleted(int frame)54   void notifyFrameCompleted(int frame) { emit frameCompleted(frame); }
notifyError()55   void notifyError() {
56     m_errorCount++;
57     emit error();
58   }
notifyLevelCompleted(const TFilePath & fullPath)59   void notifyLevelCompleted(const TFilePath &fullPath) {
60     emit levelCompleted(fullPath);
61   }
62 
abortTask()63   bool abortTask() { return m_abort; }
reset()64   void reset() { m_abort = false; }
65 
getErrorCount()66   int getErrorCount() const { return m_errorCount; }
67 
68 signals:
69 
70   void frameCompleted(int);
71   void levelCompleted(const TFilePath &fullPath);
72   void error();
73 
74 protected slots:
75 
onCancelTask()76   void onCancelTask() { m_abort = true; }
77 };
78 
79 //----------------------------------------------------
80 
81 TFilePath DVAPI duplicate(const TFilePath &levelPath);
82 
83 void DVAPI premultiply(const TFilePath &levelPath);
84 
85 void DVAPI convert(
86     const TFilePath &source,  //!< Level path to convert from.
87     const TFilePath &dest,    //!< Level path to convert to.
88     const TFrameId &from,     //!< First source frame to convert. Supports
89                               //! TFrameId::EMPTY_FRAME
90     //!  to specify conversion from the beginning of level.
91     const TFrameId
92         &to,  //!< Last source frame to convert. Supports TFrameId::EMPTY_FRAME
93               //!  to specify conversion to the end of level.
94     double framerate,      //!< Frame rate for destination movie formats.
95     TPropertyGroup *prop,  //!< Format properties for the destination level.
96     FrameTaskNotifier
97         *frameNotifier,  //!< Observer class for frame success notifications.
98     const TPixel &bgColor =
99         TPixel::Transparent,  //!< Destination Background color.
100     bool removeDotBeforeFrameNumber =
101         false /*-- ConvertPopup
102                  での指定に合わせて、[レベル名].[フレーム番号].[拡張子]のうち、
103                                                                                           [レベル名]と[フレーム番号]の間のドットを消す。 --*/
104 );            //!< Converts a saved level to fullcolor, and saves the result.
105 
106 void DVAPI convertNaa2Tlv(
107     const TFilePath &source,  //!< Level path to convert from.
108     const TFilePath &dest,    //!< Level path to convert to.
109     const TFrameId &from,     //!< First source frame to convert.
110     const TFrameId &to,       //!< Last source frame to convert.
111     FrameTaskNotifier
112         *frameNotifier,  //!< Observer class for frame success notifications.
113     TPalette *palette =
114         0,  //!< Special conversion function from an antialiased level to tlv.
115             //!  \sa  Function ImageUtils::convert().
116     bool removeUnusedStyles = false,
117     double dpi = 0.0);  //! Remove unused styles from input palette.
118 
119 // convert old levels (tzp / tzu) to tlv
120 void DVAPI convertOldLevel2Tlv(
121     const TFilePath &source,  //!< Level path to convert from.
122     const TFilePath &dest,    //!< Level path to convert to.
123     const TFrameId &from,     //!< First source frame to convert.
124     const TFrameId &to,       //!< Last source frame to convert.
125     FrameTaskNotifier
126         *frameNotifier  //!< Observer class for frame success notifications.
127 );
128 
129 double DVAPI getQuantizedZoomFactor(double zf, bool forward);
130 
131 void DVAPI getFillingInformationOverlappingArea(
132     const TVectorImageP &vi, std::vector<TFilledRegionInf> &regs,
133     const TRectD &area1, const TRectD &area2 = TRectD());
134 
135 void DVAPI getFillingInformationInArea(const TVectorImageP &vi,
136                                        std::vector<TFilledRegionInf> &regs,
137                                        const TRectD &area);
138 
139 void DVAPI assignFillingInformation(TVectorImage &vi,
140                                     const std::vector<TFilledRegionInf> &regs);
141 
142 void DVAPI getStrokeStyleInformationInArea(
143     const TVectorImageP &vi,
144     std::vector<std::pair<int, int>>
145         &strokesInfo,  // pair:strokeIndex, styleIndex
146     const TRectD &area);
147 
148 //*********************************************************************************************
149 //    FullScreenWidget  declaration
150 //*********************************************************************************************
151 
152 /*!
153   \brief    Temporary class used to deal with QTBUG #7556 - QGLWidgets going
154   fullscreen \a need
155             a containing widget that leaves a small margin to prevent the widget
156   from covering other
157             widgets (specifically, context menus).
158 */
159 
160 class DVAPI FullScreenWidget final : public QWidget {
161   Q_OBJECT
162 
163   QWidget *m_widget;  //!< (Owned) The content widget.
164 
165 public:
166   FullScreenWidget(QWidget *parent = 0);
167 
168   void setWidget(
169       QWidget *widget);  //!< Sets the content, surrendering ownership.
widget()170   QWidget *widget() const { return m_widget; }
171 
172 public slots:
173 
174   bool toggleFullScreen(bool quit = false);
175 };
176 
177 //*********************************************************************************************
178 //    ShortcutZoomer  declaration
179 //*********************************************************************************************
180 
181 /*!
182   \brief    The ShortcutZoomer abstract base class is used by viewer widget to
183   access
184             shortcut-related commands.
185 
186   \details  This class is a wrapper for shortcuts established by the
187   CommandManager
188             interface.
189 
190             Subclass it defining the required view commands, then implement a
191             \p keyPressEvent() event handler in the viewer widget you want:
192 
193             \code
194             void MyViewer::keyPressEvent(QKeyEvent* ke)
195             {
196               if(ViewerZoomer(this).exec(event))
197                 return;
198 
199               return MyViewerBase::keyPressEvent(ke);
200             }
201             \endcode
202 
203   \warning  Use the FullScreenWidget class to wrap a viewer class that
204             needs to go fullscreen.
205 */
206 
207 class DVAPI ShortcutZoomer {
208   QWidget *m_widget;  //!< Viewer widget being processed.
209 
210 public:
211   ShortcutZoomer(
212       QWidget *viewerWidget);  //!< Constructs on the specified viewer widget.
213 
getWidget()214   QWidget *getWidget() {
215     return m_widget;
216   }  //!< Returns the processed viewer widget.
217 
218   bool exec(
219       QKeyEvent *event);  //!< Processes a key event for shortcuts related to
220                           //!  viewer commands.
221                           //!  \return  Whether a shortcut was recognized.
222 protected:
223   virtual bool zoom(
224       bool zoomin,
225       bool resetView) = 0;  //!< Handler for zoom commands. Required.
fit()226   virtual bool fit() {
227     return false;
228   }  //!< Handler for 'fit to image' commands.
setActualPixelSize()229   virtual bool setActualPixelSize() {
230     return false;
231   }  //!< Handler for 'use actual pixel size' commands.
setFlipX()232   virtual bool setFlipX() {
233     return false;
234   }  //!< Handler for 'flip viewer vertically' commands.
setFlipY()235   virtual bool setFlipY() {
236     return false;
237   }  //!< Handler for 'flip viewer horizontally' commands.
resetZoom()238   virtual bool resetZoom() {
239     return false;
240   }  //!< Handler for 'reset zoom' commands.
resetRotation()241   virtual bool resetRotation() {
242     return false;
243   }  //!< Handler for 'reset rotation' commands.
resetPosition()244   virtual bool resetPosition() {
245     return false;
246   }  //!< Handler for 'reset position' commands.
247   virtual bool toggleFullScreen(
248       bool quit = false)  //!  Handler for 'toggle fullscreen' commands.
249   {
250     return false;
251   }
252 };
253 
254 }  // namespace ImageUtils
255 
256 #endif
257