微调部分按钮
This commit is contained in:
parent
982b11b396
commit
2e8d9b29e8
@ -29,31 +29,32 @@ void ctai_history_textedit::init_layout(msg_type msg_type_mode)
|
||||
headerLayout->addLayout(header_info_Layout);
|
||||
// 2.tokens功能按钮
|
||||
m_msg_tokens = new QPushButton();
|
||||
m_msg_tokens->setObjectName("m_msg_tokens");
|
||||
m_history_to_send = new QPushButton();
|
||||
m_history_to_send->setObjectName("m_history_to_send");
|
||||
m_msg_system_del = new QPushButton();
|
||||
m_restart_to_send = 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_restart_to_send);
|
||||
header_info_Layout->addWidget(m_msg_system_del);
|
||||
// 3.消息功能区
|
||||
|
||||
header_opts_Layout = new QHBoxLayout();
|
||||
m_msg_system_del = new QPushButton();
|
||||
header_opts_Layout = new QHBoxLayout();
|
||||
m_msg_copy = new QPushButton();
|
||||
m_msg_save = new QPushButton();
|
||||
m_msg_menu = new QPushButton();
|
||||
m_msg_fold = new QPushButton();
|
||||
m_restart_to_send = new QPushButton();
|
||||
m_msg_system_del->setObjectName("m_msg_system_del");
|
||||
m_restart_to_send->setObjectName("m_restart_to_send");
|
||||
|
||||
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->setMinimumSize(QSize(25, 25));
|
||||
header_opts_Layout->addItem(sparcer_item);
|
||||
header_opts_Layout->addWidget(m_restart_to_send);
|
||||
header_opts_Layout->addWidget(m_msg_system_del);
|
||||
header_opts_Layout->addItem(sparcer_item);
|
||||
header_opts_Layout->addWidget(m_msg_copy);
|
||||
header_opts_Layout->addWidget(m_msg_save);
|
||||
header_opts_Layout->addWidget(m_msg_menu);
|
||||
@ -77,9 +78,9 @@ void ctai_history_textedit::init_layout(msg_type msg_type_mode)
|
||||
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_restart_to_send);
|
||||
m_restart_to_send->setObjectName("m_restart_to_send");
|
||||
header_info_Layout->addWidget(m_history_to_send);
|
||||
header_info_Layout->addWidget(m_restart_to_send);
|
||||
header_info_Layout->addWidget(m_msg_user_del);
|
||||
}
|
||||
// 4.分割线区域
|
||||
@ -201,10 +202,9 @@ void ctai_history_textedit::on_fold_clicked()
|
||||
m_is_folded = !m_is_folded;
|
||||
|
||||
m_msg_history->setFixedHeight(m_is_folded ? 0 : m_original_height);
|
||||
|
||||
m_msg_fold->setIcon(QIcon(m_is_folded ? ":res/img/btn/btn_info_down.png" : ":res/img/btn/btn_info_up.png"));
|
||||
updateGeometry();
|
||||
emit fold_row_height_changed();
|
||||
emit row_height_changed(m_is_folded);
|
||||
}
|
||||
void ctai_history_textedit::on_text_height()
|
||||
{
|
||||
@ -236,7 +236,7 @@ void ctai_history_textedit::on_text_height()
|
||||
m_msg_history->setFixedHeight(newHeight);
|
||||
updateGeometry();
|
||||
m_msg_history->blockSignals(wasBlocked);
|
||||
emit current_row_height_changed();
|
||||
emit row_height_changed(false);
|
||||
|
||||
// 延迟发送布局更新请求
|
||||
if (QWidget *parent = parentWidget())
|
||||
|
||||
@ -67,8 +67,7 @@ private slots:
|
||||
void on_text_height();
|
||||
signals:
|
||||
void delete_requested(QString); // 请求删除此消息
|
||||
void current_row_height_changed();
|
||||
void fold_row_height_changed();
|
||||
void row_height_changed(bool);
|
||||
private:
|
||||
void connect_signals(msg_type msg_type_mode); // 连接信号和槽
|
||||
private:
|
||||
|
||||
@ -48,13 +48,13 @@ void ctai_history_widget::add_message(const model_data &message)
|
||||
model_data *stored_data = it->second.first;
|
||||
int row = it->second.second;
|
||||
|
||||
//如果传入的对象属性为null或者[DONE]表示传输完毕或者其他情况
|
||||
//此时需要将tokens更新掉所有其他属性不更新传输数据
|
||||
// 如果传入的对象属性为null或者[DONE]表示传输完毕或者其他情况
|
||||
// 此时需要将tokens更新掉所有其他属性不更新传输数据
|
||||
QWidget *widget = cellWidget(row, 0);
|
||||
if (!QSL(message.postback_model_data).isEmpty() &&
|
||||
!QSL(message.postback_model_data).contains("[DONE]"))
|
||||
{
|
||||
//更新传入信息
|
||||
// 更新传入信息
|
||||
stored_data->postback_model_data += message.postback_model_data;
|
||||
if (auto message_widget = qobject_cast<ctai_history_textedit *>(widget))
|
||||
{
|
||||
@ -63,7 +63,7 @@ void ctai_history_widget::add_message(const model_data &message)
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新tokens信息
|
||||
// 更新tokens信息
|
||||
update_stored_data(stored_data, message);
|
||||
if (auto message_widget = qobject_cast<ctai_history_textedit *>(widget))
|
||||
{
|
||||
@ -78,15 +78,18 @@ void ctai_history_widget::add_message(const model_data &message)
|
||||
ctai_history_textedit *message_widget = new ctai_history_textedit(this);
|
||||
message_widget->init_layout(new_data->msg_type_mode);
|
||||
message_widget->show();
|
||||
if(new_data->msg_type_mode==SYSTEM){
|
||||
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);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
message_widget->add_header_message(*new_data);
|
||||
message_widget->add_user_message(*new_data);
|
||||
}
|
||||
|
||||
|
||||
// 创建新行
|
||||
int row = rowCount();
|
||||
insertRow(row);
|
||||
@ -96,35 +99,38 @@ void ctai_history_widget::add_message(const model_data &message)
|
||||
// 连接删除信号
|
||||
connect(message_widget, SIGNAL(delete_requested(QString)), this, SLOT(on_msg_remove(QString)));
|
||||
// 连接高度变化信号
|
||||
connect(message_widget, &ctai_history_textedit::current_row_height_changed,this, &ctai_history_widget::on_current_rows_height_changed);
|
||||
connect(message_widget, &ctai_history_textedit::fold_row_height_changed,this, &ctai_history_widget::on_rows_height_changed);
|
||||
connect(message_widget, SIGNAL(row_height_changed(bool)), this, SLOT(on_rows_height_changed(bool)));
|
||||
// 滚动到新消息
|
||||
scrollToItem(item(row, 0));
|
||||
}
|
||||
// 立即滚动到底部
|
||||
scrollToBottom();
|
||||
}
|
||||
//适合信息折叠
|
||||
void ctai_history_widget::on_rows_height_changed()
|
||||
// 自适应信息高度
|
||||
void ctai_history_widget::on_rows_height_changed(bool fold_state)
|
||||
{
|
||||
//全部行高自适应
|
||||
for (int row = 0; row < rowCount()-1; ++row) {
|
||||
resizeRowToContents(row);
|
||||
if (fold_state)
|
||||
{
|
||||
// 全部行高自适应
|
||||
for (int row = 0; row < rowCount(); ++row)
|
||||
{
|
||||
setRowHeight(row, 87);
|
||||
resizeRowToContents(row);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int row = rowCount() - 1;
|
||||
if (row >= 0 && row < rowCount())
|
||||
{
|
||||
int currentHeight = rowHeight(row);
|
||||
setRowHeight(row, currentHeight + 100);
|
||||
resizeRowToContents(row);
|
||||
}
|
||||
}
|
||||
scrollToBottom();
|
||||
}
|
||||
//适合自适应流式输出内容
|
||||
void ctai_history_widget::on_current_rows_height_changed()
|
||||
{
|
||||
int row = rowCount()-1;
|
||||
if (row >= 0 && row < rowCount()) {
|
||||
int currentHeight = rowHeight(row);
|
||||
setRowHeight(row, currentHeight + 100);
|
||||
resizeRowToContents(row);
|
||||
}
|
||||
//resizeRowToContents(rowCount()-1);
|
||||
//scrollToBottom();
|
||||
}
|
||||
|
||||
void ctai_history_widget::on_msg_remove(QString send_id)
|
||||
{
|
||||
int row = this->rowCount();
|
||||
|
||||
@ -24,7 +24,6 @@ private:
|
||||
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(); // 新增槽函数处理高度变化
|
||||
void on_current_rows_height_changed();
|
||||
void on_rows_height_changed(bool); // 新增槽函数处理高度变化
|
||||
};
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user