From 98f67cd3a9992e1984737476d2d08e000d1b5995 Mon Sep 17 00:00:00 2001 From: Alexandre Lision <alexandre.lision@savoirfairelinux.com> Date: Mon, 22 Jun 2015 14:27:34 -0400 Subject: [PATCH] chat: add sender name and interline space Refs #76102 Change-Id: I5b89dee637cf98ada09c1c1af3fe403f8559285d --- src/ChatVC.mm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ChatVC.mm b/src/ChatVC.mm index bedbdd29..b23cfb8c 100644 --- a/src/ChatVC.mm +++ b/src/ChatVC.mm @@ -77,6 +77,11 @@ [=](const QModelIndex ¤t, const QModelIndex &previous) { [self setupChat]; }); + + // Override default style to add interline space + NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; + paragraphStyle.lineSpacing = 8; + [chatView setDefaultParagraphStyle:paragraphStyle]; } - (void) setupChat @@ -141,10 +146,23 @@ if (!msgIdx.isValid()) return; - QVariant message = msgIdx.data(); - NSAttributedString* attr = [[NSAttributedString alloc] initWithString: - [NSString stringWithFormat:@"%@\n",message.value<QString>().toNSString()]]; + NSString* message = msgIdx.data(Qt::DisplayRole).value<QString>().toNSString(); + NSString* author = msgIdx.data((int)Media::TextRecording::Role::AuthorDisplayname).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]; + + // 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)]; } -- GitLab