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

Revision 6193, 4.0 kB (checked in by flynd, 7 months ago)

Revised r6191. scrollTo needs to be called for some cases. It's just the call triggered by layoutChanged that we want to ignore. And I don't see any reason to have this configurable.

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 USERVIEWBASE_H
22#define USERVIEWBASE_H
23
24#include <QTreeView>
25
26class QAbstractProxyModel;
27
28namespace LicqQtGui
29{
30
31class ContactListModel;
32
33/**
34 * Base class for contact views
35 *
36 * Contains common functionallity for the views such as accepting dragged items
37 */
38class UserViewBase : public QTreeView
39{
40  Q_OBJECT
41
42public:
43  /**
44   * Constructor
45   *
46   * @param contactList The contact list instance
47   * @param parent Parent object
48   */
49  UserViewBase(ContactListModel* contactList, QWidget* parent = 0);
50
51  /**
52   * Destructor
53   */
54  virtual ~UserViewBase();
55
56  /**
57   * Set skin colors
58   *
59   * @param back Background color
60   */
61  virtual void setColors(QColor back);
62
63  /**
64   * Make sure a specified index is visible
65   * Overloaded to stop annoying auto scrolling triggered by layoutChanged
66   *
67   * @param index Index to scroll to
68   * @param hint Where to place the index
69   */
70  virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible);
71
72signals:
73  /**
74   * Signal emitted when user has double clicked on a contact
75   *
76   * @param id User id of contact
77   * @param ppid Protocol id of contact
78   */
79  void userDoubleClicked(QString id, unsigned long ppid);
80
81protected slots:
82  /**
83   * Apply new skin
84   */
85  virtual void applySkin();
86
87  /**
88   * Current index has changed
89   * Overloaded as workaround for scrollTo()
90   *
91   * @param current New current index
92   * @param previous Previously current index
93   */
94  virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
95
96protected:
97  /**
98   * Mouse button was pressed
99   *
100   * @param event Mouse event
101   */
102  virtual void mousePressEvent(QMouseEvent* event);
103
104  /**
105   * Mouse button was released
106   *
107   * @param event Mouse event
108   */
109  virtual void mouseReleaseEvent(QMouseEvent* event);
110
111  /**
112   * Context menu should be displayed
113   *
114   * @param event Menu event
115   */
116  virtual void contextMenuEvent(QContextMenuEvent* event);
117
118  /**
119   * Show popup menu for an item
120   *
121   * @param point Coordinate to show menu from
122   * @param item Index to show menu for
123   */
124  void popupMenu(QPoint point, QModelIndex item);
125
126  /**
127   * Item is being dragged
128   *
129   * @param event Drag event
130   */
131  virtual void dragEnterEvent(QDragEnterEvent* event);
132
133  /**
134   * Item was dropped
135   *
136   * @param event Drag event
137   */
138  virtual void dropEvent(QDropEvent* event);
139
140  /**
141   * Dragged item has moved
142   *
143   * @param event Drag event
144   */
145  virtual void dragMoveEvent(QDragMoveEvent* event);
146
147  ContactListModel* myContactList;
148  QAbstractProxyModel* myListProxy;
149  QPoint myMousePressPos;
150
151  /**
152   * Overload branches drawing method with an empty one
153   * to avoid unnecessary Qt processing
154   */
155  virtual void drawBranches(QPainter*, const QRect&, const QModelIndex&) const {}
156
157  /**
158   * A timer event happened
159   * Overloaded as workaround for scrollTo()
160   *
161   * @param event Timer event
162   */
163  virtual void timerEvent(QTimerEvent* event);
164
165private slots:
166  /**
167   * User double clicked in list
168   *
169   * @param index Item index that was double clicked
170   */
171  void slotDoubleClicked(const QModelIndex& index);
172
173private:
174  bool midEvent;
175  bool myAllowScrollTo;
176};
177
178} // namespace LicqQtGui
179
180#endif
Note: See TracBrowser for help on using the browser.