Revert "Work around MOC ignoring -D options by having dummy stubs"
[quassel.git] / src / qtui / topiclabel.cpp
index ea84b1e..5949777 100644 (file)
@@ -37,8 +37,11 @@ TopicLabel::TopicLabel(QWidget *parent)
   : QFrame(parent),
     offset(0),
     dragStartX(0),
+    textWidth(0),
     dragMode(false)
 {
+  setToolTip(tr("Drag to scroll the topic!"));
+  setCursor(Qt::OpenHandCursor);
 }
 
 void TopicLabel::paintEvent(QPaintEvent *event) {
@@ -63,6 +66,7 @@ void TopicLabel::paintEvent(QPaintEvent *event) {
     painter.drawText(drawRect, Qt::AlignLeft|Qt::AlignVCenter, textPart, &brect);
     drawRect.setLeft(brect.right());
   }
+  textWidth = brect.right();
 #endif
 }
 
@@ -88,7 +92,6 @@ void TopicLabel::setText(const QString &text) {
   // setFixedHeight(height);
 #endif  
   // show topic in tooltip
-  setToolTip(_text);
 }
 
 
@@ -97,7 +100,12 @@ void TopicLabel::mouseMoveEvent(QMouseEvent *event) {
     return;
 
   event->accept();
-  offset = event->pos().x() - dragStartX;
+  int newOffset = event->pos().x() - dragStartX;
+  if(newOffset > 0)
+    offset = 0;
+  else if(width() + 1 < textWidth || offset < newOffset)
+    offset = newOffset;
+
   update();
 }
 
@@ -105,6 +113,7 @@ void TopicLabel::mousePressEvent(QMouseEvent *event) {
   event->accept();
   dragMode = true;
   dragStartX = event->pos().x() - offset;
+  setCursor(Qt::ClosedHandCursor);
 }
 
 void TopicLabel::mouseReleaseEvent(QMouseEvent *event) {
@@ -114,27 +123,25 @@ void TopicLabel::mouseReleaseEvent(QMouseEvent *event) {
     offset = 0;
     update();
   }
+  setCursor(Qt::OpenHandCursor);
 }
 
 void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) {
 #ifndef SPUTDEV
   event->accept();
-  int textPart = 0;
-  int textOffset = 0;
-
   if(textPartOffset.isEmpty())
     return;
 
   // find the text part that contains the url. We don't expect color codes in urls so we expect only full parts (yet?)
-  int x = event->pos().x();
+  int textPart = 0;
+  int x = event->pos().x() + offset;
   while(textPart + 1 < textPartOffset.count()) {
-    if(textPartOffset[textPart + 1] < x) {
+    if(textPartOffset[textPart + 1] < x)
       textPart++;
-      textOffset = textPartOffset[textPart];
-    } else {
+    else
       break;
-    }
   }
+  int textOffset = textPartOffset[textPart];
 
   // we've Identified the needed text part \o/
   QString text = styledContents.plainText.mid(styledContents.formatList[textPart].start, styledContents.formatList[textPart].length);
@@ -144,6 +151,7 @@ void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) {
   
   int start = 0;
   int spacePos = text.indexOf(" ");
+  x -= offset; // offset needs to go here as it's already in the textOffset
   while(spacePos != -1) {
     if(fontMetric.width(text.left(spacePos + 1)) + textOffset < x) {
       start = spacePos + 1;
@@ -159,7 +167,6 @@ void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) {
     len = end - start;
   }
   QString word = text.mid(start, len);
-  qDebug() << word;
   QRegExp regex("^(h|f)t{1,2}ps?:\\/\\/");
   if(regex.indexIn(word) != -1) {
     QDesktopServices::openUrl(QUrl(word));