Update ChatViews whenever the stylesheet is reloaded
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 25 Jun 2009 19:18:59 +0000 (21:18 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 6 Aug 2009 18:25:05 +0000 (20:25 +0200)
UiStyle now emits a signal when loadStyleSheet() (now a slot) is called.
ChatView reacts by invalidating the scene. Note that the ChatLines are not re-layouted,
which means that changes in font sizes and possibly styles might lead to a broken appearance.
This is primarily thought for testing color combinations without restarting the client
all the time.

src/qtui/chatitem.cpp
src/qtui/chatitem.h
src/qtui/chatview.cpp
src/qtui/chatview.h
src/uisupport/uistyle.cpp
src/uisupport/uistyle.h

index 5c44815..290542b 100644 (file)
@@ -363,13 +363,13 @@ ContentsChatItem::ContentsChatItem(const qreal &width, const QPointF &pos, QGrap
   : ChatItem(0, 0, pos, parent),
     _data(0)
 {
-  const QAbstractItemModel *model_ = model();
-  QModelIndex index = model_->index(row(), column());
-  _fontMetrics = QtUi::style()->fontMetrics(model_->data(index, ChatLineModel::FormatRole).value<UiStyle::FormatList>().at(0).second);
-
   setGeometryByWidth(width);
 }
 
+QFontMetricsF *ContentsChatItem::fontMetrics() const {
+  return QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value<UiStyle::FormatList>().at(0).second);
+}
+
 ContentsChatItem::~ContentsChatItem() {
   delete _data;
 }
index c73d7c1..5796f5e 100644 (file)
@@ -171,7 +171,7 @@ public:
   virtual inline int type() const { return Type; }
 
   inline ChatLineModel::ColumnType column() const { return ChatLineModel::ContentsColumn; }
-  inline QFontMetricsF *fontMetrics() const { return _fontMetrics; }
+  QFontMetricsF *fontMetrics() const;
 
 protected:
   virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
index 2787492..eac76a2 100644 (file)
@@ -28,6 +28,8 @@
 #include "chatview.h"
 #include "client.h"
 #include "messagefilter.h"
+#include "qtui.h"
+#include "qtuistyle.h"
 
 ChatView::ChatView(BufferId bufferId, QWidget *parent)
   : QGraphicsView(parent),
@@ -71,6 +73,7 @@ void ChatView::init(MessageFilter *filter) {
   setScene(_scene);
 
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
+  connect(QtUi::style(), SIGNAL(changed()), this, SLOT(styleChanged()));
 }
 
 bool ChatView::event(QEvent *event) {
@@ -169,6 +172,10 @@ void ChatView::verticalScrollbarChanged(int newPos) {
     vbar->setValue(vbar->maximum());
 }
 
+void ChatView::styleChanged() {
+  invalidateScene();
+}
+
 MsgId ChatView::lastMsgId() const {
   if(!scene())
     return MsgId();
index 5969f72..6f385bb 100644 (file)
@@ -68,6 +68,7 @@ private slots:
   void lastLineChanged(QGraphicsItem *chatLine, qreal offset);
   void mouseMoveWhileSelecting(const QPointF &scenePos);
   void scrollTimerTimeout();
+  void styleChanged();
 
 private:
   void init(MessageFilter *filter);
index 5909c19..5ad89f0 100644 (file)
@@ -77,6 +77,8 @@ void UiStyle::loadStyleSheet() {
   _formatCache = parser.formats();
 
   qApp->setStyleSheet(styleSheet); // pass the remaining sections to the application
+
+  emit changed();
 }
 
 QString UiStyle::loadStyleSheet(const QString &styleSheet, bool shouldExist) {
index 5c6f090..9b9365d 100644 (file)
@@ -103,8 +103,6 @@ public:
 
   class StyledMessage;
 
-  void loadStyleSheet();
-
   static FormatType formatType(Message::Type msgType);
   static StyledString styleString(const QString &string, quint32 baseFormat = None);
   static QString mircToInternal(const QString &);
@@ -116,6 +114,12 @@ public:
 
   QList<QTextLayout::FormatRange> toTextLayoutList(const FormatList &, int textLength, quint32 messageLabel = 0);
 
+public slots:
+  void loadStyleSheet();
+
+signals:
+  void changed();
+
 protected:
   QString loadStyleSheet(const QString &name, bool shouldExist = false);