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 QTreeWidget
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 mousePressEvent( QMouseEvent * e );
181 * Handle mouse clicks.
182 * Reimplemented from QScrollView.
184 virtual void mouseReleaseEvent( QMouseEvent * );
187 * Handle mouse clicks.
188 * Reimplemented from QScrollView.
190 virtual void mouseDoubleClickEvent( 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.
255 * Reimplemented from QTreeWidgetItem
257 virtual bool operator< ( const QTreeWidgetItem & other ) const;
260 * Return this item's serial number.
261 * Useful for comparison functions that order by insertion sequence.
263 int serial() const { return _serial; }
266 * Set the text foreground color for all columns.
267 * For more specific purposes reimiplement paintCell().
269 void setTextColor( const QColor & col )
270 { _textColor = col; }
273 * Set the text background color for all columns.
274 * For more specific purposes reimiplement paintCell().
276 void setBackgroundColor( const QColor & col )
277 { _backgroundColor = col; }
280 * Returns a tool tip text for a specific column of this item.
281 * 'column' is -1 if the mouse pointer is in the tree indentation area.
283 * This default implementation does nothing.
285 virtual QString toolTip( int column ) { return QString::null; }
291 * Paint method. Reimplemented from @ref QTreeWidgetItem so different
292 * colors can be used.
294 * Reimplemented from QTreeWidgetItem.
297 virtual void paintCell( QPainter * painter,
298 const QColorGroup & colorGroup,
310 QColor _backgroundColor;
316 * Enhanced QCheckListItem
318 class QY2CheckListItem: public QY2ListViewItem
323 * Constructor for toplevel items.
325 QY2CheckListItem( QY2ListView * parentListView,
326 const QString & text );
330 * Constructor for deeper level items.
332 QY2CheckListItem( QTreeWidgetItem * parentItem,
333 const QString & text );
338 virtual ~QY2CheckListItem();
341 * Update this item's status.
342 * Triggered by QY2ListView::updateAllItemStates().
343 * Derived classes should overwrite this.
344 * This default implementation does nothing.
346 virtual void updateStatus() {}
349 * Update this item's data completely.
350 * Triggered by QY2ListView::updateAllItemData().
351 * Derived classes should overwrite this.
352 * This default implementation does nothing.
354 virtual void updateData() {}
357 * Return this item's serial number.
358 * Useful for comparison functions that order by insertion sequence.
360 int serial() const { return _serial; }
363 * Set the text foreground color for all columns.
364 * For more specific purposes reimiplement paintCell().
366 void setTextColor( const QColor & col )
367 { _textColor = col; }
370 * Set the text background color for all columns.
371 * For more specific purposes reimiplement paintCell().
373 void setBackgroundColor( const QColor & col )
374 { _backgroundColor = col; }
377 * Returns a tool tip text for a specific column of this item.
378 * 'column' is -1 if the mouse pointer is in the tree indentation area.
380 * This default implementation does nothing.
382 virtual QString toolTip( int column ) { return QString(); }
388 * Paint method. Reimplemented from @ref QTreeWidgetItem so different
389 * colors can be used.
391 * Reimplemented from QTreeWidgetItem.
393 /*virtual void paintCell( QPainter * painter,
394 const QColorGroup & colorGroup,
406 QColor _backgroundColor;
412 * Tool tip for a QY2ListView widget: Enables individual tool tips specific to
413 * each list item and each column. Overwrite QY2ListViewItem::toolTip() to use
416 class QY2ListViewToolTip : public QToolTip
423 QY2ListViewToolTip( QY2ListView * parent )
424 : QToolTip( parent->viewport() )
425 , _listView( parent ) {}
428 * Destructor (to make gcc 4.x happy)
430 virtual ~QY2ListViewToolTip() {}
436 * Decide if there is a tool tip text at 'p' and display it if there is one.
438 * Reimplemented from QToolTip.
440 virtual void maybeTip( const QPoint & p );
447 QY2ListView * _listView;
451 #endif // ifndef QY2ListView_h