+void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos) {
+ Q_UNUSED(pos); // we assume that the current mouse cursor pos is the point of invocation
+
+ if(privateData()->currentClickable.isValid()) {
+ switch(privateData()->currentClickable.type) {
+ case Clickable::Url:
+ privateData()->activeClickable = privateData()->currentClickable;
+ menu->addAction(SmallIcon("edit-copy"), tr("Copy Link Address"),
+ &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ // Buffer-specific actions
+ // We add these in ChatItem (rather than the scene), because they depend on the current clickable
+ if(chatScene()->isSingleBufferScene()) {
+ QModelIndex index = Client::networkModel()->bufferIndex(chatScene()->singleBufferId());
+ if(index.isValid()) {
+ menu->addSeparator();
+ QtUi::mainWindow()->allBuffersView()->addActionsToMenu(menu, index);
+ }
+ }
+
+}
+
+void ContentsChatItem::copyLinkToClipboard() {
+ Clickable click = privateData()->activeClickable;
+ if(click.isValid() && click.type == Clickable::Url) {
+ QString url = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length);
+ if(!url.contains("://"))
+ url = "http://" + url;
+ chatScene()->stringToClipboard(url);
+ }
+}
+
+/******** WEB PREVIEW *****************************************************************************/
+
+void ContentsChatItem::showWebPreview(const Clickable &click) {
+#ifndef HAVE_WEBKIT
+ Q_UNUSED(click);
+#else
+ QTextLine line = layout()->lineForTextPosition(click.start);
+ qreal x = line.cursorToX(click.start);
+ qreal width = line.cursorToX(click.start + click.length) - x;
+ qreal height = line.height();
+ qreal y = height * line.lineNumber();
+
+ QPointF topLeft = scenePos() + QPointF(x, y);
+ QRectF urlRect = QRectF(topLeft.x(), topLeft.y(), width, height);
+
+ QString url = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length);
+ if(!url.contains("://"))
+ url = "http://" + url;
+ chatScene()->loadWebPreview(this, url, urlRect);
+#endif
+}
+
+void ContentsChatItem::clearWebPreview() {
+#ifdef HAVE_WEBKIT
+ chatScene()->clearWebPreview(this);
+#endif
+}
+