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
13#include <QDir>
14#include <QMainWindow>
15#include <QPointer>
16#include <QSpacerItem>
17
20#include "App/UI/MainWindowUI.h"
21
22class ElementLabel;
23class ElementPalette;
24class ExerciseEngine;
25class ExerciseOverlay;
27class ICController;
28class ICPreviewPopup;
29class LanguageManager;
30class BewavedDolphin;
31class RecentFiles;
32class SceneUiBinder;
33class TourEngine;
34class TourOverlay;
35class WorkSpace;
37
46class MainWindow : public QMainWindow, public DolphinHost, public MainWindowHost
47{
48 Q_OBJECT
49 friend class TestMainWindowGui;
50
51public:
52 // --- Lifecycle ---
53
59 explicit MainWindow(const QString &fileName = {}, QWidget *parent = nullptr);
60 ~MainWindow() override;
61
63 void show();
64
65 // --- Tab Management ---
66
68 void createNewTab();
69
71 WorkSpace *currentTab() const override;
72
73 // --- File Operations ---
74
79 void save(const QString &fileName = {}) override;
80
85 void loadPandaFile(const QString &fileName);
86
88 void openICInTab(const QString &blobName, int icElementId, const QByteArray &blob);
89
91 QFileInfo currentFile() const override;
92
94 bool hasModifiedFiles();
95
97 QDir currentDir() const override;
98
100 QWidget *widget() override;
101
103 DolphinHost *dolphinHost() override;
104
106 ElementPalette *palette() const override;
107
109 void showStatusMessage(const QString &message, int timeout) override;
110
112 void requestSave() override;
113
115 void setICButtonsVisible(bool visible) override;
116
118 void refreshICButtonsEnabled() override;
119
120 // --- Help ---
121
126 QString shortcutsHelpHtml() const;
127
128 // --- Export ---
129
134 void exportToArduino(QString fileName);
135
140 void exportToSystemVerilog(QString fileName);
141
146 void exportToWaveFormFile(const QString &fileName);
147
150
151 // --- BeWavedDolphin Integration ---
152
154 QString dolphinFileName() override;
155
160 void setDolphinFileName(const QString &fileName) override;
161
162 // --- Translation ---
163
168 void loadTranslation(const QString &language);
169
172
173 // --- Palette ---
174
181 void populateMenu(QSpacerItem *spacer, const QStringList &names, QLayout *layout);
182
183 // --- View / Rendering ---
184
186 void retranslateUi();
187
192 void setFastMode(const bool fastMode);
193
194 // --- Qt Event Override ---
195
197 bool event(QEvent *event) override;
198
199protected:
200 // --- Protected Interface ---
201
203 void closeEvent(QCloseEvent *event) override;
204
205private:
206 Q_DISABLE_COPY(MainWindow)
207
208 // --- Tab Lifecycle ---
209
210
211 void onCurrentTabChanged(WorkSpace *newTab);
212
215 void updateWindowTitle();
216
218 QFileInfo icListFile() const override;
219
221 void connectSceneAction(QAction *action, void (Scene::*method)());
222
223 // --- File Helpers ---
224
225 void createRecentFileActions();
226 void updateRecentFileActions();
227 void openRecentFile();
228
229 // --- Settings & Theme ---
230
231 void updateSettings();
232 void updateTheme();
233 void aboutThisVersion();
234
235 // --- Action Handlers ---
236
237 void startExercise(const QString &resourcePath);
238 void startTour(const QString &resourcePath);
239 QRect resolveTourTarget(const QString &id) const;
240
241 void clickTarget(const QString &id);
242
243 static void on_actionDarkTheme_triggered();
244 static void on_actionLightTheme_triggered();
245 static void on_actionSystemTheme_triggered();
246 void on_actionAboutQt_triggered();
247 void on_actionAbout_triggered();
248 void on_actionExit_triggered();
249 void on_actionFastMode_triggered(const bool checked);
250 void on_actionFlipHorizontally_triggered();
251 void on_actionFlipVertically_triggered();
252 void on_actionAlignLeft_triggered();
253 void on_actionAlignRight_triggered();
254 void on_actionAlignTop_triggered();
255 void on_actionAlignBottom_triggered();
256 void on_actionAlignHorizontalCenter_triggered();
257 void on_actionAlignVerticalCenter_triggered();
258 void on_actionDistributeHorizontally_triggered();
259 void on_actionDistributeVertically_triggered();
260 void on_actionFullscreen_triggered();
261 void on_actionGates_triggered(const bool checked);
262 void on_actionLabelsUnderIcons_triggered(const bool checked);
263 void on_actionICPreview_triggered(const bool checked);
264 void on_actionCheckForUpdates_triggered(const bool checked);
265 void on_actionMute_triggered(const bool checked);
266 void on_actionPlay_toggled(const bool checked);
267 void on_actionReportTranslationError_triggered();
268 void on_actionResetZoom_triggered() const;
269 void on_actionZoomToFit_triggered() const;
270 void on_actionRestart_triggered();
271 void on_actionRotateLeft_triggered();
272 void on_actionRotateRight_triggered();
273 void on_actionSelectAll_triggered();
274 void on_actionShortcuts_and_Tips_triggered();
275 void on_actionShowMinimap_triggered(const bool checked);
276 void on_actionWaveform_triggered();
277 void on_actionWires_triggered(const bool checked);
278 void on_actionZoomIn_triggered() const;
279 void on_actionZoomOut_triggered() const;
280
281#ifdef Q_OS_WASM
283 static const char *onBeforeUnload(int eventType, const void *reserved, void *userData);
284#endif
285
286 // --- Constructor Setup ---
287
289 void setupLanguage();
291 void setupGeometry();
293 void setupTheme();
295 void setupRecentFiles();
297 void setupExamplesMenu();
299 void setupExercisesMenu();
301 void setupToursMenu();
304 void populateContentMenu(QMenu *menu, const QString &categoryKey,
305 const QString &openFolderText, const QString &openFolderFailureText,
306 const QStringList &completed, const std::function<void(const QString &)> &onSelect);
308 void setupShortcuts();
310 void setupConnections();
311
312 // --- Members ---
313
314 std::unique_ptr<MainWindowUi> m_ui;
315
316 ElementPalette *m_palette = nullptr;
317 LanguageManager *m_languageManager = nullptr;
318 RecentFiles *m_recentFiles = nullptr;
319 ExportController *m_exportController = nullptr;
320 ICController *m_icController = nullptr;
321 SceneUiBinder *m_binder = nullptr;
322 WorkspaceManager *m_workspaceManager = nullptr;
323
324 ExerciseEngine *m_exerciseEngine = nullptr;
325 ExerciseOverlay *m_exerciseOverlay = nullptr;
326
327 TourEngine *m_tourEngine = nullptr;
330 QPointer<TourOverlay> m_tourOverlay;
331
332 QPointer<BewavedDolphin> m_bwd;
333
338 QPointer<WorkSpace> m_previousTab;
339
342 QPointer<ICPreviewPopup> m_icPreviewPopup;
343};
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
Icon and name widget shown in the left-panel element palette.
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:49
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 populateMenu(QSpacerItem *spacer, const QStringList &names, QLayout *layout)
Fills layout with ElementLabel buttons from names, preceded by spacer.
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/...