29 #include <QHeaderView> 30 #include <QMouseEvent> 32 #include "QY2ListView.h" 34 #define YUILogComponent "qt-pkg" 35 #include <yui/YUILog.h> 38 : QTreeWidget( parent )
39 , _mousePressedItem(0)
40 , _mousePressedCol( -1 )
41 , _mousePressedButton( Qt::NoButton )
42 , _sortByInsertionSequence( false )
44 , _mouseButton1PressedInHeader( false )
45 , _finalSizeChangeExpected( false )
48 setRootIsDecorated(
false);
51 _toolTip =
new QY2ListViewToolTip(
this );
56 header()->installEventFilter(
this );
57 header()->setStretchLastSection(
false );
60 connect( header(), &pclass(header())::sectionResized,
63 connect(
this, &pclass(
this)::itemExpanded,
66 connect(
this, &pclass(
this)::itemCollapsed,
84 QTreeWidgetItemIterator it(
this );
90 if ( item && (item->flags() & Qt::ItemIsSelectable) )
92 item->setSelected(
true);
104 QTreeWidget::clear();
112 QTreeWidgetItemIterator it(
this );
129 QTreeWidgetItemIterator it(
this );
146 if ( ! listViewItem )
147 return QString::null;
158 return item->
toolTip( column );
163 return checkListItem->
toolTip( column );
165 return QString::null;
172 _savedColumnWidth.clear();
173 _savedColumnWidth.reserve( columnCount() );
175 for (
int i = 0; i < columnCount(); i++ )
177 int size = header()->sectionSize(i);
179 _savedColumnWidth.push_back( size );
187 if ( _savedColumnWidth.size() != (unsigned) columnCount() )
190 for (
int i = 0; i < columnCount(); i++ )
191 resizeColumnToContents(i);
196 for (
int i = 0; i < columnCount(); i++ )
198 header()->resizeSection( i, _savedColumnWidth[ i ] );
201 yuiDebug() <<
"Restoring size " << _savedColumnWidth[i]
202 <<
" for section " << i
203 <<
" now " << header()->sectionSize(i)
215 QTreeWidgetItem * item = itemAt( ev->pos() );
218 if ( item && ( item->flags() & Qt::ItemIsEnabled ) )
220 _mousePressedItem = item;
221 _mousePressedCol = header()->logicalIndexAt( ev->pos().x() );
222 _mousePressedButton = ev->button();
226 _mousePressedItem = 0;
227 _mousePressedCol = -1;
228 _mousePressedButton = Qt::NoButton;
232 QTreeWidget::mousePressEvent( ev );
240 QTreeWidgetItem * item = itemAt( ev->pos() );
242 if ( item && ( item->flags() & Qt::ItemIsEnabled ) && item == _mousePressedItem )
244 int col = header()->logicalIndexAt( ev->pos().x() );
246 if ( item == _mousePressedItem &&
247 col == _mousePressedCol &&
248 ev->button() == _mousePressedButton )
250 emit(
columnClicked( ev->button(), item, col, ev->globalPos() ) );
257 _mousePressedItem = 0;
258 _mousePressedCol = -1;
259 _mousePressedButton = Qt::NoButton;
262 QTreeWidget::mouseReleaseEvent( ev );
269 QTreeWidgetItem * item = itemAt( mapToGlobal( ev->pos() ) );
271 if ( item && ( item->flags() & Qt::ItemIsEnabled ) )
273 int col = header()->logicalIndexAt( ev->pos().x() );
279 _mousePressedItem = 0;
280 _mousePressedCol = -1;
281 _mousePressedButton = Qt::NoButton;
284 QTreeWidget::mouseDoubleClickEvent( ev );
302 if ( _mouseButton1PressedInHeader || _finalSizeChangeExpected )
309 if ( ! _mouseButton1PressedInHeader )
310 _finalSizeChangeExpected =
false;
319 if ( event && obj && obj == header() )
321 if ( event->type() == QEvent::MouseButtonPress )
323 QMouseEvent * mouseEvent = (QMouseEvent *) event;
325 if ( mouseEvent->button() == 1 )
327 _mouseButton1PressedInHeader =
true;
328 _finalSizeChangeExpected =
false;
331 else if ( event->type() == QEvent::MouseButtonRelease )
333 QMouseEvent * mouseEvent = (QMouseEvent *) event;
335 if ( mouseEvent->button() == 1 )
337 _finalSizeChangeExpected =
true;
338 _mouseButton1PressedInHeader =
false;
343 return QTreeWidget::eventFilter( obj, event );
350 return QSize( 0, 0 );
359 header()->setSectionsClickable( ! _sortByInsertionSequence );
369 const QString & text )
370 : QTreeWidgetItem( parentListView, QStringList(text), 1)
377 const QString & text )
378 : QTreeWidgetItem( parentItem, QStringList(text), 1 )
384 if ( parentListView )
398 bool sortByInsertionSequence =
false;
401 if ( parentListView )
404 if ( sortByInsertionSequence )
417 if ( otherCheckListItem )
419 return ( this->
serial() < otherCheckListItem->
serial() );
425 int column = treeWidget()->sortColumn();
426 QString text1=text(column).trimmed();
427 QString text2=otherListViewItem.text(column).trimmed();
429 text1=text1.left(text1.indexOf(QChar(
' ')));
430 text2=text2.left(text2.indexOf(QChar(
' ')));
433 bool retval = text1.toInt(&ok1) < text2.toInt(&ok2);
437 else if (ok1 && !ok2)
439 else if (!ok1 && ok2)
443 return QTreeWidgetItem::operator<(otherListViewItem);
448 const QString & text )
451 setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
452 setCheckState(0, Qt::Unchecked);
458 const QString & text )
464 setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
465 setCheckState(0, Qt::Unchecked);
467 if ( parentListView )
480 QY2ListViewToolTip::maybeTip(
const QPoint & pos )
482 Q3Header * header = _listView->header();
483 QTreeWidgetItem * item = _listView->itemAt( pos );
488 int x = _listView->viewportToContents( pos ).x();
489 int column = header->sectionAt(x);
494 indent = item->depth() + ( _listView->rootIsDecorated() ? 1 : 0 );
495 indent *= _listView->treeStepSize();
497 if ( pos.x() < indent )
501 QString text = _listView->toolTip( item, column );
503 if ( ! text.isEmpty() )
505 QRect rect( _listView->itemRect( item ) );
510 rect.setWidth( indent );
514 QPoint topLeft( header->sectionPos( column ), 0 );
515 topLeft = _listView->contentsToViewport( topLeft );
516 rect.setX( topLeft.x() );
517 rect.setWidth( header->sectionSize( column ) );
529 if ( columnCount() == 1 && header() && header()->isHidden() )
530 resizeColumnToContents( 0 );
536 if ( columnCount() == 1 && header() && header()->isHidden())
537 resizeColumnToContents( 0 );
543 #include "QY2ListView.moc" int serial() const
Return this item's serial number.
bool sortByInsertionSequence() const
Returns 'true' if the sort order should always be the item insertion order, 'false' if the user can c...
virtual void setSortByInsertionSequence(bool sortByInsertionSequence)
Enforce sorting by item insertion order (true) or let user change sorting by clicking on a column hea...
virtual bool operator<(const QTreeWidgetItem &other) const
Comparison function used for sorting the list.
virtual QSize minimumSizeHint() const
Returns the minimum size required for this widget.
QY2ListViewItem(QY2ListView *parentListView, const QString &text=QString::null)
Constructor for toplevel items.
void saveColumnWidths()
Save the current column widths.
void columnWidthChanged(int col, int oldSize, int newSize)
Internal: Handle manual column resize.
QY2ListView(QWidget *parent)
Constructor.
virtual void clear()
Reimplemented from Q3ListView: Adjust header sizes after clearing contents.
void columnClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Emitted for mouse clicks on an item.
virtual void mouseDoubleClickEvent(QMouseEvent *)
Handle mouse clicks.
virtual void updateData()
Update this item's data completely.
virtual QString toolTip(QTreeWidgetItem *item, int column)
Returns a tool tip text for a specific column of a list item.
virtual bool eventFilter(QObject *obj, QEvent *event)
Event filter - inherited from QWidget.
void updateItemStates()
Update the status display of all list entries: Call QY2ListViewItem::updateStatus() for each item...
virtual ~QY2CheckListItem()
Destructor.
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
void treeCollapsed(QTreeWidgetItem *listViewItem)
Internal notification that a tree item has been collapsed.
void columnDoubleClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Emitted for mouse double clicks on an item.
virtual QString toolTip(int column)
Returns a tool tip text for a specific column of this item.
QY2CheckListItem(QY2ListView *parentListView, const QString &text)
Constructor for toplevel items.
void treeExpanded(QTreeWidgetItem *listViewItem)
Internal notification that a tree item has been expanded.
int serial() const
Return this item's serial number.
Enhanced QTreeWidgetItem.
virtual ~QY2ListViewItem()
Destructor.
virtual ~QY2ListView()
Destructor.
void updateItemData()
Update the status display of all list entries: Call QY2ListViewItem::updateData() for each item...
virtual void mouseReleaseEvent(QMouseEvent *)
Handle mouse clicks.
virtual void selectSomething()
Select a list entry (if there is any).
int nextSerial()
Returns the next free serial number for items that want to be ordered in insertion sequence...
virtual void mousePressEvent(QMouseEvent *e)
Handle mouse clicks.
void restoreColumnWidths()
Restore the column widths to what was saved previously with saveColumnWidths().
virtual void updateStatus()
Update this item's status.