Skip to content

Commit

Permalink
Use proposed hueF API for colour-coding, add UserListDock widget support
Browse files Browse the repository at this point in the history
Contributes to issue #513
  • Loading branch information
a-andreyev committed May 15, 2019
1 parent 79741f2 commit 18a41fb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
7 changes: 7 additions & 0 deletions client/models/messageeventmodel.cpp
Expand Up @@ -47,6 +47,7 @@ enum EventRoles {
SpecialMarksRole,
LongOperationRole,
AnnotationRole,
UserHueRole,
// For debugging
EventResolvedTypeRole,
};
Expand All @@ -68,6 +69,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[SpecialMarksRole] = "marks";
roles[LongOperationRole] = "progressInfo";
roles[AnnotationRole] = "annotation";
roles[UserHueRole] = "userHue";
roles[EventResolvedTypeRole] = "eventResolvedType";
return roles;
}
Expand Down Expand Up @@ -726,5 +728,10 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const
? SectionRole : AuthorRole);
}

if (role == UserHueRole)
return QVariant::fromValue(isPending
? m_currentRoom->localUser()->hueF()
: m_currentRoom->user(evt.senderId())->hueF());

return {};
}
12 changes: 12 additions & 0 deletions client/models/userlistmodel.cpp
Expand Up @@ -22,6 +22,8 @@
#include <QElapsedTimer>
#include <QtCore/QDebug>
#include <QtGui/QPixmap>
#include <QtGui/QPalette>
#include <QtWidgets/QApplication>

#include <connection.h>
#include <room.h>
Expand Down Expand Up @@ -108,6 +110,16 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const
return tooltip;
}

if (role == Qt::ForegroundRole)
{
// FIXME: boilerplate with TimelineItem.qml:57
return QColor::fromHslF(user->hueF(),
1 - QApplication::palette().color(QPalette::Window).saturationF(),
-0.7 * QApplication::palette().color(QPalette::Window).lightnessF() + 0.9,
QApplication::palette().color(QPalette::ButtonText).alphaF()
);
}

return QVariant();
}

Expand Down
35 changes: 10 additions & 25 deletions client/qml/TimelineItem.qml
Expand Up @@ -54,27 +54,12 @@ Item {
(["state", "notice", "other"].indexOf(eventType) >= 0) ?
disabledPalette.text : defaultPalette.text
readonly property string authorName: room && room.roomMembername(author.id)
function stringToHue(str) {
var hash = 0
if ((str).length === 0)
return hash
for (var i = 0; i < (str).length; i++) {
hash = (str).charCodeAt(i) + ((hash << 5) - hash)
hash = hash & hash
}
return Math.abs(hash)/2147483647
}
function stringToColor(str) {
if (str) {
return Qt.hsla(stringToHue(str),
(1-defaultPalette.window.hslSaturation),
/* contrast but not too heavy: */
(-0.6*defaultPalette.window.hslLightness + 0.9),
textColor.a)
}
return textColor
}
readonly property color fancyColor: stringToColor(authorName)
// FIXME: boilerplate with models/userlistmodel.cpp:115
readonly property string authorColor: Qt.hsla(userHue,
(1-defaultPalette.window.hslSaturation),
/* contrast but not too heavy: */
(-0.7*defaultPalette.window.hslLightness + 0.9),
defaultPalette.buttonText.a)

readonly property bool xchatStyle: settings.timeline_style === "xchat"
readonly property bool actionEvent: eventType == "state" || eventType == "emote"
Expand Down Expand Up @@ -169,7 +154,7 @@ Item {
actionEvent ? Text.AlignRight : Text.AlignLeft
elide: Text.ElideRight

color: fancyColor
color: authorColor
textFormat: Label.PlainText
font.bold: !xchatStyle
renderType: settings.render_type
Expand Down Expand Up @@ -268,9 +253,9 @@ Item {
textFormat: TextEdit.RichText
// FIXME: The text is clumsy and slows down creation
text: (actionEvent && !xchatStyle ?
("<a href='#mention' style='text-decoration:none;color:\"" +
fancyColor + "\"'><b>" +
authorName + "</b></a> ") : ""
("<a href='" + author.id + "' style='text-decoration:none;color:\"" +
authorColor + "\"'><b>" +
toHtmlEscaped(authorName) + "</b></a> ") : ""
) + display +
(annotation ? "<br><em>" + annotation + "</em>" : "")
horizontalAlignment: Text.AlignLeft
Expand Down
2 changes: 1 addition & 1 deletion lib
Submodule lib updated from 2d39b1 to d6f39d

0 comments on commit 18a41fb

Please sign in to comment.