From 47f8eca0275b02a19a36f098faaea0a3bf25460c Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Wed, 27 Feb 2008 14:41:02 +0000 Subject: [PATCH] - Buffer and NickViews have now sane sizeHints() so they won't eat up too much space when being docked. - unconnected networks will no longer be automatically expanded. --- src/uisupport/bufferview.cpp | 35 ++++++++++++++++++++++++++++++++++- src/uisupport/bufferview.h | 13 +++++++++---- src/uisupport/nickview.cpp | 12 ++++++++++++ src/uisupport/nickview.h | 3 ++- version.inc | 2 +- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 0ebfdea0..3043b83c 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -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(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); +} diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index f0fc2b6d..ae1bb37a 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -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 *); + }; diff --git a/src/uisupport/nickview.cpp b/src/uisupport/nickview.cpp index 3153ba8b..ba96c1ec 100644 --- a/src/uisupport/nickview.cpp +++ b/src/uisupport/nickview.cpp @@ -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); +} diff --git a/src/uisupport/nickview.h b/src/uisupport/nickview.h index daa130ac..18a2bd65 100644 --- a/src/uisupport/nickview.h +++ b/src/uisupport/nickview.h @@ -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); diff --git a/version.inc b/version.inc index bd9f71ef..c9576770 100644 --- a/version.inc +++ b/version.inc @@ -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; -- 2.20.1