wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
MainWindow.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <functional>
11#include <memory>
12#include <optional>
13
14#include <QDir>
15#include <QMainWindow>
16#include <QPointer>
17
20#include "App/UI/MainWindowUI.h"
21
22class ElementPalette;
23class ExerciseEngine;
24class ExerciseOverlay;
26class ICController;
27class ICPreviewPopup;
28class LanguageManager;
29class BewavedDolphin;
30class RecentFiles;
31class SceneUiBinder;
32class TourEngine;
33class TourOverlay;
34class WorkSpace;
36
45class MainWindow : public QMainWindow, public DolphinHost, public MainWindowHost
46{
47 Q_OBJECT
48 friend class TestMainWindowGui;
49
50public:
51 // --- Lifecycle ---
52
58 explicit MainWindow(const QString &fileName = {}, QWidget *parent = nullptr);
59 ~MainWindow() override;
60
62 void show();
63
64 // --- Tab Management ---
65
67 void createNewTab();
68
70 WorkSpace *currentTab() const override;
71
72 // --- File Operations ---
73
78 void save(const QString &fileName = {}) override;
79
84 void loadPandaFile(const QString &fileName);
85
87 void openICInTab(const QString &blobName, int icElementId, const QByteArray &blob);
88
90 QFileInfo currentFile() const override;
91
93 bool hasModifiedFiles();
94
96 QDir currentDir() const override;
97
99 QWidget *widget() override;
100
102 DolphinHost *dolphinHost() override;
103
105 ElementPalette *palette() const override;
106
108 void showStatusMessage(const QString &message, int timeout) override;
109
111 void requestSave() override;
112
114 void setICButtonsVisible(bool visible) override;
115
117 void refreshICButtonsEnabled() override;
118
119 // --- Help ---
120
125 QString shortcutsHelpHtml() const;
126
127 // --- Export ---
128
133 void exportToArduino(QString fileName);
134
139 void exportToSystemVerilog(QString fileName);
140
145 void exportToWaveFormFile(const QString &fileName);
146
149
150 // --- BeWavedDolphin Integration ---
151
153 QString dolphinFileName() override;
154
159 void setDolphinFileName(const QString &fileName) override;
160
161 // --- Translation ---
162
167 void loadTranslation(const QString &language);
168
171
172 // --- View / Rendering ---
173
175 void retranslateUi();
176
181 void setFastMode(const bool fastMode);
182
183 // --- Qt Event Override ---
184
186 bool event(QEvent *event) override;
187
188protected:
189 // --- Protected Interface ---
190
192 void closeEvent(QCloseEvent *event) override;
193
194private:
195 Q_DISABLE_COPY(MainWindow)
196
197 // --- Tab Lifecycle ---
198
199
200 void onCurrentTabChanged(WorkSpace *newTab);
201
204 void updateWindowTitle();
205
207 QFileInfo icListFile() const override;
208
210 void connectSceneAction(QAction *action, void (Scene::*method)());
211
212 // --- File Helpers ---
213
214 void createRecentFileActions();
215 void updateRecentFileActions();
216 void openRecentFile();
217
218 // --- Settings & Theme ---
219
220 void updateSettings();
221 void updateTheme();
222 void aboutThisVersion();
223
224 // --- Action Handlers ---
225
226 void startExercise(const QString &resourcePath);
227 void startTour(const QString &resourcePath);
228 QRect resolveTourTarget(const QString &id) const;
229
230 void clickTarget(const QString &id);
231
232 static void on_actionDarkTheme_triggered();
233 static void on_actionLightTheme_triggered();
234 static void on_actionSystemTheme_triggered();
235 void on_actionAboutQt_triggered();
236 void on_actionAbout_triggered();
237 void on_actionExit_triggered();
238 void on_actionFastMode_triggered(const bool checked);
239 void on_actionFlipHorizontally_triggered();
240 void on_actionFlipVertically_triggered();
241 void on_actionAlignLeft_triggered();
242 void on_actionAlignRight_triggered();
243 void on_actionAlignTop_triggered();
244 void on_actionAlignBottom_triggered();
245 void on_actionAlignHorizontalCenter_triggered();
246 void on_actionAlignVerticalCenter_triggered();
247 void on_actionDistributeHorizontally_triggered();
248 void on_actionDistributeVertically_triggered();
249 void on_actionFullscreen_triggered();
250 void on_actionGates_triggered(const bool checked);
251 void on_actionLabelsUnderIcons_triggered(const bool checked);
252 void on_actionICPreview_triggered(const bool checked);
253 void on_actionCheckForUpdates_triggered(const bool checked);
254 void on_actionMute_triggered(const bool checked);
255 void on_actionPlay_toggled(const bool checked);
256 void on_actionReportTranslationError_triggered();
257 void on_actionResetZoom_triggered() const;
258 void on_actionZoomToFit_triggered() const;
259 void on_actionRestart_triggered();
260 void on_actionRotateLeft_triggered();
261 void on_actionRotateRight_triggered();
262 void on_actionSelectAll_triggered();
263 void on_actionShortcuts_and_Tips_triggered();
264 void on_actionShowMinimap_triggered(const bool checked);
265 void on_actionWaveform_triggered();
266 void on_actionWires_triggered(const bool checked);
267 void on_actionZoomIn_triggered() const;
268 void on_actionZoomOut_triggered() const;
269
270#ifdef Q_OS_WASM
272 static const char *onBeforeUnload(int eventType, const void *reserved, void *userData);
273#endif
274
275 // --- Constructor Setup ---
276
278 void setupLanguage();
280 void setupGeometry();
282 void setupTheme();
284 void setupRecentFiles();
286 void setupExamplesMenu();
288 void setupExercisesMenu();
290 void setupToursMenu();
293 void populateContentMenu(QMenu *menu, const QString &categoryKey,
294 const QString &openFolderText, const QString &openFolderFailureText,
295 const QStringList &completed, const std::function<void(const QString &)> &onSelect);
297 void setupShortcuts();
299 void setupConnections();
300
301 // --- Members ---
302
303 std::unique_ptr<MainWindowUi> m_ui;
304
312 static inline std::optional<QString> s_testSystemLocaleNameOverride;
313
317 std::function<QString(const QString &)> m_preferredContentDirForTesting;
318
319 ElementPalette *m_palette = nullptr;
320 LanguageManager *m_languageManager = nullptr;
321 RecentFiles *m_recentFiles = nullptr;
322 ExportController *m_exportController = nullptr;
323 ICController *m_icController = nullptr;
324 SceneUiBinder *m_binder = nullptr;
325 WorkspaceManager *m_workspaceManager = nullptr;
326
327 ExerciseEngine *m_exerciseEngine = nullptr;
328 ExerciseOverlay *m_exerciseOverlay = nullptr;
329
330 TourEngine *m_tourEngine = nullptr;
333 QPointer<TourOverlay> m_tourOverlay;
334
335 QPointer<BewavedDolphin> m_bwd;
339 QMetaObject::Connection m_bwdDestroyed;
340
345 QPointer<WorkSpace> m_previousTab;
346
349 QPointer<ICPreviewPopup> m_icPreviewPopup;
350};
DolphinHost: the host-application context the beWavedDolphin editor depends on.
MainWindowHost: the application context that MainWindow's extracted controllers depend on.
MainWindowUi: hand-written UI class for the MainWindow.
Waveform editor main window for creating and analyzing digital signal sequences.
Interface the host application (MainWindow) provides to BewavedDolphin.
Definition DolphinHost.h:24
Controller for the left-panel element palette, IC list, and search tab.
Semi-transparent overlay displayed at the bottom of the canvas during a circuit exercise.
Owns the circuit-export workflow: Arduino / SystemVerilog code, PDF / PNG images, and beWavedDolphin ...
Owns the IC management workflow: importing file-based ICs into the project directory,...
Frameless tooltip-like widget showing a rendered preview of an IC's sub-circuit.
Owns the application QTranslator instances and provides language metadata.
Interface MainWindow provides to its extracted controllers (export, IC, …).
virtual QFileInfo icListFile() const =0
File info used to populate the file-based IC palette (parent workspace for inline IC tabs).
void closeEvent(QCloseEvent *event) override
void exportToSystemVerilog(QString fileName)
Generates SystemVerilog code for the current circuit.
QFileInfo currentFile() const override
Returns the QFileInfo of the currently active .panda file.
QWidget * widget() override
~MainWindow() override
void loadPandaFile(const QString &fileName)
Loads a .panda circuit file into the current or a new tab.
void retranslateUi()
Re-applies all translatable strings to the UI after a language change.
void setDolphinFileName(const QString &fileName) override
Associates fileName as the BeWavedDolphin file for the current tab.
ElementPalette * palette() const override
QString shortcutsHelpHtml() const
void createNewTab()
Creates a new empty circuit tab.
QDir currentDir() const override
Returns the directory of the currently active .panda file.
void save(const QString &fileName={}) override
Saves the current circuit to fileName (or prompts if empty).
friend class TestMainWindowGui
Definition MainWindow.h:48
void exportToArduino(QString fileName)
Generates Arduino sketch code for the current circuit.
QString dolphinFileName() override
Returns the BeWavedDolphin file name associated with the current tab.
WorkSpace * currentTab() const override
Returns the currently visible WorkSpace tab, or nullptr.
void populateLanguageMenu()
Populates the Language submenu with available translations.
void showStatusMessage(const QString &message, int timeout) override
void setFastMode(const bool fastMode)
Enables or disables fast (non-antialiased) rendering for all views.
void requestSave() override
void openICInTab(const QString &blobName, int icElementId, const QByteArray &blob)
Opens an embedded IC blob for editing in a new tab.
MainWindow(const QString &fileName={}, QWidget *parent=nullptr)
Constructs the MainWindow and optionally opens fileName on start.
void refreshICButtonsEnabled() override
void loadTranslation(const QString &language)
Loads and installs the Qt translation for language.
void exportToWaveFormTerminal()
Exports the current waveform simulation to standard output (terminal).
bool event(QEvent *event) override
bool hasModifiedFiles()
Returns true if any open workspace has unsaved changes or is a recovered autosave.
void exportToWaveFormFile(const QString &fileName)
Saves the BeWavedDolphin waveform session to fileName.
void show()
Shows the window and initializes child widget state.
DolphinHost * dolphinHost() override
void setICButtonsVisible(bool visible) override
Manages the list of recently opened .panda files.
Definition RecentFiles.h:22
Binds and unbinds the active WorkSpace's scene to the single-instance editor chrome (element editor,...
A widget containing a complete circuit editing environment.
Definition Workspace.h:33
Owns the document/tab model: the current tab, tab creation/closing/switching, and the file open/save/...