1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel 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) any later version. *
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 ***************************************************************************/
21 #ifndef _BUFFERTREEMODEL_H_
22 #define _BUFFERTREEMODEL_H_
26 #include "treemodel.h"
31 #include <QItemSelectionModel>
35 #include "selectionmodelsynchronizer.h"
36 #include "modelpropertymapper.h"
37 class MappedSelectionModel;
38 class QAbstractItemView;
40 /*****************************************
42 *****************************************/
43 class BufferTreeItem : public TreeItem {
47 BufferTreeItem(Buffer *, TreeItem *parent = 0);
49 virtual uint id() const;
50 QVariant data(int column, int role) const;
52 Buffer *buffer() const { return buf; }
53 void setActivity(const Buffer::ActivityLevel &);
56 QString text(int column) const;
57 QColor foreground(int column) const;
60 Buffer::ActivityLevel activity;
63 /*****************************************
65 *****************************************/
66 class NetworkTreeItem : public TreeItem {
70 NetworkTreeItem(const uint &netid, const QString &, TreeItem *parent = 0);
72 virtual QVariant data(int column, int row) const;
73 virtual uint id() const;
80 /*****************************************
82 *****************************************/
83 class BufferTreeModel : public TreeModel {
88 BufferTypeRole = Qt::UserRole,
94 BufferTreeModel(QObject *parent = 0);
95 static QList<QVariant> defaultHeader();
97 inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
98 inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; }
100 void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
101 void synchronizeView(QAbstractItemView *view);
102 void mapProperty(int column, int role, QObject *target, const QByteArray &property);
104 static bool mimeContainsBufferList(const QMimeData *mimeData);
105 static QList< QPair<uint, uint> > mimeDataToBufferList(const QMimeData *mimeData);
107 virtual QStringList mimeTypes() const;
108 virtual QMimeData *mimeData(const QModelIndexList &) const;
109 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
113 void bufferUpdated(Buffer *);
114 void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
115 void selectBuffer(Buffer *buffer);
116 void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
119 void bufferSelected(Buffer *);
120 void invalidateFilter();
121 void selectionChanged(const QModelIndex &);
124 bool isBufferIndex(const QModelIndex &) const;
125 Buffer *getBufferByIndex(const QModelIndex &) const;
126 QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
127 QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
129 QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
130 QPointer<ModelPropertyMapper> _propertyMapper;
131 Buffer *currentBuffer;