src/main.cpp

Sun, 03 Jul 2022 22:32:50 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 03 Jul 2022 22:32:50 +0300
changeset 327
2aa15daa0216
parent 325
64ddcd77639f
child 328
3ea38fd469ca
permissions
-rw-r--r--

Add copy action

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>
272
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
10 #include <ui_about.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
11 #include <ui_mainwindow.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/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
13 #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
14 #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
15 #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
16 #include "src/ldrawalgorithm.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
17 #include "src/messagelog.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
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/ui/objecteditor.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/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
23 #include "src/widgets/colorselectdialog.h"
293
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
24 #include <GL/glew.h>
24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
25
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
26 static const QDir LOCALE_DIR {":/locale"};
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
28 class ModelSubWindow : public QMdiSubWindow
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
29 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
30 Q_OBJECT
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
31 public:
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
32 const ModelId modelId;
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
33 explicit ModelSubWindow(ModelId modelId, QWidget* widget = nullptr) :
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
34 QMdiSubWindow{widget},
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
35 modelId{modelId}
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
36 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
37 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
38 protected:
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
39 void closeEvent(QCloseEvent* event) override
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
40 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
41 event->ignore();
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
42 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
43 };
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
44
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
45 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
46 {
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
47 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
48 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
49 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
50 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
51 std::unique_ptr<QItemSelectionModel> itemSelectionModel;
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
52 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
53 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
54 std::unique_ptr<GridLayer> gridLayer;
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
55 Model* model;
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 };
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
57
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
58 class Signal final : public QObject
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
59 {
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
60 Q_OBJECT
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
61 public:
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
62 Signal() : QObject{}{}
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
63 virtual ~Signal(){}
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
64 void emit()
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
65 {
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
66 Q_EMIT this->triggered();
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
67 }
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
68 Q_SIGNALS:
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
69 void triggered();
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
70 };
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
71 #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
72
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
73 static void doQtRegistrations()
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 {
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
75 QCoreApplication::setApplicationName(QStringLiteral(CMAKE_PROJECT_NAME));
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
76 QCoreApplication::setOrganizationName("hecknology.net");
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
77 QCoreApplication::setOrganizationDomain("hecknology.net");
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 236
diff changeset
78 qRegisterMetaType<Message>();
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
79 qRegisterMetaType<Library>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
80 qRegisterMetaType<QList<Library>>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
81 qRegisterMetaType<QMdiArea::ViewMode>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
82 qRegisterMetaType<gl::RenderStyle>();
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
83 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
84 qRegisterMetaTypeStreamOperators<Library>("Library");
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
85 qRegisterMetaTypeStreamOperators<Libraries>("Libraries");
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
86 qRegisterMetaTypeStreamOperators<gl::RenderStyle>();
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
87 qRegisterMetaTypeStreamOperators<QMdiArea::ViewMode>();
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 251
diff changeset
88 #endif
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
89 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
90
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
91 template<typename BaseType, typename MemberType, typename DataType>
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
92 struct MemberData
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
93 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
94 std::size_t member;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
95 DataType payload;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
96 constexpr MemberType memberInstance(BaseType* instance) const
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
97 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
98 return *reinterpret_cast<MemberType*>(reinterpret_cast<char*>(instance) + this->member);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
99 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
100 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
101
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
102 static constexpr MemberData<Ui_MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
103 { offsetof(Ui_MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
104 { offsetof(Ui_MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
105 { offsetof(Ui_MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
106 { offsetof(Ui_MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
107 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
108
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
109 static std::optional<ModelId> openModelFromPath(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
110 const QString& path,
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
111 const LibrariesModel* libraries,
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
112 DocumentManager* documents,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
113 QWidget* parent)
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 QString errorString;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
116 QTextStream errorStream{&errorString};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
117 const std::optional<ModelId> modelIdOpt = documents->openModel(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
118 path,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
119 errorStream,
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
120 OpenType::ManuallyOpened);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
121 if (modelIdOpt.has_value()) {
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
122 const DocumentManager::MissingDependencies missing = documents->loadDependenciesForAllModels(*libraries);
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
123 if (not missing.empty()) {
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
124 QMessageBox::warning(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
125 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
126 QObject::tr("Problem loading references"),
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
127 errorStringFromMissingDependencies(missing));
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
128 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
129 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
130 else {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
131 QMessageBox::critical(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
132 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
133 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
134 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
135 );
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
136 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
137 return modelIdOpt;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
138 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
139
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
140 static QString getOpenModelPath(QWidget* parent)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
141 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
142 return QFileDialog::getOpenFileName(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
143 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
144 QObject::tr("Open model"),
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 QObject::tr("LDraw models (*.ldr *.dat)"));
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
147 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
148
278
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
149 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
150 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
151 return documents->findPayload<ModelData>(modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
152 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
153
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
154 static ModelSubWindow* currentModelSubWindow(Ui_MainWindow* ui)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
155 {
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
156 auto* w = ui->mdiArea->activeSubWindow();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
157 return qobject_cast<ModelSubWindow*>(w);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
158 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
159
278
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
160 static ModelData* currentModelData(Ui_MainWindow* ui, const DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
161 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
162 if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
163 return findModelData(documents, activeSubWindow->modelId);
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
164 }
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
165 else {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
166 return nullptr;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
167 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
168 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
169
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
170 static Model* currentModelBody(Ui_MainWindow* ui, DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
171 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
172 if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
173 return documents->getModelById(activeSubWindow->modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
174 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
175 else {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
176 return nullptr;
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
177 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
178 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
179
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
180 static std::optional<ModelId> findCurrentModelId(Ui_MainWindow* ui)
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
181 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
182 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
183 if (activeSubWindow != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
184 return activeSubWindow->modelId;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
185 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
186 else {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
187 return {};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
188 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
189 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
190
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
191 static QString title(Ui_MainWindow* ui)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
192 {
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
193 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
194 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
195 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
196 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
197 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
198 }
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
199 else {
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
200 titlestring = versionString;
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
201 }
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
202 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
203 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
204 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
205 ) {
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
206 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
207 }
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
208 return titlestring;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
209 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
210
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
211 static ColorTable loadColors(const LibrariesModel* libraries)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
212 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
213 QTextStream errors;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
214 return libraries->loadColorTable(errors);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
215 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
216
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
217 static QString tabName(const QFileInfo& fileInfo)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
218 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
219 QString result = fileInfo.baseName();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
220 if (result.isEmpty()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
221 result = QObject::tr("<unnamed>");
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 result;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
224 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
225
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
226 void rebuildRecentFilesMenu(QMenu* menu, const QStringList& strings, QWidget* parent)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
227 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
228 menu->clear();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
229 for (const QString& path : strings) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
230 QAction* action = new QAction{path, parent};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
231 action->setData(path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
232 menu->addAction(action);
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 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
235
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
236 template<typename Fn>
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
237 static void forModel(const DocumentManager* documents, Fn&& fn)
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
238 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
239 forValueInMap(*documents, [&fn](const DocumentManager::ModelInfo& info)
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
240 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
241 ModelData* modelSpecificData = qobject_cast<ModelData*>(info.payload);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
242 if (modelSpecificData != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
243 fn(&info, modelSpecificData);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
244 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
245 });
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
246 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
247
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
248 static void updateRenderPreferences(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
249 Ui_MainWindow* ui,
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
250 const gl::RenderPreferences* renderPreferences,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
251 const DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
252 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
253 forModel(documents, [&renderPreferences](const void*, const ModelData* data){
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
254 if (data->canvas != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
255 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
256 data->canvas->setLayerEnabled(data->axesLayer.get(), renderPreferences->drawAxes);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
257 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
258 });
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
259 for (auto data : ::renderStyleButtons) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
260 QAction* action = data.memberInstance(ui);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
261 action->setChecked(renderPreferences->style == data.payload);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
262 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
263 ui->actionDrawAxes->setChecked(renderPreferences->drawAxes);
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
264 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
265 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
266
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
267 static gl::RenderPreferences loadRenderPreferences()
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
268 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
269 return gl::RenderPreferences{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
270 .style = setting<Setting::RenderStyle>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
271 .mainColor = setting<Setting::MainColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
272 .backgroundColor = setting<Setting::BackgroundColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
273 .selectedColor = setting<Setting::SelectedColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
274 .lineThickness = setting<Setting::LineThickness>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
275 .lineAntiAliasing = setting<Setting::LineAntiAliasing>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
276 .drawAxes = setting<Setting::DrawAxes>(),
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
277 .wireframe = setting<Setting::Wireframe>(),
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
278 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
279 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
280
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
281 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
282 {
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
283 CircleToolOptionsWidget* circleToolOptions;
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
284 ObjectEditor* objectEditor;
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
285 };
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
286
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
287 void initializeTools(Ui_MainWindow* ui, ToolWidgets* toolWidgets, QWidget* parent)
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
288 {
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
289 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
290 {
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
291 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
292 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
293 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
294 } 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
295 {
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
296 .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
297 .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
298 .icon = {":/icons/navigate-outline.png"},
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
299 .widget = toolWidgets->objectEditor,
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
300 },
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
301 {
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
302 .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
303 .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
304 .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
305 .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
306 },
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
307 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
308 .name = QObject::tr("Circle"),
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
309 .tooltip = QObject::tr("Draw circular primitives."),
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
310 .icon = {":/icons/linetype-circularprimitive.png"},
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
311 .widget = toolWidgets->circleToolOptions,
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
312 },
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
313 };
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
314 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 }
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
327 ui->toolWidgetStack->addWidget(widget);
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
328 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
329 ui->toolWidgetStack->setCurrentIndex(i);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
330 });
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
331 }
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
332 }
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
333
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
334 constexpr bool sortModelIndexesByRow(const QModelIndex& a, const QModelIndex& b)
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
335 {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
336 return a.row() < b.row();
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
337 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
338
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
339 std::vector<int> rows(const QModelIndexList& indexList)
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
340 {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
341 std::vector<int> result;
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
342 result.reserve(unsigned_cast(indexList.size()));
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
343 for (const QModelIndex& index : indexList)
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
344 {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
345 result.push_back(index.row());
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
346 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
347 return result;
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
348 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
349
272
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
350 static void about(QWidget* parent)
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
351 {
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
352 QDialog dialog{parent};
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
353 Ui_About ui;
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
354 ui.setupUi(&dialog);
293
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
355 const char* glVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
356 const QString extensions = []{
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
357 GLint numExtensions;
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
358 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
359 QStringList extensionsList;
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
360 for (GLint i = 0; i < numExtensions; i++) {
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
361 const GLubyte* ext = glGetStringi(GL_EXTENSIONS, i);
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
362 extensionsList.push_back(reinterpret_cast<const char*>(ext));
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
363 }
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
364 return extensionsList.join(" ");
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
365 }();
279
cd70c845563a Add build system information to the about dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 278
diff changeset
366 for (QTextBrowser* browser : dialog.findChildren<QTextBrowser*>()) {
cd70c845563a Add build system information to the about dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 278
diff changeset
367 browser->setHtml(
cd70c845563a Add build system information to the about dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 278
diff changeset
368 browser->toHtml()
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
369 .replace("%APPNAME%", CMAKE_PROJECT_NAME)
279
cd70c845563a Add build system information to the about dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 278
diff changeset
370 .replace("%COPYRIGHT%", COPYRIGHT)
cd70c845563a Add build system information to the about dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 278
diff changeset
371 .replace("%QTVERSION%", qVersion())
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
372 .replace("%VERSION%", detailedVersionString(QLocale::LongFormat))
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
373 .replace("%REVDATE%", revisionDateString(QLocale::LongFormat))
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
374 .replace("%BUILDTYPE%", 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
375 .replace("%COMPILER_ID%", CMAKE_CXX_COMPILER_ID)
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
376 .replace("%COMPILER_VERSION%", CMAKE_CXX_COMPILER_VERSION)
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
377 .replace("%COMPILER_FLAGS%", CMAKE_CXX_FLAGS)
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
378 .replace("%COMPILER_CPU%", CMAKE_SYSTEM_PROCESSOR)
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
379 .replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM)
292
f071ec94c022 Add GLM version string to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 289
diff changeset
380 .replace("%GLMVERSIONSTRING%", GLM_VERSION_MESSAGE)
293
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
381 .replace("%GL_VERSION%", glVersion)
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
382 .replace("%GL_EXTENSIONS%", extensions)
279
cd70c845563a Add build system information to the about dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 278
diff changeset
383 );
cd70c845563a Add build system information to the about dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 278
diff changeset
384 }
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
385 dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME));
272
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
386 dialog.exec();
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
387 }
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
388
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
389 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
390 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
391 {
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
392 // 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
393 // 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
394 // 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
395 // 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
396 // 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
397 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
398 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
399 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
400 }
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
401
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
402 static QSet<ElementId> resolveIdsFromSelection(const ModelData* data)
299
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
403 {
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
404 const auto selection = data->itemSelectionModel->selection();
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
405 QSet<ElementId> selectedIndexes;
299
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
406 for (const QModelIndex& qindex : selection.indexes()) {
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
407 const std::size_t row = unsigned_cast(qindex.row());
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
408 selectedIndexes.insert(data->model->idAt(row));
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
409 }
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
410 return selectedIndexes;
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
411 }
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
412
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
413 int main(int argc, char *argv[])
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
414 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
415 doQtRegistrations();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents: 2
diff changeset
416 QApplication app{argc, argv};
284
9266239cf72b Move app icon definition to main.cpp
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 282
diff changeset
417 QApplication::setWindowIcon(QIcon{":/icons/appicon.png"});
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
418 QMainWindow mainWindow;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
419 Ui_MainWindow ui;
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
420 DocumentManager documents;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
421 QString currentLanguage = "en";
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
422 QTranslator translator{&mainWindow};
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
423 LibrariesModel libraries{&mainWindow};
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
424 QStringList recentlyOpenedFiles;
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
425 ColorTable colorTable;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
426 gl::RenderPreferences renderPreferences;
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
427 MessageLog messageLog;
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
428 Signal settingsChanged;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
429 ui.setupUi(&mainWindow);
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
430 ToolWidgets toolWidgets{
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
431 .circleToolOptions = new CircleToolOptionsWidget{&mainWindow},
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
432 .objectEditor = new ObjectEditor{&mainWindow},
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
433 };
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
434 const auto updateTitle = [&ui, &mainWindow]{
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
435 mainWindow.setWindowTitle(title(&ui));
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
436 };
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
437 const uiutilities::KeySequenceMap defaultKeyboardShortcuts =
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
438 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow));
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
439 const auto saveSettings = [&]{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
440 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry());
240
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
441 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
442 setSetting<Setting::RecentFiles>(recentlyOpenedFiles);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
443 setSetting<Setting::RenderStyle>(renderPreferences.style);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
444 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes);
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
445 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
446 libraries.storeToSettings();
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
447 settingsChanged.emit();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
448 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
449 const auto updateRecentlyOpenedDocumentsMenu = [&]{
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
450 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
451 for (QAction* action : ui.menuRecentFiles->findChildren<QAction*>()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
452 QString path = action->data().toString();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
453 QObject::connect(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
454 action,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
455 &QAction::triggered,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
456 [path, &libraries, &documents, &mainWindow]() {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
457 openModelFromPath(path, &libraries, &documents, &mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
458 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
459 );
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
460 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
461 };
325
64ddcd77639f minor fix in main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 311
diff changeset
462 const auto executeAction = [&](
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
463 Model* model, const ModelAction& action
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
464 ) {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
465 std::visit(overloaded{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
466 [model](const AppendToModel& action){
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
467 model->append(action.newElement);
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
468 },
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
469 [model](const DeleteFromModel& action){
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
470 model->remove(action.position);
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
471 },
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
472 [model](const ModifyModel& 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
473 model->assignAt(action.position, action.newElement);
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
474 },
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
475 }, action);
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
476 };
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
477 const auto restoreSettings = [&]{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
478 recentlyOpenedFiles = setting<Setting::RecentFiles>();
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
479 renderPreferences = loadRenderPreferences();
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
480 libraries.restoreFromSettings();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
481 updateRecentlyOpenedDocumentsMenu();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
482 colorTable = loadColors(&libraries);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
483 updateRenderPreferences(&ui, &renderPreferences, &documents);
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
484 ui.mdiArea->setViewMode(setting<Setting::ViewMode>());
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
485 ui.retranslateUi(&mainWindow);
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
486 settingsChanged.emit();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
487 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
488 const auto addRecentlyOpenedFile = [&](const QString& path){
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
489 constexpr int maxRecentlyOpenedFiles = 10;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
490 recentlyOpenedFiles.removeAll(path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
491 recentlyOpenedFiles.insert(0, path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
492 while (recentlyOpenedFiles.size() > maxRecentlyOpenedFiles)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
493 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
494 recentlyOpenedFiles.removeLast();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
495 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
496 saveSettings();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
497 updateRecentlyOpenedDocumentsMenu();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
498 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
499 const auto openModelForEditing = [&](const ModelId modelId){
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
500 Model* model = documents.getModelById(modelId);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
501 if (model != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
502 ModelData* data = new ModelData(&documents);
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
503 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
504 data->canvas = std::make_unique<PartRenderer>(model, &documents, colorTable);
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
505 data->itemSelectionModel = std::make_unique<QItemSelectionModel>();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
506 data->itemSelectionModel->setModel(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
507 data->axesLayer = std::make_unique<AxesLayer>();
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
508 constexpr glm::mat4 XZ = {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}};
216
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
509 data->gridLayer = std::make_unique<GridLayer>();
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
510 data->gridLayer->setGridMatrix(XZ);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
511 data->tools->setGridMatrix(XZ);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
512 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
513 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
514 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
515 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
516 data->canvas->addRenderLayer(data->tools.get());
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
517 documents.setModelPayload(modelId, data);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
518 QObject::connect(
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
519 data->tools.get(),
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
520 &EditTools::modelAction,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
521 std::bind(executeAction, model, std::placeholders::_1));
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
522 QObject::connect(
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
523 data->itemSelectionModel.get(),
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
524 &QItemSelectionModel::selectionChanged,
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
525 [modelId, &documents, &toolWidgets]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
526 ModelData* data = findModelData(&documents, modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
527 if (data != nullptr) {
299
cf9a854b56a9 Remove functional.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
528 data->canvas->setSelection(resolveIdsFromSelection(data));
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
529 /*
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
530 if (indices.size() == 1) {
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
531 opt<std::size_t> index = data->model->find(*indices.begin());
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
532 if (index.has_value()) {
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
533 toolWidgets.objectEditor->setObject((*data->model)[*index]);
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
534 }
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
535 }
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
536 else {
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
537 toolWidgets.objectEditor->reset();
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
538 }
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
539 */
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
540 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
541 });
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
542 data->canvas->setRenderPreferences(renderPreferences);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
543 QObject::connect(
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
544 data->tools.get(),
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
545 &EditTools::newStatusText,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
546 [&](const QString& newStatusText) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
547 mainWindow.statusBar()->showMessage(newStatusText);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
548 });
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
549 QObject::connect(
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
550 data->tools.get(),
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
551 &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
552 [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
553 ModelData* data = findModelData(&documents, modelId);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
554 if (data != nullptr) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
555 if (not retain) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
556 data->itemSelectionModel->clear();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
557 }
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
558 for (const ElementId id : indices) {
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
559 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
560 if (index.has_value()) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
561 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
562 data->itemSelectionModel->select(qindex, QItemSelectionModel::Select);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
563 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
564 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
565 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
566 });
243
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
567 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
568 ModelData* data = findModelData(&documents, modelId);
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
569 if (data != nullptr) {
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
570 data->gridLayer->settingsChanged();
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
571 }
959469a7e149 Make the grid black on bright backgrounds
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 241
diff changeset
572 });
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 236
diff changeset
573 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
574 QObject::connect(
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
575 data->tools.get(),
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
576 &EditTools::suggestCursor,
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
577 data->canvas.get(),
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
578 &QWidget::setCursor);
fab454611f9b Use different cursors depending on edit mode
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
579 data->tools->setEditMode(SelectMode);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
580 const QFileInfo fileInfo{*documents.modelPath(modelId)};
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
581 auto* const subWindow = createSubWindow<ModelSubWindow>(ui.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
582 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
583 subWindow->resize({320, 200});
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
584 subWindow->setWidget(data->canvas.get());
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
585 subWindow->setWindowTitle(tabName(fileInfo));
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
586 subWindow->show();
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
587 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
588 };
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
589 QObject::connect(ui.actionNew, &QAction::triggered, [&]{
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
590 openModelForEditing(documents.newModel());
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
591 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
592 QObject::connect(ui.actionOpen, &QAction::triggered, [&]{
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
593 const QString path = getOpenModelPath(&mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
594 if (not path.isEmpty())
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
595 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
596 const std::optional<ModelId> id = openModelFromPath(path, &libraries, &documents, &mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
597 if (id.has_value()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
598 openModelForEditing(id.value());
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
599 addRecentlyOpenedFile(path);
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 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
602 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
603 QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{
285
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 284
diff changeset
604 if (ui.mdiArea->findChildren<SettingsEditor*>().isEmpty()) {
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
605 auto* const settingsEditor = createSubWindow<SettingsEditor>(ui.mdiArea, defaultKeyboardShortcuts);
285
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 284
diff changeset
606 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
607 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
608 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
609 settingsEditor->show();
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 284
diff changeset
610 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
611 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
612 QObject::connect(ui.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
613 #if 0
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
614 QObject::connect(ui.actionAdjustGridToView, &QAction::triggered, [&]{
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
615 if (ModelData* data = currentModelData(&ui, &documents)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
616 adjustGridToView(data->canvas.get());
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 });
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
619 #endif
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
620 QObject::connect(ui.actionClose, &QAction::triggered, [&ui, &documents]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
621 if (ModelData* data = currentModelData(&ui, &documents)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
622 // TODO
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
623 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
624 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
625 const auto save = [&](ModelId modelId){
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
626 QString error;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
627 QTextStream errorStream{&error};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
628 const bool succeeded = documents.saveModel(modelId, errorStream);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
629 if (not succeeded)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
630 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
631 QMessageBox::critical(&mainWindow, QObject::tr("Save error"), error);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
632 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
633 else
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
634 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
635 const QString* pathPtr = documents.modelPath(modelId);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
636 if (pathPtr != nullptr) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
637 addRecentlyOpenedFile(*pathPtr);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
638 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
639 }
272
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
640 };;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
641 const auto actionSaveAs = [&]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
642 const std::optional<ModelId> modelId = findCurrentModelId(&ui);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
643 if (modelId.has_value())
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
644 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
645 const QString* pathPtr = documents.modelPath(*modelId);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
646 QString defaultPath = (pathPtr != nullptr) ? *pathPtr : "";
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
647 const QString newPath = QFileDialog::getSaveFileName(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
648 &mainWindow,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
649 QObject::tr("Save as…"),
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
650 QFileInfo{defaultPath}.absoluteDir().path(),
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
651 QObject::tr("LDraw files (*.ldr *dat);;All files (*)")
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
652 );
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
653 if (not newPath.isEmpty()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
654 QString error;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
655 QTextStream errorStream{&error};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
656 documents.setModelPath(*modelId, newPath, libraries, errorStream);
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
657 QMdiSubWindow* const subWindow = ui.mdiArea->currentSubWindow();
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
658 if (subWindow != nullptr) {
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
659 subWindow->setWindowTitle(tabName(QFileInfo{newPath}));
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
660 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
661 save(*modelId);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
662 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
663 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
664 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
665 QObject::connect(ui.actionSaveAs, &QAction::triggered, actionSaveAs);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
666 QObject::connect(ui.actionSave, &QAction::triggered, [&]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
667 const std::optional<ModelId> modelId = findCurrentModelId(&ui);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
668 if (modelId.has_value()) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
669 const QString* path = documents.modelPath(*modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
670 if (path == nullptr or path->isEmpty()) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
671 actionSaveAs();
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
672 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
673 else {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
674 save(*modelId);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
675 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
676 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
677 });
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
678 QObject::connect(ui.actionDelete, &QAction::triggered, [&]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
679 if (Model* model = currentModelBody(&ui, &documents)) {
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
680 std::vector<int> selectedRows = rows(ui.modelListView->selectionModel()->selectedRows());
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
681 std::sort(selectedRows.begin(), selectedRows.end(), std::greater<int>{});
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
682 for (int row : selectedRows) {
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
683 executeAction(model, DeleteFromModel{.position = unsigned_cast(row)});
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
684 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
685 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
686 });
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
687 QObject::connect(ui.actionDrawAxes, &QAction::triggered, [&](bool drawAxes){
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
688 renderPreferences.drawAxes = drawAxes;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
689 saveSettings();
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
690 updateRenderPreferences(&ui, &renderPreferences, &documents);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
691 });
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
692 QObject::connect(ui.actionWireframe, &QAction::triggered, [&](bool enabled){
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
693 renderPreferences.wireframe = enabled;
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
694 saveSettings();
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
695 updateRenderPreferences(&ui, &renderPreferences, &documents);
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
696 });
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
697 for (auto data : ::renderStyleButtons) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
698 QAction* action = data.memberInstance(&ui);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
699 QObject::connect(action, &QAction::triggered, [&, data]{
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
700 renderPreferences.style = data.payload;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
701 saveSettings();
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
702 updateRenderPreferences(&ui, &renderPreferences, &documents);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
703 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
704 }
278
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
705 const auto checkEditingModeAction = [&ui, &documents](EditingMode mode) {
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
706 const bool hasDocument = currentModelData(&ui, &documents) != 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
707 for (QAction* action : ui.editingModesToolBar->actions()) {
278
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
708 action->setEnabled(hasDocument);
304386ff96a4 Make editing tools disabled until a document is selected
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 274
diff changeset
709 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
710 }
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
711 };
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
712 initializeTools(&ui, &toolWidgets, &mainWindow);
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
713 for (QAction* action : ui.editingModesToolBar->actions()) {
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
714 QObject::connect(action, &QAction::triggered, [&, action]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
715 if (ModelData* data = currentModelData(&ui, &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
716 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
717 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
718 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
719 }
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
720 });
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
721 }
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
722 QObject::connect(ui.mdiArea, &QMdiArea::subWindowActivated,
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
723 [&](QMdiSubWindow* subWindow) {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
724 ModelSubWindow* modelSubWindow = qobject_cast<ModelSubWindow*>(subWindow);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
725 if (modelSubWindow != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
726 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
727 checkEditingModeAction(data->tools->currentEditingMode());
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
728 if (data->itemSelectionModel != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
729 ui.modelListView->setModel(data->model);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
730 ui.modelListView->setSelectionModel(data->itemSelectionModel.get());
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
731 }
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
732 }
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
733 }
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 281
diff changeset
734 else {
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 281
diff changeset
735 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
736 }
274
1331aba5d36b Show current subwindow title in main window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 272
diff changeset
737 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
738 });
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
739 ui.messageLog->setModel(&messageLog);
229
38d86002d548 Add About Qt menu entry
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 221
diff changeset
740 QObject::connect(ui.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt);
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
741 QObject::connect(&documents, &DocumentManager::message, &messageLog, &MessageLog::addMessage);
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
742 QObject::connect(&messageLog, &MessageLog::rowsAboutToBeInserted, [&]{
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
743 const auto bar = ui.messageLog->verticalScrollBar();
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
744 ui.messageLog->setProperty("shouldAutoScroll", bar->value() == bar->maximum());
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
745 });
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
746 QObject::connect(&messageLog, &MessageLog::rowsInserted, [&]{
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 236
diff changeset
747 ui.messageLog->resizeRowsToContents();
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
748 if (ui.messageLog->property("shouldAutoScroll").toBool()) {
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
749 ui.messageLog->scrollToBottom();
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
750 }
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
751 });
251
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
752 QObject::connect(
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
753 toolWidgets.circleToolOptions,
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
754 &CircleToolOptionsWidget::optionsChanged,
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
755 [&ui, &documents](const CircleToolOptions& options) {
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
756 if (ModelData* data = currentModelData(&ui, &documents)) {
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
757 data->tools->setCircleToolOptions(options);
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
758 }
94b0a30a1886 Add object editor into main
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
759 });
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
760 QObject::connect(
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
761 ui.actionMakeUnofficial,
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
762 &QAction::triggered,
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
763 [&]{
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
764 if (ModelData* data = currentModelData(&ui, &documents)) {
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
765 Model* const model = data->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
766 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
767 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
768 }
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
769 }
dc33f8a707c4 Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
770 });
272
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
771 QObject::connect(
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
772 ui.actionAbout,
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
773 &QAction::triggered,
293
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
774 [&mainWindow, &ui]{
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
775 // Make sure that there's an OpenGL context active, otherwise
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
776 // we cannot obtain OpenGL information
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
777 if (ui.mdiArea->findChildren<ModelSubWindow*>().empty()) {
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
778 ui.actionNew->trigger();
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
779 }
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
780 about(&mainWindow);
9f85a54ead29 Add OpenGL information to about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 292
diff changeset
781 }
272
9d52b119b3f5 Sort out versions more, add about page
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 268
diff changeset
782 );
327
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
783 QObject::connect(
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
784 ui.actionCopy,
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
785 &QAction::triggered,
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
786 [&]{
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
787 if (Model* model = currentModelBody(&ui, &documents)) {
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
788 std::vector<int> selectedRows = rows(ui.modelListView->selectionModel()->selectedRows());
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
789 QString text;
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
790 for (int row : selectedRows) {
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
791 const std::size_t i = static_cast<std::size_t>(row);
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
792 text += modelElementToString((*model)[i]);
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
793 text += QStringLiteral("\r\n");
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
794 }
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
795 app.clipboard()->setText(text);
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
796 }
2aa15daa0216 Add copy action
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 325
diff changeset
797 });
240
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
798 mainWindow.tabifyDockWidget(ui.messageLogDock, ui.toolOptionsDock);
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
799 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>());
240
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
800 mainWindow.restoreState(setting<Setting::MainWindowState>());
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
801 // 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
802 // 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
803 for (QDockWidget* dock : mainWindow.findChildren<QDockWidget*>()) {
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
804 dock->setVisible(true);
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
805 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
806 restoreSettings();
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
807 updateRenderPreferences(&ui, &renderPreferences, &documents);
281
afed72b544f0 - Add CMake build type to about page and window title
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 279
diff changeset
808 ui.actionAbout->setText(ui.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
809 updateTitle();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
810 mainWindow.show();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
811 const int result = app.exec();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
812 saveSettings();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
813 return result;
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
814 }

mercurial