Implement quick and dirty doubleclick handler for URLs. Will be replaced by fanciness...
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 31 Jul 2008 23:27:41 +0000 (01:27 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 2 Aug 2008 13:17:11 +0000 (15:17 +0200)
src/qtui/chatitem.cpp
src/qtui/chatitem.h

index e0d3e22..adfcd9c 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <QApplication>
 #include <QClipboard>
 
 #include <QApplication>
 #include <QClipboard>
+#include <QDesktopServices>
 #include <QFontMetrics>
 #include <QGraphicsSceneMouseEvent>
 #include <QPainter>
 #include <QFontMetrics>
 #include <QGraphicsSceneMouseEvent>
 #include <QPainter>
@@ -237,6 +238,24 @@ void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
   }
 }
 
   }
 }
 
+void ChatItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
+  // FIXME dirty and fast hack to make http:// urls klickable
+
+  QRegExp regex("\\b((?:h|f)t{1,2}ps?:\\/\\/.+)\\b");
+  QString str = data(ChatLineModel::DisplayRole).toString();
+  int idx = posToCursor(event->pos());
+  int mi = 0;
+  do {
+    mi = regex.indexIn(str, mi);
+    if(mi < 0) break;
+    if(idx >= mi && idx < mi + regex.matchedLength()) {
+      QDesktopServices::openUrl(QUrl(regex.capturedTexts()[1]));
+      break;
+    }
+  } while(mi >= 0);
+  event->accept();
+}
+
 void ChatItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
   //qDebug() << (void*)this << "entering";
 
 void ChatItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
   //qDebug() << (void*)this << "entering";
 
index ddbffdb..840184d 100644 (file)
@@ -66,6 +66,7 @@ class ChatItem : public QGraphicsItem {
     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+    virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
 
     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
 
     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);