main
朱子楚\zhuzi 2023-03-18 20:20:59 +08:00
parent c622f80659
commit 8eb7e1df4a
3 changed files with 64 additions and 3 deletions

View File

@ -48,3 +48,9 @@ QJsonObject ChatController::createMessage(const QString& role,const QString& con
message.insert("content",content); message.insert("content",content);
return message; return message;
} }
void ChatController::clipText(const QString& text){
qDebug()<<text;
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(text);
}

View File

@ -7,6 +7,8 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonArray> #include <QJsonArray>
#include <QGuiApplication>
#include <QClipboard>
#include <QByteArray> #include <QByteArray>
#include "stdafx.h" #include "stdafx.h"
@ -19,6 +21,7 @@ public:
explicit ChatController(QObject *parent = nullptr); explicit ChatController(QObject *parent = nullptr);
Q_INVOKABLE void sendMessage(const QString& text); Q_INVOKABLE void sendMessage(const QString& text);
Q_INVOKABLE void clipText(const QString& text);
private: private:
QJsonObject createMessage(const QString& role,const QString& content); QJsonObject createMessage(const QString& role,const QString& content);

View File

@ -3,6 +3,7 @@ import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15 import QtQuick.Controls 2.15
import FluentUI 1.0 import FluentUI 1.0
import Controller 1.0 import Controller 1.0
import Qt.labs.platform 1.1
FluWindow { FluWindow {
@ -42,13 +43,14 @@ FluWindow {
Component{ Component{
id:com_text id:com_text
TextEdit { TextEdit {
id:item_text
text: message text: message
wrapMode: Text.WrapAnywhere wrapMode: Text.WrapAnywhere
readOnly: true readOnly: true
selectByMouse: true selectByMouse: true
selectByKeyboard: true selectByKeyboard: true
selectedTextColor: color selectedTextColor: Qt.rgba(51,153,255,1)
textFormat:TextEdit.AutoText textFormat:TextEdit.MarkdownText
color:FluColors.Black color:FluColors.Black
selectionColor: { selectionColor: {
if(FluTheme.isDark){ if(FluTheme.isDark){
@ -58,6 +60,12 @@ FluWindow {
} }
} }
width: Math.min(list_message.width-200,600,implicitWidth) width: Math.min(list_message.width-200,600,implicitWidth)
TapHandler{
acceptedButtons: Qt.RightButton
onTapped: {
menu_item.showMenu(item_text.selectedText)
}
}
} }
} }
@ -71,7 +79,13 @@ FluWindow {
margins: 10 margins: 10
} }
color: FluTheme.isDark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(245/255,245/255,245/255,1) color: FluTheme.isDark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(245/255,245/255,245/255,1)
MouseArea{
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: {
menu_pannel.popup()
}
}
ListView{ ListView{
id:list_message id:list_message
anchors.fill: parent anchors.fill: parent
@ -222,6 +236,44 @@ FluWindow {
} }
} }
FluMenu{
id:menu_item
focus: false
property string selectedText: ""
FluMenuItem{
text:"复制"
onClicked: {
controller.clipText(menu_item.selectedText)
showSuccess("复制成功")
}
}
function showMenu(text){
menu_item.selectedText = text
menu_item.popup()
}
}
FluMenu{
id:menu_pannel
focus: false
FluMenuItem{
text:"导出消息"
onClicked: {
file_dialog.currentFile = "file:///123.txt"
file_dialog.open()
}
}
}
FileDialog{
id:file_dialog
fileMode:FileDialog.SaveFile
folder: StandardPaths.writableLocation(StandardPaths.DesktopLocation)
onAccepted: {
console.log("You chose: " + file_dialog.file)
}
}
function appendMessage(isMy,text){ function appendMessage(isMy,text){
model_message.append({isMy:isMy,text:text}) model_message.append({isMy:isMy,text:text})
list_message.positionViewAtEnd() list_message.positionViewAtEnd()