Added getNetworkId(UserId user, const QString &network) to make the transition to...
[quassel.git] / src / qtgui / bufferview.cpp
index f805418..17f637b 100644 (file)
@@ -34,19 +34,34 @@ void BufferView::init() {
   header()->hideSection(1);
   expandAll();
   
+  setAnimated(true);
+  
   setDragEnabled(true);
   setAcceptDrops(true);
   setDropIndicatorShown(true);
   
-  connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), model(), SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
-  connect(this, SIGNAL(doubleClicked(const QModelIndex &)), model(), SLOT(doubleClickReceived(const QModelIndex &)));
-  connect(model(), SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)), selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
+  setSortingEnabled(true);
+  sortByColumn(0, Qt::AscendingOrder);
+  
+  connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+          model(), SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
+  
+  connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
+          model(), SLOT(doubleClickReceived(const QModelIndex &)));
+  
+  connect(model(), SIGNAL(selectionChanged(const QModelIndex &)),
+          this, SLOT(select(const QModelIndex &)));
+  
+  connect(this, SIGNAL(selectionChanged(const QModelIndex &, QItemSelectionModel::SelectionFlags)),
+          selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
 
 }
 
 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) {
   BufferViewFilter *filter = new BufferViewFilter(model, mode, nets);
   setModel(filter);
+  connect(this, SIGNAL(eventDropped(QDropEvent *)), filter, SLOT(dropEvent(QDropEvent *)));
+  connect(this, SIGNAL(removeBuffer(const QModelIndex &)), filter, SLOT(removeBuffer(const QModelIndex &)));
 }
 
 void BufferView::setModel(QAbstractItemModel *model) {
@@ -54,12 +69,34 @@ void BufferView::setModel(QAbstractItemModel *model) {
   init();
 }
 
-void BufferView::dragEnterEvent(QDragEnterEvent *event) {
-  // not yet needed... this will be usefull to keep track of the active view when customizing them with drag and drop
-  QTreeView::dragEnterEvent(event);
+void BufferView::select(const QModelIndex &current) {
+  emit selectionChanged(current, QItemSelectionModel::ClearAndSelect);
+}
+
+void BufferView::dropEvent(QDropEvent *event) {
+  if(event->source() != this) {
+    // another view(?) or widget is the source. maybe it's a drag 'n drop 
+    // view customization -> we tell our friend the filter:
+    emit eventDropped(event);
+  }
+  // in the case that the filter did not accept the event or if it's a merge
+  QTreeView::dropEvent(event);    
+}
+
+void BufferView::keyPressEvent(QKeyEvent *event) {
+  if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
+    event->accept();
+    QModelIndex index = selectionModel()->selectedIndexes().first();
+    if(index.isValid()) {
+      emit removeBuffer(index);
+    }
+  }
+  QTreeView::keyPressEvent(event);
 }
 
+// ensure that newly inserted network nodes are expanded per default
 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
-  if(parent.parent() == QModelIndex()) setExpanded(parent, true);
+  if(parent == QModelIndex())
+    setExpanded(model()->index(start, 0, parent), true);
   QTreeView::rowsInserted(parent, start, end);
 }