mirror of https://github.com/nomic-ai/gpt4all
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
3 months ago
|
#ifndef CHATVIEWTEXTPROCESSOR_H
|
||
|
#define CHATVIEWTEXTPROCESSOR_H
|
||
1 year ago
|
|
||
4 months ago
|
#include <QColor>
|
||
1 year ago
|
#include <QObject>
|
||
|
#include <QQmlEngine>
|
||
4 months ago
|
#include <QQuickTextDocument> // IWYU pragma: keep
|
||
|
#include <QRectF>
|
||
|
#include <QSizeF>
|
||
|
#include <QString>
|
||
1 year ago
|
#include <QSyntaxHighlighter>
|
||
9 months ago
|
#include <QTextObjectInterface>
|
||
4 months ago
|
#include <QVector>
|
||
|
|
||
|
class QPainter;
|
||
|
class QTextDocument;
|
||
|
class QTextFormat;
|
||
1 year ago
|
|
||
|
class SyntaxHighlighter : public QSyntaxHighlighter {
|
||
|
Q_OBJECT
|
||
|
public:
|
||
|
SyntaxHighlighter(QObject *parent);
|
||
|
~SyntaxHighlighter();
|
||
|
void highlightBlock(const QString &text) override;
|
||
|
};
|
||
|
|
||
|
struct ContextLink {
|
||
|
int startPos = -1;
|
||
|
int endPos = -1;
|
||
|
QString text;
|
||
|
QString href;
|
||
|
};
|
||
|
|
||
1 year ago
|
struct CodeCopy {
|
||
|
int startPos = -1;
|
||
|
int endPos = -1;
|
||
|
QString text;
|
||
|
};
|
||
|
|
||
3 months ago
|
class ChatViewTextProcessor : public QObject
|
||
1 year ago
|
{
|
||
|
Q_OBJECT
|
||
|
Q_PROPERTY(QQuickTextDocument* textDocument READ textDocument WRITE setTextDocument NOTIFY textDocumentChanged())
|
||
3 months ago
|
Q_PROPERTY(bool shouldProcessText READ shouldProcessText WRITE setShouldProcessText NOTIFY shouldProcessTextChanged())
|
||
1 year ago
|
QML_ELEMENT
|
||
|
public:
|
||
3 months ago
|
explicit ChatViewTextProcessor(QObject *parent = nullptr);
|
||
1 year ago
|
|
||
|
QQuickTextDocument* textDocument() const;
|
||
|
void setTextDocument(QQuickTextDocument* textDocument);
|
||
|
|
||
|
Q_INVOKABLE void setLinkColor(const QColor &c) { m_linkColor = c; }
|
||
1 year ago
|
Q_INVOKABLE void setHeaderColor(const QColor &c) { m_headerColor = c; }
|
||
|
|
||
|
Q_INVOKABLE bool tryCopyAtPosition(int position) const;
|
||
1 year ago
|
|
||
3 months ago
|
bool shouldProcessText() const;
|
||
|
void setShouldProcessText(bool b);
|
||
|
|
||
1 year ago
|
Q_SIGNALS:
|
||
|
void textDocumentChanged();
|
||
3 months ago
|
void shouldProcessTextChanged();
|
||
1 year ago
|
|
||
|
private Q_SLOTS:
|
||
|
void handleTextChanged();
|
||
1 year ago
|
void handleCodeBlocks();
|
||
3 months ago
|
void handleMarkdown();
|
||
1 year ago
|
|
||
|
private:
|
||
|
QQuickTextDocument *m_textDocument;
|
||
|
SyntaxHighlighter *m_syntaxHighlighter;
|
||
|
QVector<ContextLink> m_links;
|
||
1 year ago
|
QVector<CodeCopy> m_copies;
|
||
1 year ago
|
QColor m_linkColor;
|
||
1 year ago
|
QColor m_headerColor;
|
||
3 months ago
|
bool m_shouldProcessText = false;
|
||
1 year ago
|
bool m_isProcessingText = false;
|
||
|
};
|
||
|
|
||
3 months ago
|
#endif // CHATVIEWTEXTPROCESSOR_H
|