1 // Copyright (C) 2012-2019 The VPaint Developers. 2 // See the COPYRIGHT file at the top-level directory of this distribution 3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #ifndef MAINWINDOW_H 18 #define MAINWINDOW_H 19 20 #include <QMainWindow> 21 #include <QList> 22 #include <QString> 23 #include <QTextBrowser> 24 #include <QTimer> 25 #include <QDir> 26 27 class QScrollArea; 28 class Scene; 29 class GLWidget; 30 class MultiView; 31 class View; 32 class View3D; 33 class Timeline; 34 class DevSettings; 35 class SettingsDialog; 36 class XmlStreamWriter; 37 class XmlStreamReader; 38 class QTextStream; 39 class EditCanvasSizeDialog; 40 class ExportPngDialog; 41 class AboutDialog; 42 class BackgroundWidget; 43 class LayersWidget; 44 class View3DSettingsWidget; 45 46 namespace VectorAnimationComplex 47 { 48 class VAC; 49 class InbetweenFace; 50 } 51 class SelectionInfoWidget; 52 class ObjectPropertiesWidget; 53 class AnimatedCycleWidget; 54 55 class MainWindow : public QMainWindow 56 { 57 Q_OBJECT 58 59 public: 60 MainWindow(); 61 ~MainWindow(); 62 63 Scene * scene() const; 64 View * activeView() const; 65 View * hoveredView() const; 66 Timeline * timeline() const; 67 68 bool isShowCanvasChecked() const; 69 bool isEditCanvasSizeVisible() const; 70 71 protected: 72 void closeEvent(QCloseEvent * event); 73 void keyPressEvent(QKeyEvent *event); 74 void keyReleaseEvent(QKeyEvent *event); 75 bool eventFilter(QObject *object, QEvent *event); 76 77 public slots: 78 // ---- update what is displayed on screen ---- 79 void update(); 80 void updatePicking(); 81 82 void updateObjectProperties(); 83 void editAnimatedCycle(VectorAnimationComplex::InbetweenFace * inbetweenFace, int indexCycle); 84 85 void about(); 86 void open_(const QString & filePath); // XXX public because used in main.cpp. Should probably be refactored. 87 88 private slots: 89 // ---- File ---- 90 void newDocument(); 91 void open(); 92 void importSvg(); 93 bool save(); 94 void autosave(); 95 bool saveAs(); 96 bool exportSVG(); 97 bool exportPNG(); 98 bool acceptExportPNG(); 99 bool rejectExportPNG(); 100 101 // ---- Edit ---- 102 void addToUndoStack(); 103 void undo(); 104 void redo(); 105 void cut(); 106 void copy(); 107 void paste(); 108 109 // ---- View ---- 110 void displayModeChanged(); 111 void setDisplayModeNormal(); 112 void setDisplayModeNormalOutline(); 113 void setDisplayModeOutline(); 114 void toggleShowCanvas(bool); 115 void editCanvasSize(); 116 117 void setOnionSkinningEnabled(bool enabled); 118 119 void openClose3D(); 120 void updateView3DActionCheckState(); 121 void view3DActionSetChecked(); 122 void view3DActionSetUnchecked(); 123 124 void openClose3DSettings(); 125 void updateView3DSettingsActionCheckState(); 126 void view3DSettingsActionSetChecked(); 127 void view3DSettingsActionSetUnchecked(); 128 129 void updateViewMenu(); 130 131 // ---- Selection ---- 132 // -> deferred to Scene 133 134 // ---- Depth ---- 135 // -> deferred to Scene 136 137 // ---- Animation ---- 138 void motionPaste(); 139 void createInbetweenFace(); 140 141 // ---- Help ---- 142 void onlineDocumentation(); 143 void gettingStarted(); 144 void manual(); 145 146 // Update docks when scene changes 147 void onSceneLayerAttributesChanged_(); 148 149 private: 150 // ---------- initializations -------------- 151 void createActions(); 152 void createToolbars(); 153 void createStatusBar(); 154 void createDocks(); 155 void createMenus(); 156 157 // --------- Other properties and widgets -------- 158 // Scene and View 159 Scene * scene_; 160 MultiView * multiView_; 161 // Help 162 AboutDialog * aboutDialog_; 163 bool showAboutDialogAtStartup_; 164 QTextBrowser * gettingStarted_; 165 QTextBrowser * userManual_; 166 // Undo/Redo 167 void clearUndoStack_(); 168 void resetUndoStack_(); 169 void goToUndoIndex_(int undoIndex); 170 typedef QPair<QDir,Scene*> UndoItem; 171 QList<UndoItem> undoStack_; 172 int undoIndex_; 173 int savedUndoIndex_; 174 // I/O 175 QString fileHeader_; 176 QString documentFilePath_; 177 QString autosaveFilename_; 178 QTimer autosaveTimer_; 179 int autosaveIndex_; 180 bool autosaveOn_; 181 QDir autosaveDir_; 182 bool isNewDocument_() const; 183 bool isModified_() const; 184 void setUnmodified_(); 185 void updateWindowTitle_(); 186 void setDocumentFilePath_(const QString & filePath); 187 bool maybeSave_(); 188 bool save_(const QString & filePath, bool relativeRemap = false); 189 void doImportSvg(const QString & filename); 190 bool doExportSVG(const QString & filename); 191 bool doExportPNG(const QString & filename); 192 void read_DEPRECATED(QTextStream & in); 193 void write_DEPRECATED(QTextStream & out); 194 void read(XmlStreamReader & xml); 195 void write(XmlStreamWriter & xml); 196 void autosaveBegin(); 197 void autosaveEnd(); 198 // Copy-pasting 199 VectorAnimationComplex::VAC * clipboard_; 200 // 3D view 201 View3D * view3D_; 202 View3DSettingsWidget * view3DSettingsWidget_; 203 // timeline 204 Timeline * timeline_; 205 // Selection info 206 SelectionInfoWidget * selectionInfo_; 207 // Edit Canvas Size 208 ExportPngDialog * exportPngDialog_; 209 EditCanvasSizeDialog * editCanvasSizeDialog_; 210 bool exportPngCanvasWasVisible_; 211 QString exportPngFilename_; 212 bool exportingPng_; 213 214 // --------- Menus and actions -------- 215 // FILE 216 QMenu * menuFile; 217 QAction * actionNew; 218 QAction * actionOpen; 219 QAction * actionImportSvg; 220 QAction * actionSave; 221 QAction * actionSaveAs; 222 QAction * actionPreferences; 223 QAction * actionExportSVG; 224 QAction * actionExportPNG; 225 QAction * actionQuit; 226 // EDIT 227 QMenu * menuEdit; 228 QAction * actionUndo; 229 QAction * actionRedo; 230 QAction * actionCut; 231 QAction * actionCopy; 232 QAction * actionPaste; 233 QAction * actionSmartDelete; 234 QAction * actionHardDelete; 235 QAction * actionTest; 236 // VIEW 237 QMenu * menuView; 238 QAction * actionZoomIn; 239 QAction * actionZoomOut; 240 QAction * actionShowCanvas; 241 QAction * actionEditCanvasSize; 242 QAction * actionFitAllInWindow; 243 QAction * actionFitSelectionInWindow; 244 QAction * actionDisplayModeNormal; 245 QAction * actionDisplayModeNormalOutline; 246 QAction * actionDisplayModeOutline; 247 QAction * actionOnionSkinning; 248 QAction * actionToggleOutline; 249 QAction * actionToggleOutlineOnly; 250 QAction * actionOpenCloseView3DSettings; 251 QAction * actionOpenClose3D; 252 QAction * actionSplitVertical; 253 QAction * actionSplitHorizontal; 254 QAction * actionSplitClose; 255 QAction * actionSplitOne; 256 QMenu * advancedViewMenu; 257 // SELECTION 258 QMenu * menuSelection; 259 QAction * actionSelectAllInFrame; 260 QAction * actionSelectAllInAnimation; 261 QAction * actionDeselectAll; 262 QAction * actionInvertSelection; 263 QAction * actionSelectConnected; 264 QAction * actionSelectClosure; 265 QAction * actionSelectVertices; 266 QAction * actionSelectEdges; 267 QAction * actionSelectFaces; 268 QAction * actionDeselectVertices; 269 QAction * actionDeselectEdges; 270 QAction * actionDeselectFaces; 271 // DEPTH 272 QMenu * menuDepth; 273 QAction * actionRaise; 274 QAction * actionLower; 275 QAction * actionRaiseToTop; 276 QAction * actionLowerToBottom; 277 QAction * actionAltRaise; 278 QAction * actionAltLower; 279 QAction * actionAltRaiseToTop; 280 QAction * actionAltLowerToBottom; 281 // ANIMATION 282 QMenu * menuAnimation; 283 QAction * actionInbetweenSelection; 284 QAction * actionKeyframeSelection; 285 QAction * actionMotionPaste; 286 QAction * actionCreateInbetweenFace; 287 // PLAYBACK 288 QMenu * menuPlayback; 289 // HELP 290 QMenu * menuHelp; 291 QAction * actionOnlineDocumentation; 292 QAction * actionGettingStarted; 293 QAction * actionManual; 294 QAction * actionAbout; 295 296 // Docks 297 QDockWidget * dockInspector; 298 ObjectPropertiesWidget * inspector; 299 QDockWidget * dockTimeLine; 300 QDockWidget * dockAdvancedSettings; 301 QDockWidget * dockAnimatedCycleEditor; 302 AnimatedCycleWidget * animatedCycleEditor; 303 BackgroundWidget * backgroundWidget; 304 QDockWidget * dockBackgroundWidget; 305 LayersWidget * layersWidget; 306 QDockWidget * dockLayersWidget; 307 }; 308 309 #endif 310