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 <q3listview.h>
31 #define FIXME_TOOLTIP 0
34 class QY2ListViewItem;
35 class QY2ListViewToolTip;
39 * @short Enhanced Q3ListView
41 class QY2ListView : public Q3ListView
50 QY2ListView( QWidget * parent );
55 virtual ~QY2ListView();
61 * Select a list entry (if there is any).
62 * Usually this will be the first list entry, but don't rely on that - this
63 * might change without notice. Emits signal selectionChanged().
65 virtual void selectSomething();
68 * Reimplemented from Q3ListView:
69 * Adjust header sizes after clearing contents.
74 * Update the status display of all list entries:
75 * Call QY2ListViewItem::updateStatus() for each item.
76 * This is an expensive operation.
78 void updateItemStates();
81 * Update the status display of all list entries:
82 * Call QY2ListViewItem::updateData() for each item.
83 * This is an expensive operation.
85 void updateItemData();
88 * Save the current column widths.
90 void saveColumnWidths();
93 * Restore the column widths to what was saved previously with
96 void restoreColumnWidths();
102 * Emitted for mouse clicks on an item
104 void columnClicked ( int button,
105 Q3ListViewItem * item,
107 const QPoint & pos );
110 * Emitted for mouse double clicks on an item
112 void columnDoubleClicked ( int button,
113 Q3ListViewItem * item,
115 const QPoint & pos );
120 * Returns a tool tip text for a specific column of a list item.
121 * 'column' is -1 if the mouse pointer is in the tree indentation area.
123 * This default implementation tries to call
124 * QY2ListViewItem::toolTip( column ) or
125 * QY2CheckListItem::toolTip( column ), respectively
126 * if 'item' is a subclass of either.
128 * Derived classes may handle this differently.
130 virtual QString toolTip( Q3ListViewItem * item, int column );
133 * Returns 'true' if the sort order should always be the item insertion
134 * order, 'false' if the user can change the sort order by clicking on a
137 bool sortByInsertionSequence() const { return _sortByInsertionSequence; }
140 * Enforce sorting by item insertion order (true) or let user change
141 * sorting by clicking on a column header (false).
143 virtual void setSortByInsertionSequence( bool sortByInsertionSequence );
146 * Returns the next free serial number for items that want to be ordered in
147 * insertion sequence.
149 int nextSerial() { return _nextSerial++; }
152 * Returns the minimum size required for this widget.
153 * Inherited from QWidget.
155 virtual QSize minimumSizeHint() const;
158 * Event filter - inherited from QWidget
160 virtual bool eventFilter( QObject * obj, QEvent * event );
166 * Internal: Handle manual column resize.
167 * Save the user's preferred sizes so they don't get overwritten each time
168 * the list is cleared and filled with new contents.
170 void columnWidthChanged( int col, int oldSize, int newSize );
175 * Handle mouse clicks.
176 * Reimplemented from QScrollView.
178 virtual void contentsMousePressEvent( QMouseEvent * e );
181 * Handle mouse clicks.
182 * Reimplemented from QScrollView.
184 virtual void contentsMouseReleaseEvent( QMouseEvent * );
187 * Handle mouse clicks.
188 * Reimplemented from QScrollView.
190 virtual void contentsMouseDoubleClickEvent( QMouseEvent * );
197 Q3ListViewItem * _mousePressedItem;
198 int _mousePressedCol;
199 int _mousePressedButton;
201 std::vector<int> _savedColumnWidth;
202 bool _sortByInsertionSequence;
205 QY2ListViewToolTip * _toolTip;
206 bool _mouseButton1PressedInHeader;
207 bool _finalSizeChangeExpected;
213 * Enhanced Q3ListViewItem
215 class QY2ListViewItem: public Q3ListViewItem
220 * Constructor for toplevel items.
222 QY2ListViewItem( QY2ListView * parentListView,
223 const QString & text = QString::null );
227 * Constructor for deeper level items.
229 QY2ListViewItem( Q3ListViewItem * parentItem,
230 const QString & text = QString::null );
235 virtual ~QY2ListViewItem();
238 * Update this item's status.
239 * Triggered by QY2ListView::updateAllItemStates().
240 * Derived classes should overwrite this.
241 * This default implementation does nothing.
243 virtual void updateStatus() {}
246 * Update this item's data completely.
247 * Triggered by QY2ListView::updateAllItemData().
248 * Derived classes should overwrite this.
249 * This default implementation does nothing.
251 virtual void updateData() {}
254 * Comparison function used for sorting the list.
260 * Reimplemented from Q3ListViewItem
262 virtual int compare( Q3ListViewItem * other,
264 bool ascending ) const;
267 * Return this item's serial number.
268 * Useful for comparison functions that order by insertion sequence.
270 int serial() const { return _serial; }
273 * Set the text foreground color for all columns.
274 * For more specific purposes reimiplement paintCell().
276 void setTextColor( const QColor & col )
277 { _textColor = col; }
280 * Set the text background color for all columns.
281 * For more specific purposes reimiplement paintCell().
283 void setBackgroundColor( const QColor & col )
284 { _backgroundColor = col; }
287 * Returns a tool tip text for a specific column of this item.
288 * 'column' is -1 if the mouse pointer is in the tree indentation area.
290 * This default implementation does nothing.
292 virtual QString toolTip( int column ) { return QString::null; }
298 * Paint method. Reimplemented from @ref Q3ListViewItem so different
299 * colors can be used.
301 * Reimplemented from Q3ListViewItem.
303 virtual void paintCell( QPainter * painter,
304 const QColorGroup & colorGroup,
316 QColor _backgroundColor;
322 * Enhanced QCheckListItem
324 class QY2CheckListItem: public Q3CheckListItem
329 * Constructor for toplevel items.
331 QY2CheckListItem( QY2ListView * parentListView,
332 const QString & text,
333 Q3CheckListItem::Type type );
337 * Constructor for deeper level items.
339 QY2CheckListItem( Q3ListViewItem * parentItem,
340 const QString & text,
341 Q3CheckListItem::Type type );
345 * Constructor for deeper level items for QCheckListItem parents.
347 QY2CheckListItem( Q3CheckListItem * parentItem,
348 const QString & text,
349 Q3CheckListItem::Type type );
354 virtual ~QY2CheckListItem();
357 * Update this item's status.
358 * Triggered by QY2ListView::updateAllItemStates().
359 * Derived classes should overwrite this.
360 * This default implementation does nothing.
362 virtual void updateStatus() {}
365 * Update this item's data completely.
366 * Triggered by QY2ListView::updateAllItemData().
367 * Derived classes should overwrite this.
368 * This default implementation does nothing.
370 virtual void updateData() {}
373 * Comparison function used for sorting the list.
379 * Reimplemented from Q3ListViewItem
381 virtual int compare( Q3ListViewItem * other,
383 bool ascending ) const;
386 * Return this item's serial number.
387 * Useful for comparison functions that order by insertion sequence.
389 int serial() const { return _serial; }
392 * Set the text foreground color for all columns.
393 * For more specific purposes reimiplement paintCell().
395 void setTextColor( const QColor & col )
396 { _textColor = col; }
399 * Set the text background color for all columns.
400 * For more specific purposes reimiplement paintCell().
402 void setBackgroundColor( const QColor & col )
403 { _backgroundColor = col; }
406 * Returns a tool tip text for a specific column of this item.
407 * 'column' is -1 if the mouse pointer is in the tree indentation area.
409 * This default implementation does nothing.
411 virtual QString toolTip( int column ) { return QString(); }
417 * Paint method. Reimplemented from @ref Q3ListViewItem so different
418 * colors can be used.
420 * Reimplemented from Q3ListViewItem.
422 virtual void paintCell( QPainter * painter,
423 const QColorGroup & colorGroup,
435 QColor _backgroundColor;
441 * Tool tip for a QY2ListView widget: Enables individual tool tips specific to
442 * each list item and each column. Overwrite QY2ListViewItem::toolTip() to use
445 class QY2ListViewToolTip : public QToolTip
452 QY2ListViewToolTip( QY2ListView * parent )
453 : QToolTip( parent->viewport() )
454 , _listView( parent ) {}
457 * Destructor (to make gcc 4.x happy)
459 virtual ~QY2ListViewToolTip() {}
465 * Decide if there is a tool tip text at 'p' and display it if there is one.
467 * Reimplemented from QToolTip.
469 virtual void maybeTip( const QPoint & p );
476 QY2ListView * _listView;
480 #endif // ifndef QY2ListView_h