128 lines
3.9 KiB
C++
128 lines
3.9 KiB
C++
// ctaitextedit.h
|
|
#ifndef CTAIHISTORYTEXTEDIT_H
|
|
#define CTAIHISTORYTEXTEDIT_H
|
|
|
|
// Qt核心组件
|
|
#include <QWidget>
|
|
#include <QString>
|
|
#include <QApplication>
|
|
#include <QClipboard>
|
|
// Qt布局相关
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QSpacerItem>
|
|
|
|
// Qt控件相关
|
|
#include <QPushButton>
|
|
#include <QTextEdit>
|
|
#include <QLineEdit>
|
|
#include <QFrame>
|
|
#include <QMenu>
|
|
#include <QAction>
|
|
#include <QAbstractTextDocumentLayout>
|
|
#include <QAbstractScrollArea>
|
|
#include <QTimer>
|
|
#include <QLabel>
|
|
#include <QComboBox>
|
|
#include <QTextBlock>
|
|
#include <QChar>
|
|
// Qt对话框
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
|
|
// 系统相关
|
|
#include <mutex>
|
|
// 项目相关头文件
|
|
#include "ctai_base.h"
|
|
#include "ctaiMathConvert.h"
|
|
#include "ctaiHistoryTools.h"
|
|
|
|
typedef struct tokens_args
|
|
{
|
|
QString prompt_tokens = {};
|
|
QString completion_tokens = {};
|
|
QString total_tokens = {};
|
|
QString cache_hit_tokens = {};
|
|
QString cache_miss_tokens = {};
|
|
} tokens_data;
|
|
|
|
std::mutex m_mutex;
|
|
|
|
class ctaiHistoryTextEdit : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
ctaiHistoryTextEdit(QWidget *parent = nullptr);
|
|
~ctaiHistoryTextEdit();
|
|
void init_layout(msg_type msg_type_mode);
|
|
void init_msg_header_layout(msg_type msg_type_mode);
|
|
void init_msg_history_layout();
|
|
void init_msg_line();
|
|
void add_user_message(const model_data &message);
|
|
void add_system_message(const model_data &message);
|
|
void update_tokens_message(const model_data &message);
|
|
void add_header_message(const model_data &message);
|
|
private slots:
|
|
void on_delete_slots(); // 删除按钮
|
|
void on_copy_slots(); // 复制按钮
|
|
void on_fold_slots(); // 折叠按钮
|
|
void on_tokens_slots(); // tokens按钮
|
|
void on_display_changed(QString); // 显示模式改变
|
|
void on_display_font_size_changed(); // 字体大小改变
|
|
void on_sync_text_height();
|
|
void on_save_file(int); // 保存文本
|
|
void on_menu_slots();
|
|
signals:
|
|
void delete_requested(QString); // 请求删除此消息
|
|
void row_height_changed(bool);
|
|
|
|
private:
|
|
void connect_signals(msg_type msg_type_mode); // 连接信号和槽
|
|
void set_default_opts();
|
|
private:
|
|
ctaiMathConvert *m_math_convert;
|
|
QFrame *msg_line;
|
|
QSpacerItem *sparcer_item = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
QVBoxLayout *main_layout = {};
|
|
QVBoxLayout *header_layout = {};
|
|
QHBoxLayout *header_info_layout = {};
|
|
QHBoxLayout *header_opts_layout = {};
|
|
QVBoxLayout *history_layout = {};
|
|
|
|
QPushButton *m_msg_system_header_ico = {};
|
|
QPushButton *m_msg_user_header_ico = {};
|
|
QLineEdit *m_msg_header = {};
|
|
QTextEdit *m_msg_history = {};
|
|
QPushButton *m_msg_user_del = {};
|
|
QPushButton *m_msg_system_del = {};
|
|
QPushButton *m_msg_tokens = {};
|
|
QPushButton *m_history_to_send = {};
|
|
QPushButton *m_restart_to_send = {};
|
|
// 信息功能区
|
|
ctaiHistoryTools *m_msg_tools = {};
|
|
// tokens消耗显示
|
|
QMenu *m_msg_tokens_menu = {};
|
|
QAction *m_menu_prompt_tokens = {};
|
|
QAction *m_menu_completion_tokens = {};
|
|
QAction *m_menu_total_tokens = {};
|
|
QAction *m_menu_cache_hit_tokens = {};
|
|
QAction *m_menu_cache_miss_tokens = {};
|
|
// 保存展开时的原始高度
|
|
int m_original_height = 0;
|
|
// 折叠状态
|
|
bool m_is_folded = false;
|
|
// 本次会话的tokens消耗信息
|
|
tokens_data m_tokens_data;
|
|
// 本次信息ID
|
|
QString m_msg_sned_id = {};
|
|
// 本次信息
|
|
QString m_current_content;
|
|
//粗体字
|
|
bool m_bold=false;
|
|
std::vector<QString> save_extend={".txt",".html",".md",".pdf"};
|
|
std::vector<QString> save_extend_str={"文本文件 (*.txt)","HTML 文件 (*.html)","Markdown 文件 (*.md)","PDF 文件 (*.pdf)"};
|
|
QSpacerItem *bottom_spacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
};
|
|
|
|
#endif // ctai_history_textedit_H
|