X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatlinemodelitem.cpp;h=9b9e71c2c75ebaff1d0eaf4539c2aee7bf719df7;hp=84832cdf2a164ad215f0b62e0766dfeb973572de;hb=94be5fb31afd8f3befa8cb2cf1b3c2e5ef3cdba5;hpb=7a1eca89ead6eb300c593ace9f14c0eb2f9836b8 diff --git a/src/qtui/chatlinemodelitem.cpp b/src/qtui/chatlinemodelitem.cpp index 84832cdf..9b9e71c2 100644 --- a/src/qtui/chatlinemodelitem.cpp +++ b/src/qtui/chatlinemodelitem.cpp @@ -26,7 +26,23 @@ #include "qtui.h" #include "uistyle.h" -ChatLineModelItem::ChatLineModelItem(const Message &msg) : MessageModelItem(msg) { +// This Struct is taken from Harfbuzz. We use it only to calc it's size. +// we use a shared memory region so we do not have to malloc a buffer area for every line +typedef struct { + /*HB_LineBreakType*/ unsigned lineBreakType :2; + /*HB_Bool*/ unsigned whiteSpace :1; /* A unicode whitespace character, except NBSP, ZWNBSP */ + /*HB_Bool*/ unsigned charStop :1; /* Valid cursor position (for left/right arrow) */ + /*HB_Bool*/ unsigned wordBoundary :1; + /*HB_Bool*/ unsigned sentenceBoundary :1; + unsigned unused :2; +} HB_CharAttributes_Dummy; + +unsigned char *ChatLineModelItem::TextBoundaryFinderBuffer = (unsigned char *)malloc(512 * sizeof(HB_CharAttributes_Dummy)); +int ChatLineModelItem::TextBoundaryFinderBufferSize = 512 * (sizeof(HB_CharAttributes_Dummy) / sizeof(unsigned char)); + +ChatLineModelItem::ChatLineModelItem(const Message &msg) + : MessageModelItem(msg) +{ QtUiStyle::StyledMessage m = QtUi::style()->styleMessage(msg); _timestamp.plainText = m.timestamp.plainText; @@ -42,40 +58,49 @@ ChatLineModelItem::ChatLineModelItem(const Message &msg) : MessageModelItem(msg) QVariant ChatLineModelItem::data(int column, int role) const { - const ChatLinePart *part; + const ChatLinePart *part = 0; switch(column) { - case ChatLineModel::TimestampColumn: part = &_timestamp; break; - case ChatLineModel::SenderColumn: part = &_sender; break; - case ChatLineModel::ContentsColumn: part = &_contents; break; - default: return MessageModelItem::data(column, role); + case ChatLineModel::TimestampColumn: + part = &_timestamp; + break; + case ChatLineModel::SenderColumn: + part = &_sender; + break; + case ChatLineModel::ContentsColumn: + part = &_contents; + break; + default: + return MessageModelItem::data(column, role); } switch(role) { - case ChatLineModel::DisplayRole: - return part->plainText; - case ChatLineModel::FormatRole: - return QVariant::fromValue(part->formatList); - case ChatLineModel::WrapListRole: - if(column != ChatLineModel::ContentsColumn) return QVariant(); - return QVariant::fromValue(_wrapList); + case ChatLineModel::DisplayRole: + return part->plainText; + case ChatLineModel::FormatRole: + return QVariant::fromValue(part->formatList); + case ChatLineModel::WrapListRole: + if(column != ChatLineModel::ContentsColumn) + return QVariant(); + return QVariant::fromValue(_wrapList); } - return MessageModelItem::data(column, role); } -bool ChatLineModelItem::setData(int column, const QVariant &value, int role) { - return false; -} - void ChatLineModelItem::computeWrapList() { + if(_contents.plainText.isEmpty()) + return; + enum Mode { SearchStart, SearchEnd }; QList wplist; // use a temp list which we'll later copy into a QVector for efficiency - QTextBoundaryFinder finder(QTextBoundaryFinder::Word, _contents.plainText); + // QTextBoundaryFinder finder(QTextBoundaryFinder::Word, _contents.plainText); + QTextBoundaryFinder finder(QTextBoundaryFinder::Word, _contents.plainText.unicode(), _contents.plainText.length(), TextBoundaryFinderBuffer, TextBoundaryFinderBufferSize); + int idx; int oldidx = 0; - bool wordStart = false; bool wordEnd = false; + bool wordStart = false; + bool wordEnd = false; Mode mode = SearchEnd; ChatLineModel::Word word; word.start = 0;