mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-07-14 02:54:48 -04:00
Add components for chat
This commit is contained in:
@ -12,6 +12,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
|||||||
find_package(QtCreator REQUIRED COMPONENTS Core)
|
find_package(QtCreator REQUIRED COMPONENTS Core)
|
||||||
find_package(Qt6 COMPONENTS Core Gui Widgets Network REQUIRED)
|
find_package(Qt6 COMPONENTS Core Gui Widgets Network REQUIRED)
|
||||||
|
|
||||||
|
add_subdirectory(chatview)
|
||||||
|
|
||||||
add_qtc_plugin(QodeAssist
|
add_qtc_plugin(QodeAssist
|
||||||
PLUGIN_DEPENDS
|
PLUGIN_DEPENDS
|
||||||
QtCreator::Core
|
QtCreator::Core
|
||||||
@ -62,4 +64,7 @@ add_qtc_plugin(QodeAssist
|
|||||||
chat/ChatWidget.h chat/ChatWidget.cpp
|
chat/ChatWidget.h chat/ChatWidget.cpp
|
||||||
chat/ChatOutputPane.h chat/ChatOutputPane.cpp
|
chat/ChatOutputPane.h chat/ChatOutputPane.cpp
|
||||||
chat/ChatClientInterface.hpp chat/ChatClientInterface.cpp
|
chat/ChatClientInterface.hpp chat/ChatClientInterface.cpp
|
||||||
|
chat/NavigationPanel.hpp chat/NavigationPanel.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries(QodeAssist PUBLIC QodeAssistChatViewplugin)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"Name" : "QodeAssist",
|
"Name" : "QodeAssist",
|
||||||
"Version" : "0.2.3",
|
"Version" : "0.2.4",
|
||||||
"CompatVersion" : "${IDE_VERSION_COMPAT}",
|
"CompatVersion" : "${IDE_VERSION_COMPAT}",
|
||||||
"Vendor" : "Petr Mironychev",
|
"Vendor" : "Petr Mironychev",
|
||||||
"Copyright" : "(C) ${IDE_COPYRIGHT_YEAR} Petr Mironychev, (C) ${IDE_COPYRIGHT_YEAR} The Qt Company Ltd",
|
"Copyright" : "(C) ${IDE_COPYRIGHT_YEAR} Petr Mironychev, (C) ${IDE_COPYRIGHT_YEAR} The Qt Company Ltd",
|
||||||
|
45
chat/NavigationPanel.cpp
Normal file
45
chat/NavigationPanel.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "NavigationPanel.hpp"
|
||||||
|
|
||||||
|
#include "chatview/BaseChatWidget.hpp"
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
NavigationPanel::NavigationPanel() {
|
||||||
|
setDisplayName(tr("QodeAssist Chat"));
|
||||||
|
setPriority(500);
|
||||||
|
setId("QodeAssistChat");
|
||||||
|
setActivationSequence(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_C));
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationPanel::~NavigationPanel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::NavigationView NavigationPanel::createWidget()
|
||||||
|
{
|
||||||
|
Core::NavigationView view;
|
||||||
|
view.widget = new BaseChatWidget;
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
chat/NavigationPanel.hpp
Normal file
37
chat/NavigationPanel.hpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <coreplugin/inavigationwidgetfactory.h>
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
class NavigationPanel : public Core::INavigationWidgetFactory
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit NavigationPanel();
|
||||||
|
~NavigationPanel();
|
||||||
|
|
||||||
|
Core::NavigationView createWidget() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
35
chatview/BaseChatWidget.cpp
Normal file
35
chatview/BaseChatWidget.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "BaseChatWidget.hpp"
|
||||||
|
|
||||||
|
#include <QQmlEngine>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
BaseChatWidget::BaseChatWidget(QWidget *parent) : QQuickWidget(parent)
|
||||||
|
{
|
||||||
|
setSource(QUrl("qrc:/ChatView/qml/RootItem.qml"));
|
||||||
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||||
|
|
||||||
|
engine()->rootContext()->setContextObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
chatview/BaseChatWidget.hpp
Normal file
35
chatview/BaseChatWidget.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtQuickWidgets/QtQuickWidgets>
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
class BaseChatWidget : public QQuickWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit BaseChatWidget(QWidget *parent = nullptr);
|
||||||
|
~BaseChatWidget() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
26
chatview/CMakeLists.txt
Normal file
26
chatview/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
qt_add_library(QodeAssistChatView STATIC)
|
||||||
|
|
||||||
|
find_package(Qt6 COMPONENTS Core Widgets Quick QuickWidgets Network REQUIRED)
|
||||||
|
|
||||||
|
qt_add_qml_module(QodeAssistChatView
|
||||||
|
URI ChatView
|
||||||
|
VERSION 1.0
|
||||||
|
QML_FILES
|
||||||
|
qml/RootItem.qml
|
||||||
|
SOURCES
|
||||||
|
BaseChatWidget.hpp BaseChatWidget.cpp
|
||||||
|
ChatModel.hpp ChatModel.cpp
|
||||||
|
ChatRootView.hpp ChatRootView.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(QodeAssistChatView
|
||||||
|
PRIVATE
|
||||||
|
Qt::Widgets
|
||||||
|
Qt::Quick
|
||||||
|
Qt::QuickWidgets
|
||||||
|
Qt::Network
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(QodeAssistChatView
|
||||||
|
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
72
chatview/ChatModel.cpp
Normal file
72
chatview/ChatModel.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ChatModel.hpp"
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
ChatModel::ChatModel(QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int ChatModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return m_messages.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ChatModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid() || index.row() >= m_messages.size())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const Message &message = m_messages[index.row()];
|
||||||
|
switch (static_cast<Roles>(role)) {
|
||||||
|
case Roles::RoleType:
|
||||||
|
return QVariant::fromValue(message.role);
|
||||||
|
case Roles::Content:
|
||||||
|
return message.content;
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> ChatModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[Roles::RoleType] = "roleType";
|
||||||
|
roles[Roles::Content] = "content";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatModel::addMessage(const QString &content, ChatRole role)
|
||||||
|
{
|
||||||
|
beginInsertRows(QModelIndex(), m_messages.size(), m_messages.size());
|
||||||
|
m_messages.append({role, content});
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatModel::clear()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_messages.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Chat
|
56
chatview/ChatModel.hpp
Normal file
56
chatview/ChatModel.hpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
enum class ChatRole { System, User, Assistant };
|
||||||
|
|
||||||
|
struct Message
|
||||||
|
{
|
||||||
|
ChatRole role;
|
||||||
|
QString content;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ChatModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Roles { RoleType = Qt::UserRole, Content };
|
||||||
|
|
||||||
|
explicit ChatModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
Q_INVOKABLE void addMessage(const QString &content, ChatRole role);
|
||||||
|
Q_INVOKABLE void clear();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVector<Message> m_messages;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Chat
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(QodeAssist::Chat::ChatRole)
|
34
chatview/ChatRootView.cpp
Normal file
34
chatview/ChatRootView.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ChatRootView.hpp"
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
ChatRootView::ChatRootView(QQuickItem *parent)
|
||||||
|
: QQuickItem(parent)
|
||||||
|
, m_chatModel(new ChatModel(this))
|
||||||
|
{}
|
||||||
|
|
||||||
|
ChatModel *ChatRootView::chatModel() const
|
||||||
|
{
|
||||||
|
return m_chatModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Chat
|
46
chatview/ChatRootView.hpp
Normal file
46
chatview/ChatRootView.hpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
#include "ChatModel.hpp"
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
|
||||||
|
class ChatRootView : public QQuickItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
|
||||||
|
Q_PROPERTY(ChatModel *chatModel READ chatModel NOTIFY chatModelChanged FINAL)
|
||||||
|
public:
|
||||||
|
ChatRootView(QQuickItem *parent = nullptr);
|
||||||
|
|
||||||
|
ChatModel *chatModel() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void chatModelChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ChatModel *m_chatModel = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Chat
|
13
chatview/qml/RootItem.qml
Normal file
13
chatview/qml/RootItem.qml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import QtQuick
|
||||||
|
import ChatView
|
||||||
|
|
||||||
|
ChatRootView {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: bg
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
color: "gray"
|
||||||
|
}
|
||||||
|
}
|
@ -124,9 +124,9 @@ public:
|
|||||||
|
|
||||||
void restartClient()
|
void restartClient()
|
||||||
{
|
{
|
||||||
LanguageClient::LanguageClientManager::shutdownClient(m_qodeAssistClient);
|
LanguageClient::LanguageClientManager::shutdownClient(m_qodeAssistClient.get());
|
||||||
|
|
||||||
m_qodeAssistClient = new QodeAssistClient();
|
m_qodeAssistClient.reset(new QodeAssistClient());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool delayedInitialize() final
|
bool delayedInitialize() final
|
||||||
@ -140,7 +140,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (!m_qodeAssistClient)
|
if (!m_qodeAssistClient)
|
||||||
return SynchronousShutdown;
|
return SynchronousShutdown;
|
||||||
connect(m_qodeAssistClient,
|
connect(m_qodeAssistClient.get(),
|
||||||
&QObject::destroyed,
|
&QObject::destroyed,
|
||||||
this,
|
this,
|
||||||
&IPlugin::asynchronousShutdownFinished);
|
&IPlugin::asynchronousShutdownFinished);
|
||||||
@ -148,7 +148,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<QodeAssistClient> m_qodeAssistClient;
|
QScopedPointer<QodeAssistClient> m_qodeAssistClient;
|
||||||
QPointer<Chat::ChatOutputPane> m_chatOutputPane;
|
QPointer<Chat::ChatOutputPane> m_chatOutputPane;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user