+ }
+}
+
+void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
+ if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) {
+ _selectionEnd = posToCursor(event->pos());
+ QString selection
+ = data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
+ QApplication::clipboard()->setText(selection, QClipboard::Clipboard); // TODO configure where selections should go
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
+void ChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
+ // FIXME dirty and fast hack to make http:// urls klickable
+
+ QRegExp regex("\\b([hf]t{1,2}ps?://[^\\s]+)\\b");
+ QString str = data(ChatLineModel::DisplayRole).toString();
+ int idx = posToCursor(event->pos());
+ int mi = 0;
+ do {
+ mi = regex.indexIn(str, mi);
+ if(mi < 0) break;
+ if(idx >= mi && idx < mi + regex.matchedLength()) {
+ QDesktopServices::openUrl(QUrl(regex.capturedTexts()[1]));
+ break;
+ }
+ mi += regex.matchedLength();
+ } while(mi >= 0);
+ event->accept();
+}
+
+void ChatItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
+ //qDebug() << (void*)this << "entering";
+ event->ignore();
+}
+
+void ChatItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
+ //qDebug() << (void*)this << "leaving";
+ event->ignore();
+}
+
+void ChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
+ //qDebug() << (void*)this << event->pos();
+ event->ignore();
+}
+
+
+/*************************************************************************************************/
+
+ChatItem::WrapColumnFinder::WrapColumnFinder(ChatItem *_item) : item(_item) {
+ wrapList = item->data(ChatLineModel::WrapListRole).value<ChatLineModel::WrapList>();
+ wordidx = 0;
+ layout = 0;
+ lastwrapcol = 0;
+ lastwrappos = 0;
+ w = 0;
+}
+
+ChatItem::WrapColumnFinder::~WrapColumnFinder() {
+ delete layout;
+}
+
+qint16 ChatItem::WrapColumnFinder::nextWrapColumn() {
+ while(wordidx < wrapList.count()) {
+ w += wrapList.at(wordidx).width;
+ if(w >= item->width()) {
+ if(lastwrapcol >= wrapList.at(wordidx).start) {
+ // first word, and it doesn't fit
+ if(!line.isValid()) {
+ layout = item->createLayout(QTextOption::NoWrap);
+ layout->beginLayout();
+ line = layout->createLine();
+ line.setLineWidth(item->width());
+ layout->endLayout();
+ }
+ int idx = line.xToCursor(lastwrappos + item->width(), QTextLine::CursorOnCharacter);
+ qreal x = line.cursorToX(idx, QTextLine::Trailing);
+ w = w - wrapList.at(wordidx).width - (x - lastwrappos);
+ lastwrappos = x;
+ lastwrapcol = idx;
+ return idx;
+ }
+ // not the first word, so just wrap before this
+ lastwrapcol = wrapList.at(wordidx).start;
+ lastwrappos = lastwrappos + w - wrapList.at(wordidx).width;
+ w = 0;
+ return lastwrapcol;
+ }
+ w += wrapList.at(wordidx).trailing;
+ wordidx++;
+ }
+ return -1;