1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 #include "bufferview.h"
24 #include "buffertreemodel.h"
26 /*****************************************
27 * The TreeView showing the Buffers
28 *****************************************/
29 // Please be carefull when reimplementing methods which are used to inform the view about changes to the data
30 // to be on the safe side: call QTreeView's method aswell
31 BufferView::BufferView(QWidget *parent) : QTreeView(parent) {
34 void BufferView::init() {
37 // header()->hideSection(1);
42 #ifndef QT_NO_DRAGANDDROP
45 setDropIndicatorShown(true);
48 setSortingEnabled(true);
49 sortByColumn(0, Qt::AscendingOrder);
50 connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
53 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QList<uint> nets) {
54 BufferViewFilter *filter = new BufferViewFilter(model, mode, nets);
56 connect(this, SIGNAL(removeBuffer(const QModelIndex &)), filter, SLOT(removeBuffer(const QModelIndex &)));
59 void BufferView::setModel(QAbstractItemModel *model) {
60 delete selectionModel();
61 QTreeView::setModel(model);
66 void BufferView::joinChannel(const QModelIndex &index) {
67 Buffer::Type bufferType = (Buffer::Type)index.data(BufferTreeModel::BufferTypeRole).toInt();
69 if(bufferType != Buffer::ChannelType)
72 Client::fakeInput(index.data(BufferTreeModel::BufferUidRole).toUInt(), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString()));
75 void BufferView::keyPressEvent(QKeyEvent *event) {
76 if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
78 QModelIndex index = selectionModel()->selectedIndexes().first();
80 emit removeBuffer(index);
83 QTreeView::keyPressEvent(event);
86 // ensure that newly inserted network nodes are expanded per default
87 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
88 QTreeView::rowsInserted(parent, start, end);
89 if(model()->rowCount(parent) == 1 && parent != QModelIndex()) {
90 // without updating the parent the expand will have no effect... Qt Bug?