diff --git a/imports/Spectral/Component/AutoRectangle.qml b/imports/Spectral/Component/AutoRectangle.qml new file mode 100644 index 0000000..975e491 --- /dev/null +++ b/imports/Spectral/Component/AutoRectangle.qml @@ -0,0 +1,71 @@ +import QtQuick 2.12 + +Rectangle { + property alias topLeftRadius: topLeftRect.radius + property alias topRightRadius: topRightRect.radius + property alias bottomLeftRadius: bottomLeftRect.radius + property alias bottomRightRadius: bottomRightRect.radius + + property alias topLeftVisible: topLeftRect.visible + property alias topRightVisible: topRightRect.visible + property alias bottomLeftVisible: bottomLeftRect.visible + property alias bottomRightVisible: bottomRightRect.visible + + antialiasing: true + + Rectangle { + anchors.top: parent.top + anchors.left: parent.left + + width: parent.width / 2 + height: parent.height / 2 + + id: topLeftRect + + antialiasing: true + + color: parent.color + } + + Rectangle { + anchors.top: parent.top + anchors.right: parent.right + + width: parent.width / 2 + height: parent.height / 2 + + id: topRightRect + + antialiasing: true + + color: parent.color + } + + Rectangle { + anchors.bottom: parent.bottom + anchors.left: parent.left + + width: parent.width / 2 + height: parent.height / 2 + + id: bottomLeftRect + + antialiasing: true + + color: parent.color + } + + Rectangle { + anchors.bottom: parent.bottom + anchors.right: parent.right + + width: parent.width / 2 + height: parent.height / 2 + + id: bottomRightRect + + antialiasing: true + + color: parent.color + } +} diff --git a/imports/Spectral/Component/Avatar.qml b/imports/Spectral/Component/Avatar.qml index b9c2c8d..caf0f85 100644 --- a/imports/Spectral/Component/Avatar.qml +++ b/imports/Spectral/Component/Avatar.qml @@ -2,6 +2,8 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtGraphicalEffects 1.0 +import Spectral.Setting 0.1 + Item { property string hint: "H" property string source: "" @@ -35,7 +37,7 @@ Item { visible: !realSource || image.status != Image.Ready radius: height / 2 - color: stringToColor(hint) + color: MPalette.accent antialiasing: true Label { @@ -50,16 +52,16 @@ Item { } } - function stringToColor(str) { - var hash = 0; - for (var i = 0; i < str.length; i++) { - hash = str.charCodeAt(i) + ((hash << 5) - hash); - } - var colour = '#'; - for (var j = 0; j < 3; j++) { - var value = (hash >> (j * 8)) & 0xFF; - colour += ('00' + value.toString(16)).substr(-2); - } - return colour; - } +// function stringToColor(str) { +// var hash = 0; +// for (var i = 0; i < str.length; i++) { +// hash = str.charCodeAt(i) + ((hash << 5) - hash); +// } +// var colour = '#'; +// for (var j = 0; j < 3; j++) { +// var value = (hash >> (j * 8)) & 0xFF; +// colour += ('00' + value.toString(16)).substr(-2); +// } +// return colour; +// } } diff --git a/imports/Spectral/Component/Timeline/MessageDelegate.qml b/imports/Spectral/Component/Timeline/MessageDelegate.qml index 35e3361..670505f 100644 --- a/imports/Spectral/Component/Timeline/MessageDelegate.qml +++ b/imports/Spectral/Component/Timeline/MessageDelegate.qml @@ -67,65 +67,25 @@ ColumnLayout { Control { Layout.maximumWidth: messageListView.width - (!sentByMe ? 36 + messageRow.spacing : 0) - 48 - verticalPadding: 8 - horizontalPadding: 16 + padding: 0 + + background: AutoRectangle { + readonly property int minorRadius: 2 + + id: bubbleBackground - background: Rectangle { color: sentByMe ? MPalette.background : eventType === "notice" ? MPalette.primary : MPalette.accent radius: 18 - antialiasing: true - Rectangle { - anchors.top: parent.top - anchors.left: parent.left + topLeftVisible: !sentByMe && (bubbleShape == 3 || bubbleShape == 2) + topRightVisible: sentByMe && (bubbleShape == 3 || bubbleShape == 2) + bottomLeftVisible: !sentByMe && (bubbleShape == 1 || bubbleShape == 2) + bottomRightVisible: sentByMe && (bubbleShape == 1 || bubbleShape == 2) - width: parent.width / 2 - height: parent.height / 2 - - visible: !sentByMe && (bubbleShape == 3 || bubbleShape == 2) - - color: sentByMe ? MPalette.background : eventType === "notice" ? MPalette.primary : MPalette.accent - radius: 2 - } - - Rectangle { - anchors.top: parent.top - anchors.right: parent.right - - width: parent.width / 2 - height: parent.height / 2 - - visible: sentByMe && (bubbleShape == 3 || bubbleShape == 2) - - color: sentByMe ? MPalette.background : eventType === "notice" ? MPalette.primary : MPalette.accent - radius: 2 - } - - Rectangle { - anchors.bottom: parent.bottom - anchors.left: parent.left - - width: parent.width / 2 - height: parent.height / 2 - - visible: !sentByMe && (bubbleShape == 1 || bubbleShape == 2) - - color: sentByMe ? MPalette.background : eventType === "notice" ? MPalette.primary : MPalette.accent - radius: 2 - } - - Rectangle { - anchors.bottom: parent.bottom - anchors.right: parent.right - - width: parent.width / 2 - height: parent.height / 2 - - visible: sentByMe && (bubbleShape == 1 || bubbleShape == 2) - - color: sentByMe ? MPalette.background : eventType === "notice" ? MPalette.primary : MPalette.accent - radius: 2 - } + topLeftRadius: minorRadius + topRightRadius: minorRadius + bottomLeftRadius: minorRadius + bottomRightRadius: minorRadius AutoMouseArea { anchors.fill: parent @@ -166,60 +126,74 @@ ColumnLayout { } contentItem: ColumnLayout { - RowLayout { + spacing: 0 + + Control { Layout.fillWidth: true + padding: 8 + visible: replyVisible - Avatar { - Layout.preferredWidth: 28 - Layout.preferredHeight: 28 - Layout.alignment: Qt.AlignTop + contentItem: RowLayout { + Avatar { + Layout.preferredWidth: 28 + Layout.preferredHeight: 28 + Layout.alignment: Qt.AlignTop - source: replyVisible ? replyAuthor.avatarMediaId : "" - hint: replyVisible ? replyAuthor.displayName : "H" + source: replyVisible ? replyAuthor.avatarMediaId : "" + hint: replyVisible ? replyAuthor.displayName : "H" - RippleEffect { - anchors.fill: parent + RippleEffect { + anchors.fill: parent - circular: true + circular: true - onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": replyAuthor}).open() - } - } - - Control { - Layout.fillWidth: true - - visible: replyVisible - - padding: 0 - - background: RippleEffect { - onClicked: goToEvent(replyEventId) + onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": replyAuthor}).open() + } } - contentItem: Label { - color: darkBackground ? "white" : MPalette.lighter + Label { + Layout.fillWidth: true + + color: !sentByMe ? MPalette.foreground : "white" text: "" + (replyDisplay || "") wrapMode: Label.Wrap textFormat: Label.RichText } } - } - Rectangle { - Layout.fillWidth: true - Layout.preferredHeight: 1 + background: AutoRectangle { + color: sentByMe ? MPalette.accent : MPalette.background + radius: 16 - visible: replyVisible - color: darkBackground ? "white" : MPalette.lighter + topLeftRadius: 2 + topRightRadius: 2 + bottomLeftRadius: 0 + bottomRightRadius: 0 + + topLeftVisible: bubbleBackground.topLeftVisible + topRightVisible: bubbleBackground.topRightVisible + bottomLeftVisible: true + bottomRightVisible: true + + AutoMouseArea { + anchors.fill: parent + + onClicked: goToEvent(replyEventId) + } + } } TextEdit { Layout.fillWidth: true + Layout.leftMargin: 16 + Layout.rightMargin: 16 + Layout.topMargin: 8 + Layout.bottomMargin: 8 + id: contentLabel text: "" + display diff --git a/imports/Spectral/Component/qmldir b/imports/Spectral/Component/qmldir index 4cbc3dd..dd821c5 100644 --- a/imports/Spectral/Component/qmldir +++ b/imports/Spectral/Component/qmldir @@ -7,3 +7,4 @@ AutoListView 2.0 AutoListView.qml AutoTextField 2.0 AutoTextField.qml Avatar 2.0 Avatar.qml FullScreenImage 2.0 FullScreenImage.qml +AutoRectangle 2.0 AutoRectangle.qml diff --git a/imports/Spectral/Dialog/UserDetailDialog.qml b/imports/Spectral/Dialog/UserDetailDialog.qml index 373b1a1..786fc33 100644 --- a/imports/Spectral/Dialog/UserDetailDialog.qml +++ b/imports/Spectral/Dialog/UserDetailDialog.qml @@ -27,8 +27,8 @@ Dialog { Layout.preferredWidth: 72 Layout.preferredHeight: 72 - hint: user ? user.displayName : "No name" - source: user ? user.avatarMediaId : null + hint: user.displayName + source: user.avatarMediaId RippleEffect { anchors.fill: parent @@ -50,10 +50,19 @@ Dialog { elide: Text.ElideRight wrapMode: Text.NoWrap - text: user ? user.displayName : "No Name" + text: user.displayName color: MPalette.foreground } + Label { + Layout.fillWidth: true + + visible: user.bridgeName + + text: user.bridgeName + color: MPalette.lighter + } + Label { Layout.fillWidth: true @@ -89,7 +98,7 @@ Dialog { elide: Text.ElideRight wrapMode: Text.NoWrap - text: user ? user.id : "No ID" + text: user.id color: MPalette.accent } diff --git a/include/libqmatrixclient b/include/libqmatrixclient index 52a81df..d6f39dc 160000 --- a/include/libqmatrixclient +++ b/include/libqmatrixclient @@ -1 +1 @@ -Subproject commit 52a81dfa8a5415be369d819837f445479b833cde +Subproject commit d6f39dcb0de69322479f287514a8c36afcb3fe7b diff --git a/res.qrc b/res.qrc index a07c611..8ab4cf4 100644 --- a/res.qrc +++ b/res.qrc @@ -58,5 +58,6 @@ imports/Spectral/Dialog/OpenFileDialog.qml imports/Spectral/Dialog/OpenFolderDialog.qml imports/Spectral/Component/Timeline/VideoDelegate.qml + imports/Spectral/Component/AutoRectangle.qml diff --git a/src/spectraluser.cpp b/src/spectraluser.cpp index cf0e67d..613aebf 100644 --- a/src/spectraluser.cpp +++ b/src/spectraluser.cpp @@ -1 +1,5 @@ #include "spectraluser.h" + +QColor SpectralUser::color() { + return QColor::fromHslF(hueF(), 0.7, 0.5, 1); +} diff --git a/src/spectraluser.h b/src/spectraluser.h index e62e51e..3cb7734 100644 --- a/src/spectraluser.h +++ b/src/spectraluser.h @@ -10,9 +10,12 @@ using namespace QMatrixClient; class SpectralUser : public User { Q_OBJECT + Q_PROPERTY(QColor color READ color CONSTANT) public: SpectralUser(QString userId, Connection* connection) : User(userId, connection) {} + + QColor color(); }; #endif // SpectralUser_H