src/main.cpp

Mon, 20 Jun 2022 18:40:22 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 20 Jun 2022 18:40:22 +0300
changeset 236
1fa0e1de9f0a
parent 235
7ef03c2b46ab
child 237
10a6298f636f
permissions
-rw-r--r--

Made message log a model

201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
1 #include <QApplication>
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
2 #include <QFileDialog>
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
3 #include <QMessageBox>
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
4 #include <QMdiSubWindow>
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
5 #include <QStackedWidget>
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
6 #include <QCloseEvent>
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
7 #include "mainwindow.h"
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
8 #include "ui_mainwindow.h"
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
9 #include "version.h"
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
10 #include "gl/axesprogram.h"
216
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
11 #include "gl/gridprogram.h"
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
12 #include "gl/partrenderer.h"
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
13 #include "document.h"
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
14 #include "settingseditor/settingseditor.h"
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
15 #include "widgets/colorselectdialog.h"
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
16 #include "settings.h"
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 232
diff changeset
17 #include "ui/circletooloptionswidget.h"
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
18 #include "messagelog.h"
24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 17
diff changeset
19
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
20 static const QDir LOCALE_DIR {":/locale"};
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
22 class ModelSubWindow : public QMdiSubWindow
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
23 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
24 Q_OBJECT
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
25 public:
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
26 const ModelId modelId;
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
27 ModelSubWindow(ModelId modelId, QWidget* widget) :
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
28 QMdiSubWindow{widget},
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
29 modelId{modelId}
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
30 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
31 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
32 protected:
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
33 void closeEvent(QCloseEvent* event) override
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
34 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
35 event->ignore();
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
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
39 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
40 {
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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 };
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 #include "main.moc"
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
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
53 static void doQtRegistrations()
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 {
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
55 QCoreApplication::setApplicationName(::appName);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
56 QCoreApplication::setOrganizationName("hecknology.net");
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
57 QCoreApplication::setOrganizationDomain("hecknology.net");
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
58 qRegisterMetaTypeStreamOperators<Library>("Library");
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
59 qRegisterMetaTypeStreamOperators<Libraries>("Libraries");
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
60 qRegisterMetaTypeStreamOperators<gl::RenderStyle>();
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
61 qRegisterMetaTypeStreamOperators<QMdiArea::ViewMode>();
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
62 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
63
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
64 template<typename BaseType, typename MemberType, typename DataType>
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
65 struct MemberData
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
66 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
67 std::size_t member;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
68 DataType payload;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
69 constexpr MemberType memberInstance(BaseType* instance) const
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
70 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
71 return *reinterpret_cast<MemberType*>(reinterpret_cast<char*>(instance) + this->member);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
72 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
73 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
74
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
75 static constexpr MemberData<Ui_MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
76 { offsetof(Ui_MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
77 { offsetof(Ui_MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
78 { offsetof(Ui_MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
79 { offsetof(Ui_MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene },
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
80 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
81
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
82 static std::optional<ModelId> openModelFromPath(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
83 const QString& path,
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
84 const LibrariesModel* libraries,
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
85 DocumentManager* documents,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
86 QWidget* parent)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
87 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
88 QString errorString;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
89 QTextStream errorStream{&errorString};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
90 const std::optional<ModelId> modelIdOpt = documents->openModel(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
91 path,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
92 errorStream,
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
93 OpenType::ManuallyOpened);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
94 if (modelIdOpt.has_value()) {
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
95 const DocumentManager::MissingDependencies missing = documents->loadDependenciesForAllModels(*libraries);
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
96 if (not missing.empty()) {
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
97 QMessageBox::warning(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
98 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
99 QObject::tr("Problem loading references"),
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
100 errorStringFromMissingDependencies(missing));
201
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 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
103 else {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
104 QMessageBox::critical(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
105 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
106 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
107 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
108 );
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
109 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
110 return modelIdOpt;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
111 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
112
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
113 static QString getOpenModelPath(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 return QFileDialog::getOpenFileName(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
116 parent,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
117 QObject::tr("Open model"),
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
118 "",
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
119 QObject::tr("LDraw models (*.ldr *.dat)"));
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
120 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
121
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
122 static const QString localeCode(const QString& locale)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
123 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
124 if (locale == "system") {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
125 return QLocale::system().name();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
126 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
127 else {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
128 return locale;
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 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
131
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
132 /**
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
133 * @brief Changes the application language to the specified language
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
134 */
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
135 static void changeLanguage(const QString& locale, QTranslator* translator)
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 if (not locale.isEmpty()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
138 const QString localeCode = ::localeCode(locale);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
139 QLocale::setDefault({localeCode});
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
140 qApp->removeTranslator(translator);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
141 const QString path = LOCALE_DIR.filePath(localeCode + ".qm");
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
142 const bool loadSuccessful = translator->load(path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
143 if (loadSuccessful)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
144 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
145 qApp->installTranslator(translator);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
146 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
147 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
148 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
149
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
150 ModelData* findModelData(DocumentManager* documents, ModelId modelId)
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
151 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
152 return documents->findPayload<ModelData>(modelId);
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
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
155 static ModelSubWindow* currentModelSubWindow(Ui_MainWindow* ui)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
156 {
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
157 auto* w = ui->mdiArea->activeSubWindow();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
158 return qobject_cast<ModelSubWindow*>(w);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
159 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
160
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
161 static ModelData* currentModelData(Ui_MainWindow* ui, DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
162 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
163 if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
164 return findModelData(documents, activeSubWindow->modelId);
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
165 }
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
166 else {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
167 return nullptr;
201
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 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
170
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
171 static Model* currentModelBody(Ui_MainWindow* ui, DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
172 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
173 if (auto* const activeSubWindow = currentModelSubWindow(ui)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
174 return documents->getModelById(activeSubWindow->modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
175 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
176 else {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
177 return nullptr;
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
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
181 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
182 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
183 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
184 if (activeSubWindow != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
185 return activeSubWindow->modelId;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
186 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
187 else {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
188 return {};
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 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
191
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
192 /**
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
193 * @brief Updates the title of the main window so to contain the app's name
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
194 * and version as well as the open document name.
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
195 */
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
196 static QString title()
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
197 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
198 QString title = ::appName;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
199 title += " ";
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
200 title += fullVersionString();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
201 return title;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
202 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
203
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
204 static ColorTable loadColors(const LibrariesModel* libraries)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
205 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
206 QTextStream errors;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
207 return libraries->loadColorTable(errors);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
208 }
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 static QString tabName(const QFileInfo& fileInfo)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
211 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
212 QString result = fileInfo.baseName();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
213 if (result.isEmpty()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
214 result = QObject::tr("<unnamed>");
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 return result;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
217 }
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 void rebuildRecentFilesMenu(QMenu* menu, const QStringList& strings, QWidget* parent)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
220 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
221 menu->clear();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
222 for (const QString& path : strings) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
223 QAction* action = new QAction{path, parent};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
224 action->setData(path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
225 menu->addAction(action);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
226 }
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
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
229 template<typename Fn>
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
230 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
231 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
232 forValueInMap(*documents, [&fn](const DocumentManager::ModelInfo& info)
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
233 {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
234 ModelData* modelSpecificData = qobject_cast<ModelData*>(info.payload);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
235 if (modelSpecificData != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
236 fn(&info, modelSpecificData);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
237 }
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 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
240
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
241 static void updateRenderPreferences(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
242 Ui_MainWindow* ui,
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
243 const gl::RenderPreferences* renderPreferences,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
244 const DocumentManager* documents)
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
245 {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
246 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
247 if (data->canvas != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
248 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
249 data->canvas->setLayerEnabled(data->axesLayer.get(), renderPreferences->drawAxes);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
250 }
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
251 });
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
252 for (auto data : ::renderStyleButtons) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
253 QAction* action = data.memberInstance(ui);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
254 action->setChecked(renderPreferences->style == data.payload);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
255 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
256 ui->actionDrawAxes->setChecked(renderPreferences->drawAxes);
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
257 ui->actionWireframe->setChecked(renderPreferences->wireframe);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
258 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
259
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
260 static gl::RenderPreferences loadRenderPreferences()
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
261 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
262 return gl::RenderPreferences{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
263 .style = setting<Setting::RenderStyle>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
264 .mainColor = setting<Setting::MainColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
265 .backgroundColor = setting<Setting::BackgroundColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
266 .selectedColor = setting<Setting::SelectedColor>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
267 .lineThickness = setting<Setting::LineThickness>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
268 .lineAntiAliasing = setting<Setting::LineAntiAliasing>(),
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
269 .drawAxes = setting<Setting::DrawAxes>(),
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
270 .wireframe = setting<Setting::Wireframe>(),
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
271 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
272 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
273
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
274 void initializeTools(Ui_MainWindow* ui, DocumentManager* documents, QWidget* parent)
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
275 {
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
276 CircleToolOptionsWidget* circleToolOptions = new CircleToolOptionsWidget{parent};
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
277 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
278 {
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 202
diff changeset
279 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
280 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
281 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
282 } 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
283 {
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 202
diff changeset
284 .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
285 .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
286 .icon = {":/icons/navigate-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
287 //.widget = this->objectEditor,
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
288 },
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 {
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 .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
291 .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
292 .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
293 .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
294 },
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
295 {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
296 .name = QObject::tr("Circle"),
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
297 .tooltip = QObject::tr("Draw circular primitives."),
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
298 .icon = {":/icons/linetype-circularprimitive.png"},
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
299 .widget = circleToolOptions,
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
300 },
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
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 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
303 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
304 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
305 action->setCheckable(true);
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 action->setChecked(i == 0);
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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 }
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 ui->toolWidgetStack->addWidget(widget);
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
316 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
317 ui->toolWidgetStack->setCurrentIndex(i);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
318 });
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 }
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
320 QObject::connect(
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
321 circleToolOptions,
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
322 &CircleToolOptionsWidget::optionsChanged,
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
323 [ui, documents](const CircleToolOptions& options) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
324 if (ModelData* data = currentModelData(ui, documents)) {
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
325 data->tools->setCircleToolOptions(options);
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
326 }
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
327 });
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
328 }
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
329
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
330 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
331 {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
332 return a.row() < b.row();
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
333 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
334
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
335 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
336 {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
337 std::vector<int> result;
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
338 result.reserve(indexList.size());
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
339 for (const QModelIndex& index : 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 result.push_back(index.row());
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
342 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
343 return result;
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
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
346 #include <QScrollBar>
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
347 int main(int argc, char *argv[])
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
348 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 158
diff changeset
349 doQtRegistrations();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents: 2
diff changeset
350 QApplication app{argc, argv};
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
351 QMainWindow mainWindow;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
352 Ui_MainWindow ui;
212
27259810da6d Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 206
diff changeset
353 DocumentManager documents;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
354 QString currentLanguage = "en";
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
355 QTranslator translator{&mainWindow};
230
a1f3f7d9078b rename LibraryManager -> LibrariesModel
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 229
diff changeset
356 LibrariesModel libraries{&mainWindow};
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
357 QStringList recentlyOpenedFiles;
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 204
diff changeset
358 ColorTable colorTable;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
359 gl::RenderPreferences renderPreferences;
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
360 MessageLog messageLog;
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
361 ui.setupUi(&mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
362 const uiutilities::KeySequenceMap defaultKeyboardShortcuts =
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
363 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow));
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
364 const auto saveSettings = [&]{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
365 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry());
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
366 setSetting<Setting::RecentFiles>(recentlyOpenedFiles);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
367 setSetting<Setting::RenderStyle>(renderPreferences.style);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
368 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes);
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
369 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
370 libraries.storeToSettings();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
371 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
372 const auto updateRecentlyOpenedDocumentsMenu = [&]{
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
373 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
374 for (QAction* action : ui.menuRecentFiles->findChildren<QAction*>()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
375 QString path = action->data().toString();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
376 QObject::connect(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
377 action,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
378 &QAction::triggered,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
379 [path, &libraries, &documents, &mainWindow]() {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
380 openModelFromPath(path, &libraries, &documents, &mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
381 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
382 );
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
383 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
384 };
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
385 static constexpr auto executeAction = [&](
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
386 Model* model, const ModelAction& action
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
387 ) {
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
388 std::visit(overloaded{
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
389 [model](const AppendToModel& action){
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
390 model->append(action.newElement);
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
391 },
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
392 [model](const DeleteFromModel& action){
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
393 model->remove(action.position);
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
394 },
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
395 }, action);
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
396 };
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
397 const auto restoreSettings = [&]{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
398 recentlyOpenedFiles = setting<Setting::RecentFiles>();
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
399 renderPreferences = loadRenderPreferences();
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
400 changeLanguage(setting<Setting::Locale>(), &translator);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
401 libraries.restoreFromSettings();
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
402 updateRecentlyOpenedDocumentsMenu();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
403 colorTable = loadColors(&libraries);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
404 updateRenderPreferences(&ui, &renderPreferences, &documents);
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
405 ui.mdiArea->setViewMode(setting<Setting::ViewMode>());
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
406 ui.retranslateUi(&mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
407 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
408 const auto addRecentlyOpenedFile = [&](const QString& path){
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
409 constexpr int maxRecentlyOpenedFiles = 10;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
410 recentlyOpenedFiles.removeAll(path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
411 recentlyOpenedFiles.insert(0, path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
412 while (recentlyOpenedFiles.size() > maxRecentlyOpenedFiles)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
413 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
414 recentlyOpenedFiles.removeLast();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
415 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
416 saveSettings();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
417 updateRecentlyOpenedDocumentsMenu();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
418 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
419 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
420 Model* model = documents.getModelById(modelId);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
421 if (model != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
422 ModelData* data = new ModelData(&documents);
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
423 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
424 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
425 data->itemSelectionModel = std::make_unique<QItemSelectionModel>();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
426 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
427 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
428 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
429 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
430 data->gridLayer->setGridMatrix(XZ);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
431 data->tools->setGridMatrix(XZ);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
432 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
433 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
434 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
435 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
436 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
437 documents.setModelPayload(modelId, data);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
438 QObject::connect(
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
439 data->tools.get(),
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
440 &EditTools::modelAction,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
441 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
442 QObject::connect(
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
443 data->itemSelectionModel.get(),
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
444 &QItemSelectionModel::selectionChanged,
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
445 [modelId, &documents]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
446 ModelData* data = findModelData(&documents, modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
447 if (data != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
448 auto resolveIndex = [&data](const QModelIndex& index){
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
449 return data->model->idAt(index.row());
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
450 };
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
451 const auto selection = data->itemSelectionModel->selection();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
452 const auto indices = fn::map<QSet<ModelId>>(selection.indexes(), resolveIndex);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
453 data->canvas->setSelection(indices);
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
454 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
455 });
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
456 data->canvas->setRenderPreferences(renderPreferences);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
457 QObject::connect(
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
458 data->tools.get(),
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
459 &EditTools::newStatusText,
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
460 [&](const QString& newStatusText) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
461 mainWindow.statusBar()->showMessage(newStatusText);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
462 });
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
463 QObject::connect(
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
464 data->tools.get(),
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
465 &EditTools::select,
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
466 [modelId, &documents](const QSet<ModelId>& indices, bool retain) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
467 ModelData* data = findModelData(&documents, modelId);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
468 if (data != nullptr) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
469 if (not retain) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
470 data->itemSelectionModel->clear();
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
471 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
472 for (const ModelId id : indices) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
473 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
474 if (index.has_value()) {
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
475 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
476 data->itemSelectionModel->select(qindex, QItemSelectionModel::Select);
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
477 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
478 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
479 }
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
480 });
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
481 const QFileInfo fileInfo{*documents.modelPath(modelId)};
217
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
482 ModelSubWindow* subWindow = new ModelSubWindow{modelId, ui.mdiArea};
6d95c1a41e6e reimplement EditTools as a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
483 subWindow->setWidget(data->canvas.get());
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
484 subWindow->setWindowTitle(tabName(fileInfo));
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
485 subWindow->show();
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
486 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
487 };
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
488 QObject::connect(ui.actionNew, &QAction::triggered, [&]{
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
489 openModelForEditing(documents.newModel());
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
490 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
491 QObject::connect(ui.actionOpen, &QAction::triggered, [&]{
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
492 const QString path = getOpenModelPath(&mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
493 if (not path.isEmpty())
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
494 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
495 const std::optional<ModelId> id = openModelFromPath(path, &libraries, &documents, &mainWindow);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
496 if (id.has_value()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
497 openModelForEditing(id.value());
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
498 addRecentlyOpenedFile(path);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
499 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
500 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
501 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
502 QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
503 SettingsEditor settingsEditor{defaultKeyboardShortcuts, &mainWindow};
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
504 const int result = settingsEditor.exec();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
505 if (result == QDialog::Accepted)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
506 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
507 restoreSettings();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
508 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
509 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
510 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
511 #if 0
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
512 QObject::connect(ui.actionAdjustGridToView, &QAction::triggered, [&]{
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
513 if (ModelData* data = currentModelData(&ui, &documents)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
514 adjustGridToView(data->canvas.get());
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
515 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
516 });
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 #endif
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
518 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
519 if (ModelData* data = currentModelData(&ui, &documents)) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
520 // TODO
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
521 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
522 });
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
523 const auto save = [&](ModelId modelId){
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
524 QString error;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
525 QTextStream errorStream{&error};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
526 const bool succeeded = documents.saveModel(modelId, errorStream);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
527 if (not succeeded)
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
528 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
529 QMessageBox::critical(&mainWindow, QObject::tr("Save error"), error);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
530 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
531 else
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
532 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
533 const QString* pathPtr = documents.modelPath(modelId);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
534 if (pathPtr != nullptr) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
535 addRecentlyOpenedFile(*pathPtr);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
536 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
537 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
538 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
539 const auto actionSaveAs = [&]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
540 const std::optional<ModelId> modelId = findCurrentModelId(&ui);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
541 if (modelId.has_value())
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
542 {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
543 const QString* pathPtr = documents.modelPath(*modelId);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
544 QString defaultPath = (pathPtr != nullptr) ? *pathPtr : "";
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
545 const QString newPath = QFileDialog::getSaveFileName(
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
546 &mainWindow,
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
547 QObject::tr("Save as…"),
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
548 QFileInfo{defaultPath}.absoluteDir().path(),
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
549 QObject::tr("LDraw files (*.ldr *dat);;All files (*)")
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
550 );
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
551 if (not newPath.isEmpty()) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
552 QString error;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
553 QTextStream errorStream{&error};
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
554 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
555 QMdiSubWindow* const subWindow = ui.mdiArea->currentSubWindow();
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
556 if (subWindow != nullptr) {
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
557 subWindow->setWindowTitle(tabName(QFileInfo{newPath}));
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 201
diff changeset
558 }
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
559 save(*modelId);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
560 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
561 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
562 };
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
563 QObject::connect(ui.actionSaveAs, &QAction::triggered, actionSaveAs);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
564 QObject::connect(ui.actionSave, &QAction::triggered, [&]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
565 const std::optional<ModelId> modelId = findCurrentModelId(&ui);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
566 if (modelId.has_value()) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
567 const QString* path = documents.modelPath(*modelId);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
568 if (path == nullptr or path->isEmpty()) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
569 actionSaveAs();
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
570 }
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
571 else {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
572 save(*modelId);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
573 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
574 }
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
575 });
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
576 QObject::connect(ui.actionDelete, &QAction::triggered, [&]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
577 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
578 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
579 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
580 for (int row : selectedRows) {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
581 executeAction(model, DeleteFromModel{.position = row});
204
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
582 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
583 }
52e10e8d88cc Concentrate model editing into one coroutine inside main()
Teemu Piippo <teemu@hecknology.net>
parents: 203
diff changeset
584 });
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
585 QObject::connect(ui.actionDrawAxes, &QAction::triggered, [&](bool drawAxes){
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
586 renderPreferences.drawAxes = drawAxes;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
587 saveSettings();
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
588 updateRenderPreferences(&ui, &renderPreferences, &documents);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
589 });
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
590 QObject::connect(ui.actionWireframe, &QAction::triggered, [&](bool enabled){
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
591 renderPreferences.wireframe = enabled;
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
592 saveSettings();
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
593 updateRenderPreferences(&ui, &renderPreferences, &documents);
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 230
diff changeset
594 });
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
595 for (auto data : ::renderStyleButtons) {
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
596 QAction* action = data.memberInstance(&ui);
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
597 QObject::connect(action, &QAction::triggered, [&, data]{
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
598 renderPreferences.style = data.payload;
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
599 saveSettings();
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
600 updateRenderPreferences(&ui, &renderPreferences, &documents);
201
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 }
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
603 const auto checkEditingModeAction = [&ui](EditingMode 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
604 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
605 action->setChecked(action->data().value<EditingMode>() == 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
606 }
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
607 };
232
8efa3a33172e Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
608 initializeTools(&ui, &documents, &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
609 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
610 QObject::connect(action, &QAction::triggered, [&, action]{
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
611 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
612 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
613 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
614 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
615 }
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
616 });
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
617 }
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
618 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
619 [&](QMdiSubWindow* subWindow) {
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
620 ModelSubWindow* modelSubWindow = qobject_cast<ModelSubWindow*>(subWindow);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
621 if (modelSubWindow != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
622 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
623 checkEditingModeAction(data->tools->currentEditingMode());
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
624 if (data->itemSelectionModel != nullptr) {
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
625 ui.modelListView->setModel(data->model);
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
626 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
627 }
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
628 }
1909a0123c72 Move editing modes tool bar, tool options widget stack and model list view into the main window
Teemu Piippo <teemu@hecknology.net>
parents: 202
diff changeset
629 }
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
630 });
236
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
631 ui.messageLog->setModel(&messageLog);
229
38d86002d548 Add About Qt menu entry
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 221
diff changeset
632 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
633 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
634 QObject::connect(&messageLog, &MessageLog::rowsAboutToBeInserted, [&]{
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
635 const auto bar = ui.messageLog->verticalScrollBar();
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
636 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
637 });
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
638 QObject::connect(&messageLog, &MessageLog::rowsInserted, [&]{
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
639 if (ui.messageLog->property("shouldAutoScroll").toBool()) {
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
640 ui.messageLog->scrollToBottom();
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
641 }
1fa0e1de9f0a Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 235
diff changeset
642 });
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
643 mainWindow.setWindowTitle(title());
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 217
diff changeset
644 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>());
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
645 restoreSettings();
214
8e1fe64ce4e3 begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 212
diff changeset
646 updateRenderPreferences(&ui, &renderPreferences, &documents);
201
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
647 mainWindow.show();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
648 const int result = app.exec();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
649 saveSettings();
5d201ee4a9c3 Continue giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
650 return result;
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
651 }

mercurial