From 8be279a5fdbeaf84c7a2e52c05f0c68b0db2b9fb Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Sun, 6 Oct 2024 17:54:00 +0200 Subject: [PATCH] Add base qml chat view to navigation panel --- CMakeLists.txt | 5 +++++ chat/NavigationPanel.cpp | 45 +++++++++++++++++++++++++++++++++++++ chat/NavigationPanel.hpp | 37 ++++++++++++++++++++++++++++++ chatview/BaseChatWidget.cpp | 35 +++++++++++++++++++++++++++++ chatview/BaseChatWidget.hpp | 34 ++++++++++++++++++++++++++++ chatview/CMakeLists.txt | 24 ++++++++++++++++++++ chatview/qml/ChatView.qml | 7 ++++++ qodeassist.cpp | 3 +++ 8 files changed, 190 insertions(+) create mode 100644 chat/NavigationPanel.cpp create mode 100644 chat/NavigationPanel.hpp create mode 100644 chatview/BaseChatWidget.cpp create mode 100644 chatview/BaseChatWidget.hpp create mode 100644 chatview/CMakeLists.txt create mode 100644 chatview/qml/ChatView.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index cef074d..dfd905a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,4 +62,9 @@ add_qtc_plugin(QodeAssist chat/ChatWidget.h chat/ChatWidget.cpp chat/ChatOutputPane.h chat/ChatOutputPane.cpp chat/ChatClientInterface.hpp chat/ChatClientInterface.cpp + chat/NavigationPanel.hpp chat/NavigationPanel.cpp ) + +add_subdirectory(chatview) + +target_link_libraries(QodeAssist PUBLIC QodeAssistChatViewplugin) diff --git a/chat/NavigationPanel.cpp b/chat/NavigationPanel.cpp new file mode 100644 index 0000000..19b9211 --- /dev/null +++ b/chat/NavigationPanel.cpp @@ -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 . + */ + +#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; +} + +} diff --git a/chat/NavigationPanel.hpp b/chat/NavigationPanel.hpp new file mode 100644 index 0000000..e7eff5a --- /dev/null +++ b/chat/NavigationPanel.hpp @@ -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 . + */ + +#pragma once + +#include +#include + +namespace QodeAssist::Chat { + +class NavigationPanel : public Core::INavigationWidgetFactory +{ + Q_OBJECT +public: + explicit NavigationPanel(); + ~NavigationPanel(); + + Core::NavigationView createWidget() override; +}; + +} diff --git a/chatview/BaseChatWidget.cpp b/chatview/BaseChatWidget.cpp new file mode 100644 index 0000000..427503d --- /dev/null +++ b/chatview/BaseChatWidget.cpp @@ -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 . + */ + +#include "BaseChatWidget.hpp" + +#include +#include + +namespace QodeAssist::Chat { + +BaseChatWidget::BaseChatWidget(QWidget *parent) +{ + setSource(QUrl("qrc:/ChatView/qml/ChatView.qml")); + setResizeMode(QQuickWidget::SizeRootObjectToView); + + engine()->rootContext()->setContextObject(this); +} + +} diff --git a/chatview/BaseChatWidget.hpp b/chatview/BaseChatWidget.hpp new file mode 100644 index 0000000..79f5b7e --- /dev/null +++ b/chatview/BaseChatWidget.hpp @@ -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 . + */ + +#pragma once + +#include + +namespace QodeAssist::Chat { + +class BaseChatWidget : public QQuickWidget +{ + Q_OBJECT +public: + explicit BaseChatWidget(QWidget *parent = nullptr); + ~BaseChatWidget() = default; +}; + +} diff --git a/chatview/CMakeLists.txt b/chatview/CMakeLists.txt new file mode 100644 index 0000000..be590c8 --- /dev/null +++ b/chatview/CMakeLists.txt @@ -0,0 +1,24 @@ +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/ChatView.qml + SOURCES + BaseChatWidget.hpp BaseChatWidget.cpp +) + +target_link_libraries(QodeAssistChatView + PRIVATE + Qt::Widgets + Qt::Quick + Qt::QuickWidgets + Qt::Network +) + +target_include_directories(QodeAssistChatView + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/chatview/qml/ChatView.qml b/chatview/qml/ChatView.qml new file mode 100644 index 0000000..a6a76c4 --- /dev/null +++ b/chatview/qml/ChatView.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + id: root + + color: "gray" +} diff --git a/qodeassist.cpp b/qodeassist.cpp index 87ea06d..e3f08e0 100644 --- a/qodeassist.cpp +++ b/qodeassist.cpp @@ -43,6 +43,7 @@ #include "PromptTemplateManager.hpp" #include "QodeAssistClient.hpp" #include "chat/ChatOutputPane.h" +#include "chat/NavigationPanel.hpp" #include "providers/LMStudioProvider.hpp" #include "providers/OllamaProvider.hpp" #include "providers/OpenAICompatProvider.hpp" @@ -116,6 +117,7 @@ class QodeAssistPlugin final : public ExtensionSystem::IPlugin StatusBarManager::addStatusBarWidget(toggleButton, StatusBarManager::RightCorner); m_chatOutputPane = new Chat::ChatOutputPane(this); + m_navigationPanel.reset(new Chat::NavigationPanel()); } void extensionsInitialized() final @@ -150,6 +152,7 @@ class QodeAssistPlugin final : public ExtensionSystem::IPlugin private: QScopedPointer m_qodeAssistClient; QPointer m_chatOutputPane; + QScopedPointer m_navigationPanel; }; } // namespace QodeAssist::Internal