fixed slow buffer switches
[quassel.git] / src / uisupport / nickview.cpp
index 1a97514..78cb709 100644 (file)
@@ -30,7 +30,8 @@
 
 
 NickView::NickView(QWidget *parent)
-  : QTreeView(parent)
+  : QTreeView(parent),
+    _sizeHint(QTreeView::sizeHint())
 {
   setIndentation(10);
   setAnimated(true);
@@ -41,7 +42,7 @@ NickView::NickView(QWidget *parent)
   setContextMenuPolicy(Qt::CustomContextMenu);
 
   connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
-          this, SLOT(showContextMenu(const QPoint&)));
+         this, SLOT(showContextMenu(const QPoint&)));
   connect(this, SIGNAL(activated( const QModelIndex& )),
           this, SLOT(startQuery( const QModelIndex& )));
 }
@@ -57,6 +58,7 @@ void NickView::init() {
     setColumnHidden(i, true);
 
   expandAll();
+  updateSizeHint();
 }
 
 void NickView::setModel(QAbstractItemModel *model) {
@@ -64,9 +66,21 @@ void NickView::setModel(QAbstractItemModel *model) {
   init();
 }
 
-void NickView::rowsInserted(const QModelIndex &index, int start, int end) {
-  QTreeView::rowsInserted(index, start, end);
-  expandAll();  // FIXME We need to do this more intelligently. Maybe a pimped TreeView?
+void NickView::rowsInserted(const QModelIndex &parent, int start, int end) {
+  QTreeView::rowsInserted(parent, start, end);
+  if(model()->data(parent, NetworkModel::ItemTypeRole) == NetworkModel::UserCategoryItemType && !isExpanded(parent))
+    expand(parent);
+  updateSizeHint();
+}
+
+void NickView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
+  QTreeView::rowsAboutToBeRemoved(parent, start, end);
+  updateSizeHint();
+}
+
+void NickView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+  QTreeView::dataChanged(topLeft, bottomRight);
+  updateSizeHint();
 }
 
 QString NickView::nickFromModelIndex(const QModelIndex & index) {
@@ -81,6 +95,8 @@ BufferInfo NickView::bufferInfoFromModelIndex(const QModelIndex & index) {
 
 void NickView::showContextMenu(const QPoint & pos ) {
   QModelIndex index = indexAt(pos);
+  if(index.data(NetworkModel::ItemTypeRole) != NetworkModel::IrcUserItemType) return;
+
   QString nick = nickFromModelIndex(index);
 
   QMenu nickContextMenu(this);
@@ -98,8 +114,10 @@ void NickView::showContextMenu(const QPoint & pos ) {
   QAction *deVoiceAction = modeMenu->addAction(tr("Devoice %1").arg(nick));
 
   QMenu *kickBanMenu = nickContextMenu.addMenu(tr("Kick/Ban"));
+  //TODO: add kick message from network identity (kick reason)
   QAction *kickAction = kickBanMenu->addAction(tr("Kick %1").arg(nick));
   QAction *kickBanAction = kickBanMenu->addAction(tr("Kickban %1").arg(nick));
+  kickBanMenu->setEnabled(false);
   QAction *ignoreAction = nickContextMenu.addAction(tr("Ignore"));
   ignoreAction->setEnabled(false);
 
@@ -138,3 +156,20 @@ void NickView::startQuery(const QModelIndex & index) {
 void NickView::executeCommand(const BufferInfo & bufferInfo, const QString & command) {
   Client::instance()->userInput(bufferInfo, command);
 }
+
+void NickView::updateSizeHint() {
+  if(!model())
+    return;
+
+  int columnSize = 0;
+  for(int i = 0; i < model()->columnCount(); i++) {
+    if(!isColumnHidden(i))
+      columnSize += sizeHintForColumn(i);
+  }
+
+  _sizeHint = QSize(columnSize, 50);
+}
+
+QSize NickView::sizeHint() const {
+  return _sizeHint;
+}