return model()->data(index, role);
}
-qreal ChatItem::setWidth(qreal w) {
+qreal ChatItem::setGeometry(qreal w, qreal h) {
if(w == _boundingRect.width()) return _boundingRect.height();
prepareGeometryChange();
_boundingRect.setWidth(w);
- qreal h = computeHeight();
+ if(h < 0) h = computeHeight();
_boundingRect.setHeight(h);
if(haveLayout()) updateLayout();
return h;
}
void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
- if(event->buttons() & Qt::LeftButton) {
+ if(event->buttons() == Qt::LeftButton) {
if(_selectionMode == NoSelection) {
chatScene()->setSelectingItem(this); // removes earlier selection if exists
_selectionStart = _selectionEnd = posToCursor(event->pos());
}
void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
- if(contains(event->pos())) {
- qint16 end = posToCursor(event->pos());
- if(end != _selectionEnd) {
- _selectionEnd = end;
- update();
+ if(event->buttons() == Qt::LeftButton) {
+ if(contains(event->pos())) {
+ qint16 end = posToCursor(event->pos());
+ if(end != _selectionEnd) {
+ _selectionEnd = end;
+ update();
+ }
+ } else {
+ setFullSelection();
+ chatScene()->startGlobalSelection(this, event->pos());
}
+ event->accept();
} else {
- setFullSelection();
- chatScene()->startGlobalSelection(this, event->pos());
+ event->ignore();
}
}
void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
- if(_selectionMode != NoSelection) {
+ if(_selectionMode != NoSelection && !event->buttons() & Qt::LeftButton) {
_selectionEnd = posToCursor(event->pos());
QString selection
= data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
void ChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
// FIXME dirty and fast hack to make http:// urls klickable
- QRegExp regex("\\b((?:h|f)t{1,2}ps?://[^\\s]+)\\b");
+ QRegExp regex("\\b([hf]t{1,2}ps?://[^\\s]+)\\b");
QString str = data(ChatLineModel::DisplayRole).toString();
int idx = posToCursor(event->pos());
int mi = 0;
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();
}