From 064dcac965d1e724a0434683685a24ec7e6ba855 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 29 Jul 2009 19:16:45 +0200 Subject: [PATCH] Allow reloading stylesheets at runtime We can now relayout the ChatScene using ChatScene::layout() and this is used whenever UiStyle changes. This means that it's now possible to reload stylesheets at runtime and reflect this in the ChatView without restarting the client. --- src/qtui/chatitem.cpp | 8 ++++++-- src/qtui/chatscene.cpp | 6 ++++++ src/qtui/chatscene.h | 1 + src/qtui/chatview.cpp | 4 +--- src/qtui/mainwin.cpp | 2 +- src/uisupport/uistyle.cpp | 8 +++++++- src/uisupport/uistyle.h | 3 ++- 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 2159f3f3..819877ae 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -391,7 +391,11 @@ ContentsChatItemPrivate *ContentsChatItem::privateData() const { } qreal ContentsChatItem::setGeometryByWidth(qreal w) { - if(w != width()) { + if(w == width()) { + //qDebug() << Q_FUNC_INFO << "Geometry change requested with identical width!"; + } + // We use this for reloading layout info as well + //if(w != width()) { prepareGeometryChange(); setWidth(w); QTextLayout layout; @@ -399,7 +403,7 @@ qreal ContentsChatItem::setGeometryByWidth(qreal w) { setHeight(layout.boundingRect().height()); delete _data; _data = 0; - } + //} return height(); } diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 2f145e9a..e20f3d63 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -388,9 +388,15 @@ void ChatScene::updateForViewport(qreal width, qreal height) { void ChatScene::setWidth(qreal width) { if(width == _sceneRect.width()) return; + layout(width); +} +void ChatScene::layout(qreal width) { // clock_t startT = clock(); + if(width < 0) + width = _sceneRect.width(); + // disabling the index while doing this complex updates is about // 2 to 10 times faster! //setItemIndexMethod(QGraphicsScene::NoIndex); diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 3ec77f53..78cce78e 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -108,6 +108,7 @@ public: public slots: void updateForViewport(qreal width, qreal height); void setWidth(qreal width); + void layout(qreal width = -1); // these are used by the chatitems to notify the scene and manage selections void setSelectingItem(ChatItem *item); diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 866ad4e6..e8a06f13 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -181,9 +181,7 @@ void ChatView::verticalScrollbarChanged(int newPos) { } void ChatView::styleChanged() { - invalidateScene(); - if(scene()) - scene()->update(); + scene()->layout(); } MsgId ChatView::lastMsgId() const { diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 5dacbc2a..9ee56b82 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -320,7 +320,7 @@ void MainWin::setupActions() { coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll, this, SLOT(on_actionDebugLog_triggered()))); coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll, - QtUi::style(), SLOT(loadStyleSheet()), QKeySequence::Refresh)); + QtUi::style(), SLOT(reload()), QKeySequence::Refresh)); // Navigation coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot buffer"), coll, diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index 332344c0..4964692b 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -51,6 +51,7 @@ UiStyle::UiStyle(QObject *parent) : QObject(parent) { _formatCodes["%DU"] = Url; setTimestampFormatString("[hh:mm:ss]"); + loadStyleSheet(); } @@ -58,6 +59,10 @@ UiStyle::~UiStyle() { qDeleteAll(_metricsCache); } +void UiStyle::reload() { + loadStyleSheet(); +} + void UiStyle::loadStyleSheet() { qDeleteAll(_metricsCache); _metricsCache.clear(); @@ -230,7 +235,8 @@ UiStyle::FormatType UiStyle::formatType(Message::Type msgType) { case Message::DayChange: return DayChangeMsg; } - Q_ASSERT(false); // we need to handle all message types + //Q_ASSERT(false); // we need to handle all message types + qWarning() << Q_FUNC_INFO << "Unknown message type:" << msgType; return ErrorMsg; } diff --git a/src/uisupport/uistyle.h b/src/uisupport/uistyle.h index b09dfa7c..ca411fae 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -117,12 +117,13 @@ public: QList toTextLayoutList(const FormatList &, int textLength, quint32 messageLabel = 0); public slots: - void loadStyleSheet(); + void reload(); signals: void changed(); protected: + void loadStyleSheet(); QString loadStyleSheet(const QString &name, bool shouldExist = false); QTextCharFormat cachedFormat(quint64 key) const; -- 2.20.1