SILICON
Loading...
Searching...
No Matches
editorWorkspace.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 */
9#pragma once
10
11#include <memory>
12
13#include <QWidget>
14
16#include <ui/lifetime.hpp>
17
18class QStackedWidget;
19class QUndoStack;
20
21namespace SILICON::ui {
24class CircuitEditor;
26class DocumentEditor;
27struct EditorEditState;
30struct ProjectSession;
31
39class EditorWorkspace : public QWidget {
40 Q_OBJECT
41public:
42 class PreparedDocument;
43
44 explicit EditorWorkspace(ProjectSession& session, QWidget* parent = nullptr);
45 ~EditorWorkspace() override;
46
48 [[nodiscard]] DocumentEditor* activeEditor() const noexcept
49 {
51 }
52 [[nodiscard]] bool hasUnsavedChanges() const;
53
60 void setProjectHistory(QUndoStack* history) noexcept;
61
63 [[nodiscard]] EditorEditState activeEditState() const;
64
65 [[nodiscard]] bool canUndoActiveDocument() const;
66 [[nodiscard]] bool canRedoActiveDocument() const;
67 void resetEditorDirtyState() noexcept;
68 void reset();
69 void undoActiveDocument();
70 void redoActiveDocument();
72 void copyActiveDocument();
73 void cutActiveDocument();
76 void zoomActiveDocument(bool in);
77 [[nodiscard]] std::shared_ptr<PreparedDocument>
78 prepareDocument(const SILICON::project::Document& document);
79 void activateDocument(const PreparedDocument& prepared);
80 void loadDocument(const SILICON::project::Document& document);
81
82signals:
84
93
102
104
105private:
106 [[nodiscard]] DocumentEditor& editorFor(SILICON::project::DocumentType type);
110 [[nodiscard]] EditorNotifications notifications();
111
113 QStackedWidget* stack;
115 QUndoStack* projectHistory = nullptr;
116 std::unique_ptr<CircuitEditor> circuit;
117 std::unique_ptr<CodeDocumentEditor> code;
118 std::unique_ptr<BinaryDocumentEditor> binary;
121};
122} // namespace SILICON::ui
void setProjectHistory(QUndoStack *history) noexcept
Applies the project-wide history shared by every hosted editor.
std::unique_ptr< BinaryDocumentEditor > binary
std::unique_ptr< ArchitectureDocumentEditor > architecture
DocumentEditor & editorFor(SILICON::project::DocumentType type)
void activateDocument(const PreparedDocument &prepared)
std::unique_ptr< CodeDocumentEditor > code
ArchitectureDocumentEditor & ensureArchitectureEditor()
void editorCreated(DocumentEditor *editor)
EditorNotifications notifications()
void editStateChanged()
Emitted when the active editor's editing availability may have changed.
std::unique_ptr< CircuitEditor > circuit
std::shared_ptr< PreparedDocument > prepareDocument(const SILICON::project::Document &document)
CodeDocumentEditor & ensureCodeEditor()
DocumentEditor * activeEditor() const noexcept
void historyStateChanged()
Emitted when the active editor's undo/redo availability may have changed.
EditorWorkspace(ProjectSession &session, QWidget *parent=nullptr)
void loadDocument(const SILICON::project::Document &document)
EditorEditState activeEditState() const
Which generic editing commands the active editor currently accepts.
BinaryDocumentEditor & ensureBinaryEditor()