root/trunk/qt4-gui/src/views/contactdelegate.h

Revision 6148, 5.6 kB (checked in by flynd, 8 months ago)

Allow editing contact alias and group names directly in the contact list.

Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of Licq, an instant messaging client for UNIX.
4 * Copyright (C) 1999-2006 Licq developers
5 *
6 * Licq is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Licq is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Licq; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21#ifndef CONTACTDELEGATE_H
22#define CONTACTDELEGATE_H
23
24#include <QAbstractItemDelegate>
25
26#include "config/iconmanager.h"
27
28#include "contactlist/contactlist.h"
29
30namespace LicqQtGui
31{
32
33namespace Config
34{
35class Skin;
36}
37
38class UserViewBase;
39
40/**
41 * Delegate that renders contacts in a contact list view
42 */
43class ContactDelegate : public QAbstractItemDelegate
44{
45  Q_OBJECT
46
47public:
48  /**
49   * Constructor
50   *
51   * @param userView The contact list view the we will render for
52   * @param parent Parent object
53   */
54  ContactDelegate(UserViewBase* userView, QObject* parent = 0);
55
56  /**
57   * Calculate how large the a table cell needs to be to display the data
58   *
59   * @param option Style options
60   * @param index Model index to return required size for
61   * @return Recomended cell size
62   */
63  virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
64
65  /**
66   * Render a table cell for the contact list view
67   *
68   * @param p The painter used to draw on the view
69   * @param option Style options
70   * @param index Model index with data to render
71   */
72  virtual void paint(QPainter* p, const QStyleOptionViewItem& option, const QModelIndex& index) const;
73
74  /**
75   * Create widget that can be used for editing data in an item
76   *
77   * @param parent Parent widget for the editor
78   * @param option Style options
79   * @param index Item to edit
80   * @return An editor widget
81   */
82  virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
83
84  /**
85   * Set data for an editor widget
86   *
87   * @param editor Existing editor widget to update with data
88   * @param index Item to get data from
89   */
90  virtual void setEditorData(QWidget* editor, const QModelIndex& index) const;
91
92  /**
93   * Get data from editor widget and update model
94   *
95   * @param editor Existing editor widget with data
96   * @param model Model to write data to
97   * @param index Index of item to update
98   */
99  virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
100
101  /**
102   * Update geometry of an editor widget
103   *
104   * @param editor Existing editor widget to update geometry for
105   * @param option Style options, including new rect for editor
106   * @param index Index of item being edited
107   */
108  virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const;
109
110  /**
111   * Catch events for other objects. Used to get events for editor widget
112   *
113   * @param object Object the event happened for
114   * @param event Event for that object
115   * @return True if event should not be forwarded to object
116   */
117  virtual bool eventFilter(QObject* object, QEvent* event);
118
119private:
120  /**
121   * The data structure to be passed to private helpers
122   */
123  typedef struct
124  {
125    QPainter* p;
126    QStyleOptionViewItem option;
127    QModelIndex index;
128    int width;
129    int height;
130    int align;
131    ContactListModel::ItemType itemType;
132    Config::Skin* skin;
133    QPalette::ColorGroup cg;
134    ContactListModel::StatusType status;
135    unsigned extStatus;
136    QString text;
137  } Parameters;
138
139  /**
140   * Convenient wrapper to draw an extended icon
141   *
142   * @param arg The data structure
143   * @param iconType Type of the icon to draw
144   */
145  void drawExtIcon(Parameters& arg, IconManager::IconType iconType) const;
146
147  /**
148   * Draw an extended icon
149   *
150   * @param arg The data structure
151   * @param icon The actual icon to draw
152   */
153  void drawExtIcon(Parameters& arg, const QPixmap* icon) const;
154
155  /**
156   * Fills the cell background
157   *
158   * @param arg The data structure
159   */
160  void fillBackground(Parameters& arg) const;
161
162  /**
163   * Draws the grid around user cells
164   *
165   * @param arg The data structure
166   * @param last Denotes whether this cell is from the last column
167   */
168  void drawGrid(Parameters& arg, bool last) const;
169
170  /**
171   * Prepares the pen in the painter.
172   *
173   * @param arg The data structure
174   * @param animate Current animation role
175   */
176  void prepareForeground(Parameters& arg, QVariant animate) const;
177
178  /**
179   * Draws the delimiting bar.
180   *
181   * @param arg The data structure
182   */
183  void drawBar(Parameters& arg) const;
184
185  /**
186   * Draws the status icon in the first column,
187   * always left-aligned
188   *
189   * @param arg The data structure
190   */
191  void drawStatusIcon(Parameters& arg) const;
192
193  /**
194   * Draws "Checked Auto-Response" animation
195   *
196   * @param arg The data structure
197   * @param counter The animation step
198   */
199  void drawCarAnimation(Parameters& arg, int counter) const;
200
201  /**
202   * Draws the text
203   *
204   * @param arg The data structure
205   */
206  void drawText(Parameters& arg) const;
207
208  /**
209   * Draws all extended icons
210   *
211   * @param arg The data structure
212   */
213  void drawExtIcons(Parameters& arg) const;
214
215  UserViewBase* myUserView;
216};
217
218} // nemaspace LicqQtGui
219
220#endif
Note: See TracBrowser for help on using the browser.