Make the newly arrived topicbutton display background colors and font styles.
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 10 Mar 2008 21:13:18 +0000 (21:13 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 10 Mar 2008 21:13:18 +0000 (21:13 +0000)
And yes, I forgot version.inc again... -.-

src/qtui/topicbutton.cpp
src/qtui/topicbutton.h
src/qtui/ui/topicwidget.ui

index 6ece970..ee91ad5 100644 (file)
@@ -33,8 +33,7 @@
 #include "message.h"
 
 TopicButton::TopicButton(QWidget *parent)
 #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);
   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);
   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.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);
   }
 }
 
 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);
 }
 }
index c5fdc22..e0b2188 100644 (file)
@@ -36,7 +36,6 @@ public:
 
 protected:
   virtual void paintEvent(QPaintEvent *event);
 
 protected:
   virtual void paintEvent(QPaintEvent *event);
-  virtual inline QSize sizeHint() const { return _sizeHint; }
 
 private:
   UiStyle::StyledText styledText;
 
 private:
   UiStyle::StyledText styledText;
index c73364c..4993bf8 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>458</width>
-    <height>28</height>
+    <width>515</width>
+    <height>44</height>
    </rect>
   </property>
   <property name="sizePolicy" >
    </rect>
   </property>
   <property name="sizePolicy" >
    <string>Form</string>
   </property>
   <layout class="QHBoxLayout" >
    <string>Form</string>
   </property>
   <layout class="QHBoxLayout" >
-   <property name="leftMargin" >
-    <number>2</number>
-   </property>
-   <property name="topMargin" >
-    <number>2</number>
-   </property>
-   <property name="rightMargin" >
-    <number>2</number>
-   </property>
-   <property name="bottomMargin" >
+   <property name="margin" >
     <number>2</number>
    </property>
    <item>
     <widget class="QLineEdit" name="topicLineEdit" />
    </item>
    <item>
     <number>2</number>
    </property>
    <item>
     <widget class="QLineEdit" name="topicLineEdit" />
    </item>
    <item>
-    <widget class="TopicButton" native="1" name="topicButton" />
+    <widget class="TopicButton" native="1" name="topicButton" >
+     <property name="sizePolicy" >
+      <sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
    </item>
    <item>
     <widget class="QToolButton" name="topicEditButton" >
    </item>
    <item>
     <widget class="QToolButton" name="topicEditButton" >
@@ -58,7 +56,9 @@
       <string>...</string>
      </property>
      <property name="icon" >
       <string>...</string>
      </property>
      <property name="icon" >
-      <iconset/>
+      <iconset>
+       <normaloff/>
+      </iconset>
      </property>
      <property name="iconSize" >
       <size>
      </property>
      <property name="iconSize" >
       <size>