整理函数,调整功能布局,实装重试和插入功能
This commit is contained in:
parent
aba2524edf
commit
8730cb19b7
@ -79,8 +79,7 @@ QPushButton#m_msg_user_header_ico{
|
||||
image:url(":/res/img/btn/default_header.png");
|
||||
}
|
||||
|
||||
QPushButton#m_msg_user_del,
|
||||
QPushButton#m_msg_system_del{
|
||||
QPushButton#m_msg_delete{
|
||||
height:25px;
|
||||
width:25px;
|
||||
border:none;
|
||||
|
||||
@ -8,13 +8,13 @@ ctaiHistoryTextEdit::ctaiHistoryTextEdit(QWidget *parent)
|
||||
ctaiHistoryTextEdit::~ctaiHistoryTextEdit()
|
||||
{
|
||||
}
|
||||
void ctaiHistoryTextEdit::init_layout(msg_type msg_type_mode)
|
||||
void ctaiHistoryTextEdit::initLayout(msg_type msg_type_mode)
|
||||
{
|
||||
// 主垂直布局
|
||||
main_layout = new QVBoxLayout();
|
||||
init_msg_line();
|
||||
init_msg_header_layout(msg_type_mode);
|
||||
init_msg_history_layout();
|
||||
initMsgLine();
|
||||
initMsgHeaderLayout(msg_type_mode);
|
||||
initMsgHistoryLayout();
|
||||
// 主布局
|
||||
main_layout->addLayout(header_layout);
|
||||
main_layout->addLayout(history_layout);
|
||||
@ -26,7 +26,7 @@ void ctaiHistoryTextEdit::init_layout(msg_type msg_type_mode)
|
||||
set_default_opts();
|
||||
connect_signals(msg_type_mode);
|
||||
}
|
||||
void ctaiHistoryTextEdit::init_msg_line()
|
||||
void ctaiHistoryTextEdit::initMsgLine()
|
||||
{
|
||||
// 分割线区域
|
||||
msg_line = new QFrame;
|
||||
@ -34,7 +34,7 @@ void ctaiHistoryTextEdit::init_msg_line()
|
||||
msg_line->setFrameShadow(QFrame::Sunken); // 凹陷效果
|
||||
msg_line->setLineWidth(2); // 线宽
|
||||
}
|
||||
void ctaiHistoryTextEdit::init_msg_history_layout()
|
||||
void ctaiHistoryTextEdit::initMsgHistoryLayout()
|
||||
{
|
||||
history_layout = new QVBoxLayout();
|
||||
// 历史信息QTextEdit
|
||||
@ -50,7 +50,7 @@ void ctaiHistoryTextEdit::init_msg_history_layout()
|
||||
history_layout->addWidget(msg_line);
|
||||
history_layout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
void ctaiHistoryTextEdit::init_msg_header_layout(msg_type msg_type_mode)
|
||||
void ctaiHistoryTextEdit::initMsgHeaderLayout(msg_type msg_type_mode)
|
||||
{
|
||||
// 消息头左区域布局,ico,id,fp,time
|
||||
header_info_layout = new QHBoxLayout();
|
||||
@ -61,6 +61,16 @@ void ctaiHistoryTextEdit::init_msg_header_layout(msg_type msg_type_mode)
|
||||
m_msg_header->setObjectName("m_msg_header");
|
||||
m_msg_header->setReadOnly(true);
|
||||
m_msg_tools = new ctaiHistoryTools();
|
||||
m_history_to_send = new QPushButton();
|
||||
m_restart_to_send = new QPushButton();
|
||||
m_msg_fold = new QPushButton();
|
||||
m_msg_delete = new QPushButton();
|
||||
m_msg_fold->setObjectName("m_msg_fold");
|
||||
m_msg_delete->setObjectName("m_msg_delete");
|
||||
m_history_to_send->setObjectName("m_history_to_send");
|
||||
m_restart_to_send->setObjectName("m_restart_to_send");
|
||||
m_msg_fold->setIcon(QIcon(":res/img/btn/btn_info_up.png"));
|
||||
m_msg_fold->setIconSize(QSize(25, 25));
|
||||
if (msg_type_mode == SYSTEM)
|
||||
{
|
||||
// 1.SYSTEM消息头水平左信息区
|
||||
@ -70,18 +80,13 @@ void ctaiHistoryTextEdit::init_msg_header_layout(msg_type msg_type_mode)
|
||||
header_info_layout->addWidget(m_msg_header);
|
||||
header_info_layout->setContentsMargins(0, 0, 0, 0);
|
||||
// 2.SYSTEM消息头水平右信息区
|
||||
m_msg_tokens = new QPushButton();
|
||||
m_history_to_send = new QPushButton();
|
||||
m_msg_system_del = new QPushButton();
|
||||
m_restart_to_send = new QPushButton();
|
||||
m_msg_tokens = new QPushButton();
|
||||
m_msg_tokens->setObjectName("m_msg_tokens");
|
||||
m_history_to_send->setObjectName("m_history_to_send");
|
||||
m_msg_system_del->setObjectName("m_msg_system_del");
|
||||
m_restart_to_send->setObjectName("m_restart_to_send");
|
||||
header_info_layout->addWidget(m_history_to_send);
|
||||
header_info_layout->addWidget(m_msg_tokens);
|
||||
header_info_layout->addWidget(m_msg_fold);
|
||||
header_info_layout->addWidget(m_history_to_send);
|
||||
header_info_layout->addWidget(m_restart_to_send);
|
||||
header_info_layout->addWidget(m_msg_system_del);
|
||||
header_info_layout->addWidget(m_msg_tokens);
|
||||
header_info_layout->addWidget(m_msg_delete);
|
||||
// 3.SYSTEM消息头垂直第二排功能区
|
||||
header_opts_layout->addWidget(m_msg_tools);
|
||||
// 4.添加到消息头主布局
|
||||
@ -90,22 +95,16 @@ void ctaiHistoryTextEdit::init_msg_header_layout(msg_type msg_type_mode)
|
||||
}
|
||||
else
|
||||
{
|
||||
// SYSTEM MSG ICO
|
||||
// USER MSG ICO
|
||||
m_msg_user_header_ico = new QPushButton();
|
||||
m_msg_user_header_ico->setObjectName("m_msg_system_header_ico");
|
||||
header_info_layout->addWidget(m_msg_user_header_ico);
|
||||
header_info_layout->addWidget(m_msg_header);
|
||||
header_info_layout->setContentsMargins(0, 0, 0, 0);
|
||||
// USER DELETE BUTTON
|
||||
m_msg_user_del = new QPushButton();
|
||||
m_msg_user_del->setObjectName("m_msg_user_del");
|
||||
m_history_to_send = new QPushButton();
|
||||
m_history_to_send->setObjectName("m_history_to_send");
|
||||
m_restart_to_send = new QPushButton();
|
||||
m_restart_to_send->setObjectName("m_restart_to_send");
|
||||
header_info_layout->addWidget(m_msg_header);
|
||||
header_info_layout->addWidget(m_msg_fold);
|
||||
header_info_layout->addWidget(m_history_to_send);
|
||||
header_info_layout->addWidget(m_restart_to_send);
|
||||
header_info_layout->addWidget(m_msg_user_del);
|
||||
header_info_layout->addWidget(m_msg_delete);
|
||||
header_info_layout->setContentsMargins(0, 0, 0, 0);
|
||||
header_layout->addLayout(header_info_layout);
|
||||
}
|
||||
}
|
||||
@ -116,53 +115,74 @@ void ctaiHistoryTextEdit::set_default_opts()
|
||||
void ctaiHistoryTextEdit::connect_signals(msg_type msg_type_mode)
|
||||
{
|
||||
if (msg_type_mode == SYSTEM)
|
||||
{
|
||||
connect(m_msg_system_del, SIGNAL(clicked()), this, SLOT(on_delete_slots()));
|
||||
connect(m_msg_tools, SIGNAL(on_signals_copy()), this, SLOT(on_copy_slots()));
|
||||
connect(m_msg_tools, SIGNAL(on_signals_fold()), this, SLOT(on_fold_slots()));
|
||||
connect(m_msg_tokens, SIGNAL(clicked()), this, SLOT(on_tokens_slots()));
|
||||
connect(m_msg_tools, SIGNAL(on_signals_display_mode(QString)), this, SLOT(on_display_changed(QString)));
|
||||
connect(m_msg_tools, SIGNAL(on_signals_display_font_size()), this, SLOT(on_display_font_size_changed()));
|
||||
connect(m_msg_tools, SIGNAL(on_signals_send_browser()), this, SLOT(on_send_browser()));
|
||||
// save菜单功能
|
||||
connect(m_msg_tools, SIGNAL(on_signals_save_file(QString,int)), this, SLOT(on_save_file(QString,int)));
|
||||
{
|
||||
//复制功能
|
||||
connect(m_msg_tools, SIGNAL(signalsOnCopy()), this, SLOT(slotsOnCopy()));
|
||||
//tokens显示功能
|
||||
connect(m_msg_tokens, SIGNAL(clicked()), this, SLOT(slotsOnTokens()));
|
||||
//显示模式功能
|
||||
connect(m_msg_tools, SIGNAL(signalsDisplayMode(QString)), this, SLOT(slotsOnDisplay(QString)));
|
||||
//字体大小功能
|
||||
connect(m_msg_tools, SIGNAL(signalsDisplayFontSize()), this, SLOT(slotsOnDisplayFontSize()));
|
||||
//浏览器功能
|
||||
connect(m_msg_tools, SIGNAL(signalsSendBrowser()), this, SLOT(slotsOnSendBrowser()));
|
||||
//保存菜单功能
|
||||
connect(m_msg_tools, SIGNAL(signalsSaveFile(QString, int)), this, SLOT(slotsOnSave(QString, int)));
|
||||
// 其他功能菜单
|
||||
connect(m_msg_tools, SIGNAL(on_signals_menu()), this, SLOT(on_menu_slots()));
|
||||
connect(m_msg_tools, SIGNAL(signalsOnOptsMenu()), this, SLOT(slotsOnOptsMenu()));
|
||||
}
|
||||
//删除信息
|
||||
connect(m_msg_delete, SIGNAL(clicked()), this, SLOT(slotsOnDelete()));
|
||||
//折叠信息功能
|
||||
connect(m_msg_fold, SIGNAL(clicked()), this, SLOT(slotsOnFold()));
|
||||
//同步行高
|
||||
connect(m_msg_history, SIGNAL(textChanged()), this, SLOT(slotsOnSyncHeight()));
|
||||
//插入msg到send
|
||||
connect(m_history_to_send, SIGNAL(clicked()), this, SLOT(slotsHisResToSend()));
|
||||
//重试send
|
||||
connect(m_restart_to_send, SIGNAL(clicked()), this, SLOT(slotsHisResToSend()));
|
||||
}
|
||||
void ctaiHistoryTextEdit::slotsHisResToSend()
|
||||
{
|
||||
if (sender()->objectName() == "m_history_to_send")
|
||||
{
|
||||
emit signalsEditHisResToSend(m_current_content, HISTORY_SEND_INSERT);
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(m_msg_user_del, SIGNAL(clicked()), this, SLOT(on_delete_slots()));
|
||||
emit signalsEditHisResToSend(m_current_content, HISTORY_SEND_RESTART);
|
||||
}
|
||||
connect(m_msg_history, SIGNAL(textChanged()), this, SLOT(on_sync_text_height()));
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_send_browser(){
|
||||
QString save_path=QDir::currentPath()+"/html/"+m_msg_sned_id+".html";
|
||||
on_save_file(save_path,1);
|
||||
void ctaiHistoryTextEdit::slotsOnSendBrowser()
|
||||
{
|
||||
QString save_path = QDir::currentPath() + "/html/" + m_msg_sned_id + ".html";
|
||||
slotsOnSave(save_path, 1);
|
||||
QDesktopServices::openUrl(save_path);
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_menu_slots()
|
||||
void ctaiHistoryTextEdit::slotsOnOptsMenu()
|
||||
{
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_display_font_size_changed()
|
||||
void ctaiHistoryTextEdit::slotsOnDisplayFontSize()
|
||||
{
|
||||
m_msg_history->setFont(QFont(m_msg_tools->getFont(), m_msg_tools->getFontSize().toInt()));
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_delete_slots()
|
||||
void ctaiHistoryTextEdit::slotsOnDelete()
|
||||
{
|
||||
// 发送删除请求信号
|
||||
emit delete_requested(m_msg_sned_id);
|
||||
emit signalsDeleteMsg(m_msg_sned_id);
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_copy_slots()
|
||||
void ctaiHistoryTextEdit::slotsOnCopy()
|
||||
{
|
||||
// 获取文本并复制到剪贴板
|
||||
QString text = m_msg_history->toPlainText();
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setText(text);
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_save_file(QString save_path,int index)
|
||||
void ctaiHistoryTextEdit::slotsOnSave(QString save_path, int index)
|
||||
{
|
||||
QString temp_current_content;
|
||||
if(save_path.isEmpty()){
|
||||
if (save_path.isEmpty())
|
||||
{
|
||||
save_path = QFileDialog::getSaveFileName(this, tr("保存消息"), m_msg_sned_id + save_extend[index], save_extend_str[index]);
|
||||
}
|
||||
QFile file(save_path);
|
||||
@ -193,16 +213,15 @@ void ctaiHistoryTextEdit::on_save_file(QString save_path,int index)
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_fold_slots()
|
||||
void ctaiHistoryTextEdit::slotsOnFold()
|
||||
{
|
||||
m_is_folded = !m_is_folded;
|
||||
|
||||
m_msg_history->setFixedHeight(m_is_folded ? 0 : m_original_height);
|
||||
m_msg_tools->setFoldIco(QIcon(m_is_folded ? ":res/img/btn/btn_info_down.png" : ":res/img/btn/btn_info_up.png"));
|
||||
m_msg_fold->setIcon(QIcon(m_is_folded ? ":res/img/btn/btn_info_down.png" : ":res/img/btn/btn_info_up.png"));
|
||||
updateGeometry();
|
||||
emit row_height_changed(m_is_folded);
|
||||
emit signalsRowHeightChanged(m_is_folded);
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_display_changed(QString mode)
|
||||
void ctaiHistoryTextEdit::slotsOnDisplay(QString mode)
|
||||
{
|
||||
// 根据显示模式设置文本
|
||||
if (mode == "原始文本")
|
||||
@ -219,7 +238,7 @@ void ctaiHistoryTextEdit::on_display_changed(QString mode)
|
||||
doc->adjustSize();
|
||||
}
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_tokens_slots()
|
||||
void ctaiHistoryTextEdit::slotsOnTokens()
|
||||
{
|
||||
if (!m_msg_tokens_menu)
|
||||
{
|
||||
@ -252,7 +271,7 @@ void ctaiHistoryTextEdit::on_tokens_slots()
|
||||
m_msg_tokens_menu->addAction(m_menu_total_tokens);
|
||||
m_msg_tokens_menu->exec(QCursor::pos());
|
||||
}
|
||||
void ctaiHistoryTextEdit::on_sync_text_height()
|
||||
void ctaiHistoryTextEdit::slotsOnSyncHeight()
|
||||
{
|
||||
// 防抖动处理:如果上次更新在100ms内,则延迟处理
|
||||
static QTimer debounceTimer;
|
||||
@ -281,7 +300,7 @@ void ctaiHistoryTextEdit::on_sync_text_height()
|
||||
m_msg_history->setFixedHeight(newHeight);
|
||||
updateGeometry();
|
||||
m_msg_history->blockSignals(wasBlocked);
|
||||
emit row_height_changed(false);
|
||||
emit signalsRowHeightChanged(false);
|
||||
|
||||
// 延迟发送布局更新请求
|
||||
if (QWidget *parent = parentWidget())
|
||||
@ -296,15 +315,14 @@ void ctaiHistoryTextEdit::on_sync_text_height()
|
||||
// 设置下一次检查的延迟
|
||||
debounceTimer.start(100);
|
||||
}
|
||||
void ctaiHistoryTextEdit::add_user_message(const model_data &message)
|
||||
void ctaiHistoryTextEdit::addUserMessage(const model_data &message)
|
||||
{
|
||||
QString disp_data;
|
||||
disp_data = QSL(message.send_user_data);
|
||||
m_current_content = QSL(message.send_user_data);
|
||||
m_msg_sned_id = QSL(message.send_user_id);
|
||||
m_msg_history->setText(disp_data);
|
||||
m_msg_history->setText(m_current_content);
|
||||
}
|
||||
|
||||
void ctaiHistoryTextEdit::add_system_message(const model_data &message)
|
||||
void ctaiHistoryTextEdit::addSystemMessage(const model_data &message)
|
||||
{
|
||||
m_msg_sned_id = QSL(message.postback_send_id);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
@ -321,7 +339,7 @@ void ctaiHistoryTextEdit::add_system_message(const model_data &message)
|
||||
m_msg_history->setMarkdown(m_current_content);
|
||||
}
|
||||
// 增加tokens信息
|
||||
void ctaiHistoryTextEdit::update_tokens_message(const model_data &message)
|
||||
void ctaiHistoryTextEdit::updateTokensMessage(const model_data &message)
|
||||
{
|
||||
if (message.msg_type_mode == SYSTEM)
|
||||
{
|
||||
@ -333,7 +351,7 @@ void ctaiHistoryTextEdit::update_tokens_message(const model_data &message)
|
||||
}
|
||||
}
|
||||
// 增加头信息
|
||||
void ctaiHistoryTextEdit::add_header_message(const model_data &message)
|
||||
void ctaiHistoryTextEdit::addHeaderMessage(const model_data &message)
|
||||
{
|
||||
QString disp_header;
|
||||
if (message.msg_type_mode == SYSTEM)
|
||||
|
||||
@ -37,49 +37,41 @@
|
||||
#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);
|
||||
void initLayout(msg_type msg_type_mode);
|
||||
void initMsgHeaderLayout(msg_type msg_type_mode);
|
||||
void initMsgHistoryLayout();
|
||||
void initMsgLine();
|
||||
void addUserMessage(const model_data &message);
|
||||
void addSystemMessage(const model_data &message);
|
||||
void updateTokensMessage(const model_data &message);
|
||||
void addHeaderMessage(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(QString,int); // 保存文本
|
||||
void on_menu_slots();
|
||||
void on_send_browser();
|
||||
void slotsOnDelete(); // 删除按钮
|
||||
void slotsOnCopy(); // 复制按钮
|
||||
void slotsOnFold(); // 折叠按钮
|
||||
void slotsOnTokens(); // tokens按钮
|
||||
void slotsOnDisplay(QString); // 显示模式改变
|
||||
void slotsOnDisplayFontSize(); // 字体大小改变
|
||||
void slotsOnSyncHeight();
|
||||
void slotsOnSave(QString,int); // 保存文本
|
||||
void slotsOnOptsMenu();
|
||||
void slotsOnSendBrowser();
|
||||
void slotsHisResToSend();
|
||||
signals:
|
||||
void delete_requested(QString); // 请求删除此消息
|
||||
void row_height_changed(bool);
|
||||
|
||||
void signalsDeleteMsg(QString); // 请求删除此消息
|
||||
void signalsRowHeightChanged(bool);
|
||||
void signalsEditHisResToSend(QString,HISTORY_SEND_MODE);
|
||||
private:
|
||||
void connect_signals(msg_type msg_type_mode); // 连接信号和槽
|
||||
void set_default_opts();
|
||||
void set_default_opts();
|
||||
private:
|
||||
ctaiMathConvert *m_math_convert;
|
||||
QFrame *msg_line;
|
||||
@ -94,8 +86,8 @@ private:
|
||||
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_fold = {};
|
||||
QPushButton *m_msg_delete = {};
|
||||
QPushButton *m_msg_tokens = {};
|
||||
QPushButton *m_history_to_send = {};
|
||||
QPushButton *m_restart_to_send = {};
|
||||
|
||||
@ -16,7 +16,6 @@ void ctaiHistoryTools::initLayout()
|
||||
m_msg_copy = new QPushButton();
|
||||
m_msg_save = new QPushButton();
|
||||
m_msg_menu = new QPushButton();
|
||||
m_msg_fold = new QPushButton();
|
||||
m_msg_display_combobox = new QComboBox();
|
||||
m_msg_display_font_size_combobox = new QComboBox();
|
||||
m_msg_display_font_combobox = new QComboBox();
|
||||
@ -32,10 +31,7 @@ void ctaiHistoryTools::initLayout()
|
||||
m_msg_browser->setObjectName("m_msg_browser");
|
||||
m_msg_copy->setObjectName("m_msg_copy");
|
||||
m_msg_save->setObjectName("m_msg_save");
|
||||
m_msg_menu->setObjectName("m_msg_menu");
|
||||
m_msg_fold->setObjectName("m_msg_fold");
|
||||
m_msg_fold->setIcon(QIcon(":res/img/btn/btn_info_up.png"));
|
||||
m_msg_fold->setIconSize(QSize(25, 25));
|
||||
m_msg_menu->setObjectName("m_msg_menu");
|
||||
initDisplayMode();
|
||||
header_opts_Layout->addItem(sparcer_item);
|
||||
header_opts_Layout->addWidget(m_msg_display_font_label);
|
||||
@ -48,7 +44,6 @@ void ctaiHistoryTools::initLayout()
|
||||
header_opts_Layout->addWidget(m_msg_copy);
|
||||
header_opts_Layout->addWidget(m_msg_save);
|
||||
header_opts_Layout->addWidget(m_msg_menu);
|
||||
header_opts_Layout->addWidget(m_msg_fold);
|
||||
header_opts_Layout->addItem(sparcer_item);
|
||||
header_opts_Layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(header_opts_Layout);
|
||||
@ -71,21 +66,16 @@ void ctaiHistoryTools::initDisplayMode()
|
||||
}
|
||||
void ctaiHistoryTools::initConnect()
|
||||
{
|
||||
connect(m_msg_browser, SIGNAL(clicked()), this, SIGNAL(on_signals_send_browser()));
|
||||
connect(m_msg_copy, SIGNAL(clicked()), this, SIGNAL(on_signals_copy()));
|
||||
connect(m_msg_save, SIGNAL(clicked()), this, SLOT(on_save_menu_slots()));
|
||||
connect(m_msg_menu, SIGNAL(clicked()), this, SLOT(on_opts_menu_slots()));
|
||||
connect(m_msg_fold, SIGNAL(clicked()), this, SIGNAL(on_signals_fold()));
|
||||
connect(m_msg_display_combobox, SIGNAL(currentTextChanged(QString)), this, SIGNAL(on_signals_display_mode(QString)));
|
||||
connect(m_msg_display_font_size_combobox, SIGNAL(currentTextChanged(QString)), this, SIGNAL(on_signals_display_font_size()));
|
||||
connect(m_msg_display_font_combobox, SIGNAL(currentTextChanged(QString)), this, SIGNAL(on_signals_display_font_size()));
|
||||
}
|
||||
void ctaiHistoryTools::setFoldIco(QIcon ico)
|
||||
{
|
||||
m_msg_fold->setIcon(ico);
|
||||
connect(m_msg_browser, SIGNAL(clicked()), this, SIGNAL(signalsSendBrowser()));
|
||||
connect(m_msg_copy, SIGNAL(clicked()), this, SIGNAL(signalsOnCopy()));
|
||||
connect(m_msg_save, SIGNAL(clicked()), this, SLOT(slotsSaveMenu()));
|
||||
connect(m_msg_menu, SIGNAL(clicked()), this, SLOT(slotsOptsMenu()));
|
||||
connect(m_msg_display_combobox, SIGNAL(currentTextChanged(QString)), this, SIGNAL(signalsDisplayMode(QString)));
|
||||
connect(m_msg_display_font_size_combobox, SIGNAL(currentTextChanged(QString)), this, SIGNAL(signalsDisplayFontSize()));
|
||||
connect(m_msg_display_font_combobox, SIGNAL(currentTextChanged(QString)), this, SIGNAL(signalsDisplayFontSize()));
|
||||
}
|
||||
// save按钮实现功能的槽函数
|
||||
void ctaiHistoryTools::on_save_menu_slots()
|
||||
void ctaiHistoryTools::slotsSaveMenu()
|
||||
{
|
||||
if (!m_msg_save_menu)
|
||||
{
|
||||
@ -100,11 +90,11 @@ void ctaiHistoryTools::on_save_menu_slots()
|
||||
}
|
||||
m_msg_save_menu->exec(QCursor::pos());
|
||||
}
|
||||
void ctaiHistoryTools::on_save_action_slots(){
|
||||
void ctaiHistoryTools::slotsSaveAction(){
|
||||
save_index=sender()->objectName().toInt();
|
||||
emit on_signals_save_file({},save_index);
|
||||
emit signalsSaveFile({},save_index);
|
||||
}
|
||||
void ctaiHistoryTools::on_opts_menu_slots()
|
||||
void ctaiHistoryTools::slotsOptsMenu()
|
||||
{
|
||||
QMenu menu(this);
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include "sui_base.h"
|
||||
|
||||
class ctaiHistoryTools : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -17,7 +18,6 @@ public:
|
||||
~ctaiHistoryTools();
|
||||
void initLayout();
|
||||
void initConnect();
|
||||
void setFoldIco(QIcon ico);
|
||||
QString getFontSize();
|
||||
QString getFont();
|
||||
private:
|
||||
@ -26,7 +26,6 @@ private:
|
||||
QPushButton *m_msg_copy = {};
|
||||
QPushButton *m_msg_save = {};
|
||||
QPushButton *m_msg_menu = {};
|
||||
QPushButton *m_msg_fold = {};
|
||||
//显示模式
|
||||
QLabel *m_msg_display_label = {};
|
||||
QComboBox *m_msg_display_combobox = {};
|
||||
@ -47,15 +46,15 @@ private:
|
||||
private:
|
||||
void initDisplayMode();
|
||||
signals:
|
||||
void on_signals_copy();
|
||||
void on_signals_fold();
|
||||
void on_signals_display_mode(QString);
|
||||
void on_signals_display_font_size();
|
||||
void on_signals_save_file(QString,int);
|
||||
void on_signals_send_browser();
|
||||
void signalsOnCopy();
|
||||
void signalsDisplayMode(QString);
|
||||
void signalsDisplayFontSize();
|
||||
void signalsSaveFile(QString,int);
|
||||
void signalsSendBrowser();
|
||||
void signalsOnOptsMenu();
|
||||
public slots:
|
||||
void on_save_menu_slots();
|
||||
void on_opts_menu_slots();
|
||||
void on_save_action_slots();
|
||||
void slotsSaveMenu();
|
||||
void slotsOptsMenu();
|
||||
void slotsSaveAction();
|
||||
};
|
||||
#endif
|
||||
@ -58,7 +58,7 @@ void ctaiHistoryWidget::add_message(const model_data &message)
|
||||
stored_data->postback_model_data += message.postback_model_data;
|
||||
if (auto message_widget = qobject_cast<ctaiHistoryTextEdit *>(widget))
|
||||
{
|
||||
message_widget->add_system_message(message);
|
||||
message_widget->addSystemMessage(message);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -67,27 +67,29 @@ void ctaiHistoryWidget::add_message(const model_data &message)
|
||||
update_stored_data(stored_data, message);
|
||||
if (auto message_widget = qobject_cast<ctaiHistoryTextEdit *>(widget))
|
||||
{
|
||||
message_widget->update_tokens_message(message);
|
||||
message_widget->updateTokensMessage(message);
|
||||
}
|
||||
}
|
||||
// 立即滚动到底部
|
||||
scrollToBottom();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 添加新消息
|
||||
model_data *new_data = new model_data(message);
|
||||
ctaiHistoryTextEdit *message_widget = new ctaiHistoryTextEdit(this);
|
||||
message_widget->init_layout(new_data->msg_type_mode);
|
||||
message_widget->initLayout(new_data->msg_type_mode);
|
||||
message_widget->show();
|
||||
if (new_data->msg_type_mode == SYSTEM)
|
||||
{
|
||||
message_widget->add_header_message(*new_data);
|
||||
message_widget->update_tokens_message(*new_data);
|
||||
message_widget->add_system_message(*new_data);
|
||||
message_widget->addHeaderMessage(*new_data);
|
||||
message_widget->updateTokensMessage(*new_data);
|
||||
message_widget->addSystemMessage(*new_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
message_widget->add_header_message(*new_data);
|
||||
message_widget->add_user_message(*new_data);
|
||||
message_widget->addHeaderMessage(*new_data);
|
||||
message_widget->addUserMessage(*new_data);
|
||||
}
|
||||
|
||||
// 创建新行
|
||||
@ -97,17 +99,16 @@ void ctaiHistoryWidget::add_message(const model_data &message)
|
||||
// 存储到map中
|
||||
message_map_[send_id] = std::make_pair(new_data, row);
|
||||
// 连接删除信号
|
||||
connect(message_widget, SIGNAL(delete_requested(QString)), this, SLOT(on_msg_remove(QString)));
|
||||
connect(message_widget, SIGNAL(signalsDeleteMsg(QString)), this, SLOT(slotsRemoveMsg(QString)));
|
||||
// 连接高度变化信号
|
||||
connect(message_widget, SIGNAL(row_height_changed(bool)), this, SLOT(on_rows_height_changed(bool)));
|
||||
connect(message_widget, SIGNAL(signalsRowHeightChanged(bool)), this, SLOT(slotsRowsHeightSync(bool)));
|
||||
connect(message_widget, SIGNAL(signalsEditHisResToSend(QString,HISTORY_SEND_MODE)), this, SIGNAL(signalsWidgetHisResToSend(QString, HISTORY_SEND_MODE)));
|
||||
// 滚动到新消息
|
||||
scrollToItem(item(row, 0));
|
||||
}
|
||||
// 立即滚动到底部
|
||||
scrollToBottom();
|
||||
}
|
||||
// 自适应信息高度
|
||||
void ctaiHistoryWidget::on_rows_height_changed(bool fold_state)
|
||||
void ctaiHistoryWidget::slotsRowsHeightSync(bool fold_state)
|
||||
{
|
||||
if (fold_state)
|
||||
{
|
||||
@ -128,35 +129,42 @@ void ctaiHistoryWidget::on_rows_height_changed(bool fold_state)
|
||||
setRowHeight(row, currentHeight + 100);
|
||||
resizeRowToContents(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ctaiHistoryWidget::on_msg_remove(QString send_id)
|
||||
void ctaiHistoryWidget::slotsRemoveMsg(QString send_id)
|
||||
{
|
||||
qDebug()<<"send_id:"<<send_id;
|
||||
auto it = message_map_.find(send_id);
|
||||
if (it != message_map_.end())
|
||||
{
|
||||
// 获取要删除的行号
|
||||
int row_to_remove = it->second.second-1;
|
||||
qDebug()<<"row_to_remove:"<<row_to_remove;
|
||||
// 删除model_data
|
||||
delete it->second.first;
|
||||
|
||||
// 从map中移除该元素
|
||||
message_map_.erase(it);
|
||||
|
||||
// 从表格中移除该行
|
||||
removeRow(row_to_remove);
|
||||
|
||||
// 更新map中所有大于被删除行号的行号
|
||||
for (auto& pair : message_map_)
|
||||
int row = it->second.second;
|
||||
|
||||
// 确保行号有效
|
||||
if (row >= 0 && row < rowCount())
|
||||
{
|
||||
if (pair.second.second > row_to_remove)
|
||||
// 在删除行之前,先删除单元格中的widget
|
||||
QWidget *widget = cellWidget(row, 0);
|
||||
if (widget)
|
||||
{
|
||||
// 更新行号
|
||||
pair.second.second--;
|
||||
removeCellWidget(row, 0);
|
||||
delete widget;
|
||||
}
|
||||
|
||||
// 删除行
|
||||
// removeRow(row);
|
||||
qDebug() << "row:" << row;
|
||||
// 更新map中后续行的行号
|
||||
for (auto &pair : message_map_)
|
||||
{
|
||||
if (pair.second.second > row)
|
||||
{
|
||||
pair.second.second--;
|
||||
}
|
||||
}
|
||||
|
||||
// 从map中移除该条目
|
||||
delete it->second.first;
|
||||
message_map_.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,14 +16,14 @@ public:
|
||||
|
||||
void add_message(const model_data &message);
|
||||
ctaiHistoryTextEdit *current_message() const;
|
||||
|
||||
private:
|
||||
std::map<QString, std::pair<model_data *, int>> message_map_; // int存储行号
|
||||
|
||||
void setup_table();
|
||||
void update_stored_data(model_data *stored_data, const model_data &message);
|
||||
private slots:
|
||||
void on_msg_remove(QString send_id);
|
||||
void on_rows_height_changed(bool); // 新增槽函数处理高度变化
|
||||
void slotsRemoveMsg(QString send_id);
|
||||
void slotsRowsHeightSync(bool); // 新增槽函数处理高度变化
|
||||
signals:
|
||||
void signalsWidgetHisResToSend(QString, HISTORY_SEND_MODE);
|
||||
};
|
||||
#endif
|
||||
@ -5,6 +5,7 @@ ctaiSessionInfo::ctaiSessionInfo()
|
||||
init_layout();
|
||||
init_sub_layout();
|
||||
init_curl();
|
||||
initConnect();
|
||||
}
|
||||
ctaiSessionInfo::~ctaiSessionInfo()
|
||||
{
|
||||
@ -120,6 +121,18 @@ void ctaiSessionInfo::init_curl()
|
||||
connect(m_curl, SIGNAL(send_post_out_data(model_data)), this, SLOT(ctai_session_postback_info(model_data)));
|
||||
connect(m_curl, SIGNAL(send_post_out_error(std::string)), this, SLOT(ctai_session_curl_state_tips(std::string)));
|
||||
}
|
||||
void ctaiSessionInfo::initConnect(){
|
||||
connect(m_session_systeam_info, SIGNAL(signalsWidgetHisResToSend(QString, HISTORY_SEND_MODE)), this, SLOT(ctaiSessionHisToSend(QString, HISTORY_SEND_MODE)));
|
||||
}
|
||||
void ctaiSessionInfo::ctaiSessionHisToSend(QString msg, HISTORY_SEND_MODE send_mode)
|
||||
{
|
||||
m_session_user_edit_info->setText(msg);
|
||||
if(send_mode==HISTORY_SEND_RESTART)
|
||||
{
|
||||
ctai_session_user_sending();
|
||||
}
|
||||
}
|
||||
|
||||
void ctaiSessionInfo::btn_disable_enable(bool state)
|
||||
{
|
||||
m_btns[5]->setEnabled(state);
|
||||
|
||||
@ -24,8 +24,9 @@ private:
|
||||
void init_layout();
|
||||
void init_sub_layout();
|
||||
void init_user_btn_layout();
|
||||
void init_user_btn_size_tips(QPushButton &btn, QSize, QString);
|
||||
void init_user_btn_size_tips(QPushButton &btn, QSize, QString);
|
||||
void btn_disable_enable(bool);
|
||||
void initConnect();
|
||||
private:
|
||||
QVBoxLayout* mainLayout;
|
||||
QSplitter *splitter;
|
||||
@ -78,5 +79,6 @@ private slots:
|
||||
void ctai_session_postback_info(model_data resp_data);
|
||||
void ctai_session_set_steam_mode(bool);
|
||||
void ctai_session_curl_state_tips(std::string);
|
||||
void ctaiSessionHisToSend(QString, HISTORY_SEND_MODE);
|
||||
};
|
||||
#endif // CTAI_SESSION_TABLE_H
|
||||
|
||||
@ -23,7 +23,7 @@ bool ctaiSwitchButton::SwBtn_isChecked() const
|
||||
void ctaiSwitchButton::setSwBtn_Status(bool check)
|
||||
{
|
||||
m_SwBtn_Status=check;
|
||||
m_SwBtn_timer.start(1);
|
||||
m_SwBtn_timer.start(5);
|
||||
}
|
||||
|
||||
void ctaiSwitchButton::setSwBtn_BackgroundColor(QColor color)
|
||||
@ -116,7 +116,7 @@ void ctaiSwitchButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
event->accept();
|
||||
m_SwBtn_Status=!m_SwBtn_Status;
|
||||
emit SwBtn_SWITCH(m_SwBtn_Status);
|
||||
m_SwBtn_timer.start(10);
|
||||
m_SwBtn_timer.start(5);
|
||||
}
|
||||
else{
|
||||
event->ignore();
|
||||
|
||||
@ -12,11 +12,28 @@
|
||||
#define QSN(str) (QString::number)(str)
|
||||
#endif
|
||||
|
||||
// tokens消耗数据
|
||||
typedef struct tokens_args
|
||||
{
|
||||
QString prompt_tokens = {};
|
||||
QString completion_tokens = {};
|
||||
QString total_tokens = {};
|
||||
QString cache_hit_tokens = {};
|
||||
QString cache_miss_tokens = {};
|
||||
} tokens_data;
|
||||
|
||||
//插入SEND信息框模式,主要区分插入和重试
|
||||
typedef enum HISTORY_SEND_MODE{
|
||||
HISTORY_SEND_INSERT,
|
||||
HISTORY_SEND_RESTART
|
||||
}HISTORY_SEND_MODE;
|
||||
|
||||
// 消息模式,主要用于区分传入ctaiHistoryTextEdit控件信息来源
|
||||
typedef enum msg_mode{
|
||||
SYSTEM,
|
||||
USER
|
||||
}msg_type;
|
||||
|
||||
//CURL配置
|
||||
typedef struct curl_opts
|
||||
{
|
||||
bool ssl_state = true;
|
||||
@ -25,7 +42,7 @@ typedef struct curl_opts
|
||||
bool keepalive = false;
|
||||
bool verbose = true;
|
||||
} curl_opts;
|
||||
|
||||
//模型参数和数据,包含大模型返回数据
|
||||
typedef struct model_data{
|
||||
std::string api_url = "https://api.deepseek.com/chat/completions";
|
||||
std::string api_key = "Authorization: Bearer sk-7e6932ed45674c389dea1cd3481e0ec2";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user