From 68cd9a2621c71005cda0ed4fb796bbf5fcbe007e Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 25 Jun 2009 21:18:59 +0200 Subject: [PATCH 1/1] Update ChatViews whenever the stylesheet is reloaded 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 | 8 ++++---- src/qtui/chatitem.h | 2 +- src/qtui/chatview.cpp | 7 +++++++ src/qtui/chatview.h | 1 + src/uisupport/uistyle.cpp | 2 ++ src/uisupport/uistyle.h | 8 ++++++-- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 5c44815a..290542be 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -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().at(0).second); - setGeometryByWidth(width); } +QFontMetricsF *ContentsChatItem::fontMetrics() const { + return QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value().at(0).second); +} + ContentsChatItem::~ContentsChatItem() { delete _data; } diff --git a/src/qtui/chatitem.h b/src/qtui/chatitem.h index c73d7c14..5796f5e9 100644 --- a/src/qtui/chatitem.h +++ b/src/qtui/chatitem.h @@ -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); diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 27874928..eac76a20 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -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(); diff --git a/src/qtui/chatview.h b/src/qtui/chatview.h index 5969f728..6f385bb7 100644 --- a/src/qtui/chatview.h +++ b/src/qtui/chatview.h @@ -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); diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index 5909c19f..5ad89f08 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -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) { diff --git a/src/uisupport/uistyle.h b/src/uisupport/uistyle.h index 5c6f0900..9b9365d4 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -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 toTextLayoutList(const FormatList &, int textLength, quint32 messageLabel = 0); +public slots: + void loadStyleSheet(); + +signals: + void changed(); + protected: QString loadStyleSheet(const QString &name, bool shouldExist = false); -- 2.20.1