1 #pragma once 2 3 #ifndef TAPP_H 4 #define TAPP_H 5 6 #include <QObject> 7 8 #include "tools/tool.h" 9 10 // forward declaration 11 class TSceneHandle; 12 class TXsheetHandle; 13 class TXshLevelHandle; 14 class TFrameHandle; 15 class TColumnHandle; 16 class ToolHandle; 17 class TObjectHandle; 18 class TSelectionHandle; 19 class TOnionSkinMaskHandle; 20 class TFxHandle; 21 class PaletteController; 22 class QTimer; 23 class TXshLevel; 24 class QMainWindow; 25 26 class TMainWindow; 27 class ComboViewerPanel; 28 class SceneViewer; 29 class XsheetViewer; 30 31 //============================================================================= 32 // TXsheeHandle 33 //----------------------------------------------------------------------------- 34 //! This is the instance of the main application. 35 36 /*! This class is a singleton and is used to initialize the main application 37 window. 38 It defines the basic signals used in the application, as the 39 status changing of 40 the scene and connects them to the basic handlers. 41 \n It is also used to retrieve a pointer to the current state of 42 the application, 43 as the pointer to the main window, a pointer to the current 44 scene or a pointer 45 to the current selection, etc... 46 \n For example to get the pointer to the main window in any part 47 of the code one has to write: 48 49 \code 50 // A pointer to the main windows is 51 52 QMainWindow * mainwindow = TApp::instance()->getMainWindow(); 53 54 // To get the current object id 55 56 TStageObjectId currentObjectId = 57 TApp::instance()->getCurrentObject()->getObjectId(); 58 59 \endcode 60 This class is used to take care of changes on the state of the 61 application and to 62 notify through event handling to the rest of the code. 63 */ 64 class TApp final : public QObject, 65 public TTool::Application // Singleton 66 { 67 Q_OBJECT 68 69 TSceneHandle *m_currentScene; 70 TXsheetHandle *m_currentXsheet; 71 TFrameHandle *m_currentFrame; 72 TColumnHandle *m_currentColumn; 73 TXshLevelHandle *m_currentLevel; 74 ToolHandle *m_currentTool; 75 TObjectHandle *m_currentObject; 76 TSelectionHandle *m_currentSelection; 77 TOnionSkinMaskHandle *m_currentOnionSkinMask; 78 TFxHandle *m_currentFx; 79 80 PaletteController *m_paletteController; 81 82 QMainWindow *m_mainWindow; 83 84 SceneViewer *m_activeViewer; 85 XsheetViewer *m_xsheetViewer; 86 87 int m_autosavePeriod; // minutes 88 bool m_autosaveSuspended; 89 QTimer *m_autosaveTimer; 90 91 TApp(); 92 93 bool m_isStarting; 94 bool m_isPenCloseToTablet; 95 96 public: 97 /*! 98 A static pointer to the main application. 99 */ 100 static TApp *instance(); 101 102 ~TApp(); 103 /*! 104 Returns a pointer to the current scene. 105 */ getCurrentScene()106 TSceneHandle *getCurrentScene() const override { return m_currentScene; } 107 /*! 108 Returns a pointer to the current Xsheet. 109 */ getCurrentXsheet()110 TXsheetHandle *getCurrentXsheet() const override { return m_currentXsheet; } 111 /*! 112 Returns a pointer to the current frame. 113 */ getCurrentFrame()114 TFrameHandle *getCurrentFrame() const override { return m_currentFrame; } 115 /*! 116 Returns a pointer to the current column. 117 */ getCurrentColumn()118 TColumnHandle *getCurrentColumn() const override { return m_currentColumn; } 119 /*! 120 Returns a pointer to the current level. 121 */ getCurrentLevel()122 TXshLevelHandle *getCurrentLevel() const override { return m_currentLevel; } 123 /*! 124 Returns a pointer to the current tool used. 125 */ getCurrentTool()126 ToolHandle *getCurrentTool() const override { return m_currentTool; } 127 /*! 128 Returns a pointer to the current object in use. 129 */ getCurrentObject()130 TObjectHandle *getCurrentObject() const override { return m_currentObject; } 131 /*! 132 Returns a pointer to the current selection. 133 */ getCurrentSelection()134 TSelectionHandle *getCurrentSelection() const override { 135 return m_currentSelection; 136 } 137 /*! 138 Returns a pointer to the current layer's mask. 139 */ getCurrentOnionSkin()140 TOnionSkinMaskHandle *getCurrentOnionSkin() const override { 141 return m_currentOnionSkinMask; 142 } 143 /*! 144 Returns a pointer to the current effect. 145 */ getCurrentFx()146 TFxHandle *getCurrentFx() const override { return m_currentFx; } 147 getPaletteController()148 PaletteController *getPaletteController() const override { 149 return m_paletteController; 150 } 151 /*! 152 Sets a pointer to the main window.. 153 */ 154 155 // Current Palette (PaletteController) methods 156 157 TPaletteHandle *getCurrentPalette() const override; 158 159 TColorStyle *getCurrentLevelStyle() const override; 160 161 int getCurrentLevelStyleIndex() const override; 162 163 void setCurrentLevelStyleIndex(int index, bool forceUpdate = false) override; 164 setMainWindow(QMainWindow * mainWindow)165 void setMainWindow(QMainWindow *mainWindow) { m_mainWindow = mainWindow; } 166 /*! 167 Returns a pointer to the main window. 168 */ getMainWindow()169 QMainWindow *getMainWindow() const { return m_mainWindow; } 170 /*! 171 Returns a pointer to the current room. The current room is the window 172 environment in use, 173 i.e. the drawing tab, the animation tab, the pltedit tab etc... 174 */ 175 TMainWindow *getCurrentRoom() const; 176 /*! 177 Returns the current image type that can be a raster or a vector image. 178 \sa TImage::Type. 179 */ 180 int getCurrentImageType(); 181 /*! 182 Initializes the main window application. It is called in the main 183 function 184 after the environment initialization. 185 */ 186 void init(); 187 188 QString getCurrentRoomName() const; 189 setActiveViewer(SceneViewer * viewer)190 void setActiveViewer(SceneViewer *viewer) { 191 if (m_activeViewer == viewer) return; 192 m_activeViewer = viewer; 193 emit activeViewerChanged(); 194 } 195 getActiveViewer()196 SceneViewer *getActiveViewer() const { return m_activeViewer; } 197 isApplicationStarting()198 bool isApplicationStarting() { return m_isStarting; } 199 isPenCloseToTablet()200 bool isPenCloseToTablet() const { return m_isPenCloseToTablet; } 201 202 void writeSettings(); 203 setCurrentXsheetViewer(XsheetViewer * viewer)204 void setCurrentXsheetViewer(XsheetViewer *viewer) { m_xsheetViewer = viewer; } 205 getCurrentXsheetViewer()206 XsheetViewer *getCurrentXsheetViewer() const { return m_xsheetViewer; } 207 208 protected: 209 bool eventFilter(QObject *obj, QEvent *event) override; 210 211 private: 212 void updateXshLevel(); 213 void updateCurrentFrame(); 214 215 protected slots: 216 void onXsheetChanged(); 217 void onSceneSwitched(); 218 void onXsheetSwitched(); 219 void onXsheetSoundChanged(); 220 void onFrameSwitched(); 221 void onFxSwitched(); 222 void onColumnIndexSwitched(); 223 void onXshLevelSwitched(TXshLevel *); 224 void onXshLevelChanged(); 225 void onObjectSwitched(); 226 void onSplineChanged(); 227 void onSceneChanged(); 228 229 void onImageChanged(); 230 231 void onPaletteChanged(); 232 void onLevelColorStyleChanged(); 233 void onLevelColorStyleSwitched(); 234 235 void autosave(); 236 void onToolEditingFinished(); 237 void onStartAutoSave(); 238 void onStopAutoSave(); 239 240 signals: 241 // on OSX, there is a critical bug that SceneViewer::mousePressEvent is called 242 // when leaving the stylus and it causes unwanted stroke drawn while 243 // hover-moving of the pen. 244 // This signal is to detect tablet leave and force initializing such irregular 245 // mouse press. 246 // NOTE: For now QEvent::TabletLeaveProximity is NOT detected on Windows. See 247 // QTBUG-53628. 248 void tabletLeft(); 249 250 void 251 activeViewerChanged(); // TODO: put widgets-related stuffs in some new handle 252 }; 253 254 #endif // TAPP_H 255