ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
editor.hpp
Go to the documentation of this file.
1#ifndef EDITOR_HPP
2#define EDITOR_HPP
3
4/**
5 * @file editor.hpp
6 * @brief Shader text editor widgets with line numbers and GLSL highlighting.
7 */
8
9#include "syntax.hpp"
10#include <QCloseEvent>
11#include <QDialog>
12#include <QHash>
13#include <QKeyEvent>
14#include <QLabel>
15#include <QMouseEvent>
16#include <QPaintEvent>
17#include <QPlainTextEdit>
18#include <QStatusBar>
19#include <QString>
20#include <QStringList>
21#include <QSyntaxHighlighter>
22#include <QVector>
23#include <QWidget>
24
25class LineNumberArea;
26class QAction;
27class QCompleter;
28class QMenu;
29class QCheckBox;
30class QDoubleSpinBox;
31class QSlider;
32class QScrollArea;
33class QTimer;
34class QVBoxLayout;
35class QStringListModel;
36
38
45
47 QString name;
48 int slot = -1;
49 double minimum = 0.0;
50 double maximum = 1.0;
51 double step = 0.01;
52 double value = 0.0;
53};
54
55/**
56 * @brief Add bounded iteration guards and preserve original GLSL diagnostic lines.
57 */
58QString inject_safety_counters(const QString &glsl_source);
59
60/**
61 * @brief Plain-text editor with line numbers and code-editing helpers.
62 */
63class CustomTextEdit : public QPlainTextEdit {
64 Q_OBJECT
65 public:
66 explicit CustomTextEdit(QWidget *parent = nullptr);
67
68 /// @brief Paint callback used by the line-number side widget.
69 void lineNumberAreaPaintEvent(QPaintEvent *event);
70 /// @brief Compute width required for current line-number digit count.
72 void updateLineNumberAreaWidth(int newBlockCount);
73 /// @brief Replace the line markers and underlines shown for compiler messages.
74 void setDiagnostics(const QVector<ShaderDiagnostic> &diagnostics);
75 /// @brief Replace the keywords offered by code completion.
76 void setCompletionWords(const QStringList &words);
77
78 signals:
80 void includeRequested(const QString &includeName);
81
82 protected:
83 void changeEvent(QEvent *event) override;
84 void keyPressEvent(QKeyEvent *event) override;
85 void mousePressEvent(QMouseEvent *event) override;
86 void resizeEvent(QResizeEvent *event) override;
87
88 private slots:
89 void updateLineNumberArea(const QRect &rect, int dy);
91 void matchBrackets();
92
93 public:
94 void indentSelection();
95 void unindentSelection();
96 void duplicateLine();
97 void moveLineUp();
98 void moveLineDown();
99 void toggleComment();
100
101 private:
102 void autoIndentNewLine();
103 void smartHome(bool shift);
105 QString completionPrefix() const;
106 void insertCompletion(const QString &completion);
107 void showCompletionPopup(bool forced);
108
110 QVector<ShaderDiagnostic> m_diagnostics;
111 QCompleter *m_completer = nullptr;
112 QStringListModel *m_completionModel = nullptr;
113};
114
115class LineNumberArea : public QWidget {
116 public:
117 explicit LineNumberArea(CustomTextEdit *editor) : QWidget(editor), m_editor(editor) {}
118
119 QSize sizeHint() const override { return QSize(m_editor->lineNumberAreaWidth(), 0); }
120
121 protected:
122 void paintEvent(QPaintEvent *event) override { m_editor->lineNumberAreaPaintEvent(event); }
123
124 private:
126};
127
128/**
129 * @brief Modal shader editor dialog used by ACMX2.
130 */
131class TextEditor : public QDialog {
132 Q_OBJECT
133
134 public:
135 explicit TextEditor(QWidget *parent = nullptr);
136 /// @brief Replace editor contents and reset displayed text.
137 void setText(const QString &text);
138 /// @brief Associate editor with a shader file path.
139 void setFileName(const QString &filename);
140 /// @brief Return the file currently associated with this editor.
141 QString fileName() const;
142 /// @brief Move to a one-based line and select the requested source match.
143 void revealLocation(int lineNumber, int columnNumber = 0, int matchLength = 0);
144 /// @brief Mark the associated shader as being compiled.
145 void setCompilePending();
146 /// @brief Show compiler status and source diagnostics for the associated shader.
147 void setCompileResult(bool success, const QString &compilerOutput);
148 /// @brief Configure ACMXVK completion and snippets from the active manifest.
149 void setShaderContext(bool acmxvk, const QVector<ShaderEditorUniform> &uniforms, const QString &libraryDirectory = QString());
150 void setUniformValue(const QString &name, double value);
151
152 signals:
153 /// @brief Emitted after the editor successfully writes its contents to disk.
154 void fileSaved(const QString &path);
155 void openFileRequested(const QString &path, int lineNumber);
156 void previewRequested(const QString &path, const QString &source);
157 void uniformValueChanged(const QString &name, double value);
158
159 protected:
160 void closeEvent(QCloseEvent *event) override;
161 void keyPressEvent(QKeyEvent *event) override;
162
163 private:
164 void init();
165 /// @brief Show a Save/Discard/Cancel prompt if the document is modified.
166 /// @return True if the editor may close, false to cancel the close.
167 bool maybePromptSave();
168 /// @brief Atomically write the document to disk.
169 /// @return True when the file was committed successfully.
170 bool writeFile(const QString &filePath);
171 void saveContents();
172 void saveAs();
173 void findText();
174 void findNext();
175 void findPrevious();
176 void replaceText();
177 void gotoLine();
178 void increaseFontSize();
179 void decreaseFontSize();
180 void resetFontSize();
181 void updateFontSize();
183 void updateWindowTitle();
184 void navigateDiagnostic(int offset);
185 QVector<ShaderDiagnostic> parseDiagnostics(const QString &compilerOutput) const;
188 void insertSnippet(const QString &snippet);
189 QString customUniformDefines() const;
190 void openInclude(const QString &includeName);
191 void requestPreview();
192 void revertContents();
194
195 bool m_modified = false;
198 QStatusBar *m_statusBar = nullptr;
199 QLabel *m_lineColLabel = nullptr;
200 QLabel *m_compileStatusLabel = nullptr;
201 QAction *m_nextDiagnosticAction = nullptr;
202 QAction *m_previousDiagnosticAction = nullptr;
203 QMenu *m_snippetsMenu = nullptr;
204 QWidget *m_uniformPanel = nullptr;
205 QScrollArea *m_uniformScroll = nullptr;
206 QVBoxLayout *m_uniformLayout = nullptr;
207 QCheckBox *m_livePreviewCheck = nullptr;
208 QCheckBox *m_loopSafetyCheck = nullptr;
209 QTimer *m_previewTimer = nullptr;
210 QHash<QString, QDoubleSpinBox *> m_uniformSpins;
211 QHash<QString, QSlider *> m_uniformSliders;
212 QVector<ShaderDiagnostic> m_diagnostics;
214 bool m_acmxvkContext = false;
215 QVector<ShaderEditorUniform> m_uniforms;
217 QString filename;
219 int m_fontSize = 24;
220};
221
222#endif
Plain-text editor with line numbers and code-editing helpers.
Definition editor.hpp:63
void matchBrackets()
Definition editor.cpp:366
void indentSelection()
Definition editor.cpp:459
LineNumberArea * m_lineNumberArea
Definition editor.hpp:109
CustomTextEdit(QWidget *parent=nullptr)
Definition editor.cpp:198
void moveLineDown()
Definition editor.cpp:593
void highlightCurrentLine()
Definition editor.cpp:346
bool hasMultiLineSelection()
Definition editor.cpp:450
int lineNumberAreaWidth()
Compute width required for current line-number digit count.
Definition editor.cpp:227
QVector< ShaderDiagnostic > m_diagnostics
Definition editor.hpp:110
void autoIndentNewLine()
Definition editor.cpp:512
void setCompletionWords(const QStringList &words)
Replace the keywords offered by code completion.
Definition editor.cpp:244
void setDiagnostics(const QVector< ShaderDiagnostic > &diagnostics)
Replace the line markers and underlines shown for compiler messages.
Definition editor.cpp:238
void insertCompletion(const QString &completion)
Definition editor.cpp:267
void lineNumberAreaPaintEvent(QPaintEvent *event)
Paint callback used by the line-number side widget.
Definition editor.cpp:313
void showCompletionPopup(bool forced)
Definition editor.cpp:278
void mousePressEvent(QMouseEvent *event) override
Definition editor.cpp:867
QString completionPrefix() const
Definition editor.cpp:251
void updateLineNumberAreaWidth(int newBlockCount)
Definition editor.cpp:295
void resizeEvent(QResizeEvent *event) override
Definition editor.cpp:307
void smartHome(bool shift)
Definition editor.cpp:665
QCompleter * m_completer
Definition editor.hpp:111
void unindentSelection()
Definition editor.cpp:480
void keyPressEvent(QKeyEvent *event) override
Definition editor.cpp:689
void themeChanged()
void duplicateLine()
Definition editor.cpp:557
QStringListModel * m_completionModel
Definition editor.hpp:112
void toggleComment()
Definition editor.cpp:616
void changeEvent(QEvent *event) override
Definition editor.cpp:217
void moveLineUp()
Definition editor.cpp:569
void includeRequested(const QString &includeName)
void updateLineNumberArea(const QRect &rect, int dy)
Definition editor.cpp:297
Rule-based GLSL syntax highlighter.
Definition syntax.hpp:19
CustomTextEdit * m_editor
Definition editor.hpp:125
void paintEvent(QPaintEvent *event) override
Definition editor.hpp:122
LineNumberArea(CustomTextEdit *editor)
Definition editor.hpp:117
QSize sizeHint() const override
Definition editor.hpp:119
TextEditor(QWidget *parent=nullptr)
Definition editor.cpp:887
QString m_lastSearchText
Definition editor.hpp:218
void updateFontSize()
Definition editor.cpp:1699
void updateCursorPosition()
Definition editor.cpp:1722
CustomTextEdit * m_textEdit
Definition editor.hpp:196
QHash< QString, QDoubleSpinBox * > m_uniformSpins
Definition editor.hpp:210
int m_currentDiagnostic
Definition editor.hpp:213
QHash< QString, QSlider * > m_uniformSliders
Definition editor.hpp:211
bool m_acmxvkContext
Definition editor.hpp:214
bool m_modified
Definition editor.hpp:195
QVector< ShaderEditorUniform > m_uniforms
Definition editor.hpp:215
void decreaseFontSize()
Definition editor.cpp:1685
QLabel * m_lineColLabel
Definition editor.hpp:199
void saveContents()
Definition editor.cpp:1525
QVector< ShaderDiagnostic > m_diagnostics
Definition editor.hpp:212
void setUniformValue(const QString &name, double value)
Definition editor.cpp:972
void updateWindowTitle()
Definition editor.cpp:1230
void increaseFontSize()
Definition editor.cpp:1677
void updateDiagnosticActions()
Definition editor.cpp:1224
QString filename
Definition editor.hpp:217
void setShaderContext(bool acmxvk, const QVector< ShaderEditorUniform > &uniforms, const QString &libraryDirectory=QString())
Configure ACMXVK completion and snippets from the active manifest.
Definition editor.cpp:961
void fileSaved(const QString &path)
Emitted after the editor successfully writes its contents to disk.
void updateCompletionWords()
Definition editor.cpp:1086
QVBoxLayout * m_uniformLayout
Definition editor.hpp:206
QStatusBar * m_statusBar
Definition editor.hpp:198
QWidget * m_uniformPanel
Definition editor.hpp:204
void previewRequested(const QString &path, const QString &source)
void revealLocation(int lineNumber, int columnNumber=0, int matchLength=0)
Move to a one-based line and select the requested source match.
Definition editor.cpp:904
void setCompilePending()
Mark the associated shader as being compiled.
Definition editor.cpp:922
void findNext()
Definition editor.cpp:1588
void uniformValueChanged(const QString &name, double value)
void insertSnippet(const QString &snippet)
Definition editor.cpp:1147
void init()
Definition editor.cpp:1241
void findText()
Definition editor.cpp:1575
void requestPreview()
Definition editor.cpp:1004
void replaceText()
Definition editor.cpp:1639
void keyPressEvent(QKeyEvent *event) override
Definition editor.cpp:1741
QString customUniformDefines() const
Definition editor.cpp:1136
void saveAs()
Definition editor.cpp:1563
GlslSyntaxHighlighter * m_highlighter
Definition editor.hpp:197
QTimer * m_previewTimer
Definition editor.hpp:209
bool writeFile(const QString &filePath)
Atomically write the document to disk.
Definition editor.cpp:1534
void openFileRequested(const QString &path, int lineNumber)
void openInclude(const QString &includeName)
Definition editor.cpp:991
void gotoLine()
Definition editor.cpp:1667
void setFileName(const QString &filename)
Associate editor with a shader file path.
Definition editor.cpp:897
QScrollArea * m_uniformScroll
Definition editor.hpp:205
QCheckBox * m_loopSafetyCheck
Definition editor.hpp:208
void resetFontSize()
Definition editor.cpp:1693
QCheckBox * m_livePreviewCheck
Definition editor.hpp:207
bool maybePromptSave()
Show a Save/Discard/Cancel prompt if the document is modified.
Definition editor.cpp:1753
void rebuildUniformControls()
Definition editor.cpp:1025
QVector< ShaderDiagnostic > parseDiagnostics(const QString &compilerOutput) const
Definition editor.cpp:1164
void setCompileResult(bool success, const QString &compilerOutput)
Show compiler status and source diagnostics for the associated shader.
Definition editor.cpp:932
QString fileName() const
Return the file currently associated with this editor.
Definition editor.cpp:902
QMenu * m_snippetsMenu
Definition editor.hpp:203
int m_fontSize
Definition editor.hpp:219
void navigateDiagnostic(int offset)
Definition editor.cpp:1212
void setText(const QString &text)
Replace editor contents and reset displayed text.
Definition editor.cpp:889
void closeEvent(QCloseEvent *event) override
Definition editor.cpp:1732
QAction * m_previousDiagnosticAction
Definition editor.hpp:202
QAction * m_nextDiagnosticAction
Definition editor.hpp:201
void revertContents()
Definition editor.cpp:1013
QString m_libraryDirectory
Definition editor.hpp:216
QLabel * m_compileStatusLabel
Definition editor.hpp:200
void findPrevious()
Definition editor.cpp:1614
QString inject_safety_counters(const QString &glsl_source)
Add bounded iteration guards and preserve original GLSL diagnostic lines.
Definition editor.cpp:107
ShaderDiagnosticSeverity
Definition editor.hpp:37
ShaderDiagnosticSeverity severity
Definition editor.hpp:42
QString message
Definition editor.hpp:43
GLSL syntax highlighter for the embedded text editor.