X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Ftopicbutton.cpp;h=f2f60af199422fcb671e29c18500c203052fb741;hp=ee91ad59e57d04e11756df8dd4087546470288fd;hb=bf01681e9e6108517bfa997422b84e04b801a40a;hpb=87828aeae2510b29619aa79a3bd76885e2c1ebd4 diff --git a/src/qtui/topicbutton.cpp b/src/qtui/topicbutton.cpp index ee91ad59..f2f60af1 100644 --- a/src/qtui/topicbutton.cpp +++ b/src/qtui/topicbutton.cpp @@ -35,6 +35,8 @@ TopicButton::TopicButton(QWidget *parent) : QAbstractButton(parent) { + setFixedHeight(QFontMetrics(qApp->font()).height()); + setToolTip(tr("Click to edit!")); } void TopicButton::paintEvent(QPaintEvent *event) { @@ -43,25 +45,42 @@ void TopicButton::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setBackgroundMode(Qt::OpaqueMode); + // FIXME re-enable topic painting +#ifndef SPUTDEV QRect drawRect = rect(); QRect brect; QString textPart; - foreach(QTextLayout::FormatRange fr, styledText.formats) { - textPart = styledText.text.mid(fr.start, fr.length); + foreach(QTextLayout::FormatRange fr, styledContents.formatList) { + textPart = styledContents.plainText.mid(fr.start, fr.length); painter.setFont(fr.format.font()); painter.setPen(QPen(fr.format.foreground(), 0)); painter.setBackground(fr.format.background()); painter.drawText(drawRect, Qt::AlignLeft|Qt::TextSingleLine, textPart, &brect); drawRect.setLeft(brect.right()); } +#endif } void TopicButton::setAndStyleText(const QString &text) { - styledText = QtUi::style()->styleString(Message::mircToInternal(text)); - setText(styledText.text); + if(QAbstractButton::text() == text) + return; + + setText(text); // this triggers a repaint event + +#ifndef SPUTDEV + styledContents = QtUi::style()->styleString(Message::mircToInternal(text)); int height = 1; - foreach(QTextLayout::FormatRange fr, styledText.formats) { + foreach(QTextLayout::FormatRange fr, styledContents.formatList) { height = qMax(height, QFontMetrics(fr.format.font()).height()); } + + // ensure the button is editable (height != 1) if there is no text to show + if(text.isEmpty()) + height = QFontMetrics(qApp->font()).height(); + setFixedHeight(height); +#endif + // show topic in tooltip + setToolTip(tr("%1\n\nClick to edit!").arg(QAbstractButton::text())); } +