+ bool onClickable = false;
+ qint16 idx = posToCursor(event->pos());
+ for(int i = 0; i < privateData()->clickables.count(); i++) {
+ Clickable click = privateData()->clickables.at(i);
+ if(idx >= click.start && idx < click.start + click.length) {
+ if(click.type == Clickable::Url) {
+ onClickable = true;
+ showWebPreview(click);
+ } else if(click.type == Clickable::Channel) {
+ // TODO: don't make clickable if it's our own name
+ //onClickable = true; //FIXME disabled for now
+ }
+ if(onClickable) {
+ setCursor(Qt::PointingHandCursor);
+ privateData()->currentClickable = click;
+ update();
+ break;
+ }
+ }
+ }
+ if(!onClickable) endHoverMode();
+ event->accept();
+}
+
+void ContentsChatItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
+ qint16 idx = posToCursor(event->pos());
+ for(int i = 0; i < privateData()->clickables.count(); i++) {
+ Clickable click = privateData()->clickables.at(i);
+ if(idx >= click.start && idx < click.start + click.length) {
+ if(click.type == Clickable::Url) {
+ QMenu menu;
+ QAction *copyToClipboard = menu.addAction(QObject::tr("Copy to Clipboard"));
+ QAction *selected = menu.exec(event->screenPos());
+ if(selected == copyToClipboard) {
+ QString url = data(ChatLineModel::DisplayRole).toString().mid(click.start, click.length);
+# ifdef Q_WS_X11
+ QApplication::clipboard()->setText(url, QClipboard::Selection);
+# endif
+//# else
+ QApplication::clipboard()->setText(url);
+//# endif
+ }
+ }
+ }
+ }
+}
+
+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