From 1deeeacbd2c9ed139f9e3549b5de0ef1c35130d3 Mon Sep 17 00:00:00 2001 From: liuyangming Date: Fri, 17 Nov 2023 14:50:50 +0800 Subject: [PATCH] fix: set delete button disable while ai anwsering. as title --- src/plugins/codegeex/codegeexmanager.cpp | 2 ++ src/plugins/codegeex/codegeexmanager.h | 1 + src/plugins/codegeex/data/messagedata.cpp | 9 ----- .../codegeex/widgets/codegeexwidget.cpp | 34 ++++++++++++++----- src/plugins/codegeex/widgets/codegeexwidget.h | 2 ++ 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/plugins/codegeex/codegeexmanager.cpp b/src/plugins/codegeex/codegeexmanager.cpp index bef86b54e..3642dca8d 100644 --- a/src/plugins/codegeex/codegeexmanager.cpp +++ b/src/plugins/codegeex/codegeexmanager.cpp @@ -103,6 +103,8 @@ void CodeGeeXManager::sendMessage(const QString &prompt) } QString machineId = QSysInfo::machineUniqueId(); askApi.postSSEChat(kUrlSSEChat, sessionId, prompt, machineId, history); + + Q_EMIT chatStarted(); } void CodeGeeXManager::onSessionCreated(const QString &talkId, bool isSuccessful) diff --git a/src/plugins/codegeex/codegeexmanager.h b/src/plugins/codegeex/codegeexmanager.h index 2a5809105..1efc46129 100644 --- a/src/plugins/codegeex/codegeexmanager.h +++ b/src/plugins/codegeex/codegeexmanager.h @@ -39,6 +39,7 @@ class CodeGeeXManager : public QObject void createdNewSession(); void requestMessageUpdate(const MessageData &msg); void requestToTransCode(const QString &code); + void chatStarted(); void chatFinished(); public Q_SLOTS: diff --git a/src/plugins/codegeex/data/messagedata.cpp b/src/plugins/codegeex/data/messagedata.cpp index af46de967..ca1de7b7c 100644 --- a/src/plugins/codegeex/data/messagedata.cpp +++ b/src/plugins/codegeex/data/messagedata.cpp @@ -24,15 +24,6 @@ void MessageData::updateData(const QString &data) if (lines.length() < msgDataLines.length()) return; -// QStringList newLines = lines.mid(msgDataLines.length()); -// for (auto line : newLines) { -// if (line.startsWith("```")) { -// CodeData data; -// data.langueage = line.mid(3); -// codeDataList.append(data); -// } -// } - msgData = data; msgDataLines = lines; // qInfo() << "update msg line" << msgDataLines; diff --git a/src/plugins/codegeex/widgets/codegeexwidget.cpp b/src/plugins/codegeex/widgets/codegeexwidget.cpp index 667203adc..cbf626045 100644 --- a/src/plugins/codegeex/widgets/codegeexwidget.cpp +++ b/src/plugins/codegeex/widgets/codegeexwidget.cpp @@ -73,6 +73,22 @@ void CodeGeeXWidget::toTranslateCode(const QString &code) tabBar->setCurrentIndex(1); } +void CodeGeeXWidget::onAnwserFinished() +{ + if (deleteBtn) + deleteBtn->setEnabled(true); + if (createNewBtn) + createNewBtn->setEnabled(true); +} + +void CodeGeeXWidget::onAnwserStarted() +{ + if (deleteBtn) + deleteBtn->setEnabled(false); + if (createNewBtn) + createNewBtn->setEnabled(false); +} + void CodeGeeXWidget::initUI() { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -119,6 +135,8 @@ void CodeGeeXWidget::initConnection() connect(CodeGeeXManager::instance(), &CodeGeeXManager::loginSuccessed, this, &CodeGeeXWidget::onLoginSuccessed); connect(CodeGeeXManager::instance(), &CodeGeeXManager::createdNewSession, this, &CodeGeeXWidget::onNewSessionCreated); connect(CodeGeeXManager::instance(), &CodeGeeXManager::requestToTransCode, this, &CodeGeeXWidget::toTranslateCode); + connect(CodeGeeXManager::instance(), &CodeGeeXManager::chatFinished, this, &CodeGeeXWidget::onAnwserFinished); + connect(CodeGeeXManager::instance(), &CodeGeeXManager::chatStarted, this, &CodeGeeXWidget::onAnwserStarted); } void CodeGeeXWidget::initAskWidget() @@ -145,10 +163,10 @@ void CodeGeeXWidget::initAskWidget() deleteBtn->setFlat(true); deleteBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_del_hover.png"))); headerLayout->addWidget(deleteBtn); - historyBtn = new DPushButton(this); - historyBtn->setFlat(true); - historyBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_history_hover.png"))); - headerLayout->addWidget(historyBtn); +// historyBtn = new DPushButton(this); +// historyBtn->setFlat(true); +// historyBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_history_hover.png"))); +// headerLayout->addWidget(historyBtn); createNewBtn = new DPushButton(this); createNewBtn->setFlat(true); createNewBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_new_hover.png"))); @@ -211,25 +229,25 @@ void CodeGeeXWidget::initAskWidgetConnection() stackWidget->setCurrentIndex(index + 1); }); connect(deleteBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onDeleteBtnClicked); - connect(historyBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onHistoryBtnClicked); +// connect(historyBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onHistoryBtnClicked); connect(createNewBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onCreateNewBtnClicked); } void CodeGeeXWidget::resetHeaderBtns() { - if (!deleteBtn || !historyBtn || !createNewBtn || !askPage) + if (!deleteBtn || /*!historyBtn ||*/ !createNewBtn || !askPage) return; switch (currentState) { case AskPage: deleteBtn->setVisible(!askPage->isIntroPageState()); createNewBtn->setVisible(!askPage->isIntroPageState()); - historyBtn->setVisible(true); +// historyBtn->setVisible(true); break; case TrasnlatePage: deleteBtn->setVisible(false); createNewBtn->setVisible(false); - historyBtn->setVisible(false); +// historyBtn->setVisible(false); break; } } diff --git a/src/plugins/codegeex/widgets/codegeexwidget.h b/src/plugins/codegeex/widgets/codegeexwidget.h index bf7625498..9e855c63a 100644 --- a/src/plugins/codegeex/widgets/codegeexwidget.h +++ b/src/plugins/codegeex/widgets/codegeexwidget.h @@ -38,6 +38,8 @@ public Q_SLOTS: void onHistoryBtnClicked(); void onCreateNewBtnClicked(); void toTranslateCode(const QString &code); + void onAnwserFinished(); + void onAnwserStarted(); private: void initUI();