+#include "qtuistyle.h"
+
+// 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));
+
+// ****************************************
+// the actual ChatLineModelItem
+// ****************************************
+ChatLineModelItem::ChatLineModelItem(const Message &msg)
+ : MessageModelItem(),
+ _styledMsg(msg)
+{
+ if (!msg.sender().contains('!'))
+ _styledMsg.setFlags(msg.flags() |= Message::ServerMsg);
+}
+
+
+bool ChatLineModelItem::setData(int column, const QVariant &value, int role)
+{
+ switch (role) {
+ case MessageModel::FlagsRole:
+ _styledMsg.setFlags((Message::Flags)value.toUInt());
+ return true;
+ default:
+ return MessageModelItem::setData(column, value, role);
+ }
+}
+
+
+QVariant ChatLineModelItem::data(int column, int role) const
+{
+ if (role == ChatLineModel::MsgLabelRole)
+ return messageLabel();
+
+ QVariant variant;
+ MessageModel::ColumnType col = (MessageModel::ColumnType)column;
+ switch (col) {
+ case ChatLineModel::TimestampColumn:
+ variant = timestampData(role);
+ break;
+ case ChatLineModel::SenderColumn:
+ variant = senderData(role);
+ break;
+ case ChatLineModel::ContentsColumn:
+ variant = contentsData(role);
+ break;
+ default:
+ break;
+ }
+ if (!variant.isValid())
+ return MessageModelItem::data(column, role);
+ return variant;
+}
+
+
+QVariant ChatLineModelItem::timestampData(int role) const
+{
+ switch (role) {
+ case ChatLineModel::DisplayRole:
+ return _styledMsg.decoratedTimestamp();
+ case ChatLineModel::EditRole:
+ return _styledMsg.timestamp();
+ case ChatLineModel::BackgroundRole:
+ return backgroundBrush(UiStyle::Timestamp);
+ case ChatLineModel::SelectedBackgroundRole:
+ return backgroundBrush(UiStyle::Timestamp, true);
+ case ChatLineModel::FormatRole:
+ return QVariant::fromValue<UiStyle::FormatList>(UiStyle::FormatList()
+ << qMakePair((quint16)0, (quint32) UiStyle::formatType(_styledMsg.type()) | UiStyle::Timestamp));
+ }
+ return QVariant();
+}
+