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 <QTreeWidget>
31 #define FIXME_TOOLTIP 0
34 class QY2ListViewItem;
35 class QY2ListViewToolTip;
39 * @short Enhanced Q3ListView
41 class QY2ListView : public QTreeWidget
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 QTreeWidgetItem * item,
107 const QPoint & pos );
110 * Emitted for mouse double clicks on an item
112 void columnDoubleClicked ( int button,
113 QTreeWidgetItem * 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( QTreeWidgetItem * 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 QTreeWidgetItem * _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 QTreeWidgetItem
215 class QY2ListViewItem: public QTreeWidgetItem
220 * Constructor for toplevel items.
222 QY2ListViewItem( QY2ListView * parentListView,
223 const QString & text = QString::null );
227 * Constructor for deeper level items.
229 QY2ListViewItem( QTreeWidgetItem * 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 QTreeWidgetItem
262 virtual int compare( QTreeWidgetItem * 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 QTreeWidgetItem so different
299 * colors can be used.
301 * Reimplemented from QTreeWidgetItem.
304 virtual void paintCell( QPainter * painter,
305 const QColorGroup & colorGroup,
317 QColor _backgroundColor;
323 * Enhanced QCheckListItem
325 class QY2CheckListItem: public QTreeWidgetItem
330 * Constructor for toplevel items.
332 QY2CheckListItem( QY2ListView * parentListView,
333 const QString & text );
337 * Constructor for deeper level items.
339 QY2CheckListItem( QTreeWidgetItem * parentItem,
340 const QString & text );
345 virtual ~QY2CheckListItem();
348 * Update this item's status.
349 * Triggered by QY2ListView::updateAllItemStates().
350 * Derived classes should overwrite this.
351 * This default implementation does nothing.
353 virtual void updateStatus() {}
356 * Update this item's data completely.
357 * Triggered by QY2ListView::updateAllItemData().
358 * Derived classes should overwrite this.
359 * This default implementation does nothing.
361 virtual void updateData() {}
364 * Comparison function used for sorting the list.
370 * Reimplemented from QTreeWidgetItem
372 virtual int compare( QTreeWidgetItem * other,
374 bool ascending ) const;
377 * Return this item's serial number.
378 * Useful for comparison functions that order by insertion sequence.
380 int serial() const { return _serial; }
383 * Set the text foreground color for all columns.
384 * For more specific purposes reimiplement paintCell().
386 void setTextColor( const QColor & col )
387 { _textColor = col; }
390 * Set the text background color for all columns.
391 * For more specific purposes reimiplement paintCell().
393 void setBackgroundColor( const QColor & col )
394 { _backgroundColor = col; }
397 * Returns a tool tip text for a specific column of this item.
398 * 'column' is -1 if the mouse pointer is in the tree indentation area.
400 * This default implementation does nothing.
402 virtual QString toolTip( int column ) { return QString(); }
408 * Paint method. Reimplemented from @ref QTreeWidgetItem so different
409 * colors can be used.
411 * Reimplemented from QTreeWidgetItem.
413 /*virtual void paintCell( QPainter * painter,
414 const QColorGroup & colorGroup,
426 QColor _backgroundColor;
432 * Tool tip for a QY2ListView widget: Enables individual tool tips specific to
433 * each list item and each column. Overwrite QY2ListViewItem::toolTip() to use
436 class QY2ListViewToolTip : public QToolTip
443 QY2ListViewToolTip( QY2ListView * parent )
444 : QToolTip( parent->viewport() )
445 , _listView( parent ) {}
448 * Destructor (to make gcc 4.x happy)
450 virtual ~QY2ListViewToolTip() {}
456 * Decide if there is a tool tip text at 'p' and display it if there is one.
458 * Reimplemented from QToolTip.
460 virtual void maybeTip( const QPoint & p );
467 QY2ListView * _listView;
471 #endif // ifndef QY2ListView_h