~quassel-dev/quassel/i18n-master

« back to all changes in this revision

Viewing changes to src/qtgui/bufferviewwidget.h

  • Committer: Manuel Nickschas
  • Date: 2007-06-20 01:21:00 UTC
  • Revision ID: git-v1:077d44f36d2f5c730283ef6be839aea7dd073d56
Starting reorganization of files in preparation of separation of client and GUI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005-07 by The Quassel Team                             *
 
3
 *   devel@quassel-irc.org                                                 *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#ifndef _BUFFERVIEW_H_
 
22
#define _BUFFERVIEW_H_
 
23
 
 
24
#include <QtGui>
 
25
#include <QtCore>
 
26
 
 
27
#include "guiproxy.h"
 
28
#include "buffer.h"
 
29
#include "gui/ui_bufferviewwidget.h"
 
30
#include "bufferview.h"
 
31
 
 
32
/*****************************************
 
33
 *  general item used in the Tree Model
 
34
 *****************************************/
 
35
class TreeItem {
 
36
public:
 
37
  TreeItem(QList<QVariant> &data, TreeItem *parent = 0);
 
38
  TreeItem(TreeItem *parent = 0);
 
39
  virtual ~TreeItem();
 
40
  
 
41
  void appendChild(TreeItem *child);
 
42
  void removeChild(int row);
 
43
                   
 
44
  TreeItem *child(int row);
 
45
  int childCount() const;
 
46
  int columnCount() const;
 
47
  virtual QVariant data(int column, int role) const;
 
48
  int row() const;
 
49
  TreeItem *parent();
 
50
 
 
51
  void setForeground(QColor);
 
52
    
 
53
private:
 
54
  QList<TreeItem*> childItems;
 
55
  TreeItem *parentItem;
 
56
  QList<QVariant> itemData;
 
57
  
 
58
  QColor foreground;
 
59
};
 
60
 
 
61
 
 
62
/*****************************************
 
63
 *  Fancy Buffer Items
 
64
 *****************************************/
 
65
class BufferTreeItem : public TreeItem{
 
66
public:
 
67
  BufferTreeItem(Buffer *, TreeItem *parent = 0);
 
68
  QVariant data(int column, int role) const;
 
69
  Buffer *buffer() const { return buf; }
 
70
  void setActivity(const Buffer::ActivityLevel &);
 
71
  
 
72
private:
 
73
    QString text(int column) const;
 
74
    QColor foreground(int column) const;
 
75
    Buffer *buf;
 
76
    Buffer::ActivityLevel activity;
 
77
};
 
78
 
 
79
 
 
80
/*****************************************
 
81
 * BufferTreeModel
 
82
 *****************************************/
 
83
class BufferTreeModel : public QAbstractItemModel {
 
84
  Q_OBJECT
 
85
  
 
86
public:
 
87
  enum  myRoles {
 
88
    BufferTypeRole = Qt::UserRole,
 
89
    BufferActiveRole
 
90
  };
 
91
  
 
92
  
 
93
  BufferTreeModel(QObject *parent = 0);
 
94
  ~BufferTreeModel();
 
95
  
 
96
  QVariant data(const QModelIndex &index, int role) const;
 
97
  Qt::ItemFlags flags(const QModelIndex &index) const;
 
98
  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 
99
  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
 
100
  QModelIndex parent(const QModelIndex &index) const;
 
101
  int rowCount(const QModelIndex &parent = QModelIndex()) const;
 
102
  int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
103
  
 
104
  void clearActivity(Buffer *buffer);
 
105
  
 
106
public slots:
 
107
  void bufferUpdated(Buffer *);    
 
108
  void changeCurrent(const QModelIndex &, const QModelIndex &);
 
109
  void selectBuffer(Buffer *buffer);
 
110
  void doubleClickReceived(const QModelIndex &);
 
111
  void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
 
112
  
 
113
signals:
 
114
  void bufferSelected(Buffer *);
 
115
  void invalidateFilter();
 
116
  void fakeUserInput(BufferId, QString);
 
117
  void updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags);
 
118
    
 
119
private:
 
120
  bool isBufferIndex(const QModelIndex &) const;
 
121
  Buffer *getBufferByIndex(const QModelIndex &) const;
 
122
  QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
 
123
  QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
 
124
 
 
125
  bool removeRow(int row, const QModelIndex &parent = QModelIndex());
 
126
    
 
127
  QStringList mimeTypes() const;
 
128
  QMimeData *mimeData(const QModelIndexList &) const;
 
129
  bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
 
130
  TreeItem *rootItem;
 
131
  
 
132
  QHash<QString, TreeItem*> networkItem;
 
133
  QHash<Buffer *, BufferTreeItem*> bufferItem;
 
134
  Buffer *currentBuffer;
 
135
};
 
136
 
 
137
 
 
138
 
 
139
 
 
140
/*****************************************
 
141
 * This Widget Contains the BufferView
 
142
 *****************************************/
 
143
class BufferViewWidget : public QWidget {
 
144
  Q_OBJECT
 
145
 
 
146
public:
 
147
  BufferViewWidget(QWidget *parent = 0);
 
148
  virtual QSize sizeHint () const;
 
149
  BufferView *treeView() { return ui.treeView; }  
 
150
 
 
151
private:
 
152
  Ui::BufferViewWidget ui;
 
153
  
 
154
};
 
155
 
 
156
 
 
157
/*****************************************
 
158
 * Dock and API for the BufferViews
 
159
 *****************************************/
 
160
class BufferViewDock : public QDockWidget {
 
161
  Q_OBJECT
 
162
 
 
163
public:
 
164
  BufferViewDock(QAbstractItemModel *model, QString name, BufferViewFilter::Modes mode, QStringList nets = QStringList(), QWidget *parent = 0);
 
165
};
 
166
 
 
167
 
 
168
#endif