Allow reloading stylesheets at runtime
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 29 Jul 2009 17:16:45 +0000 (19:16 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 6 Aug 2009 18:25:06 +0000 (20:25 +0200)
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
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/chatview.cpp
src/qtui/mainwin.cpp
src/uisupport/uistyle.cpp
src/uisupport/uistyle.h

index 2159f3f..819877a 100644 (file)
@@ -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();
 }
 
index 2f145e9..e20f3d6 100644 (file)
@@ -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);
index 3ec77f5..78cce78 100644 (file)
@@ -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);
index 866ad4e..e8a06f1 100644 (file)
@@ -181,9 +181,7 @@ void ChatView::verticalScrollbarChanged(int newPos) {
 }
 
 void ChatView::styleChanged() {
-  invalidateScene();
-  if(scene())
-    scene()->update();
+  scene()->layout();
 }
 
 MsgId ChatView::lastMsgId() const {
index 5dacbc2..9ee56b8 100644 (file)
@@ -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,
index 332344c..4964692 100644 (file)
@@ -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;
 }
 
index b09dfa7..ca411fa 100644 (file)
@@ -117,12 +117,13 @@ public:
   QList<QTextLayout::FormatRange> 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;