X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Ftopiclabel.cpp;h=1e1e1da42fc4062f5d85a2940e1d07da5e0744c8;hp=33a752c04a19bb3423936a2aee92725a71afe515;hb=92789e6323ca73383a7954d834ecfc093234f5e2;hpb=982ece4929696e3817875543cab527740cc7e023 diff --git a/src/qtui/topiclabel.cpp b/src/qtui/topiclabel.cpp index 33a752c0..1e1e1da4 100644 --- a/src/qtui/topiclabel.cpp +++ b/src/qtui/topiclabel.cpp @@ -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) { @@ -50,7 +53,7 @@ void TopicLabel::paintEvent(QPaintEvent *event) { painter.setBackgroundMode(Qt::OpaqueMode); // FIXME re-enable topic painting -#ifndef SPUTDEV + /* QRect drawRect = rect().adjusted(offset, 0, 0, 0); QRect brect; QString textPart; @@ -63,7 +66,8 @@ void TopicLabel::paintEvent(QPaintEvent *event) { painter.drawText(drawRect, Qt::AlignLeft|Qt::AlignVCenter, textPart, &brect); drawRect.setLeft(brect.right()); } -#endif + textWidth = brect.right(); + */ } void TopicLabel::setText(const QString &text) { @@ -71,9 +75,10 @@ void TopicLabel::setText(const QString &text) { return; _text = text; + offset = 0; update(); -#ifndef SPUTDEV + /* FIXME SPUTDEV reenable styledContents = QtUi::style()->styleString(Message::mircToInternal(text)); int height = 1; foreach(QTextLayout::FormatRange fr, styledContents.formatList) { @@ -85,9 +90,8 @@ void TopicLabel::setText(const QString &text) { height = QFontMetrics(qApp->font()).height(); // setFixedHeight(height); -#endif + */ // show topic in tooltip - setToolTip(_text); } @@ -96,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(); } @@ -104,36 +113,35 @@ void TopicLabel::mousePressEvent(QMouseEvent *event) { event->accept(); dragMode = true; dragStartX = event->pos().x() - offset; + setCursor(Qt::ClosedHandCursor); } void TopicLabel::mouseReleaseEvent(QMouseEvent *event) { event->accept(); dragMode = false; - if(qAbs(offset) < 10) { + if(qAbs(offset) < 30) { offset = 0; update(); } + setCursor(Qt::OpenHandCursor); } void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) { -#ifndef SPUTDEV + /* FIXME SPUTDEV reenable 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); @@ -143,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; @@ -158,11 +167,10 @@ 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)); } -#endif + */ }