src/mainwindow.cpp

Sat, 05 Mar 2022 18:26:18 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 05 Mar 2022 18:26:18 +0200
changeset 170
9b655f6fe5a1
parent 169
6da096930534
child 174
3016b494685c
permissions
-rw-r--r--

Added a toggle for setting whether axes are drawn

24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
1 /*
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
2 * LDForge: LDraw parts authoring CAD
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
4 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
6 * it under the terms of the GNU General Public License as published by
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
8 * (at your option) any later version.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
9 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
10 * This program is distributed in the hope that it will be useful,
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
13 * GNU General Public License for more details.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
14 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
15 * You should have received a copy of the GNU General Public License
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
17 */
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 23
diff changeset
18
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
19 #include <QLabel>
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
20 #include <QVBoxLayout>
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
21 #include <QCloseEvent>
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
22 #include <QFileDialog>
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
23 #include <QMessageBox>
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 #include "mainwindow.h"
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 #include "ui_mainwindow.h"
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
26 #include "settingseditor/settingseditor.h"
1
51d14b0c68c0 add version
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
27 #include "version.h"
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
28 #include "document.h"
16
Teemu Piippo <teemu@hecknology.net>
parents: 12
diff changeset
29 #include "uiutilities.h"
94
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 79
diff changeset
30 #include "widgets/colorselectdialog.h"
169
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
31 #include "modeleditor.h"
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
33 template<typename BaseType, typename MemberType, typename DataType>
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
34 struct MemberData
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
35 {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
36 std::size_t member;
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
37 DataType payload;
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
38 constexpr MemberType memberInstance(BaseType* instance) const
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
39 {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
40 return *reinterpret_cast<MemberType*>(reinterpret_cast<char*>(instance) + this->member);
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
41 }
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
42 };
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
43
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
44 static constexpr MemberData<Ui_MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
45 { offsetof(Ui_MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal },
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
46 { offsetof(Ui_MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen },
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
47 { offsetof(Ui_MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors },
79
5fe2dd4e161a added a render style for pick scene
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
48 { offsetof(Ui_MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene },
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
49 };
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
50
41
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
51 class A : public QSettings
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
52 {
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
53 using QSettings::QSettings;
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
54 };
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
55
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 MainWindow::MainWindow(QWidget *parent) :
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents: 1
diff changeset
57 QMainWindow{parent},
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
58 ui{std::make_unique<Ui_MainWindow>()},
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
59 documents{this},
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
60 settings{},
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
61 libraries{this}
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 {
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
63 this->ui->setupUi(this);
16
Teemu Piippo <teemu@hecknology.net>
parents: 12
diff changeset
64 defaultKeyboardShortcuts = uiutilities::makeKeySequenceMap(uiutilities::collectActions(this));
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
65 connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newModel);
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
66 connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openModel);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents: 1
diff changeset
67 connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close);
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
68 connect(ui->actionSettingsEditor, &QAction::triggered, this, &MainWindow::runSettingsEditor);
128
7c834fe36b25 Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
69 connect(ui->actionAdjustGridToView, &QAction::triggered, [&]()
7c834fe36b25 Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
70 {
7c834fe36b25 Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
71 if (this->currentDocument() != nullptr)
7c834fe36b25 Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
72 {
7c834fe36b25 Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
73 this->currentDocument()->adjustGridToView();
7c834fe36b25 Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
74 }
7c834fe36b25 Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents: 125
diff changeset
75 });
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
76 connect(this->ui->actionSave, &QAction::triggered,
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
77 this, &MainWindow::actionSave);
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
78 connect(this->ui->actionSaveAs, &QAction::triggered,
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
79 this, &MainWindow::actionSaveAs);
160
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
80 connect(this->ui->actionClose, &QAction::triggered, this, &MainWindow::actionClose);
169
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
81 connect(this->ui->actionDelete, &QAction::triggered, this, &MainWindow::actionDelete);
160
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
82 connect(this->ui->tabs, &QTabWidget::tabCloseRequested, this, &MainWindow::handleTabCloseButton);
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
83 for (auto data : ::renderStyleButtons)
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
84 {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
85 QAction* action = data.memberInstance(this->ui.get());
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
86 connect(action, &QAction::triggered, [this, data]()
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
87 {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
88 this->setRenderStyle(data.payload);
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
89 });
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
90 }
170
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
91 connect(this->ui->actionDrawAxes, &QAction::triggered, this, &MainWindow::setDrawAxes);
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
92 this->updateTitle();
40
30cb5e836736 added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
93 this->restoreStartupSettings();
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
94 this->restoreSettings();
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
95 this->updateRenderPreferences();
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
96 this->newModel();
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
97 }
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
98
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
99 // MainWindow needs a destructor even if it is empty because otherwise the destructor of the
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
100 // std::unique_ptr is resolved in the header file, where it will complain about Ui_MainWindow
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
101 // being incomplete.
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
102 MainWindow::~MainWindow()
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
103 {
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
104 }
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
105
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
106 void MainWindow::newModel()
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
107 {
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
108 this->openModelForEditing(documents.newModel());
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
109 }
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
110
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
111 void MainWindow::openModel()
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
112 {
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
113 const QString path = QFileDialog::getOpenFileName(
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
114 this,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
115 tr("Open model"),
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
116 "",
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
117 tr("LDraw models (*.ldr *.dat)"));
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
118 if (not path.isEmpty())
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
119 {
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
120 this->openModelFromPath(path);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
121 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
122 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
123
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
124 void MainWindow::openModelFromPath(const QString& path)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
125 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
126 QString errorString;
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
127 QTextStream errorStream{&errorString};
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
128 std::optional<ModelId> modelIdOpt = this->documents.openModel(
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
129 path,
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
130 errorStream,
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
131 DocumentManager::OpenType::ManuallyOpened);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
132 if (modelIdOpt.has_value())
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
133 {
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
134 const ModelId modelId = modelIdOpt.value();
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
135 this->documents.loadDependenciesForModel(modelId, path, this->libraries, errorStream);
12
fe67489523b5 added dependency loading
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
136 if (not errorString.isEmpty())
fe67489523b5 added dependency loading
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
137 {
fe67489523b5 added dependency loading
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
138 QMessageBox::warning(
fe67489523b5 added dependency loading
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
139 this,
fe67489523b5 added dependency loading
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
140 tr("Problem loading references"),
fe67489523b5 added dependency loading
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
141 errorString);
fe67489523b5 added dependency loading
Teemu Piippo <teemu@hecknology.net>
parents: 9
diff changeset
142 }
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
143 this->openModelForEditing(modelId);
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
144 this->addRecentlyOpenedFile(path);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
145 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
146 else
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
147 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
148 QMessageBox::critical(
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
149 this,
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
150 tr("Problem opening file"),
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
151 utility::format(
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
152 tr("Could not open %1: %2"),
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
153 path,
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
154 errorString));
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
155 }
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
156 }
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
157
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
158 /**
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
159 * @brief Changes the application language to the specified language
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
160 * @param localeCode Code of the locale to translate to
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
161 */
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
162 void MainWindow::changeLanguage(QString localeCode)
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
163 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
164 if (not localeCode.isEmpty() and localeCode != this->currentLanguage)
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
165 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
166 this->currentLanguage = localeCode;
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
167 if (localeCode == "system")
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
168 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
169 localeCode = QLocale::system().name();
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
170 }
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
171 QLocale::setDefault({localeCode});
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
172 qApp->removeTranslator(&this->translator);
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
173 const bool loadSuccessful = this->translator.load(pathToTranslation(localeCode));
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
174 if (loadSuccessful)
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
175 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
176 qApp->installTranslator(&this->translator);
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
177 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
178 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
179 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
180
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
181 void MainWindow::addRecentlyOpenedFile(const QString& path)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
182 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
183 this->recentlyOpenedFiles.removeAll(path);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
184 this->recentlyOpenedFiles.insert(0, path);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
185 while (this->recentlyOpenedFiles.size() > maxRecentlyOpenedFiles)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
186 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
187 this->recentlyOpenedFiles.removeLast();
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
188 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
189 this->saveSettings();
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
190 this->updateRecentlyOpenedDocumentsMenu();
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
191 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
192
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
193 void MainWindow::openModelForEditing(const ModelId modelId)
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
194 {
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
195 Document* document = new Document{this->documents.getModelById(modelId), &this->documents, this->colorTable};
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
196 document->setRenderPreferences(this->renderPreferences);
47
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 45
diff changeset
197 connect(document, &Document::newStatusText, [&](const QString& newStatusText)
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 45
diff changeset
198 {
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 45
diff changeset
199 this->statusBar()->showMessage(newStatusText);
cd6704009eb9 picking works now
Teemu Piippo <teemu@hecknology.net>
parents: 45
diff changeset
200 });
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
201 const QFileInfo fileInfo{*this->documents.modelPath(modelId)};
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
202 this->ui->tabs->addTab(document, fileInfo.baseName());
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
203 this->ui->tabs->setCurrentWidget(document);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
204 document->restoreSplitterState(this->documentSplitterState);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
205 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
206
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
207 void MainWindow::runSettingsEditor()
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
208 {
16
Teemu Piippo <teemu@hecknology.net>
parents: 12
diff changeset
209 SettingsEditor settingsEditor{&this->settings, this->defaultKeyboardShortcuts, this};
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
210 const int result = settingsEditor.exec();
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
211 if (result == QDialog::Accepted)
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
212 {
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
213 this->restoreSettings();
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
214 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
215 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
216
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
217 Document* MainWindow::currentDocument()
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
218 {
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
219 return qobject_cast<Document*>(this->ui->tabs->currentWidget());
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
220 }
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
221
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
222 void MainWindow::handleDocumentSplitterChange()
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
223 {
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
224 Document* currentDocument = this->currentDocument();
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
225 if (currentDocument != nullptr)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
226 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
227 this->documentSplitterState = currentDocument->saveSplitterState();
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
228 for (int i = 0; i < this->ui->tabs->count(); i += 1)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
229 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
230 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(i));
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
231 if (document != nullptr and document != currentDocument)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
232 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
233 document->restoreSplitterState(this->documentSplitterState);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
234 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
235 }
41
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
236 this->settings.setMainSplitterState(this->documentSplitterState);
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
237 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
238 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
239
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
240 void MainWindow::updateRecentlyOpenedDocumentsMenu()
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
241 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
242 this->ui->menuRecentFiles->clear();
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
243 for (const QString& path : this->recentlyOpenedFiles)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
244 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
245 QAction* action = new QAction{path, this};
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
246 action->setData(path);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
247 this->ui->menuRecentFiles->addAction(action);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
248 connect(action, &QAction::triggered, this, &MainWindow::openRecentFile);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
249 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
250 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
251
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
252 void MainWindow::openRecentFile()
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
253 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
254 QAction* action = qobject_cast<QAction*>(this->sender());
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
255 if (action != nullptr)
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
256 {
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
257 const QString path = action->data().toString();
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
258 this->openModelFromPath(path);
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
259 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
260 }
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
261
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
262 void MainWindow::setRenderStyle(gl::RenderStyle renderStyle)
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
263 {
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
264 this->renderPreferences.style = renderStyle;
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
265 this->saveSettings();
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
266 this->updateRenderPreferences();
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
267 }
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
268
170
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
269 void MainWindow::setDrawAxes(bool drawAxes)
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
270 {
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
271 this->renderPreferences.drawAxes = drawAxes;
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
272 this->saveSettings();
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
273 this->updateRenderPreferences();
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
274 }
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
275
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
276 /**
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
277 * @brief Handles the "Save" (Ctrl+S) action
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
278 */
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
279 void MainWindow::actionSave()
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
280 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
281 if (this->currentDocument() != nullptr)
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
282 {
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
283 const ModelId modelId = {0};
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
284 const QString* path = this->documents.modelPath(modelId);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
285 if (path == nullptr or path->isEmpty())
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
286 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
287 this->actionSaveAs();
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
288 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
289 else
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
290 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
291 QString error;
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
292 QTextStream errorStream{&error};
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
293 const bool succeeded = this->documents.saveModel(modelId, errorStream);
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
294 if (not succeeded)
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
295 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
296 QMessageBox::critical(this, tr("Save error"), error);
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
297 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
298 else
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
299 {
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
300 this->addRecentlyOpenedFile(*path);
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
301 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
302 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
303 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
304 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
305
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
306 /**
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
307 * @brief Handles the "Save as…" (Ctrl+Shift+S) action
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
308 */
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
309 void MainWindow::actionSaveAs()
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
310 {
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
311 if (this->currentDocument() != nullptr)
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
312 {
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
313 const ModelId modelId = {0};
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
314 const QString* pathPtr = this->documents.modelPath(modelId);
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
315 QString defaultPath = (pathPtr != nullptr) ? *pathPtr : "";
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
316 const QString newPath = QFileDialog::getSaveFileName(
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
317 this,
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
318 tr("Save as…"),
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
319 QFileInfo{defaultPath}.absoluteDir().path(),
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
320 tr("LDraw files (*.ldr *dat);;All files (*)")
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
321 );
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
322 if (not newPath.isEmpty())
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
323 {
148
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
324 QString error;
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
325 QTextStream errorStream{&error};
e1ced2523cad reworking
Teemu Piippo <teemu@hecknology.net>
parents: 147
diff changeset
326 this->documents.setModelPath(modelId, newPath, this->libraries, errorStream);
142
e085f36e4d9f Update document tab label after saving
Teemu Piippo <teemu@hecknology.net>
parents: 141
diff changeset
327 this->ui->tabs->setTabText(this->ui->tabs->currentIndex(), QFileInfo{newPath}.fileName());
141
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
328 this->actionSave();
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
329 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
330 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
331 }
185eb297dc1e Saving works now
Teemu Piippo <teemu@hecknology.net>
parents: 128
diff changeset
332
160
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
333 /**
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
334 * @brief Handles the "Close" (Ctrl+W) action
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
335 */
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
336 void MainWindow::actionClose()
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
337 {
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
338 if (this->currentDocument() != nullptr)
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
339 {
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
340 this->closeDocument(this->currentDocument());
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
341 }
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
342 }
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
343
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
344 /**
169
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
345 * @brief Handles the "Delete" (Del) action
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
346 */
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
347 void MainWindow::actionDelete()
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
348 {
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
349 Document* document = this->currentDocument();
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
350 if (document != nullptr)
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
351 {
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
352 std::unique_ptr<ModelEditor> modelEditor = document->editModel();
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
353 QSet<ldraw::id_t> ids = document->selectedObjects(); // copy
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
354 for (const ldraw::id_t id : ids)
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
355 {
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
356 const QModelIndex index = modelEditor->model().find(id);
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
357 if (index.isValid())
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
358 {
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
359 modelEditor->remove(index.row());
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
360 }
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
361 }
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
362 }
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
363 }
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
364
6da096930534 Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents: 160
diff changeset
365 /**
160
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
366 * @brief Removes the document at the specified tab index
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
367 * @param index
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
368 */
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
369 void MainWindow::handleTabCloseButton(int tabIndex)
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
370 {
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
371 if (tabIndex >= 0 and tabIndex < this->ui->tabs->count())
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
372 {
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
373 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(tabIndex));
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
374 if (document != nullptr)
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
375 {
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
376 this->closeDocument(document);
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
377 }
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
378 }
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
379 }
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
380
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
381 /**
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
382 * @brief Closes the specified document
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
383 * @param document
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
384 */
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
385 void MainWindow::closeDocument(Document *document)
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
386 {
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
387 std::optional<ModelId> modelId = this->documents.findIdForModel(&document->getModel());
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
388 if (modelId.has_value())
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
389 {
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
390 this->documents.closeDocument(modelId.value());
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
391 delete document;
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
392 }
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
393 }
536efae7137e Add document closing
Teemu Piippo <teemu@hecknology.net>
parents: 148
diff changeset
394
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
395 void MainWindow::changeEvent(QEvent* event)
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
396 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
397 if (event != nullptr)
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
398 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
399 switch (event->type())
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
400 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
401 case QEvent::LanguageChange:
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
402 this->ui->retranslateUi(this);
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
403 break;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
404 default:
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
405 break;
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
406 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
407 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
408 QMainWindow::changeEvent(event);
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
409 }
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
410
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
411 /**
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
412 * @brief Handles closing the main window
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
413 * @param event Event information
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
414 */
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
415 void MainWindow::closeEvent(QCloseEvent* event)
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
416 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
417 saveSettings();
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
418 event->accept();
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
419 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
420
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
421 /**
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
422 * @brief Updates the title of the main window so to contain the app's name
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
423 * and version as well as the open document name.
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
424 */
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
425 void MainWindow::updateTitle()
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
426 {
1
51d14b0c68c0 add version
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
427 QString title = ::appName;
51d14b0c68c0 add version
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
428 title += " ";
51d14b0c68c0 add version
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
429 title += fullVersionString();
51d14b0c68c0 add version
Teemu Piippo <teemu@hecknology.net>
parents: 0
diff changeset
430 setWindowTitle(title);
0
f9f4d4d6f162 initial commit
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
431 }
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
432
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
433 void MainWindow::updateRenderPreferences()
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
434 {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
435 for (int i = 0; i < this->ui->tabs->count(); i += 1)
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
436 {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
437 Document* document = qobject_cast<Document*>(this->ui->tabs->widget(i));
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
438 if (document != nullptr)
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
439 {
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
440 document->setRenderPreferences(this->renderPreferences);
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
441 }
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
442 }
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
443 for (auto data : ::renderStyleButtons)
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
444 {
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
445 QAction* action = data.memberInstance(this->ui.get());
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
446 action->setChecked(this->renderPreferences.style == data.payload);
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
447 }
170
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
448 this->ui->actionDrawAxes->setChecked(this->renderPreferences.drawAxes);
36
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
449 }
bbb901b97404 added render style storage
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
450
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
451 /**
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
452 * @brief Stores the settings of the main window, storing geometry, etc
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
453 */
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
454 void MainWindow::saveSettings()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
455 {
41
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
456 this->settings.setMainWindowGeometry(this->saveGeometry());
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
457 this->settings.setRecentFiles(this->recentlyOpenedFiles);
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
458 this->settings.setMainSplitterState(this->documentSplitterState);
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
459 this->settings.setRenderStyle(static_cast<int>(this->renderPreferences.style));
170
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
460 this->settings.setDrawAxes(this->renderPreferences.drawAxes);
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
461 this->libraries.storeToSettings(&this->settings);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
462 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
463
40
30cb5e836736 added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
464 void MainWindow::restoreStartupSettings()
30cb5e836736 added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
465 {
41
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
466 this->restoreGeometry(this->settings.mainWindowGeometry());
40
30cb5e836736 added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
467 }
30cb5e836736 added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents: 39
diff changeset
468
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
469 /**
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
470 * @brief Restores saved settings relating to the main window
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
471 */
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
472 void MainWindow::restoreSettings()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
473 {
41
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
474 this->recentlyOpenedFiles = this->settings.recentFiles();
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
475 this->documentSplitterState = this->settings.mainSplitterState();
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
476 this->renderPreferences.style = static_cast<gl::RenderStyle>(this->settings.renderStyle());
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
477 this->renderPreferences.mainColor = this->settings.mainColor();
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
478 this->renderPreferences.backgroundColor = this->settings.backgroundColor();
44
c6114b3af3a6 added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents: 41
diff changeset
479 this->renderPreferences.lineThickness = this->settings.lineThickness();
45
272c84c7c87e added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents: 44
diff changeset
480 this->renderPreferences.lineAntiAliasing = this->settings.lineAntiAliasing();
48
3c10f0e2fbe0 added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents: 47
diff changeset
481 this->renderPreferences.selectedColor = this->settings.selectedColor();
170
9b655f6fe5a1 Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents: 169
diff changeset
482 this->renderPreferences.drawAxes = this->settings.drawAxes();
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
483 const QString systemLocale = QLocale::system().name();
41
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
484 const QVariant defaultLocale = this->settings.locale();
0abada2a9802 added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents: 40
diff changeset
485 this->changeLanguage(defaultLocale.toString());
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
486 this->libraries.restoreFromSettings(&this->settings);
9
8b9780700b5e added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
487 this->updateRecentlyOpenedDocumentsMenu();
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
488 this->loadColors();
39
caac957e9834 Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents: 36
diff changeset
489 this->updateRenderPreferences();
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
490 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
491
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
492 QString MainWindow::pathToTranslation(const QString& localeCode)
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
493 {
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
494 QDir dir {":/locale"};
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
495 return dir.filePath(localeCode + ".qm");
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
496 }
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
497
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
498 void MainWindow::loadColors()
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
499 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
500 QTextStream errors;
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
501 this->colorTable = this->libraries.loadColorTable(errors);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
502 }
97
d9a3b153f679 work on tools
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
503
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
504 void MainWindow::keyReleaseEvent(QKeyEvent* event)
97
d9a3b153f679 work on tools
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
505 {
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
506 Document* document = this->currentDocument();
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
507 if (document != nullptr)
97
d9a3b153f679 work on tools
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
508 {
125
f127982d3412 Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents: 124
diff changeset
509 document->handleKeyPress(event);
97
d9a3b153f679 work on tools
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
510 }
d9a3b153f679 work on tools
Teemu Piippo <teemu@hecknology.net>
parents: 96
diff changeset
511 }

mercurial