Tue, 11 Apr 2023 11:11:28 +0300
More refactor and renaming
Added a test function that makes recolors stuff red
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
1 | #include <QApplication> |
327 | 2 | #include <QClipboard> |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
3 | #include <QCloseEvent> |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
4 | #include <QFileDialog> |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
5 | #include <QMdiSubWindow> |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
6 | #include <QMessageBox> |
237
10a6298f636f
Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
236
diff
changeset
|
7 | #include <QScrollBar> |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
8 | #include <QStackedWidget> |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
9 | #include <QTranslator> |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
10 | #include "src/gl/partrenderer.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
11 | #include "src/layers/axeslayer.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
12 | #include "src/layers/edittools.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
13 | #include "src/layers/gridlayer.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
14 | #include "src/ldrawalgorithm.h" |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
15 | #include "src/mainwindow.h" |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
16 | #include "src/messagelog.h" |
355
e81f4ad53efd
Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
354
diff
changeset
|
17 | #include "src/modelsubwindow.h" |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
18 | #include "src/settings.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
19 | #include "src/settingseditor/settingseditor.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
20 | #include "src/ui/circletooloptionswidget.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
21 | #include "src/version.h" |
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
22 | #include "src/widgets/colorselectdialog.h" |
328
3ea38fd469ca
Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
327
diff
changeset
|
23 | #include "src/parser.h" |
331
638a7458ef5e
Add basic syntax highlighting
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
330
diff
changeset
|
24 | #include "src/ldrawsyntaxhighlighter.h" |
293
9f85a54ead29
Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
292
diff
changeset
|
25 | #include <GL/glew.h> |
24 | 26 | |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
27 | static const QDir LOCALE_DIR {":/locale"}; |
0 | 28 | |
215
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
29 | class ModelData : public QObject |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
30 | { |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
31 | Q_OBJECT |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
32 | public: |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
33 | ModelData(QObject* parent) : QObject {parent} {} |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
34 | std::unique_ptr<PartRenderer> canvas; |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
35 | std::unique_ptr<EditTools> tools; |
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
36 | std::unique_ptr<AxesLayer> axesLayer; |
216
c7241f504117
Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
215
diff
changeset
|
37 | std::unique_ptr<GridLayer> gridLayer; |
328
3ea38fd469ca
Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
327
diff
changeset
|
38 | std::unique_ptr<QTextCursor> textcursor; |
338 | 39 | QTextDocument* model; |
215
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
40 | }; |
243
959469a7e149
Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
241
diff
changeset
|
41 | |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
263
diff
changeset
|
42 | #include <main.moc> |
215
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
43 | |
200 | 44 | static void doQtRegistrations() |
0 | 45 | { |
281
afed72b544f0
- Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
279
diff
changeset
|
46 | QCoreApplication::setApplicationName(QStringLiteral(CMAKE_PROJECT_NAME)); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
47 | QCoreApplication::setOrganizationName("hecknology.net"); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
48 | QCoreApplication::setOrganizationDomain("hecknology.net"); |
237
10a6298f636f
Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
236
diff
changeset
|
49 | qRegisterMetaType<Message>(); |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
251
diff
changeset
|
50 | qRegisterMetaType<Library>(); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
251
diff
changeset
|
51 | qRegisterMetaType<QList<Library>>(); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
251
diff
changeset
|
52 | qRegisterMetaType<QMdiArea::ViewMode>(); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
251
diff
changeset
|
53 | qRegisterMetaType<gl::RenderStyle>(); |
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
251
diff
changeset
|
54 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
200 | 55 | qRegisterMetaTypeStreamOperators<Library>("Library"); |
56 | qRegisterMetaTypeStreamOperators<Libraries>("Libraries"); | |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
57 | qRegisterMetaTypeStreamOperators<gl::RenderStyle>(); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
58 | qRegisterMetaTypeStreamOperators<QMdiArea::ViewMode>(); |
335 | 59 | qRegisterMetaTypeStreamOperators<Qt::ToolButtonStyle>(); |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
251
diff
changeset
|
60 | #endif |
200 | 61 | } |
62 | ||
368
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
63 | struct ToolWidgets |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
64 | { |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
65 | CircleToolOptionsWidget* circleToolOptions; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
66 | }; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
67 | |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
68 | struct MainState |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
69 | { |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
70 | MainWindow mainWindow; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
71 | DocumentManager documents; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
72 | QString currentLanguage = "en"; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
73 | QTranslator translator{&mainWindow}; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
74 | LibrariesModel libraries{&mainWindow}; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
75 | QStringList recentlyOpenedFiles; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
76 | ColorTable colorTable; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
77 | gl::RenderPreferences renderPreferences; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
78 | MessageLog messageLog; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
79 | ToolWidgets toolWidgets{ |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
80 | .circleToolOptions = new CircleToolOptionsWidget{&mainWindow}, |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
81 | }; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
82 | }; |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
83 | |
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
84 | static std::optional<ModelId> openModelFromPath(MainState* state, const QString& path) |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
85 | { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
86 | QString errorString; |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
87 | QTextStream errorStream{&errorString}; |
368
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
88 | const std::optional<ModelId> modelIdOpt = state->documents.openModel( |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
89 | path, |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
90 | errorStream, |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
91 | OpenType::ManuallyOpened); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
92 | if (modelIdOpt.has_value()) { |
368
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
93 | const DocumentManager::MissingDependencies missing = state->documents.loadDependenciesForAllModels(state->libraries); |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
94 | if (not missing.empty()) { |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
95 | QMessageBox::warning( |
368
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
96 | &state->mainWindow, |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
97 | QObject::tr("Problem loading references"), |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
98 | errorStringFromMissingDependencies(missing)); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
99 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
100 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
101 | else { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
102 | QMessageBox::critical( |
368
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
103 | &state->mainWindow, |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
104 | QObject::tr("Problem opening file"), |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
205
diff
changeset
|
105 | QObject::tr("Could not open %1: %2").arg(quoted(path), errorString) |
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
205
diff
changeset
|
106 | ); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
107 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
108 | return modelIdOpt; |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
109 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
110 | |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
111 | static QString getOpenModelPath(QWidget* parent) |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
112 | { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
113 | return QFileDialog::getOpenFileName( |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
114 | parent, |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
115 | QObject::tr("Open model"), |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
116 | "", |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
117 | QObject::tr("LDraw models (*.ldr *.dat)")); |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
118 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
119 | |
278
304386ff96a4
Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
274
diff
changeset
|
120 | static ModelData* findModelData(const DocumentManager* documents, ModelId modelId) |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
121 | { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
122 | return documents->findPayload<ModelData>(modelId); |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
123 | } |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
124 | |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
125 | static ModelSubWindow* currentModelSubWindow(MainWindow* ui) |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
126 | { |
217
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
216
diff
changeset
|
127 | auto* w = ui->mdiArea->activeSubWindow(); |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
216
diff
changeset
|
128 | return qobject_cast<ModelSubWindow*>(w); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
129 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
130 | |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
131 | static ModelData* currentModelData(MainWindow* ui, const DocumentManager* documents) |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
132 | { |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
133 | if (auto* const activeSubWindow = currentModelSubWindow(ui)) { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
134 | return findModelData(documents, activeSubWindow->modelId); |
202
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
201
diff
changeset
|
135 | } |
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
201
diff
changeset
|
136 | else { |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
137 | return nullptr; |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
138 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
139 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
140 | |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
141 | static std::optional<ModelId> findCurrentModelId(MainWindow* ui) |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
142 | { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
143 | ModelSubWindow* activeSubWindow = qobject_cast<ModelSubWindow*>(ui->mdiArea->activeSubWindow()); |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
144 | if (activeSubWindow != nullptr) { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
145 | return activeSubWindow->modelId; |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
146 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
147 | else { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
148 | return {}; |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
149 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
150 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
151 | |
230
a1f3f7d9078b
rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
229
diff
changeset
|
152 | static ColorTable loadColors(const LibrariesModel* libraries) |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
153 | { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
154 | QTextStream errors; |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
155 | return libraries->loadColorTable(errors); |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
156 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
157 | |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
158 | static QString tabName(const QFileInfo& fileInfo) |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
159 | { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
160 | QString result = fileInfo.baseName(); |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
161 | if (result.isEmpty()) { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
162 | result = QObject::tr("<unnamed>"); |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
163 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
164 | return result; |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
165 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
166 | |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
167 | template<typename Fn> |
352
59a31dd8a33a
Rename forModel -> forEachModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
351
diff
changeset
|
168 | static void forEachModel(const DocumentManager* documents, Fn&& fn) |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
169 | { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
170 | forValueInMap(*documents, [&fn](const DocumentManager::ModelInfo& info) |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
171 | { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
172 | ModelData* modelSpecificData = qobject_cast<ModelData*>(info.payload); |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
173 | if (modelSpecificData != nullptr) { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
174 | fn(&info, modelSpecificData); |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
175 | } |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
176 | }); |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
177 | } |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
178 | |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
179 | static void updateRenderPreferences( |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
180 | MainWindow* ui, |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
181 | const gl::RenderPreferences* renderPreferences, |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
182 | const DocumentManager* documents) |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
183 | { |
352
59a31dd8a33a
Rename forModel -> forEachModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
351
diff
changeset
|
184 | forEachModel(documents, [&renderPreferences](const void*, const ModelData* data){ |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
185 | if (data->canvas != nullptr) { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
186 | data->canvas->setRenderPreferences(*renderPreferences); |
215
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
187 | data->canvas->setLayerEnabled(data->axesLayer.get(), renderPreferences->drawAxes); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
188 | } |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
189 | }); |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
190 | ui->setRenderStyle(renderPreferences->style); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
191 | ui->actionDrawAxes->setChecked(renderPreferences->drawAxes); |
231
a9bf6bab5ea2
Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
192 | ui->actionWireframe->setChecked(renderPreferences->wireframe); |
250
2837b549e616
I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
249
diff
changeset
|
193 | } |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
194 | |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
195 | static gl::RenderPreferences loadRenderPreferences() |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
196 | { |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
197 | return gl::RenderPreferences{ |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
198 | .style = setting<Setting::RenderStyle>(), |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
199 | .mainColor = setting<Setting::MainColor>(), |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
200 | .backgroundColor = setting<Setting::BackgroundColor>(), |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
201 | .selectedColor = setting<Setting::SelectedColor>(), |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
202 | .lineThickness = setting<Setting::LineThickness>(), |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
203 | .lineAntiAliasing = setting<Setting::LineAntiAliasing>(), |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
217
diff
changeset
|
204 | .drawAxes = setting<Setting::DrawAxes>(), |
231
a9bf6bab5ea2
Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
205 | .wireframe = setting<Setting::Wireframe>(), |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
206 | }; |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
207 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
208 | |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
209 | static void initializeTools(MainWindow* ui, ToolWidgets* toolWidgets, QWidget* parent) |
251
94b0a30a1886
Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
210 | { |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
211 | const struct |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
212 | { |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
213 | QString name, tooltip; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
214 | QPixmap icon; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
215 | QWidget* widget; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
216 | } editingModesInfo[] = { |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
217 | { |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
218 | .name = QObject::tr("Select"), |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
219 | .tooltip = QObject::tr("Select elements from the model."), |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
220 | .icon = {":/icons/navigate-outline.png"}, |
330
edb6c09cdd3c
Delete object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
329
diff
changeset
|
221 | .widget = nullptr, |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
222 | }, |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
223 | { |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
224 | .name = QObject::tr("Draw"), |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
225 | .tooltip = QObject::tr("Draw new elements into the model."), |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
226 | .icon = {":/icons/pencil-outline.png"}, |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
227 | .widget = nullptr, |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
228 | }, |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
229 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
230 | .name = QObject::tr("Circle"), |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
231 | .tooltip = QObject::tr("Draw circular primitives."), |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
232 | .icon = {":/icons/linetype-circularprimitive.png"}, |
251
94b0a30a1886
Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
233 | .widget = toolWidgets->circleToolOptions, |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
234 | }, |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
235 | }; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
236 | for (int i = 0; i < countof(editingModesInfo); ++i) { |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
237 | const auto& editingModeInfo = editingModesInfo[i]; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
238 | QAction* action = new QAction{editingModeInfo.name, parent}; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
239 | action->setCheckable(true); |
278
304386ff96a4
Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
274
diff
changeset
|
240 | action->setEnabled(false); |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
241 | action->setData(QVariant::fromValue(static_cast<editing_mode_e>(i))); |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
242 | action->setToolTip(editingModeInfo.tooltip); |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
243 | action->setIcon(QPixmap{editingModeInfo.icon}); |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
244 | ui->editingModesToolBar->addAction(action); |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
245 | QWidget* widget = editingModeInfo.widget; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
246 | if (widget == nullptr) { |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
247 | widget = new QWidget{parent}; |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
248 | } |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
249 | ui->toolWidgetStack->addWidget(widget); |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
250 | QObject::connect(action, &QAction::triggered, [ui, i]{ |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
251 | ui->toolWidgetStack->setCurrentIndex(i); |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
231
diff
changeset
|
252 | }); |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
253 | } |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
254 | } |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
255 | |
289
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
256 | template<class SubWindow, class... Args> |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
257 | SubWindow* createSubWindow(QMdiArea* mdiArea, Args&&... args) |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
258 | { |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
259 | // Qt seems to have a bug where the first created sub window does not render |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
260 | // properly until it is minimized and maximized again. This only happens |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
261 | // if we give the mdi area as a parent argument. As a work-around, we create |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
262 | // the sub window with parent=nullptr, and add it manually. |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
263 | // c.f. https://bugreports.qt.io/browse/QTBUG-69495 |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
264 | SubWindow* subWindow = new SubWindow{args..., nullptr}; |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
265 | mdiArea->addSubWindow(subWindow); |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
266 | return subWindow; |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
267 | } |
a0ddbc9a4e77
Work around a Qt bug involving the rendering behavior of the first created sub window
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
286
diff
changeset
|
268 | |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
269 | static void executeAction(QTextDocument* model, const ModelAction& action) |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
270 | { |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
271 | std::visit(overloaded{ |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
272 | [model](const AppendToModel& action){ |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
273 | QTextCursor cursor{model}; |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
274 | cursor.movePosition(QTextCursor::End); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
275 | const QString newText = modelElementToString(action.newElement); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
276 | // Make sure we have an empty line |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
277 | if (not model->lastBlock().text().isEmpty()) { |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
278 | cursor.insertBlock(); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
279 | } |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
280 | cursor.insertText(newText); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
281 | }, |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
282 | [](const DeleteFromModel&){}, |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
283 | [model](const ModifyModel& action){ |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
284 | QTextBlock block = model->findBlockByLineNumber((int) action.position); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
285 | if (block.isValid()) { |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
286 | QTextCursor cursor{block}; |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
287 | cursor.select(QTextCursor::LineUnderCursor); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
288 | cursor.insertText(modelElementToString(action.newElement)); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
289 | } |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
290 | //model->assignAt(action.position, action.newElement); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
291 | }, |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
292 | }, action); |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
293 | } |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
294 | |
356
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
295 | QFont codeEditorFontFromSettings() |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
296 | { |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
297 | QFont font{}; |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
298 | if (setting<Setting::CodeEditorUseSystemFont>()) |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
299 | { |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
300 | font.setStyleHint(QFont::Monospace); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
301 | } |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
302 | else |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
303 | { |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
304 | font.setFamily(setting<Setting::CodeEditorFontFamily>()); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
305 | font.setPointSize(setting<Setting::CodeEditorFontSize>()); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
306 | } |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
307 | return font; |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
308 | } |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
309 | |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
310 | static void openModelForEditing(MainState* state, const ModelId modelId) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
311 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
312 | QTextDocument* model = state->documents.getModelById(modelId); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
313 | if (model != nullptr) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
314 | ModelData* data = new ModelData(&state->documents); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
315 | data->tools = std::make_unique<EditTools>(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
316 | data->canvas = std::make_unique<PartRenderer>(model, &state->documents, state->colorTable); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
317 | data->axesLayer = std::make_unique<AxesLayer>(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
318 | data->gridLayer = std::make_unique<GridLayer>(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
319 | data->gridLayer->setGridMatrix(DEFAULT_GRID_MATRIX); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
320 | data->tools->setGridMatrix(DEFAULT_GRID_MATRIX); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
321 | data->model = model; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
322 | data->canvas->addRenderLayer(data->axesLayer.get()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
323 | data->canvas->setLayerEnabled(data->axesLayer.get(), setting<Setting::DrawAxes>()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
324 | data->canvas->addRenderLayer(data->gridLayer.get()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
325 | data->canvas->addRenderLayer(data->tools.get()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
326 | new LDrawSyntaxHighlighter{model}; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
327 | data->textcursor = std::make_unique<QTextCursor>(model); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
328 | state->documents.setModelPayload(modelId, data); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
329 | QObject::connect( |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
330 | data->tools.get(), |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
331 | &EditTools::modelAction, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
332 | std::bind(executeAction, model, std::placeholders::_1)); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
333 | data->canvas->setRenderPreferences(state->renderPreferences); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
334 | QObject::connect( |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
335 | data->tools.get(), |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
336 | &EditTools::newStatusText, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
337 | [&state](const QString& newStatusText) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
338 | state->mainWindow.statusBar()->showMessage(newStatusText); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
339 | }); |
328
3ea38fd469ca
Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
327
diff
changeset
|
340 | #if 0 |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
341 | QObject::connect( |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
342 | data->tools.get(), |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
343 | &EditTools::select, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
344 | [modelId, &documents](const QSet<ElementId>& indices, bool retain) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
345 | ModelData* data = findModelData(&documents, modelId); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
346 | if (data != nullptr) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
347 | if (not retain) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
348 | data->textcursor->clearSelection(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
349 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
350 | for (const ElementId id : indices) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
351 | opt<int> index = data->model->find(id); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
352 | if (index.has_value()) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
353 | const QModelIndex qindex = data->model->index(*index); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
354 | data->itemSelectionModel->select(qindex, QItemSelectionModel::Select); |
217
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
216
diff
changeset
|
355 | } |
6d95c1a41e6e
reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
216
diff
changeset
|
356 | } |
243
959469a7e149
Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
241
diff
changeset
|
357 | } |
959469a7e149
Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
241
diff
changeset
|
358 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
359 | #endif |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
360 | #if 0 |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
361 | QObject::connect(this, &Main::settingsChanged, [modelId, this]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
362 | ModelData* data = findModelData(&state.documents, modelId); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
363 | if (data != nullptr) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
364 | data->gridLayer->settingsChanged(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
365 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
366 | }); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
367 | #endif |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
368 | QObject::connect(data->canvas.get(), &PartRenderer::message, &state->messageLog, &MessageLog::addMessage); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
369 | QObject::connect( |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
370 | data->tools.get(), |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
371 | &EditTools::suggestCursor, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
372 | data->canvas.get(), |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
373 | &QWidget::setCursor); |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
374 | data->tools->setEditMode(editing_mode_e::select); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
375 | const QFileInfo fileInfo{*state->documents.modelPath(modelId)}; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
376 | auto* const subWindow = createSubWindow<ModelSubWindow>(state->mainWindow.mdiArea, modelId); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
377 | subWindow->setMinimumSize({96, 96}); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
378 | subWindow->resize({320, 200}); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
379 | subWindow->setWidget(data->canvas.get()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
380 | subWindow->setWindowTitle(tabName(fileInfo)); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
381 | subWindow->show(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
382 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
383 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
384 | |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
385 | static void updateRecentlyOpenedDocumentsMenu(MainState* state) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
386 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
387 | state->mainWindow.rebuildRecentFilesMenu(state->recentlyOpenedFiles); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
388 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
389 | |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
390 | static void restoreSettings(MainState* state) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
391 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
392 | state->recentlyOpenedFiles = setting<Setting::RecentFiles>(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
393 | state->renderPreferences = loadRenderPreferences(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
394 | state->libraries.restoreFromSettings(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
395 | updateRecentlyOpenedDocumentsMenu(state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
396 | state->colorTable = loadColors(&state->libraries); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
397 | updateRenderPreferences(&state->mainWindow, &state->renderPreferences, &state->documents); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
398 | state->mainWindow.mdiArea->setViewMode(setting<Setting::ViewMode>()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
399 | state->mainWindow.retranslateUi(&state->mainWindow); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
400 | state->mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
401 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
402 | |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
403 | static void saveSettings(MainState* state) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
404 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
405 | setSetting<Setting::MainWindowGeometry>(state->mainWindow.saveGeometry()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
406 | setSetting<Setting::MainWindowState>(state->mainWindow.saveState()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
407 | setSetting<Setting::RecentFiles>(state->recentlyOpenedFiles); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
408 | setSetting<Setting::RenderStyle>(state->renderPreferences.style); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
409 | setSetting<Setting::DrawAxes>(state->renderPreferences.drawAxes); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
410 | setSetting<Setting::Wireframe>(state->renderPreferences.wireframe); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
411 | state->libraries.storeToSettings(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
412 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
413 | |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
414 | static void addRecentlyOpenedFile(MainState* state, const QString& path) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
415 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
416 | constexpr int maxRecentlyOpenedFiles = 10; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
417 | state->recentlyOpenedFiles.removeAll(path); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
418 | state->recentlyOpenedFiles.insert(0, path); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
419 | while (state->recentlyOpenedFiles.size() > maxRecentlyOpenedFiles) |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
420 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
421 | state->recentlyOpenedFiles.removeLast(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
422 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
423 | saveSettings(state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
424 | updateRecentlyOpenedDocumentsMenu(state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
425 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
426 | |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
427 | static void saveCurrentModel(MainState* state, ModelId modelId) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
428 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
429 | QString error; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
430 | QTextStream errorStream{&error}; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
431 | const bool succeeded = state->documents.saveModel(modelId, errorStream); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
432 | if (not succeeded) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
433 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
434 | QMessageBox::critical(&state->mainWindow, QObject::tr("Save error"), error); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
435 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
436 | else |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
437 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
438 | const QString* pathPtr = state->documents.modelPath(modelId); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
439 | if (pathPtr != nullptr) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
440 | addRecentlyOpenedFile(state, *pathPtr); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
441 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
442 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
443 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
444 | |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
445 | static void saveCurrentModelAs(MainState* state) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
446 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
447 | const std::optional<ModelId> modelId = findCurrentModelId(&state->mainWindow); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
448 | if (modelId.has_value()) |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
449 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
450 | const QString* pathPtr = state->documents.modelPath(*modelId); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
451 | QString defaultPath = (pathPtr != nullptr) ? *pathPtr : ""; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
452 | const QString newPath = QFileDialog::getSaveFileName( |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
453 | &state->mainWindow, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
454 | QObject::tr("Save as…"), |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
455 | QFileInfo{defaultPath}.absoluteDir().path(), |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
456 | QObject::tr("LDraw files (*.ldr *dat);;All files (*)") |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
457 | ); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
458 | if (not newPath.isEmpty()) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
459 | QString error; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
460 | QTextStream errorStream{&error}; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
461 | state->documents.setModelPath(*modelId, newPath, state->libraries, errorStream); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
462 | QMdiSubWindow* const subWindow = state->mainWindow.mdiArea->currentSubWindow(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
463 | if (subWindow != nullptr) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
464 | subWindow->setWindowTitle(tabName(QFileInfo{newPath})); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
465 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
466 | saveCurrentModel(state, *modelId); |
350
676d0b43b577
Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
338
diff
changeset
|
467 | } |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
468 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
469 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
470 | |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
471 | static void checkEditingModeAction(MainState* state, const editing_mode_e mode) |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
472 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
473 | const bool hasDocument = currentModelData(&state->mainWindow, &state->documents) != nullptr; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
474 | for (QAction* action : state->mainWindow.editingModesToolBar->actions()) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
475 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
476 | action->setEnabled(hasDocument); |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
477 | action->setChecked(hasDocument and action->data().value<editing_mode_e>() == mode); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
478 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
479 | } |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
480 | |
370
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
481 | static void update_model_grid_matrix(MainState* state) |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
482 | { |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
483 | const glm::mat4 new_grid_matrix = state->mainWindow.gridMatrix->value(); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
484 | forEachModel(&state->documents, [&](const void*, const ModelData* data) |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
485 | { |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
486 | if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr) |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
487 | { |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
488 | data->gridLayer->setGridMatrix(new_grid_matrix); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
489 | data->tools->setGridMatrix(new_grid_matrix); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
490 | data->canvas->setModelViewOrigin(new_grid_matrix[3]); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
491 | data->canvas->update(); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
492 | } |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
493 | }); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
494 | } |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
495 | |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
496 | static void set_grid_scale(MainState* state, const float factor) |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
497 | { |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
498 | const glm::mat4 original = state->mainWindow.gridMatrix->value(); |
371
171d3f9638a9
rename some functions
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
370
diff
changeset
|
499 | const glm::mat4 unscaled = unscale_matrix(original).unscaled; |
370
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
500 | const glm::mat4 rescaled = factor * unscaled; |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
501 | state->mainWindow.gridMatrix->setValue(rescaled); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
502 | update_model_grid_matrix(state); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
503 | } |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
504 | |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
505 | static void replace_color_in_selected_code(QTextCursor* cursor, const ColorIndex color) |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
506 | { |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
507 | const auto pattern = R"(^(\s*(?:1|2|3|4|5)\s+)\d+)"; |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
508 | static const QRegularExpression regular_expression{pattern, QRegularExpression::MultilineOption}; |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
509 | QString text = cursor->selectedText(); |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
510 | // Qt has decided to be "smart" and uses strange unicode characters instead of newlines |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
511 | text.replace("\u2029", "\n"); |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
512 | text.replace(regular_expression, QStringLiteral(R"(\1%1)").arg(color.index)); |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
513 | cursor->removeSelectedText(); |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
514 | cursor->insertText(text); |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
515 | } |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
516 | |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
517 | int main(int argc, char *argv[]) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
518 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
519 | doQtRegistrations(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
520 | QApplication app{argc, argv}; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
521 | QApplication::setWindowIcon(QIcon{":/icons/appicon.png"}); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
522 | MainState state; |
361
c5e8b68e34f8
Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
359
diff
changeset
|
523 | QObject::connect( |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
524 | &state.mainWindow, |
361
c5e8b68e34f8
Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
359
diff
changeset
|
525 | &MainWindow::recentFileSelected, |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
526 | [&state](const QString& path) { |
368
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
527 | const auto id = openModelFromPath(&state, path); |
361
c5e8b68e34f8
Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
359
diff
changeset
|
528 | if (id.has_value()) |
c5e8b68e34f8
Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
359
diff
changeset
|
529 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
530 | openModelForEditing(&state, id.value()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
531 | addRecentlyOpenedFile(&state, path); |
361
c5e8b68e34f8
Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
359
diff
changeset
|
532 | } |
c5e8b68e34f8
Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
359
diff
changeset
|
533 | } |
c5e8b68e34f8
Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
359
diff
changeset
|
534 | ); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
535 | QObject::connect(state.mainWindow.actionNew, &QAction::triggered, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
536 | [&state]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
537 | openModelForEditing(&state, state.documents.newModel()); |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
538 | } |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
539 | ); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
540 | QObject::connect(state.mainWindow.actionOpen, &QAction::triggered, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
541 | [&state] |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
542 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
543 | const QString path = getOpenModelPath(&state.mainWindow); |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
544 | if (not path.isEmpty()) |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
545 | { |
368
9444de9762c3
Simplify signature of openModelFromPath
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
367
diff
changeset
|
546 | const std::optional<ModelId> id = openModelFromPath(&state, path); |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
547 | if (id.has_value()) { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
548 | openModelForEditing(&state, id.value()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
549 | addRecentlyOpenedFile(&state, path); |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
550 | } |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
551 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
552 | } |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
553 | ); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
554 | QObject::connect(state.mainWindow.actionSettingsEditor, &QAction::triggered, [ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
555 | &state, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
556 | defaultKeyboardShortcuts = uiutilities::makeKeySequenceMap(uiutilities::collectActions(&state.mainWindow))] |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
557 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
558 | if (state.mainWindow.mdiArea->findChildren<SettingsEditor*>().isEmpty()) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
559 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
560 | auto* const settingsEditor = createSubWindow<SettingsEditor>(state.mainWindow.mdiArea, defaultKeyboardShortcuts); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
561 | QObject::connect(settingsEditor, &SettingsEditor::settingsChanged, [&]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
562 | restoreSettings(&state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
563 | }); |
285
99af8bf63d10
Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
284
diff
changeset
|
564 | settingsEditor->setAttribute(Qt::WA_DeleteOnClose); |
99af8bf63d10
Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
284
diff
changeset
|
565 | settingsEditor->show(); |
99af8bf63d10
Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
284
diff
changeset
|
566 | } |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
567 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
568 | QObject::connect(state.mainWindow.actionQuit, &QAction::triggered, &state.mainWindow, &QMainWindow::close); |
215
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
569 | #if 0 |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
570 | QObject::connect(ui.actionAdjustGridToView, &QAction::triggered, [&]{ |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
571 | if (ModelData* data = currentModelData(&ui, &documents)) { |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
572 | adjustGridToView(data->canvas.get()); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
573 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
574 | }); |
215
34c6e7bc4ee1
Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
575 | #endif |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
576 | QObject::connect(state.mainWindow.actionClose, &QAction::triggered, [&state]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
577 | if (ModelData* data = currentModelData(&state.mainWindow, &state.documents)) { |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
578 | // TODO |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
579 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
580 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
581 | QObject::connect(state.mainWindow.actionSaveAs, &QAction::triggered, [&state]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
582 | saveCurrentModelAs(&state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
583 | }); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
584 | QObject::connect(state.mainWindow.actionSave, &QAction::triggered, [&state] |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
585 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
586 | const std::optional<ModelId> modelId = findCurrentModelId(&state.mainWindow); |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
587 | if (modelId.has_value()) { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
588 | const QString* path = state.documents.modelPath(*modelId); |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
589 | if (path == nullptr or path->isEmpty()) { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
590 | saveCurrentModelAs(&state); |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
591 | } |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
592 | else { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
593 | saveCurrentModel(&state, *modelId); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
594 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
595 | } |
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
596 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
597 | QObject::connect(state.mainWindow.actionDrawAxes, &QAction::triggered, [&state] |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
598 | (bool drawAxes) |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
599 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
600 | state.renderPreferences.drawAxes = drawAxes; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
601 | saveSettings(&state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
602 | updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
603 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
604 | QObject::connect(state.mainWindow.actionWireframe, &QAction::triggered, [&state] |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
605 | (bool enabled) |
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
606 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
607 | state.renderPreferences.wireframe = enabled; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
608 | saveSettings(&state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
609 | updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); |
231
a9bf6bab5ea2
Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
230
diff
changeset
|
610 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
611 | QObject::connect(&state.mainWindow, &MainWindow::renderStyleSelected, [&state] |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
612 | (gl::RenderStyle newStyle) |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
613 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
614 | state.renderPreferences.style = newStyle; |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
615 | saveSettings(&state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
616 | updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
353
diff
changeset
|
617 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
618 | initializeTools(&state.mainWindow, &state.toolWidgets, &state.mainWindow); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
619 | for (QAction* action : state.mainWindow.editingModesToolBar->actions()) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
620 | QObject::connect(action, &QAction::triggered, [action, &state] |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
621 | { |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
622 | if (ModelData* data = currentModelData(&state.mainWindow, &state.documents)) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
623 | { |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
624 | const editing_mode_e mode = action->data().value<editing_mode_e>(); |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
625 | data->tools->setEditMode(mode); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
626 | checkEditingModeAction(&state, mode); |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
627 | } |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
628 | }); |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
629 | } |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
630 | QObject::connect(state.mainWindow.mdiArea, &QMdiArea::subWindowActivated, |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
631 | [&state](QMdiSubWindow* subWindow) |
353
c229d38f04c6
Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
352
diff
changeset
|
632 | { |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
633 | ModelSubWindow* modelSubWindow = qobject_cast<ModelSubWindow*>(subWindow); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
634 | if (modelSubWindow != nullptr) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
635 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
636 | if (ModelData* data = state.documents.findPayload<ModelData>(modelSubWindow->modelId)) |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
637 | { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
638 | checkEditingModeAction(&state, data->tools->currentEditingMode()); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
639 | state.mainWindow.modelEdit->setDocument(data->model); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
640 | state.mainWindow.modelEdit->setTextCursor(*data->textcursor); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
641 | state.mainWindow.modelEdit->setFont(codeEditorFontFromSettings()); |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
642 | } |
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
643 | } |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
644 | else |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
645 | { |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
646 | checkEditingModeAction(&state, editing_mode_e::select); |
282
f2dc3bbecbfa
Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
281
diff
changeset
|
647 | } |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
648 | state.mainWindow.modelEdit->setEnabled(modelSubWindow != nullptr); |
203
1909a0123c72
Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents:
202
diff
changeset
|
649 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
650 | state.mainWindow.messageLog->setModel(&state.messageLog); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
651 | QObject::connect(&state.documents, &DocumentManager::message, &state.messageLog, &MessageLog::addMessage); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
652 | QObject::connect(&state.messageLog, &MessageLog::rowsAboutToBeInserted, [&state]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
653 | const auto bar = state.mainWindow.messageLog->verticalScrollBar(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
654 | state.mainWindow.messageLog->setProperty("shouldAutoScroll", bar->value() == bar->maximum()); |
236
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
235
diff
changeset
|
655 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
656 | QObject::connect(&state.messageLog, &MessageLog::rowsInserted, [&state]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
657 | state.mainWindow.messageLog->resizeRowsToContents(); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
658 | if (state.mainWindow.messageLog->property("shouldAutoScroll").toBool()) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
659 | state.mainWindow.messageLog->scrollToBottom(); |
236
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
235
diff
changeset
|
660 | } |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
235
diff
changeset
|
661 | }); |
251
94b0a30a1886
Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
662 | QObject::connect( |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
663 | state.toolWidgets.circleToolOptions, |
251
94b0a30a1886
Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
664 | &CircleToolOptionsWidget::optionsChanged, |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
665 | [&state](const CircleToolOptions& options) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
666 | if (ModelData* data = currentModelData(&state.mainWindow, &state.documents)) { |
251
94b0a30a1886
Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
667 | data->tools->setCircleToolOptions(options); |
94b0a30a1886
Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
668 | } |
94b0a30a1886
Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
250
diff
changeset
|
669 | }); |
262
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
670 | QObject::connect( |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
671 | state.mainWindow.actionMakeUnofficial, |
262
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
672 | &QAction::triggered, |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
673 | [&state]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
674 | if (ModelData* data = currentModelData(&state.mainWindow, &state.documents)) { |
338 | 675 | QTextDocument* const model = data->model; |
262
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
676 | for (const ModelAction& action : ldraw::makeUnofficial(model)) { |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
677 | executeAction(model, action); |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
678 | } |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
679 | } |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
259
diff
changeset
|
680 | }); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
681 | QObject::connect(state.mainWindow.actionAboutQt, &QAction::triggered, &QApplication::aboutQt); |
327 | 682 | QObject::connect( |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
683 | state.mainWindow.modelEdit, |
328
3ea38fd469ca
Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
327
diff
changeset
|
684 | &QPlainTextEdit::textChanged, |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
685 | [&state]{ |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
686 | if (ModelData* data = currentModelData(&state.mainWindow, &state.documents)) { |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
687 | state.documents.loadDependenciesForAllModels(state.libraries); |
328
3ea38fd469ca
Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
327
diff
changeset
|
688 | data->canvas->update(); |
327 | 689 | } |
690 | }); | |
356
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
691 | QObject::connect( |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
692 | state.mainWindow.gridMatrix, |
356
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
693 | &MatrixEditor::valueChanged, |
370
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
694 | [&state] |
356
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
695 | { |
370
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
696 | update_model_grid_matrix(&state); |
356
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
697 | } |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
355
diff
changeset
|
698 | ); |
367
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
699 | QObject::connect( |
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
700 | state.mainWindow.actionDelete, |
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
701 | &QAction::triggered, |
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
702 | [&state]{ |
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
703 | QTextCursor cursor = state.mainWindow.modelEdit->textCursor(); |
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
704 | cursor.removeSelectedText(); |
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
705 | } |
df61cd3d5ab4
Also connect up the "Delete" action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
363
diff
changeset
|
706 | ); |
370
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
707 | QObject::connect( |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
708 | state.mainWindow.actionGridCoarse, |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
709 | &QAction::triggered, |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
710 | [&state]{ |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
711 | set_grid_scale(&state, 5.0f); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
712 | } |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
713 | ); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
714 | QObject::connect( |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
715 | state.mainWindow.actionGridMedium, |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
716 | &QAction::triggered, |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
717 | [&state]{ |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
718 | set_grid_scale(&state, 1.0f); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
719 | } |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
720 | ); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
721 | QObject::connect( |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
722 | state.mainWindow.actionGridFine, |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
723 | &QAction::triggered, |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
724 | [&state]{ |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
725 | set_grid_scale(&state, 0.1f); |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
726 | } |
b2f9ded235a6
Grid scaling buttons now work
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
368
diff
changeset
|
727 | ); |
374
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
728 | QObject::connect( |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
729 | state.mainWindow.action_make_stuff_red, |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
730 | &QAction::triggered, |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
731 | [&state]{ |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
732 | QTextCursor cursor = state.mainWindow.modelEdit->textCursor(); |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
733 | replace_color_in_selected_code(&cursor, ColorIndex{4}); |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
734 | } |
75efc3ba5a56
More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
371
diff
changeset
|
735 | ); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
736 | restoreSettings(&state); |
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
737 | updateRenderPreferences(&state.mainWindow, &state.renderPreferences, &state.documents); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
738 | const int result = app.exec(); |
362
e1d646a4cbd8
Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
361
diff
changeset
|
739 | saveSettings(&state); |
201
5d201ee4a9c3
Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
740 | return result; |
0 | 741 | } |