| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef CODEHELPER_H |
| 5 | #define CODEHELPER_H |
| 6 | |
| 7 | #include <QObject> |
| 8 | #include <QTimer> |
| 9 | #include <QtQuick/private/qquicktextedit_p_p.h> |
| 10 | #include "codecompletionmodel.h" |
| 11 | |
| 12 | class EffectManager; |
| 13 | |
| 14 | class CodeHelper : public QObject |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | Q_PROPERTY(CodeCompletionModel *codeCompletionModel READ codeCompletionModel NOTIFY codeCompletionModelChanged) |
| 18 | Q_PROPERTY(bool codeCompletionVisible READ codeCompletionVisible WRITE setCodeCompletionVisible NOTIFY codeCompletionVisibleChanged) |
| 19 | |
| 20 | public: |
| 21 | explicit CodeHelper(QObject *parent = nullptr); |
| 22 | |
| 23 | CodeCompletionModel *codeCompletionModel() const; |
| 24 | bool codeCompletionVisible() const; |
| 25 | |
| 26 | public Q_SLOTS: |
| 27 | bool processKey(QQuickTextEdit *textEdit, int keyCode, int modifiers); |
| 28 | QString autoIndentGLSLCode(const QString &code); |
| 29 | QString autoIndentGLSLNextLine(const QString &codeLine, bool ); |
| 30 | QString getCurrentWord(QQuickTextEdit *textEdit); |
| 31 | void removeCurrentWord(QQuickTextEdit *textEdit); |
| 32 | void updateCodeCompletion(QQuickTextEdit *textEdit, bool force = false); |
| 33 | void setCodeCompletionVisible(bool visible); |
| 34 | void applyCodeCompletion(QQuickTextEdit *textEdit); |
| 35 | |
| 36 | signals: |
| 37 | void codeCompletionModelChanged(); |
| 38 | void codeCompletionVisibleChanged(); |
| 39 | |
| 40 | private: |
| 41 | friend class EffectManager; |
| 42 | |
| 43 | void showCodeCompletion(); |
| 44 | |
| 45 | EffectManager *m_effectManager = nullptr; |
| 46 | CodeCompletionModel *m_codeCompletionModel = nullptr; |
| 47 | QQuickTextEdit *m_textEdit = nullptr; |
| 48 | bool m_codeCompletionVisible = false; |
| 49 | QTimer m_codeCompletionTimer; |
| 50 | |
| 51 | QList<QString> m_reservedArgumentNames; |
| 52 | QList<QString> m_reservedTagNames; |
| 53 | QList<QString> m_reservedFunctionNames; |
| 54 | |
| 55 | }; |
| 56 | |
| 57 | #endif // CODEHELPER_H |
| 58 | |