diff --git a/src/qml/FancyMessageDelegate.qml b/src/qml/FancyMessageDelegate.qml index 4e5630c8..976d0b1a 100644 --- a/src/qml/FancyMessageDelegate.qml +++ b/src/qml/FancyMessageDelegate.qml @@ -1,190 +1,102 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . * */ import QtQuick 2.0 // import "marked.js" as Markdown import "js/marked.js" as MarkDown; import QtQuick.Controls 2.2 import org.kde.kirigami 2.1 as Kirigami import QtQuick.Layouts 1.1 Rectangle { function getTextFor(type) { if (type === "uj") { return qsTr("has joined the channel"); } else if (type === "ul") { return qsTr("has left the channel"); } else if (type === "room_changed_topic") { return qsTr("changed topic to \"%1\"").arg(i_messageText) } else if (type === "au") { return qsTr("added %1 to the conversation").arg(i_messageText) } else if (type === "r") { return qsTr("changed room name to \"%1\"").arg(i_messageText) } else if (type === "room_changed_description") { return qsTr("changed room description to \"%1\"").arg(i_messageText) } else { console.log("Unkown type for message"); console.log(type); console.log(i_messageText) return qsTr("Unknown action!"); } } property string i_messageText property string i_username property bool i_systemMessage property string i_systemMessageType property string i_avatar property var i_timestamp id: messageMain color: "#eeeeee" // implicitHeight: textLabel.contentHeight - implicitHeight: 4*Kirigami.Units.smallSpacing + Math.max(textLabel.implicitHeight+usernameLabel.implicitHeight, avatarRect.implicitHeight) + implicitHeight: 4*Kirigami.Units.smallSpacing + loaded.implicitHeight implicitWidth: 150 anchors.bottomMargin: 200 // anchors.margins: 50 - RowLayout { - + Loader { + id: loaded anchors.topMargin: Kirigami.Units.smallSpacing anchors.fill: parent -// implicitHeight: textLabel.contentHeight - - spacing: Kirigami.Units.smallSpacing -// spacing: 12 - - Rectangle { - Layout.fillHeight: false - - id: avatarRect - implicitWidth: 24 - implicitHeight: 24 - - anchors.margins: Kirigami.Units.smallSpacing - - color: "gray" - anchors.top: parent.top - } - - Rectangle { - id: textRect - - Layout.fillWidth: true -// radius: 4 -// color: "#eeeeee" - anchors.top: parent.top - anchors.bottom: parent.bottom - anchors.bottomMargin: Kirigami.Units.smallSpacing -// height: textLabel.implicitHeight + usernameLabel.implicitHeight - - Column { -// implicitWidth: 100 - anchors.fill:parent - Kirigami.Heading { - level: 5 - id: usernameLabel - font.bold: true - text: i_username - // anchors.top: parent.top - anchors.right: parent.right - anchors.left: parent.left - } - Kirigami.Label { - id: textLabel - // anchors.top: usernameLabel.bottom - anchors.right: parent.right - anchors.left: parent.left - // anchors.bottom: parent.bottom - text: i_messageText - wrapMode: Label.Wrap - } - -// Rectangle { -// color: "red" -// // anchors.top: textLabel.bottom -// anchors.right: parent.right -// anchors.left: parent.left -// // anchors.bottom: parent.bottom -// implicitHeight: 2*Kirigami.Units.smallSpacing -// } + Component.onCompleted: { + if (i_systemMessage) { + setSource("messages/SystemMessage.qml", + { + i_messageText: i_messageText, + i_username: i_username, + i_timestamp: i_timestamp, + i_systemMessageType: i_systemMessageType + } + ) + } else { + setSource("messages/UserMessage.qml", + { + i_messageText: i_messageText, + i_username: i_username, + i_timestamp: i_timestamp + } + ) } } - -// Kirigami.Label { -// id: timeLabel -// text: "["+(new Date(i_timestamp)).toLocaleTimeString(Locale.ShortFormat)+"]" -// -// anchors.top: parent.top -// anchors.bottom: parent.bottom -// -// color: Kirigami.Theme.textColor -// opacity: .5 -// -// z:1 -// } -// } -// - - -// Label { -// color: i_systemMessage? "#999" : "#555" -// text: i_username -// id: usernameLabel -// clip: true -// -// horizontalAlignment: Text.AlignRight -// -// anchors.top: parent.top -// anchors.bottom: parent.bottom -// anchors.left: timeLabel.left -// -// width: 100 -// } -// -// Label { -// color: i_systemMessage? "#999" : "#111" -// id: textLabel -// text: i_systemMessage? getTextFor(i_systemMessageType) : MarkDown.md2html(i_messageText) -// -// -// anchors.top: parent.top -// anchors.bottom: parent.bottom -// -// anchors.left: usernameLabel.right -// anchors.right: parent.right -// -// wrapMode: Label.Wrap -// -// anchors.leftMargin: 5 -// + } } diff --git a/src/qml/FancyMessageDelegate.qml b/src/qml/messages/SystemMessage.qml similarity index 98% copy from src/qml/FancyMessageDelegate.qml copy to src/qml/messages/SystemMessage.qml index 4e5630c8..72f315ba 100644 --- a/src/qml/FancyMessageDelegate.qml +++ b/src/qml/messages/SystemMessage.qml @@ -1,190 +1,190 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . * */ import QtQuick 2.0 // import "marked.js" as Markdown -import "js/marked.js" as MarkDown; +// import "js/marked.js" as MarkDown; import QtQuick.Controls 2.2 import org.kde.kirigami 2.1 as Kirigami import QtQuick.Layouts 1.1 Rectangle { function getTextFor(type) { if (type === "uj") { return qsTr("has joined the channel"); } else if (type === "ul") { return qsTr("has left the channel"); } else if (type === "room_changed_topic") { return qsTr("changed topic to \"%1\"").arg(i_messageText) } else if (type === "au") { return qsTr("added %1 to the conversation").arg(i_messageText) } else if (type === "r") { return qsTr("changed room name to \"%1\"").arg(i_messageText) } else if (type === "room_changed_description") { return qsTr("changed room description to \"%1\"").arg(i_messageText) } else { console.log("Unkown type for message"); console.log(type); console.log(i_messageText) return qsTr("Unknown action!"); } } property string i_messageText property string i_username property bool i_systemMessage property string i_systemMessageType - property string i_avatar property var i_timestamp id: messageMain color: "#eeeeee" // implicitHeight: textLabel.contentHeight implicitHeight: 4*Kirigami.Units.smallSpacing + Math.max(textLabel.implicitHeight+usernameLabel.implicitHeight, avatarRect.implicitHeight) implicitWidth: 150 anchors.bottomMargin: 200 // anchors.margins: 50 RowLayout { anchors.topMargin: Kirigami.Units.smallSpacing anchors.fill: parent // implicitHeight: textLabel.contentHeight spacing: Kirigami.Units.smallSpacing // spacing: 12 Rectangle { Layout.fillHeight: false id: avatarRect implicitWidth: 24 implicitHeight: 24 anchors.margins: Kirigami.Units.smallSpacing color: "gray" anchors.top: parent.top } Rectangle { id: textRect Layout.fillWidth: true // radius: 4 // color: "#eeeeee" anchors.top: parent.top anchors.bottom: parent.bottom anchors.bottomMargin: Kirigami.Units.smallSpacing // height: textLabel.implicitHeight + usernameLabel.implicitHeight Column { // implicitWidth: 100 anchors.fill:parent Kirigami.Heading { level: 5 id: usernameLabel font.bold: true text: i_username // anchors.top: parent.top anchors.right: parent.right anchors.left: parent.left } Kirigami.Label { id: textLabel // anchors.top: usernameLabel.bottom anchors.right: parent.right anchors.left: parent.left // anchors.bottom: parent.bottom - text: i_messageText + text: getTextFor(i_systemMessageType) + wrapMode: Label.Wrap } // Rectangle { // color: "red" // // anchors.top: textLabel.bottom // anchors.right: parent.right // anchors.left: parent.left // // anchors.bottom: parent.bottom // implicitHeight: 2*Kirigami.Units.smallSpacing // } } } // Kirigami.Label { // id: timeLabel // text: "["+(new Date(i_timestamp)).toLocaleTimeString(Locale.ShortFormat)+"]" // // anchors.top: parent.top // anchors.bottom: parent.bottom // // color: Kirigami.Theme.textColor // opacity: .5 // // z:1 // } // } // // Label { // color: i_systemMessage? "#999" : "#555" // text: i_username // id: usernameLabel // clip: true // // horizontalAlignment: Text.AlignRight // // anchors.top: parent.top // anchors.bottom: parent.bottom // anchors.left: timeLabel.left // // width: 100 // } // // Label { // color: i_systemMessage? "#999" : "#111" // id: textLabel // text: i_systemMessage? getTextFor(i_systemMessageType) : MarkDown.md2html(i_messageText) // // // anchors.top: parent.top // anchors.bottom: parent.bottom // // anchors.left: usernameLabel.right // anchors.right: parent.right // // wrapMode: Label.Wrap // // anchors.leftMargin: 5 // } } diff --git a/src/qml/FancyMessageDelegate.qml b/src/qml/messages/UserMessage.qml similarity index 99% copy from src/qml/FancyMessageDelegate.qml copy to src/qml/messages/UserMessage.qml index 4e5630c8..f6b83d02 100644 --- a/src/qml/FancyMessageDelegate.qml +++ b/src/qml/messages/UserMessage.qml @@ -1,190 +1,190 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 this program. If not, see . * */ import QtQuick 2.0 // import "marked.js" as Markdown -import "js/marked.js" as MarkDown; +// import "js/marked.js" as MarkDown; import QtQuick.Controls 2.2 import org.kde.kirigami 2.1 as Kirigami import QtQuick.Layouts 1.1 Rectangle { function getTextFor(type) { if (type === "uj") { return qsTr("has joined the channel"); } else if (type === "ul") { return qsTr("has left the channel"); } else if (type === "room_changed_topic") { return qsTr("changed topic to \"%1\"").arg(i_messageText) } else if (type === "au") { return qsTr("added %1 to the conversation").arg(i_messageText) } else if (type === "r") { return qsTr("changed room name to \"%1\"").arg(i_messageText) } else if (type === "room_changed_description") { return qsTr("changed room description to \"%1\"").arg(i_messageText) } else { console.log("Unkown type for message"); console.log(type); console.log(i_messageText) return qsTr("Unknown action!"); } } property string i_messageText property string i_username property bool i_systemMessage property string i_systemMessageType property string i_avatar property var i_timestamp id: messageMain color: "#eeeeee" // implicitHeight: textLabel.contentHeight implicitHeight: 4*Kirigami.Units.smallSpacing + Math.max(textLabel.implicitHeight+usernameLabel.implicitHeight, avatarRect.implicitHeight) implicitWidth: 150 anchors.bottomMargin: 200 // anchors.margins: 50 RowLayout { anchors.topMargin: Kirigami.Units.smallSpacing anchors.fill: parent // implicitHeight: textLabel.contentHeight spacing: Kirigami.Units.smallSpacing // spacing: 12 Rectangle { Layout.fillHeight: false id: avatarRect implicitWidth: 24 implicitHeight: 24 anchors.margins: Kirigami.Units.smallSpacing color: "gray" anchors.top: parent.top } Rectangle { id: textRect Layout.fillWidth: true // radius: 4 // color: "#eeeeee" anchors.top: parent.top anchors.bottom: parent.bottom anchors.bottomMargin: Kirigami.Units.smallSpacing // height: textLabel.implicitHeight + usernameLabel.implicitHeight Column { // implicitWidth: 100 anchors.fill:parent Kirigami.Heading { level: 5 id: usernameLabel font.bold: true text: i_username // anchors.top: parent.top anchors.right: parent.right anchors.left: parent.left } Kirigami.Label { id: textLabel // anchors.top: usernameLabel.bottom anchors.right: parent.right anchors.left: parent.left // anchors.bottom: parent.bottom text: i_messageText wrapMode: Label.Wrap } // Rectangle { // color: "red" // // anchors.top: textLabel.bottom // anchors.right: parent.right // anchors.left: parent.left // // anchors.bottom: parent.bottom // implicitHeight: 2*Kirigami.Units.smallSpacing // } } } // Kirigami.Label { // id: timeLabel // text: "["+(new Date(i_timestamp)).toLocaleTimeString(Locale.ShortFormat)+"]" // // anchors.top: parent.top // anchors.bottom: parent.bottom // // color: Kirigami.Theme.textColor // opacity: .5 // // z:1 // } // } // // Label { // color: i_systemMessage? "#999" : "#555" // text: i_username // id: usernameLabel // clip: true // // horizontalAlignment: Text.AlignRight // // anchors.top: parent.top // anchors.bottom: parent.bottom // anchors.left: timeLabel.left // // width: 100 // } // // Label { // color: i_systemMessage? "#999" : "#111" // id: textLabel // text: i_systemMessage? getTextFor(i_systemMessageType) : MarkDown.md2html(i_messageText) // // // anchors.top: parent.top // anchors.bottom: parent.bottom // // anchors.left: usernameLabel.right // anchors.right: parent.right // // wrapMode: Label.Wrap // // anchors.leftMargin: 5 // } } diff --git a/src/qml/qml.qrc b/src/qml/qml.qrc index 794cc88b..7e3557b3 100644 --- a/src/qml/qml.qrc +++ b/src/qml/qml.qrc @@ -1,21 +1,25 @@ JSONListModel.qml RoomModel.qml Desktop.qml Message.qml FancyMessageDelegate.qml RoomsView.qml RoomDelegate.qml ChannelsList.qml Login.qml + + messages/SystemMessage.qml + messages/UserMessage.qml + js/jsonpath.js js/marked.js icons/systray.png icons/attach-button.jpg