22 #include <emscripten/emscripten.h>
29#include <QApplication>
31#include <QContextMenuEvent>
39#include <QResizeEvent>
67using namespace SILICON::core;
79 for (
const auto& dock :
docks) {
85 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPointF(), QPointF(),
86 Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
87 QApplication::sendEvent(
toolBar, &releaseEvent);
102 const auto centralWidget =
new QWidget();
103 setCentralWidget(centralWidget);
105 const auto layout =
new QHBoxLayout();
106 layout->setContentsMargins(5, 5, 5, 5);
107 centralWidget->setLayout(layout);
111 logDock =
new QDockWidget(
this);
118 addDockWidget(Qt::BottomDockWidgetArea,
logDock);
120 propertyDock->setFeatures(QDockWidget::DockWidgetMovable);
121 documentDock->setFeatures(QDockWidget::DockWidgetMovable);
122 logDock->setFeatures(QDockWidget::DockWidgetMovable);
123 logDock->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
127 logDock->setWindowTitle(
"Logs");
135 [
this] { updateStatus(); });
145 undoStack = std::make_unique<QUndoStack>(
this);
158 refreshActiveDocumentUi();
161 [
this] { refreshProjectUi(); });
168 [
this] { refreshProjectUi(); });
171 [
this] { documentController->rebuildTree(); });
176 [
this] { selectionChanged(); });
185 const auto zoomToolBar =
new QToolBar(
this);
186 zoomToolBar->setFloatable(
false);
187 zoomToolBar->setMovable(
false);
188 zoomToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
189 const auto zoomOutAct = zoomToolBar->addAction(
Icon(
"minus"), tr(
"Zoom Out"));
190 const auto zoomInAct = zoomToolBar->addAction(
Icon(
"plus"), tr(
"Zoom In"));
191 callbacks.connect(zoomOutAct, &QAction::triggered,
192 [
this] {
workspace->zoomActiveDocument(
false); });
193 callbacks.connect(zoomInAct, &QAction::triggered,
194 [
this] {
workspace->zoomActiveDocument(
true); });
195 statusBar()->addPermanentWidget(zoomToolBar);
210 resizeDocks({
logDock}, {180}, Qt::Vertical);
212 setWindowTitle(tr(
"SILICON"));
213 setMinimumSize(160, 160);
219 uiLog.info(
"Qt logging sideview initialized");
229 [
this] { fileController->save(); });
231 [
this] { exportImage(); });
235 callbacks.connect(
actionSet->project.about, &QAction::triggered, [
this] { about(); });
255 addAction(
actionSet->circuit.setComponentPlacingMode);
256 addAction(
actionSet->circuit.cancelInteraction);
264#ifndef QT_NO_CONTEXTMENU
267 #ifdef __EMSCRIPTEN__
268 auto* menu =
new QMenu(
this);
269 menu->setAttribute(Qt::WA_DeleteOnClose);
273 menu->addAction(
actionSet->circuit.rotate);
275 menu->popup(event->globalPos());
281 menu.addAction(
actionSet->circuit.rotate);
283 menu.exec(event->globalPos());
291 if (watched ==
viewportFilter.target() && event->type() == QEvent::Resize) {
295 return QMainWindow::eventFilter(watched, event);
300 QMainWindow::resizeEvent(event);
303 const int currentWidth =
event->size().width();
304 const int currentHeight =
event->size().height();
306 const int minWidth = std::min(288, currentWidth / 4);
307 const int maxWidth = currentWidth / 2;
309 const int minHeight = currentHeight / 3;
311 auto configureSizeConstraints = [minWidth, maxWidth, minHeight](QDockWidget* widget) {
312 widget->setMinimumWidth(minWidth);
313 widget->setMaximumWidth(maxWidth);
314 widget->setMinimumHeight(minHeight);
321 logDock->setMaximumWidth(QWIDGETSIZE_MAX);
322 logDock->setMinimumHeight(120);
323 logDock->setMaximumHeight(std::max(160, currentHeight / 3));
331 closeAfterSaveConfirmation = true;
338 QMainWindow::closeEvent(event);
356 actionSet->updateSubcircuitShapeAction();
385 if (
const auto selection =
405 item->setSelected(
true);
411 auto* menu =
new QMenu(
this);
412 menu->setAttribute(Qt::WA_DeleteOnClose);
414 QMenu stackMenu(
this);
415 auto* menu = &stackMenu;
418 auto* newMenu = menu->addMenu(
Icon(
"file"), tr(
"New"));
419 newMenu->addAction(
actionSet->documents.newCircuit);
420 newMenu->addAction(
actionSet->documents.newCodeFile);
421 newMenu->addAction(
actionSet->documents.newArchitecture);
422 newMenu->addAction(
actionSet->documents.newBinaryFile);
424 menu->addSeparator();
428 if (
const auto selection =
projectTree->selectedDocument()) {
433 menu->addSeparator();
436 architecture ? tr(
"Rename ISA Architecture...") : tr(
"Rename Document..."),
438 auto* deleteAction = menu->addAction(
440 architecture ? tr(
"Delete ISA Architecture")
443 const auto circuitCount = std::ranges::count_if(
445 [](
const auto& document) {
446 return document.getType() == SILICON::project::DocumentType::Circuit;
449 || circuitCount > 1);
453 menu->popup(
projectTree->viewport()->mapToGlobal(position));
455 menu->exec(
projectTree->viewport()->mapToGlobal(position));
void modeChanged(InteractionMode mode)
Emitted when the interaction mode changes.
void logsClearRequested()
void lineReceived(QString line)
void appendLine(const QString &line)
void exportSelectedDocument()
void renameSelectedDocument()
void importProjectDocument()
void createArchitecture()
void projectDocumentsChanged()
Emitted when the set of project documents was added to, changed, or removed.
void activeDocumentChanged(const QString &path, SILICON::project::DocumentCategory category)
Emitted after a document was loaded and made visible.
void deleteSelectedDocument()
void convertActiveDocument()
Project document navigator used by the SILICON editor.
static ProjectTreeItemKind itemKind(const QTreeWidgetItem *item)
void updateStatus() const
Refreshes the status bar text for the current scene mode.
void updateComponentCatalogGeometry()
Repositions and resizes the component catalog overlay.
void refreshProjectUi()
Refreshes the property dock after a project-level change.
ProjectSession projectSession
SiliconWindow()
Constructs and initializes the SILICON editor window.
AboutDialog * aboutDialog
std::unique_ptr< EditorWorkspace > workspace
void contextMenuEvent(QContextMenuEvent *event) override
Opens the diagram context menu for mode and editing actions.
CircuitEditor * circuitEditor
QDockWidget * propertyDock
Dock containing the current property editor.
std::unique_ptr< ProjectFileController > fileController
bool closeAfterSaveConfirmation
Allows the close event triggered after an accepted dirty-file prompt.
void initializeProjectTree()
Creates and wires the project tree widget shown in the project dock.
void closeEvent(QCloseEvent *event) override
void about() const
Shows the application about dialog.
bool eventFilter(QObject *watched, QEvent *event) override
Handles viewport events needed by floating child widgets.
std::unique_ptr< WindowLifetime > windowLifetime
QDockWidget * logDock
Dock containing application log output.
void projectTreeSelectionChanged()
Handles user selection changes in the project circuit tree.
void showProjectTreeContextMenu(const QPoint &position)
Shows the context menu for project-tree circuit actions.
void resizeEvent(QResizeEvent *event) override
Keeps floating overlays aligned when the main window is resized.
ComponentCatalogOverlay * componentCatalogOverlay
ProjectTree * projectTree
Borrowed handles into the workspace and Qt widget hierarchy.
std::unique_ptr< ProjectDocumentController > documentController
std::unique_ptr< WindowActions > actionSet
std::unique_ptr< PropertyPanel > propertyPanel
ScopedEventFilter viewportFilter
std::unique_ptr< DiagramInteractionController > interactionController
std::unique_ptr< WaveformController > waveformController
QDockWidget * documentDock
Dock containing the project document tree.
std::unique_ptr< QUndoStack > undoStack
LogSideView * logSideView
void updatePropertyDock()
Rebuilds the property dock for the current selection or active circuit.
~SiliconWindow() override
Releases scoped callbacks and UI owners in dependency order.
void refreshActiveDocumentUi()
Refreshes actions and docks that depend on the active document.
std::unique_ptr< ArchitectureController > architectureController
std::unique_ptr< GraphicalLogStream > graphicalLogStream
WindowLifetime(QMainWindow &window)
QPointer< QDockWidget > docks[3]
QPointer< QToolBar > toolBar
const SILICON::logging::Logger uiLog("ui")
QString documentTypeName(SILICON::project::DocumentType type)