Mon, 06 Jun 2022 22:01:22 +0300
Giant refactor
24 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2020 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
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 | 24 | #include "mainwindow.h" |
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 | 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 | 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" |
0 | 31 | |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
32 | template<typename BaseType, typename MemberType, typename DataType> |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
33 | struct MemberData |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
34 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
35 | std::size_t member; |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
36 | DataType payload; |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
37 | constexpr MemberType memberInstance(BaseType* instance) const |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
38 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
39 | return *reinterpret_cast<MemberType*>(reinterpret_cast<char*>(instance) + this->member); |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
40 | } |
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 | static constexpr MemberData<Ui_MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
44 | { offsetof(Ui_MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal }, |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
45 | { offsetof(Ui_MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen }, |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
46 | { 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
|
47 | { offsetof(Ui_MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene }, |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
48 | }; |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
49 | |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
50 | class A : public QSettings |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
51 | { |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
52 | using QSettings::QSettings; |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
53 | }; |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
54 | |
0 | 55 | MainWindow::MainWindow(QWidget *parent) : |
3 | 56 | QMainWindow{parent}, |
5 | 57 | ui{std::make_unique<Ui_MainWindow>()}, |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
58 | documents{this}, |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
59 | settings{}, |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
60 | libraries{this} |
0 | 61 | { |
6 | 62 | this->ui->setupUi(this); |
16 | 63 | defaultKeyboardShortcuts = uiutilities::makeKeySequenceMap(uiutilities::collectActions(this)); |
5 | 64 | connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newModel); |
6 | 65 | connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openModel); |
3 | 66 | connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
67 | 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
|
68 | connect(ui->actionAdjustGridToView, &QAction::triggered, [&]() |
7c834fe36b25
Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents:
125
diff
changeset
|
69 | { |
7c834fe36b25
Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents:
125
diff
changeset
|
70 | if (this->currentDocument() != nullptr) |
7c834fe36b25
Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents:
125
diff
changeset
|
71 | { |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
72 | adjustGridToView(this->currentDocument()->canvas); |
128
7c834fe36b25
Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents:
125
diff
changeset
|
73 | } |
7c834fe36b25
Moved automatic grid adjusting into a new action
Teemu Piippo <teemu@hecknology.net>
parents:
125
diff
changeset
|
74 | }); |
141 | 75 | connect(this->ui->actionSave, &QAction::triggered, |
76 | this, &MainWindow::actionSave); | |
77 | connect(this->ui->actionSaveAs, &QAction::triggered, | |
78 | this, &MainWindow::actionSaveAs); | |
160 | 79 | connect(this->ui->actionClose, &QAction::triggered, this, &MainWindow::actionClose); |
169
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
80 | connect(this->ui->actionDelete, &QAction::triggered, this, &MainWindow::actionDelete); |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
81 | connect(this->ui->actionInvert, &QAction::triggered, this, &MainWindow::actionInvert); |
160 | 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 | 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 | 97 | } |
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 | 102 | MainWindow::~MainWindow() |
103 | { | |
104 | } | |
105 | ||
106 | void MainWindow::newModel() | |
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 | 109 | } |
110 | ||
111 | void MainWindow::openModel() | |
112 | { | |
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 | 118 | if (not path.isEmpty()) |
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 | 128 | std::optional<ModelId> modelIdOpt = this->documents.openModel( |
129 | path, | |
130 | errorStream, | |
131 | DocumentManager::OpenType::ManuallyOpened); | |
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 | 134 | const ModelId modelId = modelIdOpt.value(); |
135 | this->documents.loadDependenciesForModel(modelId, path, this->libraries, errorStream); | |
12 | 136 | if (not errorString.isEmpty()) |
137 | { | |
138 | QMessageBox::warning( | |
139 | this, | |
140 | tr("Problem loading references"), | |
141 | errorString); | |
142 | } | |
148 | 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 | 155 | } |
156 | } | |
157 | ||
158 | /** | |
6 | 159 | * @brief Changes the application language to the specified language |
160 | * @param localeCode Code of the locale to translate to | |
161 | */ | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
162 | void MainWindow::changeLanguage(QString localeCode) |
6 | 163 | { |
164 | if (not localeCode.isEmpty() and localeCode != this->currentLanguage) | |
165 | { | |
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 | 171 | QLocale::setDefault({localeCode}); |
172 | qApp->removeTranslator(&this->translator); | |
173 | const bool loadSuccessful = this->translator.load(pathToTranslation(localeCode)); | |
174 | if (loadSuccessful) | |
175 | { | |
176 | qApp->installTranslator(&this->translator); | |
177 | } | |
178 | } | |
179 | } | |
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 | 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 | { |
200 | 195 | EditorTabWidget* document = new EditorTabWidget{ |
196 | this->documents.getModelById(modelId), | |
197 | &this->documents, | |
198 | this->colorTable, | |
199 | }; | |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
200 | document->canvas->setRenderPreferences(this->renderPreferences); |
200 | 201 | connect(document, &EditorTabWidget::newStatusText, [&](const QString& newStatusText) |
47 | 202 | { |
203 | this->statusBar()->showMessage(newStatusText); | |
204 | }); | |
148 | 205 | const QFileInfo fileInfo{*this->documents.modelPath(modelId)}; |
174
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
206 | QString tabName = fileInfo.baseName(); |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
207 | if (tabName.isEmpty()) |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
208 | { |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
209 | tabName = tr("<unnamed>"); |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
210 | } |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
211 | this->ui->tabs->addTab(document, tabName); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
212 | this->ui->tabs->setCurrentWidget(document); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
213 | document->restoreSplitterState(this->documentSplitterState); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
214 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
215 | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
216 | void MainWindow::runSettingsEditor() |
6 | 217 | { |
16 | 218 | SettingsEditor settingsEditor{&this->settings, this->defaultKeyboardShortcuts, this}; |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
219 | const int result = settingsEditor.exec(); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
220 | if (result == QDialog::Accepted) |
6 | 221 | { |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
222 | this->restoreSettings(); |
6 | 223 | } |
224 | } | |
225 | ||
200 | 226 | EditorTabWidget* MainWindow::currentDocument() |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
227 | { |
200 | 228 | return qobject_cast<EditorTabWidget*>(this->ui->tabs->currentWidget()); |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
229 | } |
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
230 | |
200 | 231 | const EditorTabWidget* MainWindow::currentDocument() const |
178 | 232 | { |
200 | 233 | return qobject_cast<const EditorTabWidget*>(this->ui->tabs->currentWidget()); |
178 | 234 | } |
235 | ||
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
236 | void MainWindow::handleDocumentSplitterChange() |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
237 | { |
200 | 238 | EditorTabWidget* currentDocument = this->currentDocument(); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
239 | if (currentDocument != nullptr) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
240 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
241 | this->documentSplitterState = currentDocument->saveSplitterState(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
242 | 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
|
243 | { |
200 | 244 | EditorTabWidget* document = qobject_cast<EditorTabWidget*>(this->ui->tabs->widget(i)); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
245 | if (document != nullptr and document != currentDocument) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
246 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
247 | document->restoreSplitterState(this->documentSplitterState); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
248 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
249 | } |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
250 | this->settings.setMainSplitterState(this->documentSplitterState); |
9
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 | } |
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 | void MainWindow::updateRecentlyOpenedDocumentsMenu() |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
255 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
256 | this->ui->menuRecentFiles->clear(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
257 | for (const QString& path : this->recentlyOpenedFiles) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
258 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
259 | QAction* action = new QAction{path, this}; |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
260 | action->setData(path); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
261 | this->ui->menuRecentFiles->addAction(action); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
262 | 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
|
263 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
264 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
265 | |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
266 | void MainWindow::openRecentFile() |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
267 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
268 | 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
|
269 | if (action != nullptr) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
270 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
271 | const QString path = action->data().toString(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
272 | this->openModelFromPath(path); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
273 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
274 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
275 | |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
276 | void MainWindow::setRenderStyle(gl::RenderStyle renderStyle) |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
277 | { |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
278 | this->renderPreferences.style = renderStyle; |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
279 | this->saveSettings(); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
280 | this->updateRenderPreferences(); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
281 | } |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
282 | |
170
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
283 | void MainWindow::setDrawAxes(bool drawAxes) |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
284 | { |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
285 | this->renderPreferences.drawAxes = drawAxes; |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
286 | this->saveSettings(); |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
287 | this->updateRenderPreferences(); |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
288 | } |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
289 | |
141 | 290 | /** |
291 | * @brief Handles the "Save" (Ctrl+S) action | |
292 | */ | |
293 | void MainWindow::actionSave() | |
294 | { | |
295 | if (this->currentDocument() != nullptr) | |
296 | { | |
178 | 297 | const std::optional<ModelId> modelId = this->findCurrentModelId(); |
298 | if (modelId.has_value()) | |
141 | 299 | { |
178 | 300 | const QString* path = this->documents.modelPath(*modelId); |
301 | if (path == nullptr or path->isEmpty()) | |
141 | 302 | { |
178 | 303 | this->actionSaveAs(); |
141 | 304 | } |
305 | else | |
306 | { | |
178 | 307 | QString error; |
308 | QTextStream errorStream{&error}; | |
309 | const bool succeeded = this->documents.saveModel(*modelId, errorStream); | |
310 | if (not succeeded) | |
311 | { | |
312 | QMessageBox::critical(this, tr("Save error"), error); | |
313 | } | |
314 | else | |
315 | { | |
316 | this->addRecentlyOpenedFile(*path); | |
317 | } | |
141 | 318 | } |
319 | } | |
320 | } | |
321 | } | |
322 | ||
323 | /** | |
324 | * @brief Handles the "Save as…" (Ctrl+Shift+S) action | |
325 | */ | |
326 | void MainWindow::actionSaveAs() | |
327 | { | |
328 | if (this->currentDocument() != nullptr) | |
329 | { | |
178 | 330 | const std::optional<ModelId> modelId = this->findCurrentModelId(); |
331 | if (modelId.has_value()) | |
141 | 332 | { |
178 | 333 | const QString* pathPtr = this->documents.modelPath(*modelId); |
334 | QString defaultPath = (pathPtr != nullptr) ? *pathPtr : ""; | |
335 | const QString newPath = QFileDialog::getSaveFileName( | |
336 | this, | |
337 | tr("Save as…"), | |
338 | QFileInfo{defaultPath}.absoluteDir().path(), | |
339 | tr("LDraw files (*.ldr *dat);;All files (*)") | |
340 | ); | |
341 | if (not newPath.isEmpty()) | |
342 | { | |
343 | QString error; | |
344 | QTextStream errorStream{&error}; | |
345 | this->documents.setModelPath(*modelId, newPath, this->libraries, errorStream); | |
346 | this->ui->tabs->setTabText(this->ui->tabs->currentIndex(), QFileInfo{newPath}.fileName()); | |
347 | this->actionSave(); | |
348 | } | |
141 | 349 | } |
350 | } | |
351 | } | |
352 | ||
160 | 353 | /** |
354 | * @brief Handles the "Close" (Ctrl+W) action | |
355 | */ | |
356 | void MainWindow::actionClose() | |
357 | { | |
358 | if (this->currentDocument() != nullptr) | |
359 | { | |
360 | this->closeDocument(this->currentDocument()); | |
361 | } | |
362 | } | |
363 | ||
364 | /** | |
169
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
365 | * @brief Handles the "Delete" (Del) action |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
366 | */ |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
367 | void MainWindow::actionDelete() |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
368 | { |
200 | 369 | /* |
370 | EditorTabWidget* document = this->currentDocument(); | |
169
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
371 | if (document != nullptr) |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
372 | { |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
373 | std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
374 | QSet<ldraw::id_t> ids = document->selectedObjects(); // copy |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
375 | for (const ldraw::id_t id : ids) |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
376 | { |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
377 | const QModelIndex index = modelEditor->model().find(id); |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
378 | if (index.isValid()) |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
379 | { |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
380 | modelEditor->remove(index.row()); |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
381 | } |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
382 | } |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
383 | } |
200 | 384 | */ |
169
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
385 | } |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
386 | |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
387 | /** |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
388 | * @brief Handles the "Invert" action |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
389 | */ |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
390 | void MainWindow::actionInvert() |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
391 | { |
200 | 392 | /* |
393 | EditorTabWidget* document = this->currentDocument(); | |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
394 | if (document != nullptr) |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
395 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
396 | // TODO: simplify |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
397 | std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
398 | const std::optional<ModelId> modelId = this->documents.findIdForModel(&modelEditor->model()); |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
399 | if (modelId.has_value()) |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
400 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
401 | ldraw::GetPolygonsContext context = { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
402 | .modelId = modelId.value(), |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
403 | .documents = &this->documents, |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
404 | }; |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
405 | for (const ldraw::id_t id : document->selectedObjects()) |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
406 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
407 | modelEditor->modifyObject(id, [&context](ldraw::Object* object) |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
408 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
409 | object->invert(&context); |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
410 | }); |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
411 | } |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
412 | } |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
413 | } |
200 | 414 | */ |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
415 | } |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
416 | |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
417 | /** |
160 | 418 | * @brief Removes the document at the specified tab index |
419 | * @param index | |
420 | */ | |
421 | void MainWindow::handleTabCloseButton(int tabIndex) | |
422 | { | |
423 | if (tabIndex >= 0 and tabIndex < this->ui->tabs->count()) | |
424 | { | |
200 | 425 | EditorTabWidget* document = qobject_cast<EditorTabWidget*>(this->ui->tabs->widget(tabIndex)); |
160 | 426 | if (document != nullptr) |
427 | { | |
428 | this->closeDocument(document); | |
429 | } | |
430 | } | |
431 | } | |
432 | ||
433 | /** | |
434 | * @brief Closes the specified document | |
435 | * @param document | |
436 | */ | |
200 | 437 | void MainWindow::closeDocument(EditorTabWidget *document) |
160 | 438 | { |
200 | 439 | std::optional<ModelId> modelId = this->documents.findIdForModel(document->model); |
160 | 440 | if (modelId.has_value()) |
441 | { | |
442 | this->documents.closeDocument(modelId.value()); | |
443 | delete document; | |
444 | } | |
445 | } | |
446 | ||
178 | 447 | std::optional<ModelId> MainWindow::findCurrentModelId() const |
448 | { | |
200 | 449 | const EditorTabWidget* document = this->currentDocument(); |
178 | 450 | if (document != nullptr) |
451 | { | |
200 | 452 | return this->documents.findIdForModel(document->model); |
178 | 453 | } |
454 | else | |
455 | { | |
456 | return {}; | |
457 | } | |
458 | } | |
459 | ||
6 | 460 | void MainWindow::changeEvent(QEvent* event) |
461 | { | |
462 | if (event != nullptr) | |
463 | { | |
464 | switch (event->type()) | |
465 | { | |
466 | case QEvent::LanguageChange: | |
467 | this->ui->retranslateUi(this); | |
468 | break; | |
469 | default: | |
470 | break; | |
471 | } | |
472 | } | |
473 | QMainWindow::changeEvent(event); | |
474 | } | |
475 | ||
476 | /** | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
477 | * @brief Handles closing the main window |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
478 | * @param event Event information |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
479 | */ |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
480 | void MainWindow::closeEvent(QCloseEvent* event) |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
481 | { |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
482 | saveSettings(); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
483 | event->accept(); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
484 | } |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
485 | |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
486 | /** |
5 | 487 | * @brief Updates the title of the main window so to contain the app's name |
488 | * and version as well as the open document name. | |
489 | */ | |
490 | void MainWindow::updateTitle() | |
491 | { | |
1 | 492 | QString title = ::appName; |
493 | title += " "; | |
494 | title += fullVersionString(); | |
495 | setWindowTitle(title); | |
0 | 496 | } |
6 | 497 | |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
498 | void MainWindow::updateRenderPreferences() |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
499 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
500 | 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
|
501 | { |
200 | 502 | EditorTabWidget* document = qobject_cast<EditorTabWidget*>(this->ui->tabs->widget(i)); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
503 | if (document != nullptr) |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
504 | { |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
505 | document->canvas->setRenderPreferences(this->renderPreferences); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
506 | } |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
507 | } |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
508 | for (auto data : ::renderStyleButtons) |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
509 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
510 | QAction* action = data.memberInstance(this->ui.get()); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
511 | action->setChecked(this->renderPreferences.style == data.payload); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
512 | } |
170
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
513 | this->ui->actionDrawAxes->setChecked(this->renderPreferences.drawAxes); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
514 | } |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
515 | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
516 | /** |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
517 | * @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
|
518 | */ |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
519 | void MainWindow::saveSettings() |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
520 | { |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
521 | this->settings.setMainWindowGeometry(this->saveGeometry()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
522 | this->settings.setRecentFiles(this->recentlyOpenedFiles); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
523 | this->settings.setMainSplitterState(this->documentSplitterState); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
524 | 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
|
525 | this->settings.setDrawAxes(this->renderPreferences.drawAxes); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
526 | this->libraries.storeToSettings(&this->settings); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
527 | } |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
528 | |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
529 | void MainWindow::restoreStartupSettings() |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
530 | { |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
531 | this->restoreGeometry(this->settings.mainWindowGeometry()); |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
532 | } |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
533 | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
534 | /** |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
535 | * @brief Restores saved settings relating to the main window |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
536 | */ |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
537 | void MainWindow::restoreSettings() |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
538 | { |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
539 | this->recentlyOpenedFiles = this->settings.recentFiles(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
540 | this->documentSplitterState = this->settings.mainSplitterState(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
541 | this->renderPreferences.style = static_cast<gl::RenderStyle>(this->settings.renderStyle()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
542 | this->renderPreferences.mainColor = this->settings.mainColor(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
543 | this->renderPreferences.backgroundColor = this->settings.backgroundColor(); |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
41
diff
changeset
|
544 | this->renderPreferences.lineThickness = this->settings.lineThickness(); |
45
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
545 | this->renderPreferences.lineAntiAliasing = this->settings.lineAntiAliasing(); |
48
3c10f0e2fbe0
added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
546 | 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
|
547 | this->renderPreferences.drawAxes = this->settings.drawAxes(); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
548 | const QString systemLocale = QLocale::system().name(); |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
549 | const QVariant defaultLocale = this->settings.locale(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
550 | this->changeLanguage(defaultLocale.toString()); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
551 | this->libraries.restoreFromSettings(&this->settings); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
552 | this->updateRecentlyOpenedDocumentsMenu(); |
26 | 553 | this->loadColors(); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
554 | this->updateRenderPreferences(); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
555 | } |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
556 | |
6 | 557 | QString MainWindow::pathToTranslation(const QString& localeCode) |
558 | { | |
559 | QDir dir {":/locale"}; | |
560 | return dir.filePath(localeCode + ".qm"); | |
561 | } | |
26 | 562 | |
563 | void MainWindow::loadColors() | |
564 | { | |
565 | QTextStream errors; | |
566 | this->colorTable = this->libraries.loadColorTable(errors); | |
567 | } | |
97 | 568 | |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
569 | void MainWindow::keyReleaseEvent(QKeyEvent* /*event*/) |
97 | 570 | { |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
571 | /* |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
572 | Document* document = this->currentDocument(); |
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
573 | if (document != nullptr) |
97 | 574 | { |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
575 | document->handleKeyPress(event); |
97 | 576 | } |
191
d355d4c52d51
made editing tools not a polymorphic class tree
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
577 | */ |
97 | 578 | } |