微调部分按钮
This commit is contained in:
parent
982b11b396
commit
2e8d9b29e8
@ -29,22 +29,25 @@ void ctai_history_textedit::init_layout(msg_type msg_type_mode)
|
|||||||
headerLayout->addLayout(header_info_Layout);
|
headerLayout->addLayout(header_info_Layout);
|
||||||
// 2.tokens功能按钮
|
// 2.tokens功能按钮
|
||||||
m_msg_tokens = new QPushButton();
|
m_msg_tokens = new QPushButton();
|
||||||
m_msg_tokens->setObjectName("m_msg_tokens");
|
|
||||||
m_history_to_send = new QPushButton();
|
m_history_to_send = new QPushButton();
|
||||||
|
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_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_history_to_send);
|
||||||
header_info_Layout->addWidget(m_msg_tokens);
|
header_info_Layout->addWidget(m_msg_tokens);
|
||||||
|
header_info_Layout->addWidget(m_restart_to_send);
|
||||||
|
header_info_Layout->addWidget(m_msg_system_del);
|
||||||
// 3.消息功能区
|
// 3.消息功能区
|
||||||
|
|
||||||
header_opts_Layout = new QHBoxLayout();
|
header_opts_Layout = new QHBoxLayout();
|
||||||
m_msg_system_del = new QPushButton();
|
|
||||||
m_msg_copy = new QPushButton();
|
m_msg_copy = new QPushButton();
|
||||||
m_msg_save = new QPushButton();
|
m_msg_save = new QPushButton();
|
||||||
m_msg_menu = new QPushButton();
|
m_msg_menu = new QPushButton();
|
||||||
m_msg_fold = 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_copy->setObjectName("m_msg_copy");
|
||||||
m_msg_save->setObjectName("m_msg_save");
|
m_msg_save->setObjectName("m_msg_save");
|
||||||
m_msg_menu->setObjectName("m_msg_menu");
|
m_msg_menu->setObjectName("m_msg_menu");
|
||||||
@ -52,8 +55,6 @@ void ctai_history_textedit::init_layout(msg_type msg_type_mode)
|
|||||||
m_msg_fold->setIcon(QIcon(":res/img/btn/btn_info_up.png"));
|
m_msg_fold->setIcon(QIcon(":res/img/btn/btn_info_up.png"));
|
||||||
m_msg_fold->setMinimumSize(QSize(25, 25));
|
m_msg_fold->setMinimumSize(QSize(25, 25));
|
||||||
header_opts_Layout->addItem(sparcer_item);
|
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->addWidget(m_msg_copy);
|
header_opts_Layout->addWidget(m_msg_copy);
|
||||||
header_opts_Layout->addWidget(m_msg_save);
|
header_opts_Layout->addWidget(m_msg_save);
|
||||||
header_opts_Layout->addWidget(m_msg_menu);
|
header_opts_Layout->addWidget(m_msg_menu);
|
||||||
@ -78,8 +79,8 @@ void ctai_history_textedit::init_layout(msg_type msg_type_mode)
|
|||||||
m_history_to_send->setObjectName("m_history_to_send");
|
m_history_to_send->setObjectName("m_history_to_send");
|
||||||
m_restart_to_send = new QPushButton();
|
m_restart_to_send = new QPushButton();
|
||||||
m_restart_to_send->setObjectName("m_restart_to_send");
|
m_restart_to_send->setObjectName("m_restart_to_send");
|
||||||
header_info_Layout->addWidget(m_restart_to_send);
|
|
||||||
header_info_Layout->addWidget(m_history_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);
|
header_info_Layout->addWidget(m_msg_user_del);
|
||||||
}
|
}
|
||||||
// 4.分割线区域
|
// 4.分割线区域
|
||||||
@ -201,10 +202,9 @@ void ctai_history_textedit::on_fold_clicked()
|
|||||||
m_is_folded = !m_is_folded;
|
m_is_folded = !m_is_folded;
|
||||||
|
|
||||||
m_msg_history->setFixedHeight(m_is_folded ? 0 : m_original_height);
|
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"));
|
m_msg_fold->setIcon(QIcon(m_is_folded ? ":res/img/btn/btn_info_down.png" : ":res/img/btn/btn_info_up.png"));
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
emit fold_row_height_changed();
|
emit row_height_changed(m_is_folded);
|
||||||
}
|
}
|
||||||
void ctai_history_textedit::on_text_height()
|
void ctai_history_textedit::on_text_height()
|
||||||
{
|
{
|
||||||
@ -236,7 +236,7 @@ void ctai_history_textedit::on_text_height()
|
|||||||
m_msg_history->setFixedHeight(newHeight);
|
m_msg_history->setFixedHeight(newHeight);
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
m_msg_history->blockSignals(wasBlocked);
|
m_msg_history->blockSignals(wasBlocked);
|
||||||
emit current_row_height_changed();
|
emit row_height_changed(false);
|
||||||
|
|
||||||
// 延迟发送布局更新请求
|
// 延迟发送布局更新请求
|
||||||
if (QWidget *parent = parentWidget())
|
if (QWidget *parent = parentWidget())
|
||||||
|
|||||||
@ -67,8 +67,7 @@ private slots:
|
|||||||
void on_text_height();
|
void on_text_height();
|
||||||
signals:
|
signals:
|
||||||
void delete_requested(QString); // 请求删除此消息
|
void delete_requested(QString); // 请求删除此消息
|
||||||
void current_row_height_changed();
|
void row_height_changed(bool);
|
||||||
void fold_row_height_changed();
|
|
||||||
private:
|
private:
|
||||||
void connect_signals(msg_type msg_type_mode); // 连接信号和槽
|
void connect_signals(msg_type msg_type_mode); // 连接信号和槽
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -78,11 +78,14 @@ void ctai_history_widget::add_message(const model_data &message)
|
|||||||
ctai_history_textedit *message_widget = new ctai_history_textedit(this);
|
ctai_history_textedit *message_widget = new ctai_history_textedit(this);
|
||||||
message_widget->init_layout(new_data->msg_type_mode);
|
message_widget->init_layout(new_data->msg_type_mode);
|
||||||
message_widget->show();
|
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->add_header_message(*new_data);
|
||||||
message_widget->update_tokens_message(*new_data);
|
message_widget->update_tokens_message(*new_data);
|
||||||
message_widget->add_system_message(*new_data);
|
message_widget->add_system_message(*new_data);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
message_widget->add_header_message(*new_data);
|
message_widget->add_header_message(*new_data);
|
||||||
message_widget->add_user_message(*new_data);
|
message_widget->add_user_message(*new_data);
|
||||||
}
|
}
|
||||||
@ -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, 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, SIGNAL(row_height_changed(bool)), this, SLOT(on_rows_height_changed(bool)));
|
||||||
connect(message_widget, &ctai_history_textedit::fold_row_height_changed,this, &ctai_history_widget::on_rows_height_changed);
|
|
||||||
// 滚动到新消息
|
// 滚动到新消息
|
||||||
scrollToItem(item(row, 0));
|
scrollToItem(item(row, 0));
|
||||||
}
|
}
|
||||||
// 立即滚动到底部
|
// 立即滚动到底部
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
//适合信息折叠
|
// 自适应信息高度
|
||||||
void ctai_history_widget::on_rows_height_changed()
|
void ctai_history_widget::on_rows_height_changed(bool fold_state)
|
||||||
|
{
|
||||||
|
if (fold_state)
|
||||||
{
|
{
|
||||||
// 全部行高自适应
|
// 全部行高自适应
|
||||||
for (int row = 0; row < rowCount()-1; ++row) {
|
for (int row = 0; row < rowCount(); ++row)
|
||||||
|
{
|
||||||
|
setRowHeight(row, 87);
|
||||||
resizeRowToContents(row);
|
resizeRowToContents(row);
|
||||||
}
|
}
|
||||||
scrollToBottom();
|
|
||||||
}
|
}
|
||||||
//适合自适应流式输出内容
|
else
|
||||||
void ctai_history_widget::on_current_rows_height_changed()
|
|
||||||
{
|
{
|
||||||
int row = rowCount() - 1;
|
int row = rowCount() - 1;
|
||||||
if (row >= 0 && row < rowCount()) {
|
if (row >= 0 && row < rowCount())
|
||||||
|
{
|
||||||
int currentHeight = rowHeight(row);
|
int currentHeight = rowHeight(row);
|
||||||
setRowHeight(row, currentHeight + 100);
|
setRowHeight(row, currentHeight + 100);
|
||||||
resizeRowToContents(row);
|
resizeRowToContents(row);
|
||||||
}
|
}
|
||||||
//resizeRowToContents(rowCount()-1);
|
|
||||||
//scrollToBottom();
|
|
||||||
}
|
}
|
||||||
|
scrollToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
void ctai_history_widget::on_msg_remove(QString send_id)
|
void ctai_history_widget::on_msg_remove(QString send_id)
|
||||||
{
|
{
|
||||||
int row = this->rowCount();
|
int row = this->rowCount();
|
||||||
|
|||||||
@ -24,7 +24,6 @@ private:
|
|||||||
void update_stored_data(model_data* stored_data, const model_data& message);
|
void update_stored_data(model_data* stored_data, const model_data& message);
|
||||||
private slots:
|
private slots:
|
||||||
void on_msg_remove(QString send_id);
|
void on_msg_remove(QString send_id);
|
||||||
void on_rows_height_changed(); // 新增槽函数处理高度变化
|
void on_rows_height_changed(bool); // 新增槽函数处理高度变化
|
||||||
void on_current_rows_height_changed();
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user