SILICON
Loading...
Searching...
No Matches
documentEditor.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
10#pragma once
11
12#include <functional>
13#include <memory>
14#include <string>
15
17
18class QWidget;
19class QUndoStack;
20
21namespace SILICON::ui {
22
25 virtual ~PreparedEditorDocument() = default;
26};
27
31 std::function<void()> historyChanged;
33 std::function<void()> editStateChanged;
34};
35
38 bool canCut = false;
39 bool canCopy = false;
40 bool canPaste = false;
41 bool canDelete = false;
42 bool canRotate = false;
43};
44
47public:
48 virtual ~DocumentEditor() = default;
49 [[nodiscard]] virtual QWidget* widget() const noexcept = 0;
50 [[nodiscard]] virtual std::shared_ptr<PreparedEditorDocument>
51 prepare(const SILICON::project::Document& document) = 0;
52 virtual void apply(const PreparedEditorDocument& prepared) = 0;
53 virtual void flush(const std::string& path) = 0;
54 [[nodiscard]] virtual bool isDirty() const = 0;
55 virtual void resetDirtyState() noexcept = 0;
56 virtual void reset() = 0;
57 virtual void undo() = 0;
58 virtual void redo() = 0;
59 [[nodiscard]] virtual bool canUndo() const = 0;
60 [[nodiscard]] virtual bool canRedo() const = 0;
61 virtual void copy() {}
62 virtual void cut() {}
63 virtual void paste() {}
64 virtual void deleteSelection() {}
66 virtual void zoom(bool in) = 0;
67
74 [[nodiscard]] virtual EditorEditState editState() const { return {}; }
75 void setProjectHistory(QUndoStack* history) noexcept { projectHistory = history; }
76
77protected:
78 QUndoStack* projectHistory = nullptr;
79};
80
81} // namespace SILICON::ui
void setProjectHistory(QUndoStack *history) noexcept
virtual void resetDirtyState() noexcept=0
virtual std::shared_ptr< PreparedEditorDocument > prepare(const SILICON::project::Document &document)=0
virtual void zoom(bool in)=0
Zooms the document in (true) or out (false) by one step.
virtual bool isDirty() const =0
virtual bool canRedo() const =0
virtual QWidget * widget() const noexcept=0
virtual ~DocumentEditor()=default
virtual void flush(const std::string &path)=0
virtual bool canUndo() const =0
virtual void apply(const PreparedEditorDocument &prepared)=0
virtual EditorEditState editState() const
Reports which generic editing commands the editor currently accepts.
std::function< void()> historyChanged
The undo/redo availability of the hosted editor may have changed.
std::function< void()> editStateChanged
The generic editing availability of the hosted editor may have changed.
virtual ~PreparedEditorDocument()=default