1 /***************************************************************************
2 * Copyright (C) 2005/06 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "topicbutton.h"
26 #include <QApplication>
28 #include <QHBoxLayout>
30 #include <QFontMetrics>
35 TopicButton::TopicButton(QWidget *parent)
36 : QAbstractButton(parent),
41 void TopicButton::paintEvent(QPaintEvent *event) {
44 QPainter painter(this);
45 QFontMetrics metrics(qApp->font());
47 QPoint topLeft = rect().topLeft();
48 int height = sizeHint().height();
52 foreach(QTextLayout::FormatRange fr, styledText.formats) {
53 textPart = styledText.text.mid(fr.start, fr.length);
54 width = metrics.width(textPart);
55 drawRect = QRect(topLeft, QPoint(topLeft.x() + width, topLeft.y() + height));
56 // qDebug() << drawRect << textPart << width << fr.format.background();
57 painter.setPen(QPen(fr.format.foreground(), 0));
58 painter.setBackground(fr.format.background()); // no clue why this doesnt work properly o_O
59 painter.drawText(drawRect, Qt::AlignLeft|Qt::TextSingleLine, textPart);
60 topLeft.setX(topLeft.x() + width);
64 void TopicButton::setAndStyleText(const QString &text) {
65 styledText = QtUi::style()->styleString(Message::mircToInternal(text));
66 setText(styledText.text);
68 QFontMetrics metrics(qApp->font());
69 _sizeHint = metrics.boundingRect(styledText.text).size();