Skip to content

Commit

Permalink
chore: add answering state tips
Browse files Browse the repository at this point in the history
Log:
Change-Id: I4e7185538a56ae6664c28e2d3b74b25928f97130
  • Loading branch information
deepin-mozart committed Nov 16, 2023
1 parent 7983f8d commit 5fc1d71
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 24 deletions.
15 changes: 10 additions & 5 deletions assets/translations/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@
<context>
<name>AskPageWidget</name>
<message>
<location filename="../../src/plugins/codegeex/widgets/askpagewidget.cpp" line="100"/>
<location filename="../../src/plugins/codegeex/widgets/askpagewidget.cpp" line="27"/>
<source>Ask question here, press Enter to send...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/askpagewidget.cpp" line="128"/>
<source>Answering</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BinaryToolsConfigView</name>
Expand Down Expand Up @@ -2125,22 +2130,22 @@ storage: %2
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="105"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="102"/>
<source>Workspace</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="138"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="135"/>
<source>Watcher</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="238"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="235"/>
<source>Find ToolBar</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="263"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="260"/>
<source>Valgrind</source>
<translation type="unfinished"></translation>
</message>
Expand Down
15 changes: 10 additions & 5 deletions assets/translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@
<context>
<name>AskPageWidget</name>
<message>
<location filename="../../src/plugins/codegeex/widgets/askpagewidget.cpp" line="100"/>
<location filename="../../src/plugins/codegeex/widgets/askpagewidget.cpp" line="27"/>
<source>Ask question here, press Enter to send...</source>
<translation>在这里提问,按Enter键发送...</translation>
</message>
<message>
<location filename="../../src/plugins/codegeex/widgets/askpagewidget.cpp" line="128"/>
<source>Answering</source>
<translation>回答中</translation>
</message>
</context>
<context>
<name>BinaryToolsConfigView</name>
Expand Down Expand Up @@ -2160,22 +2165,22 @@ storage: %2
<translation>文本</translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="105"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="102"/>
<source>Workspace</source>
<translation>工作区</translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="138"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="135"/>
<source>Watcher</source>
<translation>视图</translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="238"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="235"/>
<source>Find ToolBar</source>
<translation>查找</translation>
</message>
<message>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="263"/>
<location filename="../../src/plugins/codeeditor/mainframe/naveditmainwindow.cpp" line="260"/>
<source>Valgrind</source>
<translation>Valgrind</translation>
</message>
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/codeeditor/mainframe/naveditmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ void NavEditMainWindow::addWidgetWorkspace(const QString &title, AbstractWidget
{
if (!qDockWidgetWorkspace) {
qTabWidgetWorkspace = new DTabWidget();
QFont font = qTabWidgetWorkspace->font();
font.setItalic(true);
qTabWidgetWorkspace->setFont(font);
qTabWidgetWorkspace->setMinimumHeight(300);
qTabWidgetWorkspace->setTabPosition(DTabWidget::West);
qDockWidgetWorkspace = new AutoHideDockWidget(DDockWidget::tr("Workspace"), this);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codegeex/codegeexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void CodeGeeXManager::onResponse(const QString &msgID, const QString &data, cons
}

if (event == "finish") {

emit chatFinished();
} else if (event == "add"){

}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/codegeex/codegeexmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CodeGeeXManager : public QObject
void loginSuccessed();
void createdNewSession();
void requestMessageUpdate(const MessageData &msg);
void chatFinished();

public Q_SLOTS:
void onSessionCreated(const QString &talkId, bool isSuccessful);
Expand Down
58 changes: 49 additions & 9 deletions src/plugins/codegeex/widgets/askpagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@
#include <QLabel>
#include <QDebug>
#include <QScrollBar>
#include <QTimer>

AskPageWidget::AskPageWidget(QWidget *parent)
: QWidget (parent)
, processTimer(new QTimer(this))
{
initUI();
initConnection();

processTimer->setInterval(200);
placeHolderText = tr("Ask question here, press Enter to send...");
}

void AskPageWidget::setIntroPage()
{
cleanWidgets();
curState = Intro;
scrollArea->setWidget(new IntroPage(scrollArea));
IntroPage *introPage = new IntroPage(scrollArea);
connect(introPage, &IntroPage::suggestionToSend, [this](const QString &suggesstion){
askQuestion(suggesstion);
});
scrollArea->setWidget(introPage);

Q_EMIT introPageShown();
}
Expand Down Expand Up @@ -64,11 +73,15 @@ void AskPageWidget::onSendBtnClicked()
if (prompt.isEmpty())
return;

CodeGeeXManager::instance()->sendMessage(prompt);
inputEdit->clear();
askQuestion(prompt);
}
}

void AskPageWidget::onChatFinished()
{
enterInputState();
}

void AskPageWidget::initUI()
{
setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -97,18 +110,24 @@ void AskPageWidget::initInputWidget()

inputEdit = new QLineEdit(inputWidget);
inputEdit->setFixedHeight(50);
inputEdit->setPlaceholderText(tr("Ask question here, press Enter to send..."));
inputEdit->setPlaceholderText(placeHolderText);
editLayout->addWidget(inputEdit);

// QLabel *inputTips = new QLabel(inputWidget);
// inputTips->setText(tr("Ctrl + Enter for Newline | \" / \" for command"));
// inputTips->setIndent(10);
// layout->addWidget(inputTips);
}

void AskPageWidget::initConnection()
{
connect(CodeGeeXManager::instance(), &CodeGeeXManager::requestMessageUpdate, this, &AskPageWidget::onMessageUpdate);
connect(CodeGeeXManager::instance(), &CodeGeeXManager::chatFinished, this, &AskPageWidget::onChatFinished);
connect(processTimer, &QTimer::timeout, [this](){
QString tips;
int maxDotNum = 4;
int dotNum = progressCalcNum++ % maxDotNum;
for (int i = 0; i < dotNum; i++) {
tips += "...";
}
QString holderText = tr("Answering") + tips;
inputEdit->setPlaceholderText(holderText);
});
connect(inputEdit, &QLineEdit::returnPressed, this, &AskPageWidget::onSendBtnClicked);
}

Expand All @@ -131,3 +150,24 @@ void AskPageWidget::setSessionPage()

Q_EMIT sessionPageShown();
}

void AskPageWidget::enterAnswerState()
{
progressCalcNum = 0;
inputEdit->clear();
inputEdit->setEnabled(false);
processTimer->start();
}

void AskPageWidget::enterInputState()
{
processTimer->stop();
inputEdit->setEnabled(true);
inputEdit->setPlaceholderText(placeHolderText);
}

void AskPageWidget::askQuestion(const QString &question)
{
CodeGeeXManager::instance()->sendMessage(question);
enterAnswerState();
}
9 changes: 9 additions & 0 deletions src/plugins/codegeex/widgets/askpagewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AskPageWidget : public QWidget
public Q_SLOTS:
void onMessageUpdate(const MessageData &msgData);
void onSendBtnClicked();
void onChatFinished();

private:
void initUI();
Expand All @@ -47,11 +48,19 @@ public Q_SLOTS:
void cleanWidgets();
void setSessionPage();

void enterAnswerState();
void enterInputState();

void askQuestion(const QString &question);

PageState curState;
QScrollArea *scrollArea { nullptr };
QWidget *inputWidget { nullptr };
QWidget *messageContainer { nullptr };
QLineEdit *inputEdit { nullptr };
QTimer *processTimer { nullptr };
int progressCalcNum = 0;
QString placeHolderText;

QMap<QString, MessageComponent*> msgComponents {};
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codegeex/widgets/intropage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ void IntroPage::appendSuggestButton(QVBoxLayout *layout, const QString &text)
layout->addWidget(suggestButton);

connect(suggestButton, &QPushButton::clicked, [ = ] {
CodeGeeXManager::instance()->sendMessage(suggestButton->text());
emit suggestionToSend(suggestButton->text());
});
}
3 changes: 3 additions & 0 deletions src/plugins/codegeex/widgets/intropage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class IntroPage : public QWidget
public:
explicit IntroPage(QWidget *parent = nullptr);

signals:
void suggestionToSend(const QString &suggesstion);

private:
void initUI();
void initLogo();
Expand Down

0 comments on commit 5fc1d71

Please sign in to comment.