+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;
+ }
+ default:
+ break;
+ }
+ } else {
+ // Buffer-specific actions
+ ChatItem::addActionsToMenu(menu, pos);
+ }
+}
+
+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
+ QTextLayout layout;
+ initLayout(&layout);
+ 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 urlstr = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
+ if(!urlstr.contains("://"))
+ urlstr= "http://" + urlstr;
+ QUrl url = QUrl::fromEncoded(urlstr.toUtf8(), QUrl::TolerantMode);
+ chatScene()->loadWebPreview(this, url, urlRect);
+#endif
+}
+
+void ContentsChatItem::clearWebPreview() {
+#ifdef HAVE_WEBKIT
+ chatScene()->clearWebPreview(this);
+#endif
+}
+