1 // This file is part of Heimer.
2 // Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
3 //
4 // Heimer is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Heimer is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Heimer. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef STATE_MACHINE_HPP
17 #define STATE_MACHINE_HPP
18 
19 #include <QObject>
20 
21 #include <memory>
22 
23 class Mediator;
24 
25 class StateMachine : public QObject
26 {
27     Q_OBJECT
28 
29 public:
30     enum class State
31     {
32         Edit,
33         Exit,
34         Init,
35         InitializeNewMindMap,
36         OpenRecent,
37         OpenDrop,
38         Save,
39         ShowBackgroundColorDialog,
40         ShowEdgeColorDialog,
41         ShowGridColorDialog,
42         ShowImageFileDialog,
43         ShowLayoutOptimizationDialog,
44         ShowNodeColorDialog,
45         ShowNotSavedDialog,
46         ShowOpenDialog,
47         ShowPngExportDialog,
48         ShowSaveAsDialog,
49         ShowSvgExportDialog,
50         ShowTextColorDialog,
51         TryCloseWindow
52     };
53 
54     enum class Action
55     {
56         BackgroundColorChanged,
57         BackgroundColorChangeRequested,
58         EdgeColorChanged,
59         EdgeColorChangeRequested,
60         GridColorChanged,
61         GridColorChangeRequested,
62         ImageAttachmentRequested,
63         ImageLoadFailed,
64         LayoutOptimizationRequested,
65         LayoutOptimized,
66         MainWindowInitialized,
67         MindMapOpened,
68         MindMapSaved,
69         MindMapSavedAs,
70         MindMapSaveFailed,
71         MindMapSaveAsCanceled,
72         MindMapSaveAsFailed,
73         NewMindMapInitialized,
74         NewSelected,
75         NodeColorChanged,
76         NodeColorChangeRequested,
77         NotSavedDialogAccepted,
78         NotSavedDialogCanceled,
79         NotSavedDialogDiscarded,
80         OpeningMindMapCanceled,
81         OpeningMindMapFailed,
82         OpenSelected,
83         PngExported,
84         PngExportSelected,
85         QuitSelected,
86         RecentFileSelected,
87         DropFileSelected,
88         RedoSelected,
89         SaveAsSelected,
90         SaveSelected,
91         SvgExported,
92         SvgExportSelected,
93         TextColorChanged,
94         TextColorChangeRequested,
95         UndoSelected
96     };
97 
98     enum class QuitType
99     {
100         None,
101         New,
102         Open,
103         OpenRecent,
104         OpenDrop,
105         Close
106     };
107 
108     StateMachine();
109 
110     void calculateState(StateMachine::Action action);
111 
112     void setMediator(std::shared_ptr<Mediator> mediator);
113 
114 signals:
115 
116     void stateChanged(StateMachine::State state);
117 
118 private:
119     State m_state = State::Init;
120 
121     QuitType m_quitType = QuitType::None;
122 
123     std::shared_ptr<Mediator> m_mediator;
124 };
125 
126 #endif // STATE_MACHINE_HPP
127