#include "chatlinemodelitem.h"
-ChatLineModel::ChatLineModel(QObject *parent) : MessageModel(parent) {
+ChatLineModel::ChatLineModel(QObject *parent)
+ : MessageModel(parent)
+{
qRegisterMetaType<WrapList>("ChatLineModel::WrapList");
qRegisterMetaTypeStreamOperators<WrapList>("ChatLineModel::WrapList");
-
-}
-
-ChatLineModel::~ChatLineModel() {
-
}
-
MessageModelItem *ChatLineModel::createMessageModelItem(const Message &msg) {
return new ChatLineModelItem(msg);
-
}
class ChatLineModel : public MessageModel {
Q_OBJECT
- public:
- enum ChatLineRole {
- WrapListRole = MessageModel::UserRole
- };
-
- ChatLineModel(QObject *parent = 0);
- virtual ~ChatLineModel();
-
- /// Used to store information about words to be used for wrapping
- struct Word {
- quint16 start;
- qreal width;
- qreal trailing;
- };
-
- typedef QVector<Word> WrapList;
-
- protected:
- virtual MessageModelItem *createMessageModelItem(const Message &);
+public:
+ enum ChatLineRole {
+ WrapListRole = MessageModel::UserRole
+ };
+
+ ChatLineModel(QObject *parent = 0);
+
+ /// Used to store information about words to be used for wrapping
+ struct Word {
+ quint16 start;
+ qreal width;
+ qreal trailing;
+ };
+ typedef QVector<Word> WrapList;
+
+protected:
+ virtual MessageModelItem *createMessageModelItem(const Message &);
};
unsigned char *ChatLineModelItem::TextBoundaryFinderBuffer = (unsigned char *)malloc(512 * sizeof(HB_CharAttributes_Dummy));
int ChatLineModelItem::TextBoundaryFinderBufferSize = 512 * (sizeof(HB_CharAttributes_Dummy) / sizeof(unsigned char));
+struct ChatLineModelItemPrivate {
+ ChatLineModel::WrapList wrapList;
+};
+
ChatLineModelItem::ChatLineModelItem(const Message &msg)
- : MessageModelItem(msg)
+ : MessageModelItem(msg),
+ _data(new ChatLineModelItemPrivate)
{
QtUiStyle::StyledMessage m = QtUi::style()->styleMessage(msg);
_timestamp.formatList = m.timestamp.formatList;
_sender.formatList = m.sender.formatList;
_contents.formatList = m.contents.formatList;
-
- computeWrapList();
}
-
QVariant ChatLineModelItem::data(int column, int role) const {
const ChatLinePart *part = 0;
case ChatLineModel::WrapListRole:
if(column != ChatLineModel::ContentsColumn)
return QVariant();
- return QVariant::fromValue<ChatLineModel::WrapList>(_wrapList);
+ if(_data->wrapList.isEmpty())
+ computeWrapList();
+ return QVariant::fromValue<ChatLineModel::WrapList>(_data->wrapList);
}
return MessageModelItem::data(column, role);
}
-void ChatLineModelItem::computeWrapList() {
+void ChatLineModelItem::computeWrapList() const {
if(_contents.plainText.isEmpty())
return;
enum Mode { SearchStart, SearchEnd };
QList<ChatLineModel::Word> 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.unicode(), _contents.plainText.length(), TextBoundaryFinderBuffer, TextBoundaryFinderBufferSize);
int idx;
} while(finder.isAtBoundary() || (finder.position() == _contents.plainText.length()));
// A QVector needs less space than a QList
- _wrapList.resize(wplist.count());
+ _data->wrapList.resize(wplist.count());
for(int i = 0; i < wplist.count(); i++) {
- _wrapList[i] = wplist.at(i);
+ _data->wrapList[i] = wplist.at(i);
}
}
#include "chatlinemodel.h"
#include "uistyle.h"
+class ChatLineModelItemPrivate;
+
class ChatLineModelItem : public MessageModelItem {
public:
ChatLineModelItem(const Message &);
virtual inline bool setData(int column, const QVariant &value, int role) { Q_UNUSED(column); Q_UNUSED(value); Q_UNUSED(role); return false; }
private:
- void computeWrapList();
+ void computeWrapList() const;
struct ChatLinePart {
QString plainText;
};
ChatLinePart _timestamp, _sender, _contents;
- ChatLineModel::WrapList _wrapList;
+ ChatLineModelItemPrivate *_data;
static unsigned char *TextBoundaryFinderBuffer;
static int TextBoundaryFinderBufferSize;