X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtgui%2Fbufferview.cpp;fp=src%2Fqtgui%2Fbufferview.cpp;h=d30e4da1172fb9878fe8039e87bde098b8f44979;hp=0000000000000000000000000000000000000000;hb=077d44f36d2f5c730283ef6be839aea7dd073d56;hpb=f0a6776fc5102ff6a7fe1469917fe231e4cd3a8a diff --git a/src/qtgui/bufferview.cpp b/src/qtgui/bufferview.cpp new file mode 100644 index 00000000..d30e4da1 --- /dev/null +++ b/src/qtgui/bufferview.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "bufferview.h" +#include "bufferviewwidget.h" + +/***************************************** +* The TreeView showing the Buffers +*****************************************/ +BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, Modes filtermode, QStringList nets, QObject *parent) : QSortFilterProxyModel(parent) { + setSourceModel(model); + mode = filtermode; + networks = nets; + + connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidateMe())); + connect(model, SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)), this, SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags))); + + connect(this, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), model, SLOT(changeCurrent(const QModelIndex &, const QModelIndex &))); + connect(this, SIGNAL(doubleClicked(const QModelIndex &)), model, SLOT(doubleClickReceived(const QModelIndex &))); +} + +void BufferViewFilter::invalidateMe() { + invalidateFilter(); +} + +void BufferViewFilter::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { + emit updateSelection(mapFromSource(index), command); +} + +void BufferViewFilter::changeCurrent(const QModelIndex ¤t, const QModelIndex &previous) { + emit currentChanged(mapToSource(current), mapToSource(previous)); +} + +void BufferViewFilter::doubleClickReceived(const QModelIndex &clicked) { + emit doubleClicked(mapToSource(clicked)); +} + +bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { + QModelIndex child = source_parent.child(source_row, 0); + if(!child.isValid()) + return true; // can't imagine this case but true sounds good :) + + Buffer::Type bufferType = (Buffer::Type) child.data(BufferTreeModel::BufferTypeRole).toInt(); + if((mode & NoChannels) && bufferType == Buffer::ChannelBuffer) return false; + if((mode & NoQueries) && bufferType == Buffer::QueryBuffer) return false; + if((mode & NoServers) && bufferType == Buffer::ServerBuffer) return false; + + bool isActive = child.data(BufferTreeModel::BufferActiveRole).toBool(); + if((mode & NoActive) && isActive) return false; + if((mode & NoInactive) && !isActive) return false; + + QString net = child.data(Qt::DisplayRole).toString(); + if((mode & SomeNets) && !networks.contains(net)) return false; + + return true; +} + +/***************************************** +* The TreeView showing the Buffers +*****************************************/ +// Please be carefull when reimplementing methods which are used to inform the view about changes to the data +// to be on the safe side: call QTreeView's method aswell +BufferView::BufferView(QWidget *parent) : QTreeView(parent) { +} + +void BufferView::init() { + setIndentation(10); + header()->hide(); + header()->hideSection(1); + + 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))); + + expandAll(); +} + +void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) { + BufferViewFilter *filter = new BufferViewFilter(model, mode, nets); + setModel(filter); +} + +void BufferView::setModel(QAbstractItemModel *model) { + QTreeView::setModel(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::rowsInserted(const QModelIndex & parent, int start, int end) { + if(parent.parent() == QModelIndex()) setExpanded(parent, true); + QTreeView::rowsInserted(parent, start, end); +}