- Buffer and NickViews have now sane sizeHints() so they won't eat up too much space...
authorMarcus Eggenberger <egs@quassel-irc.org>
Wed, 27 Feb 2008 14:41:02 +0000 (14:41 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Wed, 27 Feb 2008 14:41:02 +0000 (14:41 +0000)
- unconnected networks will no longer be automatically expanded.

src/uisupport/bufferview.cpp
src/uisupport/bufferview.h
src/uisupport/nickview.cpp
src/uisupport/nickview.h
version.inc

index 0ebfdea..3043b83 100644 (file)
@@ -115,13 +115,34 @@ void BufferView::keyPressEvent(QKeyEvent *event) {
 // ensure that newly inserted network nodes are expanded per default
 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
   QTreeView::rowsInserted(parent, start, end);
-  if(model()->rowCount(parent) == 1 && parent != QModelIndex()) {
+  if(model()->rowCount(parent) == 1 && parent.data(NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType && parent.data(NetworkModel::ItemActiveRole) == true) {
     // without updating the parent the expand will have no effect... Qt Bug?
     update(parent); 
     expand(parent);
   }
 }
 
+void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+  QTreeView::dataChanged(topLeft, bottomRight);
+  
+  // determine how many items have been changed and if any of them is a networkitem
+  // which just swichted from active to inactive or vice versa
+  if(topLeft.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
+    return;
+
+  for(int i = topLeft.row(); i <= bottomRight.row(); i++) {
+    QModelIndex networkIdx = topLeft.sibling(topLeft.row(), 0);
+    if(model()->rowCount(networkIdx) == 0)
+      continue;
+
+    bool isActive = networkIdx.data(NetworkModel::ItemActiveRole).toBool();
+    if(isExpanded(networkIdx) != isActive) {
+      setExpanded(networkIdx, isActive);
+    }
+  }
+}
+
+                            
 void BufferView::toggleHeader(bool checked) {
   QAction *action = qobject_cast<QAction *>(sender());
   header()->setSectionHidden((action->property("column")).toInt(), !checked);
@@ -251,3 +272,15 @@ void BufferView::wheelEvent(QWheelEvent* event)
   }
 }
 
+
+QSize BufferView::sizeHint() const {
+  if(!model())
+    return QTreeView::sizeHint();
+  
+  int columnSize = 0;
+  for(int i = 0; i < model()->columnCount(); i++) {
+    if(!isColumnHidden(i))
+      columnSize += sizeHintForColumn(i);
+  }
+  return QSize(columnSize, 50);
+}
index f0fc2b6..ae1bb37 100644 (file)
@@ -40,14 +40,19 @@ public:
   
 signals:
   void removeBuffer(const QModelIndex &);
-  
+
+protected:
+  virtual void keyPressEvent(QKeyEvent *);
+  virtual void rowsInserted (const QModelIndex & parent, int start, int end);
+  virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
+  virtual void wheelEvent(QWheelEvent *);
+  virtual QSize sizeHint() const;
+
 private slots:
   void joinChannel(const QModelIndex &index);
-  void keyPressEvent(QKeyEvent *);
-  void rowsInserted (const QModelIndex & parent, int start, int end);
   void toggleHeader(bool checked);
   void showContextMenu(const QPoint &);
-  void wheelEvent(QWheelEvent *);
+
 };
 
 
index 3153ba8..ba96c1e 100644 (file)
@@ -142,3 +142,15 @@ void NickView::startQuery(const QModelIndex & index) {
 void NickView::executeCommand(const BufferInfo & bufferInfo, const QString & command) {
   Client::instance()->userInput(bufferInfo, command);
 }
+
+QSize NickView::sizeHint() const {
+  if(!model())
+    return QTreeView::sizeHint();
+  
+  int columnSize = 0;
+  for(int i = 0; i < model()->columnCount(); i++) {
+    if(!isColumnHidden(i))
+      columnSize += sizeHintForColumn(i);
+  }
+  return QSize(columnSize, 50);
+}
index daa130a..18a2bd6 100644 (file)
@@ -40,7 +40,8 @@ class NickView : public QTreeView {
     virtual ~NickView();
 
   protected:
-    void rowsInserted(const QModelIndex &, int, int);
+    virtual void rowsInserted(const QModelIndex &, int, int);
+    virtual QSize sizeHint() const;
 
   public slots:
     void setModel(QAbstractItemModel *model);
index bd9f71e..c957677 100644 (file)
@@ -5,7 +5,7 @@
 
   quasselVersion = "0.2.0-alpha1+";
   quasselDate = "2008-02-27";
-  quasselBuild = 590;
+  quasselBuild = 591;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 563;