Commit 98f67cd3 authored by Alexandre Lision's avatar Alexandre Lision

chat: add sender name and interline space

Refs #76102

Change-Id: I5b89dee637cf98ada09c1c1af3fe403f8559285d
parent f47a2561
...@@ -77,6 +77,11 @@ ...@@ -77,6 +77,11 @@
[=](const QModelIndex &current, const QModelIndex &previous) { [=](const QModelIndex &current, const QModelIndex &previous) {
[self setupChat]; [self setupChat];
}); });
// Override default style to add interline space
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 8;
[chatView setDefaultParagraphStyle:paragraphStyle];
} }
- (void) setupChat - (void) setupChat
...@@ -141,10 +146,23 @@ ...@@ -141,10 +146,23 @@
if (!msgIdx.isValid()) if (!msgIdx.isValid())
return; return;
QVariant message = msgIdx.data(); NSString* message = msgIdx.data(Qt::DisplayRole).value<QString>().toNSString();
NSAttributedString* attr = [[NSAttributedString alloc] initWithString: NSString* author = msgIdx.data((int)Media::TextRecording::Role::AuthorDisplayname).value<QString>().toNSString();
[NSString stringWithFormat:@"%@\n",message.value<QString>().toNSString()]];
NSMutableAttributedString* attr = [[NSMutableAttributedString alloc] initWithString:
[NSString stringWithFormat:@"%@: %@\n",author, message]];
// put in bold type author name
[attr applyFontTraits:NSBoldFontMask range: NSMakeRange(0, [author length])];
[[chatView textStorage] appendAttributedString:attr]; [[chatView textStorage] appendAttributedString:attr];
// reapply paragraph style on all the text
NSRange range = NSMakeRange(0,[chatView textStorage].length);
[[self.chatView textStorage] addAttribute:NSParagraphStyleAttributeName
value:chatView.defaultParagraphStyle
range:range];
[chatView scrollRangeToVisible:NSMakeRange([[chatView string] length], 0)]; [chatView scrollRangeToVisible:NSMakeRange([[chatView string] length], 0)];
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment