projects
/
quassel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improvements in the build system
[quassel.git]
/
src
/
qtui
/
topiclabel.cpp
diff --git
a/src/qtui/topiclabel.cpp
b/src/qtui/topiclabel.cpp
index
33a752c
..
8703142
100644
(file)
--- a/
src/qtui/topiclabel.cpp
+++ b/
src/qtui/topiclabel.cpp
@@
-31,31
+31,35
@@
#include <QFontMetrics>
#include "qtui.h"
#include <QFontMetrics>
#include "qtui.h"
+#include "qtuistyle.h"
#include "message.h"
TopicLabel::TopicLabel(QWidget *parent)
: QFrame(parent),
offset(0),
dragStartX(0),
#include "message.h"
TopicLabel::TopicLabel(QWidget *parent)
: QFrame(parent),
offset(0),
dragStartX(0),
+ textWidth(0),
dragMode(false)
{
dragMode(false)
{
+ setToolTip(tr("Drag to scroll the topic!"));
+ setCursor(Qt::OpenHandCursor);
}
void TopicLabel::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
textPartOffset.clear();
}
void TopicLabel::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
textPartOffset.clear();
-
+
QPainter painter(this);
painter.setBackgroundMode(Qt::OpaqueMode);
QPainter painter(this);
painter.setBackgroundMode(Qt::OpaqueMode);
- // FIXME
re-enable topic painting
-#ifndef SPUTDEV
+ // FIXME
use QTextLayout instead
+
QRect drawRect = rect().adjusted(offset, 0, 0, 0);
QRect brect;
QString textPart;
QRect drawRect = rect().adjusted(offset, 0, 0, 0);
QRect brect;
QString textPart;
- foreach(QTextLayout::FormatRange fr,
styledContents.
formatList) {
- textPart =
styledContents.
plainText.mid(fr.start, fr.length);
+ foreach(QTextLayout::FormatRange fr, formatList) {
+ textPart = plainText.mid(fr.start, fr.length);
textPartOffset << drawRect.left();
painter.setFont(fr.format.font());
painter.setPen(QPen(fr.format.foreground(), 0));
textPartOffset << drawRect.left();
painter.setFont(fr.format.font());
painter.setPen(QPen(fr.format.foreground(), 0));
@@
-63,7
+67,7
@@
void TopicLabel::paintEvent(QPaintEvent *event) {
painter.drawText(drawRect, Qt::AlignLeft|Qt::AlignVCenter, textPart, &brect);
drawRect.setLeft(brect.right());
}
painter.drawText(drawRect, Qt::AlignLeft|Qt::AlignVCenter, textPart, &brect);
drawRect.setLeft(brect.right());
}
-#endif
+ textWidth = brect.right();
}
void TopicLabel::setText(const QString &text) {
}
void TopicLabel::setText(const QString &text) {
@@
-71,23
+75,23
@@
void TopicLabel::setText(const QString &text) {
return;
_text = text;
return;
_text = text;
+ offset = 0;
update();
update();
-#ifndef SPUTDEV
- styledContents = QtUi::style()->styleString(Message::mircToInternal(text));
+ UiStyle::StyledString styledContents = QtUi::style()->styleString("%D0" + QtUi::style()->mircToInternal(text));
+ plainText = styledContents.plainText;
+ formatList = QtUi::style()->toTextLayoutList(styledContents.formatList, plainText.length());
int height = 1;
int height = 1;
- foreach(QTextLayout::FormatRange fr,
styledContents.
formatList) {
+ foreach(QTextLayout::FormatRange fr, formatList) {
height = qMax(height, QFontMetrics(fr.format.font()).height());
}
// ensure the label is editable (height != 1) if there is no text to show
if(text.isEmpty())
height = QFontMetrics(qApp->font()).height();
height = qMax(height, QFontMetrics(fr.format.font()).height());
}
// ensure the label is editable (height != 1) if there is no text to show
if(text.isEmpty())
height = QFontMetrics(qApp->font()).height();
-
+
// setFixedHeight(height);
// setFixedHeight(height);
-#endif
// show topic in tooltip
// show topic in tooltip
- setToolTip(_text);
}
}
@@
-96,7
+100,12
@@
void TopicLabel::mouseMoveEvent(QMouseEvent *event) {
return;
event->accept();
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();
}
update();
}
@@
-104,45
+113,44
@@
void TopicLabel::mousePressEvent(QMouseEvent *event) {
event->accept();
dragMode = true;
dragStartX = event->pos().x() - offset;
event->accept();
dragMode = true;
dragStartX = event->pos().x() - offset;
+ setCursor(Qt::ClosedHandCursor);
}
void TopicLabel::mouseReleaseEvent(QMouseEvent *event) {
event->accept();
dragMode = false;
}
void TopicLabel::mouseReleaseEvent(QMouseEvent *event) {
event->accept();
dragMode = false;
- if(qAbs(offset) <
1
0) {
+ if(qAbs(offset) <
3
0) {
offset = 0;
update();
}
offset = 0;
update();
}
+ setCursor(Qt::OpenHandCursor);
}
void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) {
}
void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) {
-#ifndef SPUTDEV
event->accept();
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?)
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()) {
while(textPart + 1 < textPartOffset.count()) {
- if(textPartOffset[textPart + 1] < x)
{
+ if(textPartOffset[textPart + 1] < x)
textPart++;
textPart++;
- textOffset = textPartOffset[textPart];
- } else {
+ else
break;
break;
- }
}
}
+ int textOffset = textPartOffset[textPart];
// we've Identified the needed text part \o/
// we've Identified the needed text part \o/
- QString text =
styledContents.plainText.mid(styledContents.formatList[textPart].start, styledContents.
formatList[textPart].length);
+ QString text =
plainText.mid(formatList[textPart].start,
formatList[textPart].length);
// now we have to find the the left and right word delimiters of the clicked word
// now we have to find the the left and right word delimiters of the clicked word
- QFontMetrics fontMetric(
styledContents.
formatList[textPart].format.font());
-
+ QFontMetrics fontMetric(formatList[textPart].format.font());
+
int start = 0;
int spacePos = text.indexOf(" ");
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;
while(spacePos != -1) {
if(fontMetric.width(text.left(spacePos + 1)) + textOffset < x) {
start = spacePos + 1;
@@
-158,11
+166,8
@@
void TopicLabel::mouseDoubleClickEvent(QMouseEvent *event) {
len = end - start;
}
QString word = text.mid(start, len);
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));
}
QRegExp regex("^(h|f)t{1,2}ps?:\\/\\/");
if(regex.indexIn(word) != -1) {
QDesktopServices::openUrl(QUrl(word));
}
-#endif
-
}
}