MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
model_view.hpp
Go to the documentation of this file.
1
2/**
3 * @file model_view.hpp
4 * @brief Declares the Qt front end used to launch the MXVK model viewer renderer.
5 */
6
7#ifndef MODEL_VIEW_HPP
8#define MODEL_VIEW_HPP
9
10#include <QAction>
11#include <QCloseEvent>
12#include <QComboBox>
13#include <QDragEnterEvent>
14#include <QDropEvent>
15#include <QFileDialog>
16#include <QGroupBox>
17#include <QHBoxLayout>
18#include <QIcon>
19#include <QLabel>
20#include <QLineEdit>
21#include <QListWidget>
22#include <QMainWindow>
23#include <QMenu>
24#include <QMenuBar>
25#include <QMessageBox>
26#include <QMimeData>
27#include <QPlainTextEdit>
28#include <QProcess>
29#include <QPushButton>
30#include <QScrollBar>
31#include <QSettings>
32#include <QSplitter>
33#include <QStatusBar>
34#include <QStyle>
35#include <QTextCharFormat>
36#include <QToolBar>
37#include <QVBoxLayout>
38
39/**
40 * @brief Main application window for the MXMOD model viewer launcher.
41 *
42 * MainWindow does not render models directly. It collects model, texture,
43 * texture-directory, and resolution options from the user, resolves the
44 * command-line viewer executable, launches it as a QProcess, and streams
45 * process output into the in-app console.
46 */
47class MainWindow : public QMainWindow {
48 Q_OBJECT
49
50 public:
51 /**
52 * @brief Constructs the launcher window and restores persisted settings.
53 * @param parent Optional Qt parent widget.
54 */
55 explicit MainWindow(QWidget *parent = nullptr);
56
57 /**
58 * @brief Persists settings and stops any running renderer process.
59 */
60 ~MainWindow() override;
61
62 private slots:
63 /**
64 * @brief Opens a file picker for supported model files.
65 */
66 void browseModelFile();
67
68 /**
69 * @brief Opens a file picker for a texture file or material manifest.
70 */
71 void browseTextureFile();
72
73 /**
74 * @brief Opens a directory picker for external texture resources.
75 */
76 void browseTextureDirectory();
77
78 /**
79 * @brief Validates the selected inputs and launches the viewer process.
80 */
81 void openModelViewer();
82
83 /**
84 * @brief Requests termination of the active viewer process.
85 */
86 void stopProcess();
87
88 /**
89 * @brief Clears the process console and updates the status bar.
90 */
91 void clearConsole();
92
93 /**
94 * @brief Loads a model path selected from the recent-files combo box.
95 * @param index Combo-box index of the selected recent model entry.
96 */
97 void openRecentModel(int index);
98
99 /**
100 * @brief Shows application version and feature information.
101 */
102 void showAboutDialog();
103
104 /**
105 * @brief Shows the settings dialog for renderer executable and history options.
106 */
107 void showSettingsDialog();
108
109 /**
110 * @brief Restores persisted model, texture, executable, and window settings.
111 */
112 void loadSettings();
113
114 /**
115 * @brief Persists the current model, texture, executable, and window settings.
116 */
117 void saveSettings();
118
119 /**
120 * @brief Adds a model path to the recent-files list.
121 * @param modelPath Absolute or relative model path to add.
122 */
123 void updateRecentFiles(const QString &modelPath);
124
125 /**
126 * @brief Removes the currently selected recent model from history.
127 */
128 void removeRecentFile();
129
130 private:
131 /**
132 * @brief Initializes the top-level window and all child UI sections.
133 */
134 void initWindow();
135
136 /**
137 * @brief Builds the application menus and persistent menu actions.
138 */
139 void setupMenuBar();
140
141 /**
142 * @brief Builds the main toolbar and action buttons.
143 */
144 void setupToolBar();
145
146 /**
147 * @brief Builds file selectors, viewer options, and console widgets.
148 */
149 void setupCentralWidget();
150
151 /**
152 * @brief Creates status-bar widgets.
153 */
154 void setupStatusBar();
155
156 /**
157 * @brief Connects long-lived actions and widgets to their slots.
158 */
159 void createConnections();
160
161 /**
162 * @brief Enables or disables controls according to process state.
163 * @param processRunning True while the renderer child process is active.
164 */
165 void updateUIState(bool processRunning);
166
167 /**
168 * @brief Revalidates selected paths and updates launch-button availability.
169 */
170 void validatePaths();
171
172 /**
173 * @brief Restores recent model entries from settings into the combo box.
174 */
175 void loadRecentFiles();
176
177 /**
178 * @brief Populates the fixed list of renderer resolution presets.
179 */
180 void populateResolutionCombo();
181
182 /**
183 * @brief Resolves the viewer executable from settings, app-relative paths, or PATH.
184 * @return Executable path or command name passed to QProcess.
185 */
186 QString resolveExecutablePath() const;
187
188 protected:
189 /**
190 * @brief Confirms shutdown when the viewer process is still running.
191 * @param event Close event to accept or ignore.
192 */
193 void closeEvent(QCloseEvent *event) override;
194
195 /**
196 * @brief Accepts drag events that contain file or directory URLs.
197 * @param event Drag-enter event supplied by Qt.
198 */
199 void dragEnterEvent(QDragEnterEvent *event) override;
200
201 /**
202 * @brief Assigns dropped model, texture, or directory paths to the matching input.
203 * @param event Drop event supplied by Qt.
204 */
205 void dropEvent(QDropEvent *event) override;
206
207 private:
208 ///< Model file path input field.
209 QLineEdit *modelLineEdit;
210
211 ///< Texture file or material manifest path input field.
212 QLineEdit *textureLineEdit;
213
214 ///< Texture resource directory input field.
215 QLineEdit *textureDirLineEdit;
216
217 ///< Read-only console for renderer process output.
218 QPlainTextEdit *consoleOutput;
219
220 ///< Currently running renderer process, or nullptr when idle.
221 QProcess *activeProcess;
222
223 ///< Starts the renderer process with the selected options.
224 QPushButton *openButton;
225
226 ///< Stops the active renderer process.
227 QPushButton *stopButton;
228
229 ///< Clears the process console.
230 QPushButton *clearButton;
231
232 ///< Resolution preset selector passed to the renderer with -r.
233 QComboBox *resolutionCombo;
234
235 ///< Recent model selector populated from persisted settings.
236 QComboBox *recentFilesCombo;
237
238 ///< File menu action for choosing a model.
239 QAction *openModelAction;
240
241 ///< File menu action for choosing a texture file.
242 QAction *openTextureAction;
243
244 ///< File menu action for choosing a texture directory.
245 QAction *openTextureDirAction;
246
247 ///< File menu action for clearing console output.
248 QAction *clearConsoleAction;
249
250 ///< File menu action for closing the application.
251 QAction *exitAction;
252
253 ///< Help menu action for the about dialog.
254 QAction *aboutAction;
255
256 ///< Help menu action for viewer executable settings.
257 QAction *settingsAction;
258
259 ///< Status-bar text label.
260 QLabel *statusLabel;
261
262 ///< Persistent Qt settings store for this launcher.
263 QSettings *settings;
264
265 ///< User-configured renderer executable path, or empty for auto-detection.
266 QString executablePath;
267
268 ///< Persisted model history, newest first.
269 QStringList recentModels;
270
271 ///< Maximum number of recent model paths retained in settings.
272 static constexpr int MAX_RECENT_FILES = 10;
273};
274
275#endif
void closeEvent(QCloseEvent *event) override
Confirms shutdown when the viewer process is still running.
~MainWindow() override
Persists settings and stops any running renderer process.
void dragEnterEvent(QDragEnterEvent *event) override
Accepts drag events that contain file or directory URLs.
MainWindow(QWidget *parent=nullptr)
Constructs the launcher window and restores persisted settings.
void dropEvent(QDropEvent *event) override
Assigns dropped model, texture, or directory paths to the matching input.