gpt4all/gpt4all-chat/responsetext.h
AT 9273b49b62
chat: major UI redesign for v3.0.0 (#2396)
Signed-off-by: Adam Treat <treat.adam@gmail.com>
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Co-authored-by: Jared Van Bortel <jared@nomic.ai>
2024-06-24 18:49:23 -04:00

74 lines
1.7 KiB
C++

#ifndef RESPONSETEXT_H
#define RESPONSETEXT_H
#include <QColor>
#include <QObject>
#include <QQmlEngine>
#include <QQuickTextDocument> // IWYU pragma: keep
#include <QRectF>
#include <QSizeF>
#include <QString>
#include <QSyntaxHighlighter>
#include <QTextObjectInterface>
#include <QVector>
class QPainter;
class QTextDocument;
class QTextFormat;
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;
};
struct CodeCopy {
int startPos = -1;
int endPos = -1;
QString text;
};
class ResponseText : public QObject
{
Q_OBJECT
Q_PROPERTY(QQuickTextDocument* textDocument READ textDocument WRITE setTextDocument NOTIFY textDocumentChanged())
QML_ELEMENT
public:
explicit ResponseText(QObject *parent = nullptr);
QQuickTextDocument* textDocument() const;
void setTextDocument(QQuickTextDocument* textDocument);
Q_INVOKABLE void setLinkColor(const QColor &c) { m_linkColor = c; }
Q_INVOKABLE void setHeaderColor(const QColor &c) { m_headerColor = c; }
Q_INVOKABLE bool tryCopyAtPosition(int position) const;
Q_SIGNALS:
void textDocumentChanged();
private Q_SLOTS:
void handleTextChanged();
void handleCodeBlocks();
private:
QQuickTextDocument *m_textDocument;
SyntaxHighlighter *m_syntaxHighlighter;
QVector<ContextLink> m_links;
QVector<CodeCopy> m_copies;
QColor m_linkColor;
QColor m_headerColor;
bool m_isProcessingText = false;
};
#endif // RESPONSETEXT_H