src/main.cpp

Sun, 09 Apr 2023 01:12:00 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 09 Apr 2023 01:12:00 +0300
changeset 359
73b6c478378e
parent 356
65b4741b302d
child 361
c5e8b68e34f8
permissions
-rw-r--r--

The renderer now centers on the grid origin, not the part origin

201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
1 #include <QApplication>
327
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
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
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
26
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
27 static const QDir LOCALE_DIR {":/locale"};
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
719b909a7d2b Delete unused code
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 337
diff changeset
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
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
42 class Signal final : public QObject
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
43 {
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
44 Q_OBJECT
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
45 public:
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
46 Signal() : QObject{}{}
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
47 virtual ~Signal(){}
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
48 void emit()
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
49 {
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
50 Q_EMIT this->triggered();
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
51 }
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
52 Q_SIGNALS:
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
53 void triggered();
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
54 };
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
55 #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
56
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
57 static void doQtRegistrations()
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 {
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
59 QCoreApplication::setApplicationName(QStringLiteral(CMAKE_PROJECT_NAME));
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
60 QCoreApplication::setOrganizationName("hecknology.net");
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
61 QCoreApplication::setOrganizationDomain("hecknology.net");
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 236
diff changeset
62 qRegisterMetaType<Message>();
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
63 qRegisterMetaType<Library>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
64 qRegisterMetaType<QList<Library>>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
65 qRegisterMetaType<QMdiArea::ViewMode>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
66 qRegisterMetaType<gl::RenderStyle>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
67 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
68 qRegisterMetaTypeStreamOperators<Library>("Library");
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
69 qRegisterMetaTypeStreamOperators<Libraries>("Libraries");
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
70 qRegisterMetaTypeStreamOperators<gl::RenderStyle>();
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
71 qRegisterMetaTypeStreamOperators<QMdiArea::ViewMode>();
335
c5830bce1c23 Fix crashing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
72 qRegisterMetaTypeStreamOperators<Qt::ToolButtonStyle>();
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
73 #endif
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
74 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
75
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
76 static std::optional<ModelId> openModelFromPath(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
77 const QString& path,
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
78 const LibrariesModel* libraries,
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
79 DocumentManager* documents,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
80 QWidget* parent)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
81 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
82 QString errorString;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
83 QTextStream errorStream{&errorString};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
84 const std::optional<ModelId> modelIdOpt = documents->openModel(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
85 path,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
86 errorStream,
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
87 OpenType::ManuallyOpened);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
88 if (modelIdOpt.has_value()) {
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
89 const DocumentManager::MissingDependencies missing = documents->loadDependenciesForAllModels(*libraries);
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
90 if (not missing.empty()) {
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
91 QMessageBox::warning(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
92 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
93 QObject::tr("Problem loading references"),
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
94 errorStringFromMissingDependencies(missing));
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
95 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
96 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
97 else {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
98 QMessageBox::critical(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
99 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
100 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
101 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
102 );
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
103 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
104 return modelIdOpt;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
105 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
106
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
107 static QString getOpenModelPath(QWidget* parent)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
108 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
109 return QFileDialog::getOpenFileName(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
110 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
111 QObject::tr("Open model"),
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 QObject::tr("LDraw models (*.ldr *.dat)"));
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
114 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
115
278
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
116 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
117 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
118 return documents->findPayload<ModelData>(modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
119 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
120
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
121 static ModelSubWindow* currentModelSubWindow(MainWindow* ui)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
122 {
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
123 auto* w = ui->mdiArea->activeSubWindow();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
124 return qobject_cast<ModelSubWindow*>(w);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
125 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
126
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
127 static ModelData* currentModelData(MainWindow* ui, const DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
128 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
129 if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
130 return findModelData(documents, activeSubWindow->modelId);
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
131 }
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
132 else {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
133 return nullptr;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
134 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
135 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
136
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
137 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
138 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
139 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
140 if (activeSubWindow != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
141 return activeSubWindow->modelId;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
142 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
143 else {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
144 return {};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
145 }
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
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
148 static QString title(MainWindow* ui)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
149 {
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
150 QMdiSubWindow* subWindow = ui->mdiArea->activeSubWindow();
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
151 QString titlestring;
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
152 const QString versionString = fullVersionString(QLocale::ShortFormat);
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
153 if (subWindow != nullptr) {
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
154 titlestring = QObject::tr("%1 - %2").arg(subWindow->windowTitle(), versionString);
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
155 }
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
156 else {
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
157 titlestring = versionString;
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
158 }
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
159 if (/* DISABLES CODE */ (true)
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
160 and std::strcmp(CMAKE_BUILD_TYPE, "Release") != 0
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
161 and std::strcmp(CMAKE_BUILD_TYPE, "MinSizeRel") != 0
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
162 ) {
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
163 titlestring += QObject::tr(" [%1]").arg(CMAKE_BUILD_TYPE);
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
164 }
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
165 return titlestring;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
166 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
167
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
168 static ColorTable loadColors(const LibrariesModel* libraries)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
169 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
170 QTextStream errors;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
171 return libraries->loadColorTable(errors);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
172 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
173
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
174 static QString tabName(const QFileInfo& fileInfo)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
175 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
176 QString result = fileInfo.baseName();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
177 if (result.isEmpty()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
178 result = QObject::tr("<unnamed>");
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
179 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
180 return result;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
181 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
182
351
9e3c1f838406 Add missing 'static' keywords and deleted unused code
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 350
diff changeset
183 static void rebuildRecentFilesMenu(QMenu* menu, const QStringList& strings, QWidget* parent)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
184 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
185 menu->clear();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
186 for (const QString& path : strings) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
187 QAction* action = new QAction{path, parent};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
188 action->setData(path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
189 menu->addAction(action);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
190 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
191 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
192
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
193 template<typename Fn>
352
59a31dd8a33a Rename forModel -> forEachModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 351
diff changeset
194 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
195 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
196 forValueInMap(*documents, [&fn](const DocumentManager::ModelInfo& info)
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
197 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
198 ModelData* modelSpecificData = qobject_cast<ModelData*>(info.payload);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
199 if (modelSpecificData != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
200 fn(&info, modelSpecificData);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
201 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
202 });
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
203 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
204
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
205 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
206 MainWindow* ui,
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
207 const gl::RenderPreferences* renderPreferences,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
208 const DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
209 {
352
59a31dd8a33a Rename forModel -> forEachModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 351
diff changeset
210 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
211 if (data->canvas != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
212 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
213 data->canvas->setLayerEnabled(data->axesLayer.get(), renderPreferences->drawAxes);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
214 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
215 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
216 ui->setRenderStyle(renderPreferences->style);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
217 ui->actionDrawAxes->setChecked(renderPreferences->drawAxes);
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
218 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
219 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
220
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
221 static gl::RenderPreferences loadRenderPreferences()
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
222 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
223 return gl::RenderPreferences{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
224 .style = setting<Setting::RenderStyle>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
225 .mainColor = setting<Setting::MainColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
226 .backgroundColor = setting<Setting::BackgroundColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
227 .selectedColor = setting<Setting::SelectedColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
228 .lineThickness = setting<Setting::LineThickness>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
229 .lineAntiAliasing = setting<Setting::LineAntiAliasing>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
230 .drawAxes = setting<Setting::DrawAxes>(),
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
231 .wireframe = setting<Setting::Wireframe>(),
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
232 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
233 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
234
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
235 struct ToolWidgets
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
236 {
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
237 CircleToolOptionsWidget* circleToolOptions;
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
238 };
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
239
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
240 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
241 {
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 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
243 {
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 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
245 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
246 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
247 } 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
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 .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
250 .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
251 .icon = {":/icons/navigate-outline.png"},
330
edb6c09cdd3c Delete object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 329
diff changeset
252 .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
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 .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
256 .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
257 .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
258 .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
259 },
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
260 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
261 .name = QObject::tr("Circle"),
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
262 .tooltip = QObject::tr("Draw circular primitives."),
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
263 .icon = {":/icons/linetype-circularprimitive.png"},
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
264 .widget = toolWidgets->circleToolOptions,
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
265 },
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
266 };
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
267 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
268 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
269 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
270 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
271 action->setEnabled(false);
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
272 action->setData(static_cast<EditingMode>(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
273 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
274 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
275 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
276 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
277 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
278 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
279 }
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
280 ui->toolWidgetStack->addWidget(widget);
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
281 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
282 ui->toolWidgetStack->setCurrentIndex(i);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
283 });
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
284 }
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
285 }
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
286
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
287 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
288 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
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
290 // 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
291 // 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
292 // 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
293 // 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
294 // 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
295 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
296 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
297 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
298 }
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
299
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
300 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
301 {
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
302 std::visit(overloaded{
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
303 [model](const AppendToModel& action){
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
304 QTextCursor cursor{model};
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
305 cursor.movePosition(QTextCursor::End);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
306 const QString newText = modelElementToString(action.newElement);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
307 // Make sure we have an empty line
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
308 if (not model->lastBlock().text().isEmpty()) {
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
309 cursor.insertBlock();
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
310 }
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
311 cursor.insertText(newText);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
312 },
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
313 [](const DeleteFromModel&){},
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
314 [model](const ModifyModel& action){
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
315 QTextBlock block = model->findBlockByLineNumber((int) action.position);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
316 if (block.isValid()) {
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
317 QTextCursor cursor{block};
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
318 cursor.select(QTextCursor::LineUnderCursor);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
319 cursor.insertText(modelElementToString(action.newElement));
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
320 }
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
321 //model->assignAt(action.position, action.newElement);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
322 },
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
323 }, action);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
324 }
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
325
356
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
326 QFont codeEditorFontFromSettings()
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
327 {
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
328 QFont font{};
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
329 if (setting<Setting::CodeEditorUseSystemFont>())
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
330 {
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
331 font.setStyleHint(QFont::Monospace);
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
332 }
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
333 else
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
334 {
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
335 font.setFamily(setting<Setting::CodeEditorFontFamily>());
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
336 font.setPointSize(setting<Setting::CodeEditorFontSize>());
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
337 }
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
338 return font;
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
339 }
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
340
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
341 constexpr glm::mat4 DEFAULT_GRID_MATRIX = {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}};
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
342
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
343 int main(int argc, char *argv[])
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
344 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
345 doQtRegistrations();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents: 2
diff changeset
346 QApplication app{argc, argv};
284
9266239cf72b Move app icon definition to main.cpp
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 282
diff changeset
347 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"});
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
348 MainWindow mainWindow;
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
349 DocumentManager documents;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
350 QString currentLanguage = "en";
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
351 QTranslator translator{&mainWindow};
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
352 LibrariesModel libraries{&mainWindow};
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
353 QStringList recentlyOpenedFiles;
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
354 ColorTable colorTable;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
355 gl::RenderPreferences renderPreferences;
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
356 MessageLog messageLog;
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
357 Signal settingsChanged;
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
358 ToolWidgets toolWidgets{
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
359 .circleToolOptions = new CircleToolOptionsWidget{&mainWindow},
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
360 };
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
361 const auto updateTitle = [&mainWindow]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
362 mainWindow.setWindowTitle(title(&mainWindow));
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
363 };
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
364 const uiutilities::KeySequenceMap defaultKeyboardShortcuts =
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
365 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow));
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
366 const auto saveSettings = [
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
367 &libraries,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
368 &mainWindow,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
369 &recentlyOpenedFiles,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
370 &renderPreferences,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
371 &settingsChanged]
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
372 {
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
373 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry());
240
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
374 setSetting<Setting::MainWindowState>(mainWindow.saveState());
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
375 setSetting<Setting::RecentFiles>(recentlyOpenedFiles);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
376 setSetting<Setting::RenderStyle>(renderPreferences.style);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
377 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes);
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
378 setSetting<Setting::Wireframe>(renderPreferences.wireframe);
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
379 libraries.storeToSettings();
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
380 settingsChanged.emit();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
381 };
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
382 const auto openModelForEditing = [
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
383 &colorTable,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
384 &documents,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
385 &mainWindow,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
386 &messageLog,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
387 &renderPreferences,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
388 &settingsChanged]
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
389 (const ModelId modelId)
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
390 {
338
719b909a7d2b Delete unused code
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 337
diff changeset
391 QTextDocument* model = documents.getModelById(modelId);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
392 if (model != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
393 ModelData* data = new ModelData(&documents);
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
394 data->tools = std::make_unique<EditTools>();
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
395 data->canvas = std::make_unique<PartRenderer>(model, &documents, colorTable);
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
396 data->axesLayer = std::make_unique<AxesLayer>();
216
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
397 data->gridLayer = std::make_unique<GridLayer>();
356
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
398 data->gridLayer->setGridMatrix(DEFAULT_GRID_MATRIX);
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
399 data->tools->setGridMatrix(DEFAULT_GRID_MATRIX);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
400 data->model = 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
401 data->canvas->addRenderLayer(data->axesLayer.get());
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
402 data->canvas->setLayerEnabled(data->axesLayer.get(), setting<Setting::DrawAxes>());
216
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
403 data->canvas->addRenderLayer(data->gridLayer.get());
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
404 data->canvas->addRenderLayer(data->tools.get());
333
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 332
diff changeset
405 new LDrawSyntaxHighlighter{model};
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 332
diff changeset
406 data->textcursor = std::make_unique<QTextCursor>(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
407 documents.setModelPayload(modelId, data);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
408 QObject::connect(
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
409 data->tools.get(),
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
410 &EditTools::modelAction,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
411 std::bind(executeAction, model, std::placeholders::_1));
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
412 data->canvas->setRenderPreferences(renderPreferences);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
413 QObject::connect(
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
414 data->tools.get(),
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
415 &EditTools::newStatusText,
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
416 [&mainWindow](const QString& newStatusText) {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
417 mainWindow.statusBar()->showMessage(newStatusText);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
418 });
328
3ea38fd469ca Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 327
diff changeset
419 #if 0
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
420 QObject::connect(
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
421 data->tools.get(),
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
422 &EditTools::select,
309
d862721d19a3 Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 299
diff changeset
423 [modelId, &documents](const QSet<ElementId>& indices, bool retain) {
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
424 ModelData* data = findModelData(&documents, modelId);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
425 if (data != nullptr) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
426 if (not retain) {
328
3ea38fd469ca Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 327
diff changeset
427 data->textcursor->clearSelection();
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
428 }
309
d862721d19a3 Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 299
diff changeset
429 for (const ElementId id : indices) {
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
430 opt<int> index = data->model->find(id);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
431 if (index.has_value()) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
432 const QModelIndex qindex = data->model->index(*index);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
433 data->itemSelectionModel->select(qindex, QItemSelectionModel::Select);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
434 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
435 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
436 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
437 });
328
3ea38fd469ca Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 327
diff changeset
438 #endif
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
439 QObject::connect(&settingsChanged, &Signal::triggered, [modelId, &documents]{
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
440 ModelData* data = findModelData(&documents, modelId);
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
441 if (data != nullptr) {
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
442 data->gridLayer->settingsChanged();
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
443 }
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
444 });
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 236
diff changeset
445 QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage);
311
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
446 QObject::connect(
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
447 data->tools.get(),
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
448 &EditTools::suggestCursor,
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
449 data->canvas.get(),
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
450 &QWidget::setCursor);
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
451 data->tools->setEditMode(SelectMode);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
452 const QFileInfo fileInfo{*documents.modelPath(modelId)};
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
453 auto* const subWindow = createSubWindow<ModelSubWindow>(mainWindow.mdiArea, modelId);
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 281
diff changeset
454 subWindow->setMinimumSize({96, 96});
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
455 subWindow->resize({320, 200});
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
456 subWindow->setWidget(data->canvas.get());
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
457 subWindow->setWindowTitle(tabName(fileInfo));
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
458 subWindow->show();
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
459 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
460 };
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
461 const auto updateRecentlyOpenedDocumentsMenu = [
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
462 &documents,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
463 &libraries,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
464 &mainWindow,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
465 &openModelForEditing,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
466 &recentlyOpenedFiles]
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
467 {
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
468 rebuildRecentFilesMenu(mainWindow.menuRecentFiles, recentlyOpenedFiles, &mainWindow);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
469 for (QAction* action : mainWindow.menuRecentFiles->actions()) {
350
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
470 QString path = action->data().toString();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
471 QObject::connect(
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
472 action,
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
473 &QAction::triggered,
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
474 [path, &libraries, &documents, &mainWindow, &openModelForEditing]() {
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
475 const auto id = openModelFromPath(path, &libraries, &documents, &mainWindow);
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
476 if (id.has_value())
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
477 {
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
478 openModelForEditing(id.value());
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
479 }
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
480 }
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
481 );
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
482 }
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
483 };
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
484 const auto restoreSettings = [
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
485 &colorTable,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
486 &documents,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
487 &libraries,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
488 &mainWindow,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
489 &recentlyOpenedFiles,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
490 &renderPreferences,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
491 &settingsChanged,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
492 &updateRecentlyOpenedDocumentsMenu]
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
493 {
350
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
494 recentlyOpenedFiles = setting<Setting::RecentFiles>();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
495 renderPreferences = loadRenderPreferences();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
496 libraries.restoreFromSettings();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
497 updateRecentlyOpenedDocumentsMenu();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
498 colorTable = loadColors(&libraries);
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
499 updateRenderPreferences(&mainWindow, &renderPreferences, &documents);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
500 mainWindow.mdiArea->setViewMode(setting<Setting::ViewMode>());
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
501 mainWindow.retranslateUi(&mainWindow);
350
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
502 mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>());
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
503 settingsChanged.emit();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
504 };
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
505 const auto addRecentlyOpenedFile = [
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
506 &recentlyOpenedFiles,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
507 &saveSettings,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
508 &updateRecentlyOpenedDocumentsMenu]
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
509 (const QString& path)
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
510 {
350
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
511 constexpr int maxRecentlyOpenedFiles = 10;
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
512 recentlyOpenedFiles.removeAll(path);
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
513 recentlyOpenedFiles.insert(0, path);
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
514 while (recentlyOpenedFiles.size() > maxRecentlyOpenedFiles)
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
515 {
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
516 recentlyOpenedFiles.removeLast();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
517 }
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
518 saveSettings();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
519 updateRecentlyOpenedDocumentsMenu();
676d0b43b577 Opening recently opened files works again now
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
520 };
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
521 QObject::connect(mainWindow.actionNew, &QAction::triggered,
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
522 [&documents, &openModelForEditing]{
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
523 openModelForEditing(documents.newModel());
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
524 }
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
525 );
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
526 QObject::connect(mainWindow.actionOpen, &QAction::triggered,
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
527 [&addRecentlyOpenedFile, &documents, &libraries, &mainWindow, &openModelForEditing]
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
528 {
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
529 const QString path = getOpenModelPath(&mainWindow);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
530 if (not path.isEmpty())
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
531 {
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
532 const std::optional<ModelId> id = openModelFromPath(path, &libraries, &documents, &mainWindow);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
533 if (id.has_value()) {
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
534 openModelForEditing(id.value());
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
535 addRecentlyOpenedFile(path);
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
536 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
537 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
538 }
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
539 );
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
540 QObject::connect(mainWindow.actionSettingsEditor, &QAction::triggered, [&defaultKeyboardShortcuts, &restoreSettings, &settingsChanged, &mainWindow]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
541 if (mainWindow.mdiArea->findChildren<SettingsEditor*>().isEmpty()) {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
542 auto* const settingsEditor = createSubWindow<SettingsEditor>(mainWindow.mdiArea, defaultKeyboardShortcuts);
285
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 284
diff changeset
543 QObject::connect(&settingsChanged, &Signal::triggered, settingsEditor, &SettingsEditor::loadSettings);
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 284
diff changeset
544 QObject::connect(settingsEditor, &SettingsEditor::settingsChanged, restoreSettings);
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 284
diff changeset
545 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
546 settingsEditor->show();
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 284
diff changeset
547 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
548 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
549 QObject::connect(mainWindow.actionQuit, &QAction::triggered, &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
550 #if 0
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
551 QObject::connect(ui.actionAdjustGridToView, &QAction::triggered, [&]{
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
552 if (ModelData* data = currentModelData(&ui, &documents)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
553 adjustGridToView(data->canvas.get());
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
554 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
555 });
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
556 #endif
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
557 QObject::connect(mainWindow.actionClose, &QAction::triggered, [&mainWindow, &documents]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
558 if (ModelData* data = currentModelData(&mainWindow, &documents)) {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
559 // TODO
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
560 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
561 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
562 const auto save = [&addRecentlyOpenedFile, &mainWindow](DocumentManager* documents, ModelId modelId){
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
563 QString error;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
564 QTextStream errorStream{&error};
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
565 const bool succeeded = documents->saveModel(modelId, errorStream);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
566 if (not succeeded)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
567 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
568 QMessageBox::critical(&mainWindow, QObject::tr("Save error"), error);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
569 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
570 else
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
571 {
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
572 const QString* pathPtr = documents->modelPath(modelId);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
573 if (pathPtr != nullptr) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
574 addRecentlyOpenedFile(*pathPtr);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
575 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
576 }
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
577 };
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
578 const auto actionSaveAs = [&documents, &libraries, &mainWindow, &save]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
579 const std::optional<ModelId> modelId = findCurrentModelId(&mainWindow);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
580 if (modelId.has_value())
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
581 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
582 const QString* pathPtr = documents.modelPath(*modelId);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
583 QString defaultPath = (pathPtr != nullptr) ? *pathPtr : "";
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
584 const QString newPath = QFileDialog::getSaveFileName(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
585 &mainWindow,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
586 QObject::tr("Save as…"),
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
587 QFileInfo{defaultPath}.absoluteDir().path(),
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
588 QObject::tr("LDraw files (*.ldr *dat);;All files (*)")
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
589 );
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
590 if (not newPath.isEmpty()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
591 QString error;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
592 QTextStream errorStream{&error};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
593 documents.setModelPath(*modelId, newPath, libraries, errorStream);
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
594 QMdiSubWindow* const subWindow = mainWindow.mdiArea->currentSubWindow();
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
595 if (subWindow != nullptr) {
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
596 subWindow->setWindowTitle(tabName(QFileInfo{newPath}));
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
597 }
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
598 save(&documents, *modelId);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
599 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
600 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
601 };
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
602 QObject::connect(mainWindow.actionSaveAs, &QAction::triggered, actionSaveAs);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
603 QObject::connect(mainWindow.actionSave, &QAction::triggered, [
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
604 &actionSaveAs,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
605 &documents,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
606 &save,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
607 &mainWindow]
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
608 {
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
609 const std::optional<ModelId> modelId = findCurrentModelId(&mainWindow);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
610 if (modelId.has_value()) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
611 const QString* path = documents.modelPath(*modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
612 if (path == nullptr or path->isEmpty()) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
613 actionSaveAs();
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
614 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
615 else {
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
616 save(&documents, *modelId);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
617 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
618 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
619 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
620 QObject::connect(mainWindow.actionDrawAxes, &QAction::triggered, [
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
621 &documents,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
622 &renderPreferences,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
623 &saveSettings,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
624 &mainWindow]
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
625 (bool drawAxes)
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
626 {
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
627 renderPreferences.drawAxes = drawAxes;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
628 saveSettings();
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
629 updateRenderPreferences(&mainWindow, &renderPreferences, &documents);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
630 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
631 QObject::connect(mainWindow.actionWireframe, &QAction::triggered, [
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
632 &documents,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
633 &renderPreferences,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
634 &saveSettings,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
635 &mainWindow]
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
636 (bool enabled)
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
637 {
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
638 renderPreferences.wireframe = enabled;
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
639 saveSettings();
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
640 updateRenderPreferences(&mainWindow, &renderPreferences, &documents);
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
641 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
642 QObject::connect(&mainWindow, &MainWindow::renderStyleSelected, [
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
643 &documents,
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
644 &mainWindow,
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
645 &renderPreferences,
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
646 &saveSettings]
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
647 (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
648 {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
649 renderPreferences.style = newStyle;
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
650 saveSettings();
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
651 updateRenderPreferences(&mainWindow, &renderPreferences, &documents);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
652 });
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
653 const auto checkEditingModeAction = [&mainWindow, &documents](EditingMode mode) {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
654 const bool hasDocument = currentModelData(&mainWindow, &documents) != nullptr;
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
655 for (QAction* action : mainWindow.editingModesToolBar->actions()) {
278
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
656 action->setEnabled(hasDocument);
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
657 action->setChecked(hasDocument and action->data().value<EditingMode>() == 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
658 }
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
659 };
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
660 initializeTools(&mainWindow, &toolWidgets, &mainWindow);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
661 for (QAction* action : mainWindow.editingModesToolBar->actions()) {
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
662 QObject::connect(action, &QAction::triggered, [
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
663 action,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
664 &checkEditingModeAction,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
665 &documents,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
666 &mainWindow]
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
667 {
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
668 if (ModelData* data = currentModelData(&mainWindow, &documents)) {
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
669 const EditingMode mode = action->data().value<EditingMode>();
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
670 data->tools->setEditMode(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
671 checkEditingModeAction(mode);
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
672 }
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
673 });
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
674 }
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
675 QObject::connect(mainWindow.mdiArea, &QMdiArea::subWindowActivated, [
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
676 &checkEditingModeAction,
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
677 &documents,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
678 &mainWindow,
353
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
679 &updateTitle]
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
680 (QMdiSubWindow* subWindow)
c229d38f04c6 Use explicit captures in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 352
diff changeset
681 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
682 ModelSubWindow* modelSubWindow = qobject_cast<ModelSubWindow*>(subWindow);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
683 if (modelSubWindow != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
684 if (ModelData* data = documents.findPayload<ModelData>(modelSubWindow->modelId)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
685 checkEditingModeAction(data->tools->currentEditingMode());
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
686 mainWindow.modelEdit->setDocument(data->model);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
687 mainWindow.modelEdit->setTextCursor(*data->textcursor);
356
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
688 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
689 }
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
690 }
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 281
diff changeset
691 else {
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 281
diff changeset
692 checkEditingModeAction(EditingMode::SelectMode);
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 281
diff changeset
693 }
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
694 mainWindow.modelEdit->setEnabled(modelSubWindow != nullptr);
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
695 updateTitle();
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
696 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
697 mainWindow.messageLog->setModel(&messageLog);
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
698 QObject::connect(&documents, &DocumentManager::message, &messageLog, &MessageLog::addMessage);
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
699 QObject::connect(&messageLog, &MessageLog::rowsAboutToBeInserted, [&mainWindow]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
700 const auto bar = mainWindow.messageLog->verticalScrollBar();
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
701 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
702 });
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
703 QObject::connect(&messageLog, &MessageLog::rowsInserted, [&mainWindow]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
704 mainWindow.messageLog->resizeRowsToContents();
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
705 if (mainWindow.messageLog->property("shouldAutoScroll").toBool()) {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
706 mainWindow.messageLog->scrollToBottom();
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
707 }
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
708 });
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
709 QObject::connect(
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
710 toolWidgets.circleToolOptions,
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
711 &CircleToolOptionsWidget::optionsChanged,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
712 [&mainWindow, &documents](const CircleToolOptions& options) {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
713 if (ModelData* data = currentModelData(&mainWindow, &documents)) {
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
714 data->tools->setCircleToolOptions(options);
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
715 }
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
716 });
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
717 QObject::connect(
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
718 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
719 &QAction::triggered,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
720 [&documents, &mainWindow]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
721 if (ModelData* data = currentModelData(&mainWindow, &documents)) {
338
719b909a7d2b Delete unused code
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 337
diff changeset
722 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
723 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
724 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
725 }
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
726 }
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
727 });
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
728 QObject::connect(mainWindow.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt);
327
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
729 QObject::connect(
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
730 mainWindow.modelEdit,
328
3ea38fd469ca Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 327
diff changeset
731 &QPlainTextEdit::textChanged,
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
732 [&documents, &libraries, &mainWindow]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
733 if (ModelData* data = currentModelData(&mainWindow, &documents)) {
329
6d75fa09cc0c fix some issues like subfile references not showing up properly
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 328
diff changeset
734 documents.loadDependenciesForAllModels(libraries);
328
3ea38fd469ca Replace item view with a text editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 327
diff changeset
735 data->canvas->update();
327
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
736 }
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
737 });
356
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
738 QObject::connect(
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
739 mainWindow.gridMatrix,
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
740 &MatrixEditor::valueChanged,
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
741 [&](const glm::mat4& newGridMatrix)
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
742 {
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
743 forEachModel(&documents, [&](const void*, const ModelData* data)
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
744 {
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
745 if (data->gridLayer != nullptr and data->tools != nullptr and data->canvas != nullptr)
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
746 {
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
747 data->gridLayer->setGridMatrix(newGridMatrix);
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
748 data->tools->setGridMatrix(newGridMatrix);
359
73b6c478378e The renderer now centers on the grid origin, not the part origin
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 356
diff changeset
749 data->canvas->setModelViewOrigin(newGridMatrix[3]);
356
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
750 data->canvas->update();
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
751 }
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
752 });
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
753 }
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
754 );
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
755 mainWindow.gridMatrix->setValue(DEFAULT_GRID_MATRIX);
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
756 mainWindow.tabifyDockWidget(mainWindow.messageLogDock, mainWindow.toolOptionsDock);
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
757 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>());
240
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
758 mainWindow.restoreState(setting<Setting::MainWindowState>());
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
759 // If a dock is made floating and the app is closed, the dock becomes invisible
241
c4e2afabcb90 fix typo
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 240
diff changeset
760 // after the restoreState call. So we make them visible again here.
240
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
761 for (QDockWidget* dock : mainWindow.findChildren<QDockWidget*>()) {
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
762 dock->setVisible(true);
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
763 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
764 restoreSettings();
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
765 updateRenderPreferences(&mainWindow, &renderPreferences, &documents);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 353
diff changeset
766 mainWindow.actionAbout->setText(mainWindow.actionAbout->text().arg(CMAKE_PROJECT_NAME));
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
767 updateTitle();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
768 mainWindow.show();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
769 const int result = app.exec();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
770 saveSettings();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
771 return result;
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
772 }

mercurial