-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathllamamarkdownwidget.h
More file actions
55 lines (42 loc) · 1.56 KB
/
llamamarkdownwidget.h
File metadata and controls
55 lines (42 loc) · 1.56 KB
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
#pragma once
#include <utils/expected.h>
#include <QElapsedTimer>
#include <QString>
#include <QTextBrowser>
#include "llamasyntaxhighlighter.h"
#include "markdownrenderer.h"
namespace LlamaCpp {
class MarkdownLabel : public MarkdownRenderer
{
Q_OBJECT
public:
explicit MarkdownLabel(QWidget *parent = nullptr);
~MarkdownLabel() = default;
void setMarkdown(const QString &markdown, bool completed);
void resizeEvent(QResizeEvent *event) override;
int heightForWidth(int w) const override;
void invalidate();
QSize sizeHint() const override;
/* set the movie that will be used for all URLs that start with
"spinner://". The movie is *not* owned by the document – you can
reuse the same QMovie for many documents if you wish. */
void setMovie(QMovie *movie);
void setHeightAdjustment(int newHeightAdjustment);
protected:
// Called by the layout whenever an image resource is required.
QVariant loadResource(int type, const QUrl &name) override;
private slots:
void onSpinnerFrameChanged(int);
signals:
void copyToClipboard(const QString &verbatimText, const QString &highlightedText);
void saveToFile(const QString &fileName, const QString &verbatimText);
private:
void adjustMinimumWidth(const QString &markdown);
int commonPrefixLength(const QList<QByteArray> &a, const QList<QByteArray> &b) const;
void updateColorPalette();
QElapsedTimer m_markdownConversionTimer;
QMovie *m_spinner = nullptr;
QSet<QUrl> m_spinnerUrls;
int m_heightAdjustment{0};
};
} // namespace LlamaCpp