summaryrefslogtreecommitdiffstats
path: root/tools/qqem/codehelper.h
blob: e4a345115fc00d43cec8972999e97df3e970032c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef CODEHELPER_H
#define CODEHELPER_H

#include <QObject>
#include <QTimer>
#include <QtQuick/private/qquicktextedit_p_p.h>
#include "codecompletionmodel.h"

class EffectManager;

class CodeHelper : public QObject
{
    Q_OBJECT
    Q_PROPERTY(CodeCompletionModel *codeCompletionModel READ codeCompletionModel NOTIFY codeCompletionModelChanged)
    Q_PROPERTY(bool codeCompletionVisible READ codeCompletionVisible WRITE setCodeCompletionVisible NOTIFY codeCompletionVisibleChanged)

public:
    explicit CodeHelper(QObject *parent = nullptr);

    CodeCompletionModel *codeCompletionModel() const;
    bool codeCompletionVisible() const;

public Q_SLOTS:
    bool processKey(QQuickTextEdit *textEdit, int keyCode, int modifiers);
    QString autoIndentGLSLCode(const QString &code);
    QString autoIndentGLSLNextLine(const QString &codeLine, bool multilineComment);
    QString getCurrentWord(QQuickTextEdit *textEdit);
    void removeCurrentWord(QQuickTextEdit *textEdit);
    void updateCodeCompletion(QQuickTextEdit *textEdit, bool force = false);
    void setCodeCompletionVisible(bool visible);
    void applyCodeCompletion(QQuickTextEdit *textEdit);

signals:
    void codeCompletionModelChanged();
    void codeCompletionVisibleChanged();

private:
    friend class EffectManager;

    void showCodeCompletion();

    EffectManager *m_effectManager = nullptr;
    CodeCompletionModel *m_codeCompletionModel = nullptr;
    QQuickTextEdit *m_textEdit = nullptr;
    bool m_codeCompletionVisible = false;
    QTimer m_codeCompletionTimer;

    QList<QString> m_reservedArgumentNames;
    QList<QString> m_reservedTagNames;
    QList<QString> m_reservedFunctionNames;

};

#endif // CODEHELPER_H