+ default:
+ break;
+ }
+ }
+ } else if(clickMode == ChatScene::DoubleClick) {
+ chatScene()->setSelectingItem(this);
+ setSelectionMode(PartialSelection);
+ Clickable click = clickableAt(pos);
+ if(click.isValid()) {
+ setSelectionStart(click.start);
+ setSelectionEnd(click.start + click.length);
+ } else {
+ // find word boundary
+ QString str = data(ChatLineModel::DisplayRole).toString();
+ qint16 cursor = posToCursor(pos);
+ qint16 start = str.lastIndexOf(QRegExp("\\W"), cursor) + 1;
+ qint16 end = qMin(str.indexOf(QRegExp("\\W"), cursor), str.length());
+ if(end < 0) end = str.length();
+ setSelectionStart(start);
+ setSelectionEnd(end);
+ }
+ update();
+ } else if(clickMode == ChatScene::TripleClick) {
+ setSelection(PartialSelection, 0, data(ChatLineModel::DisplayRole).toString().length());
+ }
+ ChatItem::handleClick(pos, clickMode);
+}
+
+void ContentsChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+ // mouse move events always mean we're not hovering anymore...
+ endHoverMode();
+ ChatItem::mouseMoveEvent(event);
+}
+
+void ContentsChatItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
+ endHoverMode();
+ event->accept();
+}
+
+void ContentsChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
+ bool onClickable = false;
+ Clickable click = clickableAt(event->pos());
+ if(click.isValid()) {
+ if(click.type == Clickable::Url) {
+ onClickable = true;
+ showWebPreview(click);
+ } else if(click.type == Clickable::Channel) {
+ QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length);
+ // don't make clickable if it's our own name
+ BufferId myId = data(MessageModel::BufferIdRole).value<BufferId>();
+ if(Client::networkModel()->bufferName(myId) != name)
+ onClickable = true;
+ }
+ if(onClickable) {
+ setCursor(Qt::PointingHandCursor);
+ privateData()->currentClickable = click;
+ update();
+ return;
+ }
+ }
+ if(!onClickable) endHoverMode();
+ event->accept();
+}
+
+void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos) {
+ if(privateData()->currentClickable.isValid()) {
+ Clickable click = privateData()->currentClickable;
+ switch(click.type) {
+ case Clickable::Url:
+ privateData()->activeClickable = click;
+ menu->addAction(SmallIcon("edit-copy"), tr("Copy Link Address"),
+ &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
+ break;
+ case Clickable::Channel: {
+ // Hide existing menu actions, they confuse us when right-clicking on a clickable
+ foreach(QAction *action, menu->actions())
+ action->setVisible(false);
+ QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length);
+ GraphicalUi::contextMenuActionProvider()->addActions(menu, chatScene()->filter(), data(MessageModel::BufferIdRole).value<BufferId>(), name);
+ break;