Skip to content

Commit

Permalink
Add base qml chat view to navigation panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Palm1r committed Oct 6, 2024
1 parent d77e13c commit 8be279a
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
45 changes: 45 additions & 0 deletions chat/NavigationPanel.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 37 additions & 0 deletions chat/NavigationPanel.hpp
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions chatview/BaseChatWidget.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
setSource(QUrl("qrc:/ChatView/qml/ChatView.qml"));
setResizeMode(QQuickWidget::SizeRootObjectToView);

engine()->rootContext()->setContextObject(this);
}

}
34 changes: 34 additions & 0 deletions chatview/BaseChatWidget.hpp
Original file line number Diff line number Diff line change
@@ -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/>.
*/

#pragma once

#include <QtQuickWidgets/QtQuickWidgets>

namespace QodeAssist::Chat {

class BaseChatWidget : public QQuickWidget
{
Q_OBJECT
public:
explicit BaseChatWidget(QWidget *parent = nullptr);
~BaseChatWidget() = default;
};

}
24 changes: 24 additions & 0 deletions chatview/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
7 changes: 7 additions & 0 deletions chatview/qml/ChatView.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import QtQuick

Rectangle {
id: root

color: "gray"
}
3 changes: 3 additions & 0 deletions qodeassist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -150,6 +152,7 @@ class QodeAssistPlugin final : public ExtensionSystem::IPlugin
private:
QScopedPointer<QodeAssistClient> m_qodeAssistClient;
QPointer<Chat::ChatOutputPane> m_chatOutputPane;
QScopedPointer<Chat::NavigationPanel> m_navigationPanel;
};

} // namespace QodeAssist::Internal
Expand Down

0 comments on commit 8be279a

Please sign in to comment.