mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2024-09-11 21:27:37 +03:00
* Use the same font size for code blocks as we do for the rest of the chat text. * Add a conversation tray after discussion with Vincent and Andriy and gathering of feedback from some other users. This adds the reset context back as a recycle button and copy chat features back to the app for v3.0.0. Signed-off-by: Adam Treat <treat.adam@gmail.com>
87 lines
2.2 KiB
C++
87 lines
2.2 KiB
C++
#ifndef CHATVIEWTEXTPROCESSOR_H
|
|
#define CHATVIEWTEXTPROCESSOR_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 ChatViewTextProcessor : public QObject
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(QQuickTextDocument* textDocument READ textDocument WRITE setTextDocument NOTIFY textDocumentChanged())
|
|
Q_PROPERTY(bool shouldProcessText READ shouldProcessText WRITE setShouldProcessText NOTIFY shouldProcessTextChanged())
|
|
Q_PROPERTY(qreal fontPixelSize READ fontPixelSize WRITE setFontPixelSize NOTIFY fontPixelSizeChanged())
|
|
QML_ELEMENT
|
|
public:
|
|
explicit ChatViewTextProcessor(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;
|
|
|
|
bool shouldProcessText() const;
|
|
void setShouldProcessText(bool b);
|
|
|
|
qreal fontPixelSize() const;
|
|
void setFontPixelSize(qreal b);
|
|
|
|
Q_SIGNALS:
|
|
void textDocumentChanged();
|
|
void shouldProcessTextChanged();
|
|
void fontPixelSizeChanged();
|
|
|
|
private Q_SLOTS:
|
|
void handleTextChanged();
|
|
void handleCodeBlocks();
|
|
void handleMarkdown();
|
|
|
|
private:
|
|
QQuickTextDocument *m_textDocument;
|
|
SyntaxHighlighter *m_syntaxHighlighter;
|
|
QVector<ContextLink> m_links;
|
|
QVector<CodeCopy> m_copies;
|
|
QColor m_linkColor;
|
|
QColor m_headerColor;
|
|
bool m_shouldProcessText = false;
|
|
bool m_isProcessingText = false;
|
|
qreal m_fontPixelSize;
|
|
};
|
|
|
|
#endif // CHATVIEWTEXTPROCESSOR_H
|