Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all warnings in QML #30

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ find_package(Qt6 COMPONENTS Core Gui Quick Widgets Network REQUIRED)
add_subdirectory(llmcore)
add_subdirectory(settings)
add_subdirectory(logger)
add_subdirectory(chatview)
add_subdirectory(ChatView)

add_qtc_plugin(QodeAssist
PLUGIN_DEPENDS
Expand Down
6 changes: 5 additions & 1 deletion chatview/CMakeLists.txt → ChatView/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
qt_add_library(QodeAssistChatView STATIC)

qt_policy(SET QTP0001 NEW)

# URI name should match the subdirectory name to suppress the warning
qt_add_qml_module(QodeAssistChatView
URI ChatView
VERSION 1.0
DEPENDENCIES QtQuick
QML_FILES
qml/RootItem.qml
qml/ChatItem.qml
Expand Down Expand Up @@ -31,5 +35,5 @@ target_link_libraries(QodeAssistChatView
)

target_include_directories(QodeAssistChatView
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)
File renamed without changes.
2 changes: 1 addition & 1 deletion chatview/ChatModel.hpp → ChatView/ChatModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <QAbstractListModel>
#include <QJsonArray>
#include <qqmlintegration.h>
#include <QtQmlIntegration>

namespace QodeAssist::Chat {

Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions chatview/ChatRootView.hpp → ChatView/ChatRootView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ namespace QodeAssist::Chat {

class ChatRootView : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(ChatModel *chatModel READ chatModel NOTIFY chatModelChanged FINAL)
Q_OBJECT
// Possibly Qt bug: QTBUG-131004
// The class type name must be fully qualified
// including the namespace.
// Otherwise qmlls can't find it.
Q_PROPERTY(QodeAssist::Chat::ChatModel *chatModel READ chatModel NOTIFY chatModelChanged FINAL)
Q_PROPERTY(QString currentTemplate READ currentTemplate NOTIFY currentTemplateChanged FINAL)
Q_PROPERTY(QColor backgroundColor READ backgroundColor CONSTANT FINAL)
Q_PROPERTY(QColor primaryColor READ primaryColor CONSTANT FINAL)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion chatview/ChatWidget.cpp → ChatView/ChatWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace QodeAssist::Chat {
ChatWidget::ChatWidget(QWidget *parent)
: QQuickWidget(parent)
{
setSource(QUrl("qrc:/ChatView/qml/RootItem.qml"));
setSource(QUrl("qrc:/qt/qml/ChatView/qml/RootItem.qml"));
setResizeMode(QQuickWidget::SizeRootObjectToView);
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
111 changes: 111 additions & 0 deletions ChatView/qml/ChatItem.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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 ComponentBehavior: Bound

import QtQuick
import ChatView
import "./dialog"

Rectangle {
id: root

property alias msgModel: msgCreator.model
property color fontColor
property color codeBgColor
property color selectionColor

height: msgColumn.height
radius: 8

Column {
id: msgColumn

anchors.verticalCenter: parent.verticalCenter
width: parent.width
spacing: 5

Repeater {
id: msgCreator
delegate: Loader {
id: msgCreatorDelegate
// Fix me:
// why does `required property MessagePart modelData` not work?
required property var modelData

width: parent.width
sourceComponent: {
// If `required property MessagePart modelData` is used
// and conversion to MessagePart fails, you're left
// with a nullptr. This tests that to prevent crashing.
if(!modelData) {
return undefined;
}

switch(modelData.type) {
case MessagePart.Text: return textComponent;
case MessagePart.Code: return codeBlockComponent;
default: return textComponent;
}
}

Component {
id: textComponent
TextComponent {
itemData: msgCreatorDelegate.modelData
}
}

Component {
id: codeBlockComponent
CodeBlockComponent {
itemData: msgCreatorDelegate.modelData
}
}
}
}
}

component TextComponent : TextBlock {
required property var itemData
height: implicitHeight + 10
verticalAlignment: Text.AlignVCenter
leftPadding: 10
text: itemData.text
color: root.fontColor
selectionColor: root.selectionColor
}


component CodeBlockComponent : CodeBlock {
required property var itemData
anchors {
left: parent.left
leftMargin: 10
right: parent.right
rightMargin: 10
}

code: itemData.text
language: itemData.language
color: root.codeBgColor
selectionColor: root.selectionColor
}

}
13 changes: 8 additions & 5 deletions chatview/qml/RootItem.qml → ChatView/qml/RootItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/

pragma ComponentBehavior: Bound

import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic as QQC
Expand Down Expand Up @@ -51,6 +53,7 @@ ChatRootView {
cacheBuffer: 2000

delegate: ChatItem {
required property var model
width: ListView.view.width - scroll.width
msgModel: root.chatModel.processMessageContent(model.content)
color: model.roleType === ChatModel.User ? root.primaryColor : root.secondaryColor
Expand All @@ -71,12 +74,12 @@ ChatRootView {
}

onCountChanged: {
scrollToBottom()
root.scrollToBottom()
}

onContentHeightChanged: {
if (atYEnd) {
scrollToBottom()
root.scrollToBottom()
}
}
}
Expand All @@ -103,7 +106,7 @@ ChatRootView {
}
Keys.onPressed: function(event) {
if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) {
sendChatMessage()
root.sendChatMessage()
event.accepted = true;
}
}
Expand All @@ -119,7 +122,7 @@ ChatRootView {

Layout.alignment: Qt.AlignBottom
text: qsTr("Send")
onClicked: sendChatMessage()
onClicked: root.sendChatMessage()
}

Button {
Expand All @@ -135,7 +138,7 @@ ChatRootView {

Layout.alignment: Qt.AlignBottom
text: qsTr("Clear Chat")
onClicked: clearChat()
onClicked: root.clearChat()
}

CheckBox {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Rectangle {
text: root.code
readOnly: true
selectByMouse: true
font.family: monospaceFont
font.family: root.monospaceFont
font.pointSize: 12
color: parent.color.hslLightness > 0.5 ? "black" : "white"
wrapMode: Text.WordWrap
Expand Down
File renamed without changes.
91 changes: 0 additions & 91 deletions chatview/qml/ChatItem.qml

This file was deleted.