1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
9 | contributed Qt widgets |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
17 This is a pure Qt widget - it can be used independently of YaST2.
25 #include <qlistview.h>
32 class QY2ListViewItem;
33 class QY2ListViewToolTip;
37 * @short Enhanced QListView
39 class QY2ListView : public QListView
48 QY2ListView( QWidget * parent );
53 virtual ~QY2ListView();
59 * Select a list entry (if there is any).
60 * Usually this will be the first list entry, but don't rely on that - this
61 * might change without notice. Emits signal selectionChanged().
63 virtual void selectSomething();
66 * Reimplemented from QListView:
67 * Adjust header sizes after clearing contents.
72 * Update the status display of all list entries:
73 * Call QY2ListViewItem::updateStatus() for each item.
74 * This is an expensive operation.
76 void updateItemStates();
79 * Update the status display of all list entries:
80 * Call QY2ListViewItem::updateData() for each item.
81 * This is an expensive operation.
83 void updateItemData();
86 * Save the current column widths.
88 void saveColumnWidths();
91 * Restore the column widths to what was saved previously with
94 void restoreColumnWidths();
100 * Emitted for mouse clicks on an item
102 void columnClicked ( int button,
103 QListViewItem * item,
105 const QPoint & pos );
108 * Emitted for mouse double clicks on an item
110 void columnDoubleClicked ( int button,
111 QListViewItem * item,
113 const QPoint & pos );
118 * Returns a tool tip text for a specific column of a list item.
119 * 'column' is -1 if the mouse pointer is in the tree indentation area.
121 * This default implementation tries to call
122 * QY2ListViewItem::toolTip( column ) or
123 * QY2CheckListItem::toolTip( column ), respectively
124 * if 'item' is a subclass of either.
126 * Derived classes may handle this differently.
128 virtual QString toolTip( QListViewItem * item, int column );
131 * Returns 'true' if the sort order should always be the item insertion
132 * order, 'false' if the user can change the sort order by clicking on a
135 bool sortByInsertionSequence() const { return _sortByInsertionSequence; }
138 * Enforce sorting by item insertion order (true) or let user change
139 * sorting by clicking on a column header (false).
141 virtual void setSortByInsertionSequence( bool sortByInsertionSequence );
144 * Returns the next free serial number for items that want to be ordered in
145 * insertion sequence.
147 int nextSerial() { return _nextSerial++; }
150 * Returns the minimum size required for this widget.
151 * Inherited from QWidget.
153 virtual QSize minimumSizeHint() const;
156 * Event filter - inherited from QWidget
158 virtual bool eventFilter( QObject * obj, QEvent * event );
164 * Internal: Handle manual column resize.
165 * Save the user's preferred sizes so they don't get overwritten each time
166 * the list is cleared and filled with new contents.
168 void columnWidthChanged( int col, int oldSize, int newSize );
173 * Handle mouse clicks.
174 * Reimplemented from QScrollView.
176 virtual void contentsMousePressEvent( QMouseEvent * e );
179 * Handle mouse clicks.
180 * Reimplemented from QScrollView.
182 virtual void contentsMouseReleaseEvent( QMouseEvent * );
185 * Handle mouse clicks.
186 * Reimplemented from QScrollView.
188 virtual void contentsMouseDoubleClickEvent( QMouseEvent * );
195 QListViewItem * _mousePressedItem;
196 int _mousePressedCol;
197 int _mousePressedButton;
199 std::vector<int> _savedColumnWidth;
200 bool _sortByInsertionSequence;
203 QY2ListViewToolTip * _toolTip;
204 bool _mouseButton1PressedInHeader;
205 bool _finalSizeChangeExpected;
211 * Enhanced QListViewItem
213 class QY2ListViewItem: public QListViewItem
218 * Constructor for toplevel items.
220 QY2ListViewItem( QY2ListView * parentListView,
221 const QString & text = QString::null );
225 * Constructor for deeper level items.
227 QY2ListViewItem( QListViewItem * parentItem,
228 const QString & text = QString::null );
233 virtual ~QY2ListViewItem();
236 * Update this item's status.
237 * Triggered by QY2ListView::updateAllItemStates().
238 * Derived classes should overwrite this.
239 * This default implementation does nothing.
241 virtual void updateStatus() {}
244 * Update this item's data completely.
245 * Triggered by QY2ListView::updateAllItemData().
246 * Derived classes should overwrite this.
247 * This default implementation does nothing.
249 virtual void updateData() {}
252 * Comparison function used for sorting the list.
258 * Reimplemented from QListViewItem
260 virtual int compare( QListViewItem * other,
262 bool ascending ) const;
265 * Return this item's serial number.
266 * Useful for comparison functions that order by insertion sequence.
268 int serial() const { return _serial; }
271 * Set the text foreground color for all columns.
272 * For more specific purposes reimiplement paintCell().
274 void setTextColor( const QColor & col )
275 { _textColor = col; }
278 * Set the text background color for all columns.
279 * For more specific purposes reimiplement paintCell().
281 void setBackgroundColor( const QColor & col )
282 { _backgroundColor = col; }
285 * Returns a tool tip text for a specific column of this item.
286 * 'column' is -1 if the mouse pointer is in the tree indentation area.
288 * This default implementation does nothing.
290 virtual QString toolTip( int column ) { return QString::null; }
296 * Paint method. Reimplemented from @ref QListViewItem so different
297 * colors can be used.
299 * Reimplemented from QListViewItem.
301 virtual void paintCell( QPainter * painter,
302 const QColorGroup & colorGroup,
314 QColor _backgroundColor;
320 * Enhanced QCheckListItem
322 class QY2CheckListItem: public QCheckListItem
327 * Constructor for toplevel items.
329 QY2CheckListItem( QY2ListView * parentListView,
330 const QString & text,
331 QCheckListItem::Type type );
335 * Constructor for deeper level items.
337 QY2CheckListItem( QListViewItem * parentItem,
338 const QString & text,
339 QCheckListItem::Type type );
343 * Constructor for deeper level items for QCheckListItem parents.
345 QY2CheckListItem( QCheckListItem * parentItem,
346 const QString & text,
347 QCheckListItem::Type type );
352 virtual ~QY2CheckListItem();
355 * Update this item's status.
356 * Triggered by QY2ListView::updateAllItemStates().
357 * Derived classes should overwrite this.
358 * This default implementation does nothing.
360 virtual void updateStatus() {}
363 * Update this item's data completely.
364 * Triggered by QY2ListView::updateAllItemData().
365 * Derived classes should overwrite this.
366 * This default implementation does nothing.
368 virtual void updateData() {}
371 * Comparison function used for sorting the list.
377 * Reimplemented from QListViewItem
379 virtual int compare( QListViewItem * other,
381 bool ascending ) const;
384 * Return this item's serial number.
385 * Useful for comparison functions that order by insertion sequence.
387 int serial() const { return _serial; }
390 * Set the text foreground color for all columns.
391 * For more specific purposes reimiplement paintCell().
393 void setTextColor( const QColor & col )
394 { _textColor = col; }
397 * Set the text background color for all columns.
398 * For more specific purposes reimiplement paintCell().
400 void setBackgroundColor( const QColor & col )
401 { _backgroundColor = col; }
404 * Returns a tool tip text for a specific column of this item.
405 * 'column' is -1 if the mouse pointer is in the tree indentation area.
407 * This default implementation does nothing.
409 virtual QString toolTip( int column ) { return QString(); }
415 * Paint method. Reimplemented from @ref QListViewItem so different
416 * colors can be used.
418 * Reimplemented from QListViewItem.
420 virtual void paintCell( QPainter * painter,
421 const QColorGroup & colorGroup,
433 QColor _backgroundColor;
438 * Tool tip for a QY2ListView widget: Enables individual tool tips specific to
439 * each list item and each column. Overwrite QY2ListViewItem::toolTip() to use
442 class QY2ListViewToolTip : public QToolTip
449 QY2ListViewToolTip( QY2ListView * parent )
450 : QToolTip( parent->viewport() ), _listView( parent ) {}
453 * Destructor (to make gcc 4.x happy)
455 virtual ~QY2ListViewToolTip() {}
461 * Decide if there is a tool tip text at 'p' and display it if there is one.
463 * Reimplemented from QToolTip.
465 virtual void maybeTip( const QPoint & p );
472 QY2ListView * _listView;
475 #endif // ifndef QY2ListView_h