From: Manuel Nickschas Date: Mon, 10 Mar 2008 21:13:18 +0000 (+0000) Subject: Make the newly arrived topicbutton display background colors and font styles. X-Git-Tag: 0.2.0-alpha3~15 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=87828aeae2510b29619aa79a3bd76885e2c1ebd4 Make the newly arrived topicbutton display background colors and font styles. And yes, I forgot version.inc again... -.- --- diff --git a/src/qtui/topicbutton.cpp b/src/qtui/topicbutton.cpp index 6ece9709..ee91ad59 100644 --- a/src/qtui/topicbutton.cpp +++ b/src/qtui/topicbutton.cpp @@ -33,8 +33,7 @@ #include "message.h" TopicButton::TopicButton(QWidget *parent) - : QAbstractButton(parent), - _sizeHint(QSize()) + : QAbstractButton(parent) { } @@ -42,29 +41,27 @@ void TopicButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); - QFontMetrics metrics(qApp->font()); + painter.setBackgroundMode(Qt::OpaqueMode); - QPoint topLeft = rect().topLeft(); - int height = sizeHint().height(); - int width = 0; - QRect drawRect; + QRect drawRect = rect(); + QRect brect; QString textPart; foreach(QTextLayout::FormatRange fr, styledText.formats) { textPart = styledText.text.mid(fr.start, fr.length); - width = metrics.width(textPart); - drawRect = QRect(topLeft, QPoint(topLeft.x() + width, topLeft.y() + height)); - // qDebug() << drawRect << textPart << width << fr.format.background(); + painter.setFont(fr.format.font()); painter.setPen(QPen(fr.format.foreground(), 0)); - painter.setBackground(fr.format.background()); // no clue why this doesnt work properly o_O - painter.drawText(drawRect, Qt::AlignLeft|Qt::TextSingleLine, textPart); - topLeft.setX(topLeft.x() + width); + painter.setBackground(fr.format.background()); + painter.drawText(drawRect, Qt::AlignLeft|Qt::TextSingleLine, textPart, &brect); + drawRect.setLeft(brect.right()); } } void TopicButton::setAndStyleText(const QString &text) { styledText = QtUi::style()->styleString(Message::mircToInternal(text)); setText(styledText.text); - - QFontMetrics metrics(qApp->font()); - _sizeHint = metrics.boundingRect(styledText.text).size(); + int height = 1; + foreach(QTextLayout::FormatRange fr, styledText.formats) { + height = qMax(height, QFontMetrics(fr.format.font()).height()); + } + setFixedHeight(height); } diff --git a/src/qtui/topicbutton.h b/src/qtui/topicbutton.h index c5fdc228..e0b21885 100644 --- a/src/qtui/topicbutton.h +++ b/src/qtui/topicbutton.h @@ -36,7 +36,6 @@ public: protected: virtual void paintEvent(QPaintEvent *event); - virtual inline QSize sizeHint() const { return _sizeHint; } private: UiStyle::StyledText styledText; diff --git a/src/qtui/ui/topicwidget.ui b/src/qtui/ui/topicwidget.ui index c73364ce..4993bf88 100644 --- a/src/qtui/ui/topicwidget.ui +++ b/src/qtui/ui/topicwidget.ui @@ -5,8 +5,8 @@ 0 0 - 458 - 28 + 515 + 44 @@ -31,23 +31,21 @@ Form - - 2 - - - 2 - - - 2 - - + 2 - + + + + 0 + 0 + + + @@ -58,7 +56,9 @@ ... - + + +