Tue, 24 May 2022 16:11:10 +0300
more work on circle tool + cleanup
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" |
169
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
31 | #include "modeleditor.h" |
0 | 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 | 56 | MainWindow::MainWindow(QWidget *parent) : |
3 | 57 | QMainWindow{parent}, |
5 | 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 | 62 | { |
6 | 63 | this->ui->setupUi(this); |
16 | 64 | defaultKeyboardShortcuts = uiutilities::makeKeySequenceMap(uiutilities::collectActions(this)); |
5 | 65 | connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newModel); |
6 | 66 | connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openModel); |
3 | 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 | 76 | connect(this->ui->actionSave, &QAction::triggered, |
77 | this, &MainWindow::actionSave); | |
78 | connect(this->ui->actionSaveAs, &QAction::triggered, | |
79 | this, &MainWindow::actionSaveAs); | |
160 | 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); |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
82 | connect(this->ui->actionInvert, &QAction::triggered, this, &MainWindow::actionInvert); |
160 | 83 | connect(this->ui->tabs, &QTabWidget::tabCloseRequested, this, &MainWindow::handleTabCloseButton); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
84 | for (auto data : ::renderStyleButtons) |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
85 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
86 | QAction* action = data.memberInstance(this->ui.get()); |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
87 | connect(action, &QAction::triggered, [this, data]() |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
88 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
89 | this->setRenderStyle(data.payload); |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
90 | }); |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
91 | } |
170
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
92 | connect(this->ui->actionDrawAxes, &QAction::triggered, this, &MainWindow::setDrawAxes); |
6 | 93 | this->updateTitle(); |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
94 | this->restoreStartupSettings(); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
95 | this->restoreSettings(); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
96 | this->updateRenderPreferences(); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
97 | this->newModel(); |
5 | 98 | } |
99 | ||
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
100 | // 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
|
101 | // 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
|
102 | // being incomplete. |
5 | 103 | MainWindow::~MainWindow() |
104 | { | |
105 | } | |
106 | ||
107 | void MainWindow::newModel() | |
108 | { | |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
109 | this->openModelForEditing(documents.newModel()); |
5 | 110 | } |
111 | ||
112 | void MainWindow::openModel() | |
113 | { | |
114 | const QString path = QFileDialog::getOpenFileName( | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
115 | this, |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
116 | tr("Open model"), |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
117 | "", |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
118 | tr("LDraw models (*.ldr *.dat)")); |
5 | 119 | if (not path.isEmpty()) |
120 | { | |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
121 | this->openModelFromPath(path); |
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 | |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
125 | void MainWindow::openModelFromPath(const QString& path) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
126 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
127 | QString errorString; |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
128 | QTextStream errorStream{&errorString}; |
148 | 129 | std::optional<ModelId> modelIdOpt = this->documents.openModel( |
130 | path, | |
131 | errorStream, | |
132 | DocumentManager::OpenType::ManuallyOpened); | |
133 | if (modelIdOpt.has_value()) | |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
134 | { |
148 | 135 | const ModelId modelId = modelIdOpt.value(); |
136 | this->documents.loadDependenciesForModel(modelId, path, this->libraries, errorStream); | |
12 | 137 | if (not errorString.isEmpty()) |
138 | { | |
139 | QMessageBox::warning( | |
140 | this, | |
141 | tr("Problem loading references"), | |
142 | errorString); | |
143 | } | |
148 | 144 | this->openModelForEditing(modelId); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
145 | this->addRecentlyOpenedFile(path); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
146 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
147 | else |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
148 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
149 | QMessageBox::critical( |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
150 | this, |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
151 | tr("Problem opening file"), |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
152 | utility::format( |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
153 | tr("Could not open %1: %2"), |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
154 | path, |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
155 | errorString)); |
5 | 156 | } |
157 | } | |
158 | ||
159 | /** | |
6 | 160 | * @brief Changes the application language to the specified language |
161 | * @param localeCode Code of the locale to translate to | |
162 | */ | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
163 | void MainWindow::changeLanguage(QString localeCode) |
6 | 164 | { |
165 | if (not localeCode.isEmpty() and localeCode != this->currentLanguage) | |
166 | { | |
167 | this->currentLanguage = localeCode; | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
168 | if (localeCode == "system") |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
169 | { |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
170 | localeCode = QLocale::system().name(); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
171 | } |
6 | 172 | QLocale::setDefault({localeCode}); |
173 | qApp->removeTranslator(&this->translator); | |
174 | const bool loadSuccessful = this->translator.load(pathToTranslation(localeCode)); | |
175 | if (loadSuccessful) | |
176 | { | |
177 | qApp->installTranslator(&this->translator); | |
178 | } | |
179 | } | |
180 | } | |
181 | ||
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
182 | void MainWindow::addRecentlyOpenedFile(const QString& path) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
183 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
184 | this->recentlyOpenedFiles.removeAll(path); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
185 | this->recentlyOpenedFiles.insert(0, path); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
186 | while (this->recentlyOpenedFiles.size() > maxRecentlyOpenedFiles) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
187 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
188 | this->recentlyOpenedFiles.removeLast(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
189 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
190 | this->saveSettings(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
191 | this->updateRecentlyOpenedDocumentsMenu(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
192 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
193 | |
148 | 194 | 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
|
195 | { |
148 | 196 | 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
|
197 | document->setRenderPreferences(this->renderPreferences); |
47 | 198 | connect(document, &Document::newStatusText, [&](const QString& newStatusText) |
199 | { | |
200 | this->statusBar()->showMessage(newStatusText); | |
201 | }); | |
148 | 202 | 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
|
203 | QString tabName = fileInfo.baseName(); |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
204 | if (tabName.isEmpty()) |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
205 | { |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
206 | tabName = tr("<unnamed>"); |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
207 | } |
3016b494685c
show unnamed tabs as "<unnamed>" in the tab list
Teemu Piippo <teemu@hecknology.net>
parents:
170
diff
changeset
|
208 | 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
|
209 | this->ui->tabs->setCurrentWidget(document); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
210 | document->restoreSplitterState(this->documentSplitterState); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
211 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
212 | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
213 | void MainWindow::runSettingsEditor() |
6 | 214 | { |
16 | 215 | SettingsEditor settingsEditor{&this->settings, this->defaultKeyboardShortcuts, this}; |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
216 | const int result = settingsEditor.exec(); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
217 | if (result == QDialog::Accepted) |
6 | 218 | { |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
219 | this->restoreSettings(); |
6 | 220 | } |
221 | } | |
222 | ||
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
223 | Document* MainWindow::currentDocument() |
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
224 | { |
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
225 | 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
|
226 | } |
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
227 | |
178 | 228 | const Document* MainWindow::currentDocument() const |
229 | { | |
230 | return qobject_cast<const Document*>(this->ui->tabs->currentWidget()); | |
231 | } | |
232 | ||
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
233 | void MainWindow::handleDocumentSplitterChange() |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
234 | { |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
235 | Document* currentDocument = this->currentDocument(); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
236 | if (currentDocument != nullptr) |
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 | this->documentSplitterState = currentDocument->saveSplitterState(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
239 | 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
|
240 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
241 | 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
|
242 | if (document != nullptr and document != currentDocument) |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
243 | { |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
244 | document->restoreSplitterState(this->documentSplitterState); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
245 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
246 | } |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
247 | this->settings.setMainSplitterState(this->documentSplitterState); |
9
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 | } |
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 | void MainWindow::updateRecentlyOpenedDocumentsMenu() |
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 | this->ui->menuRecentFiles->clear(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
254 | for (const QString& path : this->recentlyOpenedFiles) |
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 | QAction* action = new QAction{path, this}; |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
257 | action->setData(path); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
258 | this->ui->menuRecentFiles->addAction(action); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
259 | 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
|
260 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
261 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
262 | |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
263 | void MainWindow::openRecentFile() |
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 | 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
|
266 | if (action != nullptr) |
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 | const QString path = action->data().toString(); |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
269 | this->openModelFromPath(path); |
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 | } |
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
272 | |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
273 | void MainWindow::setRenderStyle(gl::RenderStyle renderStyle) |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
274 | { |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
275 | this->renderPreferences.style = renderStyle; |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
276 | this->saveSettings(); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
277 | this->updateRenderPreferences(); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
278 | } |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
279 | |
170
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
280 | void MainWindow::setDrawAxes(bool drawAxes) |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
281 | { |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
282 | this->renderPreferences.drawAxes = drawAxes; |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
283 | this->saveSettings(); |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
284 | this->updateRenderPreferences(); |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
285 | } |
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
286 | |
141 | 287 | /** |
288 | * @brief Handles the "Save" (Ctrl+S) action | |
289 | */ | |
290 | void MainWindow::actionSave() | |
291 | { | |
292 | if (this->currentDocument() != nullptr) | |
293 | { | |
178 | 294 | const std::optional<ModelId> modelId = this->findCurrentModelId(); |
295 | if (modelId.has_value()) | |
141 | 296 | { |
178 | 297 | const QString* path = this->documents.modelPath(*modelId); |
298 | if (path == nullptr or path->isEmpty()) | |
141 | 299 | { |
178 | 300 | this->actionSaveAs(); |
141 | 301 | } |
302 | else | |
303 | { | |
178 | 304 | QString error; |
305 | QTextStream errorStream{&error}; | |
306 | const bool succeeded = this->documents.saveModel(*modelId, errorStream); | |
307 | if (not succeeded) | |
308 | { | |
309 | QMessageBox::critical(this, tr("Save error"), error); | |
310 | } | |
311 | else | |
312 | { | |
313 | this->addRecentlyOpenedFile(*path); | |
314 | } | |
141 | 315 | } |
316 | } | |
317 | } | |
318 | } | |
319 | ||
320 | /** | |
321 | * @brief Handles the "Save as…" (Ctrl+Shift+S) action | |
322 | */ | |
323 | void MainWindow::actionSaveAs() | |
324 | { | |
325 | if (this->currentDocument() != nullptr) | |
326 | { | |
178 | 327 | const std::optional<ModelId> modelId = this->findCurrentModelId(); |
328 | if (modelId.has_value()) | |
141 | 329 | { |
178 | 330 | const QString* pathPtr = this->documents.modelPath(*modelId); |
331 | QString defaultPath = (pathPtr != nullptr) ? *pathPtr : ""; | |
332 | const QString newPath = QFileDialog::getSaveFileName( | |
333 | this, | |
334 | tr("Save as…"), | |
335 | QFileInfo{defaultPath}.absoluteDir().path(), | |
336 | tr("LDraw files (*.ldr *dat);;All files (*)") | |
337 | ); | |
338 | if (not newPath.isEmpty()) | |
339 | { | |
340 | QString error; | |
341 | QTextStream errorStream{&error}; | |
342 | this->documents.setModelPath(*modelId, newPath, this->libraries, errorStream); | |
343 | this->ui->tabs->setTabText(this->ui->tabs->currentIndex(), QFileInfo{newPath}.fileName()); | |
344 | this->actionSave(); | |
345 | } | |
141 | 346 | } |
347 | } | |
348 | } | |
349 | ||
160 | 350 | /** |
351 | * @brief Handles the "Close" (Ctrl+W) action | |
352 | */ | |
353 | void MainWindow::actionClose() | |
354 | { | |
355 | if (this->currentDocument() != nullptr) | |
356 | { | |
357 | this->closeDocument(this->currentDocument()); | |
358 | } | |
359 | } | |
360 | ||
361 | /** | |
169
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
362 | * @brief Handles the "Delete" (Del) action |
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 | void MainWindow::actionDelete() |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
365 | { |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
366 | Document* document = this->currentDocument(); |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
367 | if (document != nullptr) |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
368 | { |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
369 | std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
370 | QSet<ldraw::id_t> ids = document->selectedObjects(); // copy |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
371 | for (const ldraw::id_t id : ids) |
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 | const QModelIndex index = modelEditor->model().find(id); |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
374 | if (index.isValid()) |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
375 | { |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
376 | modelEditor->remove(index.row()); |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
377 | } |
6da096930534
Added the delete action
Teemu Piippo <teemu@hecknology.net>
parents:
160
diff
changeset
|
378 | } |
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 | } |
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 | /** |
183
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
383 | * @brief Handles the "Invert" action |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
384 | */ |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
385 | void MainWindow::actionInvert() |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
386 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
387 | Document* document = this->currentDocument(); |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
388 | if (document != nullptr) |
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 | // TODO: simplify |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
391 | std::unique_ptr<ModelEditor> modelEditor = document->editModel(); |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
392 | 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
|
393 | if (modelId.has_value()) |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
394 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
395 | ldraw::GetPolygonsContext context = { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
396 | .modelId = modelId.value(), |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
397 | .documents = &this->documents, |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
398 | }; |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
399 | 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
|
400 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
401 | modelEditor->modifyObject(id, [&context](ldraw::Object* object) |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
402 | { |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
403 | object->invert(&context); |
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 | } |
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 | } |
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 | |
97b591813c8b
- Add editors for string and bool properties
Teemu Piippo <teemu@hecknology.net>
parents:
178
diff
changeset
|
410 | /** |
160 | 411 | * @brief Removes the document at the specified tab index |
412 | * @param index | |
413 | */ | |
414 | void MainWindow::handleTabCloseButton(int tabIndex) | |
415 | { | |
416 | if (tabIndex >= 0 and tabIndex < this->ui->tabs->count()) | |
417 | { | |
418 | Document* document = qobject_cast<Document*>(this->ui->tabs->widget(tabIndex)); | |
419 | if (document != nullptr) | |
420 | { | |
421 | this->closeDocument(document); | |
422 | } | |
423 | } | |
424 | } | |
425 | ||
426 | /** | |
427 | * @brief Closes the specified document | |
428 | * @param document | |
429 | */ | |
430 | void MainWindow::closeDocument(Document *document) | |
431 | { | |
432 | std::optional<ModelId> modelId = this->documents.findIdForModel(&document->getModel()); | |
433 | if (modelId.has_value()) | |
434 | { | |
435 | this->documents.closeDocument(modelId.value()); | |
436 | delete document; | |
437 | } | |
438 | } | |
439 | ||
178 | 440 | std::optional<ModelId> MainWindow::findCurrentModelId() const |
441 | { | |
442 | const Document* document = this->currentDocument(); | |
443 | if (document != nullptr) | |
444 | { | |
445 | return this->documents.findIdForModel(&document->getModel()); | |
446 | } | |
447 | else | |
448 | { | |
449 | return {}; | |
450 | } | |
451 | } | |
452 | ||
6 | 453 | void MainWindow::changeEvent(QEvent* event) |
454 | { | |
455 | if (event != nullptr) | |
456 | { | |
457 | switch (event->type()) | |
458 | { | |
459 | case QEvent::LanguageChange: | |
460 | this->ui->retranslateUi(this); | |
461 | break; | |
462 | default: | |
463 | break; | |
464 | } | |
465 | } | |
466 | QMainWindow::changeEvent(event); | |
467 | } | |
468 | ||
469 | /** | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
470 | * @brief Handles closing the main window |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
471 | * @param event Event information |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
472 | */ |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
473 | void MainWindow::closeEvent(QCloseEvent* event) |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
474 | { |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
475 | saveSettings(); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
476 | event->accept(); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
477 | } |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
478 | |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
479 | /** |
5 | 480 | * @brief Updates the title of the main window so to contain the app's name |
481 | * and version as well as the open document name. | |
482 | */ | |
483 | void MainWindow::updateTitle() | |
484 | { | |
1 | 485 | QString title = ::appName; |
486 | title += " "; | |
487 | title += fullVersionString(); | |
488 | setWindowTitle(title); | |
0 | 489 | } |
6 | 490 | |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
491 | void MainWindow::updateRenderPreferences() |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
492 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
493 | 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
|
494 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
495 | Document* document = qobject_cast<Document*>(this->ui->tabs->widget(i)); |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
496 | if (document != nullptr) |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
497 | { |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
498 | document->setRenderPreferences(this->renderPreferences); |
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 | } |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
501 | for (auto data : ::renderStyleButtons) |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
502 | { |
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
503 | QAction* action = data.memberInstance(this->ui.get()); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
504 | action->setChecked(this->renderPreferences.style == data.payload); |
36
bbb901b97404
added render style storage
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
505 | } |
170
9b655f6fe5a1
Added a toggle for setting whether axes are drawn
Teemu Piippo <teemu@hecknology.net>
parents:
169
diff
changeset
|
506 | this->ui->actionDrawAxes->setChecked(this->renderPreferences.drawAxes); |
36
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 | |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
509 | /** |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
510 | * @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
|
511 | */ |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
512 | void MainWindow::saveSettings() |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
513 | { |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
514 | this->settings.setMainWindowGeometry(this->saveGeometry()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
515 | this->settings.setRecentFiles(this->recentlyOpenedFiles); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
516 | this->settings.setMainSplitterState(this->documentSplitterState); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
517 | 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
|
518 | this->settings.setDrawAxes(this->renderPreferences.drawAxes); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
519 | this->libraries.storeToSettings(&this->settings); |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
520 | } |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
521 | |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
522 | void MainWindow::restoreStartupSettings() |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
523 | { |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
524 | this->restoreGeometry(this->settings.mainWindowGeometry()); |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
525 | } |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
526 | |
7
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 | * @brief Restores saved settings relating to the main window |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
529 | */ |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
530 | void MainWindow::restoreSettings() |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
531 | { |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
532 | this->recentlyOpenedFiles = this->settings.recentFiles(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
533 | this->documentSplitterState = this->settings.mainSplitterState(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
534 | this->renderPreferences.style = static_cast<gl::RenderStyle>(this->settings.renderStyle()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
535 | this->renderPreferences.mainColor = this->settings.mainColor(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
536 | this->renderPreferences.backgroundColor = this->settings.backgroundColor(); |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
41
diff
changeset
|
537 | this->renderPreferences.lineThickness = this->settings.lineThickness(); |
45
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
538 | this->renderPreferences.lineAntiAliasing = this->settings.lineAntiAliasing(); |
48
3c10f0e2fbe0
added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents:
47
diff
changeset
|
539 | 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
|
540 | this->renderPreferences.drawAxes = this->settings.drawAxes(); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
541 | const QString systemLocale = QLocale::system().name(); |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
542 | const QVariant defaultLocale = this->settings.locale(); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
543 | this->changeLanguage(defaultLocale.toString()); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
544 | this->libraries.restoreFromSettings(&this->settings); |
9
8b9780700b5e
added saving of splitter state and recent files
Teemu Piippo <teemu@hecknology.net>
parents:
8
diff
changeset
|
545 | this->updateRecentlyOpenedDocumentsMenu(); |
26 | 546 | this->loadColors(); |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
36
diff
changeset
|
547 | this->updateRenderPreferences(); |
7
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
548 | } |
68443f5be176
added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
549 | |
6 | 550 | QString MainWindow::pathToTranslation(const QString& localeCode) |
551 | { | |
552 | QDir dir {":/locale"}; | |
553 | return dir.filePath(localeCode + ".qm"); | |
554 | } | |
26 | 555 | |
556 | void MainWindow::loadColors() | |
557 | { | |
558 | QTextStream errors; | |
559 | this->colorTable = this->libraries.loadColorTable(errors); | |
560 | } | |
97 | 561 | |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
562 | void MainWindow::keyReleaseEvent(QKeyEvent* event) |
97 | 563 | { |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
564 | Document* document = this->currentDocument(); |
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
565 | if (document != nullptr) |
97 | 566 | { |
125
f127982d3412
Move tools under Document instead of MainWindow
Teemu Piippo <teemu@hecknology.net>
parents:
124
diff
changeset
|
567 | document->handleKeyPress(event); |
97 | 568 | } |
569 | } |