2025-02-26 19:00:41 +08:00
|
|
|
// ctaitextedit.h
|
|
|
|
#ifndef CTAI_TEXTEDIT_H
|
|
|
|
#define CTAI_TEXTEDIT_H
|
|
|
|
|
|
|
|
#include <QTextBrowser>
|
2025-02-26 21:40:56 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include "ctai_base.h"
|
|
|
|
struct MessageItem {
|
|
|
|
QString messageId;
|
|
|
|
QString messageFp;
|
|
|
|
QString timestamp;
|
|
|
|
QString content;
|
|
|
|
QString prompts_tkoens;
|
|
|
|
QString completion_tokens;
|
|
|
|
QString total_tokens;
|
|
|
|
QString cache_hit_tokens;
|
|
|
|
QString cache_miss_tokens;
|
|
|
|
bool isCollapsed;
|
|
|
|
};
|
|
|
|
|
2025-02-26 19:00:41 +08:00
|
|
|
class ctai_textedit : public QTextBrowser
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ctai_textedit(QWidget *parent = nullptr);
|
2025-02-26 21:40:56 +08:00
|
|
|
void appendMessage(const model_data& content);
|
|
|
|
void startStreamingMessage(const model_data& messageId);
|
|
|
|
void appendStreamContent(const model_data& content);
|
|
|
|
void finishStreamingMessage();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void deleteMessage(const QString& messageId);
|
|
|
|
void copyMessage(const QString& messageId);
|
|
|
|
void saveMessage(const QString& messageId);
|
|
|
|
void toggleCollapse(const QString& messageId);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void createMessageControls(const QString& messageId);
|
|
|
|
void messageDisplay(const QString& messageId);
|
|
|
|
void streamMessageDisplay(const QString& messageId);
|
|
|
|
void insertSeparatorLine();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QMap<QString, MessageItem> messages;
|
|
|
|
QString currentStreamingId;
|
|
|
|
QMap<QString, QWidget*> messageControls;
|
2025-02-26 19:00:41 +08:00
|
|
|
};
|
|
|
|
|
2025-02-26 21:40:56 +08:00
|
|
|
#endif // CTAI_TEXTEDIT_H
|
|
|
|
|