libyui-mga-qt  1.0.2
 All Classes Functions Variables
YMGA_QCBTable.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YMGA_QCBTable.h
20 
21  Author: Angelo Naselli <anaselli@linux.it>
22 
23 /-*/
24 
25 #ifndef YMGA_QCBTable_h
26 #define YMGA_QCBTable_h
27 #include <QFrame>
28 
29 #include <yui/mga/YMGA_CBTable.h>
30 #include <yui/qt/QY2ListView.h>
31 
32 
33 // class QY2ListView;
34 class QTreeWidgetItem;
35 class YQListViewItem;
36 
37 
38 class YMGA_QCBTable : public QFrame, public YMGA_CBTable
39 {
40  Q_OBJECT
41 
42 public:
43 
44  /**
45  * Constructor.
46  **/
47  YMGA_QCBTable( YWidget * parent, YTableHeader * header, YCBTableMode checkboxMode );
48 
49  /**
50  * Destructor.
51  **/
52  virtual ~YMGA_QCBTable();
53 
54  /**
55  * Switch between sorting by item insertion order (keepSorting: true) or
56  * allowing the user to sort by an arbitrary column (by clicking on the
57  * column header).
58  *
59  * Reimplemented from YTable.
60  **/
61  virtual void setKeepSorting( bool keepSorting );
62 
63  /**
64  * Add an item.
65  *
66  * Reimplemented from YSelectionWidget.
67  **/
68  virtual void addItem( YItem * item );
69 
70  /**
71  * Add multiple items.
72  *
73  * Reimplemented for efficiency from YSelectionWidget.
74  **/
75  virtual void addItems( const YItemCollection & itemCollection );
76 
77  /**
78  * Select or deselect an item.
79  *
80  * Reimplemented from YSelectionWidget.
81  **/
82  virtual void selectItem( YItem * item, bool selected = true );
83 
84  /**
85  * Deselect all items.
86  *
87  * Reimplemented from YSelectionWidget.
88  **/
89  virtual void deselectAllItems();
90 
91  /**
92  * Delete all items.
93  *
94  * Reimplemented from YSelectionWidget.
95  **/
96  virtual void deleteAllItems();
97 
98  /**
99  * Notification that a cell (its text and/or its icon) was changed from the
100  * outside. Applications are required to call this whenever a table cell is
101  * changed after adding the corresponding table item (the row) to the table
102  * widget.
103  *
104  * Reimplemented from YTable.
105  **/
106  virtual void cellChanged( const YTableCell * cell );
107 
108  /**
109  * check/uncheck Item from application.
110  *
111  * Note that item->check(true) does not update the table
112  *
113  **/
114  void checkItem( YItem * item, bool checked = true );
115 
116  /**
117  * Set enabled/disabled state.
118  *
119  * Reimplemented from YWidget.
120  **/
121  virtual void setEnabled( bool enabled );
122 
123  /**
124  * Preferred width of the widget.
125  *
126  * Reimplemented from YWidget.
127  **/
128  virtual int preferredWidth();
129 
130  /**
131  * Preferred height of the widget.
132  *
133  * Reimplemented from YWidget.
134  **/
135  virtual int preferredHeight();
136 
137  /**
138  * Set the new size of the widget.
139  *
140  * Reimplemented from YWidget.
141  **/
142  virtual void setSize( int newWidth, int newHeight );
143 
144  /**
145  * Accept the keyboard focus.
146  *
147  * Reimplemented from YWidget.
148  **/
149  virtual bool setKeyboardFocus();
150 
151  /**
152  * returns which column is managed by checkboxes, if any
153  * -1 otherwise
154  */
155  int checkboxItemColumn();
156 
157 protected slots:
158 
159  /**
160  * Notification that an item is selected (single click or keyboard).
161  **/
162  void slotSelected( QTreeWidgetItem * );
163 
164  /**
165  * Notification that an item is activated (double click or keyboard).
166  **/
167  void slotActivated( QTreeWidgetItem* listViewItem, int column );
168 
169  /**
170  * Propagate a context menu selection
171  *
172  * This will trigger an 'ContextMenuActivated' event if 'notifyContextMenu' is set.
173  **/
174  void slotContextMenu ( const QPoint & pos );
175 
176 
177  void slotcolumnClicked(QTreeWidgetItem * item,
178  int col);
179 
180 protected:
181 
182  /**
183  * Select the original item (the YCBTableItem) that corresponds to the
184  * specified listViewItem.
185  **/
186  void selectOrigItem( QTreeWidgetItem * listViewItem );
187 
188  /**
189  * Internal addItem() method that will not do expensive operations in batch
190  * mode.
191  **/
192  void addItem( YItem * item, bool batchMode, bool resizeColumnsToContent );
193 
194  //
195  // Data members
196  //
197 
198  QY2ListView * _qt_listView;
199 
200 // void keyPressEvent ( QKeyEvent * event );
201 
202 private:
203  struct Private;
204  Private *d;
205 };
206 
207 
208 
209 /**
210  * Visual representation of a YCBTableItem.
211  **/
212 class YMGA_QCBTableListViewItem: public QY2ListViewItem
213 {
214 public:
215 
216  /**
217  * Constructor.
218  **/
220  QY2ListView * parent,
221  YCBTableItem * origItem );
222 
223  /**
224  * Return the parent table widget.
225  **/
226  YMGA_QCBTable * table() const { return _table; }
227 
228  /**
229  * Return the corresponding YCBTableItem.
230  **/
231  YCBTableItem * origItem() const { return _origItem; }
232 
233  /**
234  * Update this item's display with the content of 'cell'.
235  **/
236  void updateCell( const YTableCell * cell );
237 
238 protected:
239 
240  YMGA_QCBTable * _table;
241  YCBTableItem * _origItem;
242 };
243 
244 
245 
246 #endif // YQLabel_h
YMGA_QCBTable * table() const
Return the parent table widget.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
void slotContextMenu(const QPoint &pos)
Propagate a context menu selection.
virtual void addItem(YItem *item)
Add an item.
void slotSelected(QTreeWidgetItem *)
Notification that an item is selected (single click or keyboard).
YCBTableItem * origItem() const
Return the corresponding YCBTableItem.
virtual void deselectAllItems()
Deselect all items.
virtual ~YMGA_QCBTable()
Destructor.
virtual int preferredWidth()
Preferred width of the widget.
virtual void cellChanged(const YTableCell *cell)
Notification that a cell (its text and/or its icon) was changed from the outside. ...
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
virtual void setKeepSorting(bool keepSorting)
Switch between sorting by item insertion order (keepSorting: true) or allowing the user to sort by an...
virtual int preferredHeight()
Preferred height of the widget.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
int checkboxItemColumn()
returns which column is managed by checkboxes, if any -1 otherwise
void checkItem(YItem *item, bool checked=true)
check/uncheck Item from application.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
void updateCell(const YTableCell *cell)
Update this item's display with the content of 'cell'.
YMGA_QCBTable(YWidget *parent, YTableHeader *header, YCBTableMode checkboxMode)
Constructor.
void slotActivated(QTreeWidgetItem *listViewItem, int column)
Notification that an item is activated (double click or keyboard).
void selectOrigItem(QTreeWidgetItem *listViewItem)
Select the original item (the YCBTableItem) that corresponds to the specified listViewItem.
YMGA_QCBTableListViewItem(YMGA_QCBTable *table, QY2ListView *parent, YCBTableItem *origItem)
Constructor.
virtual void deleteAllItems()
Delete all items.
Visual representation of a YCBTableItem.