|
27 | 27 | #include "FileCacheHandlers/filecachehandler.h" |
28 | 28 | #include "canvas.h" |
29 | 29 | #include "simpletask.h" |
30 | | -#include "appsupport.h" |
31 | 30 |
|
32 | 31 | Document* Document::sInstance = nullptr; |
33 | 32 |
|
34 | 33 | using namespace Friction::Core; |
35 | 34 |
|
36 | | -Document::Document(TaskScheduler& taskScheduler) { |
| 35 | +Document::Document(TaskScheduler& taskScheduler) |
| 36 | +{ |
37 | 37 | Q_ASSERT(!sInstance); |
38 | 38 | sInstance = this; |
39 | | - fShowRotateGizmo = AppSupport::getSettings("gizmos", "Rotate", true).toBool(); |
40 | | - fShowPositionGizmo = AppSupport::getSettings("gizmos", "Position", true).toBool(); |
41 | | - fShowScaleGizmo = AppSupport::getSettings("gizmos", "Scale", false).toBool(); |
42 | | - fShowShearGizmo = AppSupport::getSettings("gizmos", "Shear", false).toBool(); |
43 | 39 | connect(&taskScheduler, &TaskScheduler::finishedAllQuedTasks, |
44 | 40 | this, &Document::updateScenes); |
45 | 41 | } |
@@ -120,62 +116,78 @@ void Document::setCanvasMode(const CanvasMode mode) { |
120 | 116 | actionFinished(); |
121 | 117 | } |
122 | 118 |
|
123 | | -void Document::setShowRotateGizmo(bool show) |
| 119 | +void Document::setGizmoVisibility(const Gizmos::Interact &ti, |
| 120 | + const bool visibility) |
124 | 121 | { |
125 | | - if (fShowRotateGizmo == show) { return; } |
126 | | - fShowRotateGizmo = show; |
127 | | - for (const auto &scene : fScenes) { |
128 | | - if (scene) { scene->setShowRotateGizmo(show); } |
| 122 | + QString key; |
| 123 | + |
| 124 | + switch (ti) { |
| 125 | + case Gizmos::Interact::Position: |
| 126 | + if (fGizmoPositionVisibility == visibility) { return; } |
| 127 | + key = "Position"; |
| 128 | + fGizmoPositionVisibility = visibility; |
| 129 | + break; |
| 130 | + case Gizmos::Interact::Rotate: |
| 131 | + if (fGizmoRotateVisibility == visibility) { return; } |
| 132 | + key = "Rotate"; |
| 133 | + fGizmoRotateVisibility = visibility; |
| 134 | + break; |
| 135 | + case Gizmos::Interact::Scale: |
| 136 | + if (fGizmoScaleVisibility == visibility) { return; } |
| 137 | + key = "Scale"; |
| 138 | + fGizmoScaleVisibility = visibility; |
| 139 | + break; |
| 140 | + case Gizmos::Interact::Shear: |
| 141 | + if (fGizmoShearVisibility == visibility) { return; } |
| 142 | + key = "Shear"; |
| 143 | + fGizmoShearVisibility = visibility; |
| 144 | + break; |
| 145 | + default: return; |
129 | 146 | } |
130 | | - AppSupport::setSettings("gizmos", "Rotate", show); |
131 | | - |
132 | | - emit gizmoVisibilityChanged(Gizmos::Interact::Rotate, show); |
133 | | -} |
134 | 147 |
|
135 | | -void Document::setShowPositionGizmo(bool show) |
136 | | -{ |
137 | | - if (fShowPositionGizmo == show) { return; } |
138 | | - fShowPositionGizmo = show; |
139 | 148 | for (const auto &scene : fScenes) { |
140 | | - if (scene) { scene->setShowPositionGizmo(show); } |
| 149 | + if (scene) { scene->setGizmoVisibility(ti, visibility); } |
141 | 150 | } |
142 | | - AppSupport::setSettings("gizmos", "Position", show); |
143 | 151 |
|
144 | | - emit gizmoVisibilityChanged(Gizmos::Interact::Position, show); |
| 152 | + AppSupport::setSettings("gizmos", key, visibility); |
| 153 | + emit gizmoVisibilityChanged(ti, visibility); |
145 | 154 | } |
146 | 155 |
|
147 | | -void Document::setShowScaleGizmo(bool show) |
| 156 | +bool Document::getGizmoVisibility(const Gizmos::Interact &ti) |
148 | 157 | { |
149 | | - if (fShowScaleGizmo == show) { return; } |
150 | | - fShowScaleGizmo = show; |
151 | | - for (const auto &scene : fScenes) { |
152 | | - if (scene) { scene->setShowScaleGizmo(show); } |
| 158 | + switch (ti) { |
| 159 | + case Gizmos::Interact::Position: |
| 160 | + return fGizmoPositionVisibility; |
| 161 | + break; |
| 162 | + case Gizmos::Interact::Rotate: |
| 163 | + return fGizmoRotateVisibility; |
| 164 | + break; |
| 165 | + case Gizmos::Interact::Scale: |
| 166 | + return fGizmoScaleVisibility; |
| 167 | + break; |
| 168 | + case Gizmos::Interact::Shear: |
| 169 | + return fGizmoShearVisibility; |
| 170 | + break; |
| 171 | + default:; |
153 | 172 | } |
154 | | - AppSupport::setSettings("gizmos", "Scale", show); |
155 | | - |
156 | | - emit gizmoVisibilityChanged(Gizmos::Interact::Scale, show); |
| 173 | + return false; |
157 | 174 | } |
158 | 175 |
|
159 | | -void Document::setShowShearGizmo(bool show) |
| 176 | +Canvas *Document::createNewScene(const bool emitCreated) |
160 | 177 | { |
161 | | - if (fShowShearGizmo == show) { return; } |
162 | | - fShowShearGizmo = show; |
163 | | - for (const auto &scene : fScenes) { |
164 | | - if (scene) { scene->setShowShearGizmo(show); } |
165 | | - } |
166 | | - AppSupport::setSettings("gizmos", "Shear", show); |
167 | | - |
168 | | - emit gizmoVisibilityChanged(Gizmos::Interact::Shear, show); |
169 | | -} |
170 | | - |
171 | | -Canvas *Document::createNewScene(const bool emitCreated) { |
172 | 178 | const auto newScene = enve::make_shared<Canvas>(*this); |
173 | 179 | fScenes.append(newScene); |
174 | 180 | SWT_addChild(newScene.get()); |
175 | | - newScene->setShowRotateGizmo(fShowRotateGizmo); |
176 | | - newScene->setShowPositionGizmo(fShowPositionGizmo); |
177 | | - newScene->setShowScaleGizmo(fShowScaleGizmo); |
178 | | - newScene->setShowShearGizmo(fShowShearGizmo); |
| 181 | + |
| 182 | + newScene->setGizmoVisibility(Gizmos::Interact::Position, |
| 183 | + fGizmoPositionVisibility); |
| 184 | + newScene->setGizmoVisibility(Gizmos::Interact::Rotate, |
| 185 | + fGizmoRotateVisibility); |
| 186 | + newScene->setGizmoVisibility(Gizmos::Interact::Scale, |
| 187 | + fGizmoScaleVisibility); |
| 188 | + newScene->setGizmoVisibility(Gizmos::Interact::Shear, |
| 189 | + fGizmoShearVisibility); |
| 190 | + |
179 | 191 | if (emitCreated) { |
180 | 192 | emit sceneCreated(newScene.get()); |
181 | 193 | } |
|
0 commit comments