⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlistview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	h++;    setHeight( h );}/*!  This virtual function is called whenever the user clicks on this  item or presses Space on it.  \sa activatedPos()*/void QListViewItem::activate(){}/*!  When called from a reimplementation of activate(), this function  gives information on how the item was activated. Otherwise, the  behaviour is undefined.  If activate() was caused by a mouse press, the function sets \a  pos to where the user clicked and returns TRUE, otherwise it returns  FALSE and does not change \a pos.  Pos is relative to the top-left corner of this item.  We recommend not using this function; it will most likely be  obsoleted at the first opportunity.  \sa activate()*/bool QListViewItem::activatedPos( QPoint &pos ){    if ( activatedByClick )	pos = activatedP;    return activatedByClick;}/*! \fn bool QListViewItem::isSelectable() const  Returns TRUE if the item is selectable (as it is by default) and  FALSE if it isn't.  \sa setSelectable()*//*!  Sets this items to be selectable if \a enable is TRUE (the  default) or not to be selectable if \a enable is FALSE.  The user is not able to select a non-selectable item using either  the keyboard or mouse.  The application programmer still can, of  course.  \sa isSelectable() */void QListViewItem::setSelectable( bool enable ){    selectable = enable;}/*! \fn bool QListViewItem::isExpandable() const  Returns TRUE if this item is expandable even when it has no  children.*//*!  Sets this item to be expandable even if it has no children if \a  enable is TRUE, and to be expandable only if it has children if \a  enable is FALSE (the default).  The dirview example uses this in the canonical fashion: It checks  whether the directory is empty in setup() and calls  setExpandable(TRUE) if not, and in setOpen() it reads the contents  of the directory and inserts items accordingly.  This strategy means  that dirview can display the entire file system without reading very  much at start-up.  Note that root items are not expandable by the user unless  QListView::setRootIsDecorated() is set to TRUE.  \sa setSelectable()*/void QListViewItem::setExpandable( bool enable ){    expandable = enable;}/*!  Makes sure that this object's children are sorted appropriately.  This only works if every item in the chain from the root item to  this item is sorted appropriately.  \sa sortChildItems()*/void QListViewItem::enforceSortOrder() const{    QListView *lv = listView();    if ( lv && lv->d->clearing )	return;    if( parentItem &&	(parentItem->lsc != lsc || parentItem->lso != lso) &&	(int)parentItem->lsc != Unsorted )	((QListViewItem *)this)->sortChildItems( (int)parentItem->lsc,						 (bool)parentItem->lso );    else if ( !parentItem &&	      ( (int)lsc != listView()->d->sortcolumn ||		(bool)lso != listView()->d->ascending ) &&	      listView()->d->sortcolumn != Unsorted )	((QListViewItem *)this)->sortChildItems( listView()->d->sortcolumn,						 listView()->d->ascending );}/*! \fn bool QListViewItem::isSelected() const  Returns TRUE if this item is selected, or FALSE if it is not.  \sa setSelected() QListView::setSelected() QListView::selectionChanged()*//*!  Sets this item to be selected \a s is TRUE, and to not be  selected if \a s is FALSE.  This function does not maintain any invariants or repaint anything -  QListView::setSelected() does that.  \sa height() totalHeight() */void QListViewItem::setSelected( bool s ){    selected = s && isSelectable() ? 1 : 0;}/*!  Returns the total height of this object, including any visible  children.  This height is recomputed lazily and cached for as long  as possible.  setHeight() can be used to set the item's own height, setOpen()  to show or hide its children, and invalidateHeight() to invalidate  the cached height.  \sa height()*/int QListViewItem::totalHeight() const{    if ( maybeTotalHeight >= 0 )	return maybeTotalHeight;    QListViewItem * that = (QListViewItem *)this;    if ( !that->configured ) {	that->configured = TRUE;	that->setup(); // ### virtual non-const function called in const    }    that->maybeTotalHeight = that->ownHeight;    if ( !that->isOpen() || !that->childCount() )	return that->ownHeight;    QListViewItem * child = that->childItem;    while ( child != 0 ) {	that->maybeTotalHeight += child->totalHeight();	child = child->siblingItem;    }    return that->maybeTotalHeight;}/*!  Returns the text in column \a column, or a  \link QString::operator!() null string \endlink if there  is no text in that column.  This function works even if this item is not contained in a list  view, but reimplementations of it are not required to work properly  in that case.  \sa key() paintCell()*/QString QListViewItem::text( int column ) const{    QListViewPrivate::ItemColumnInfo * l	= (QListViewPrivate::ItemColumnInfo*) columns;    while( column && l ) {	l = l->next;	column--;    }    return l ? l->text : QString::null;}/*!  Sets the text in column \a column to \a text, if \a column is a  valid column number and \a text is non-null.  If \a text() has been reimplemented, this function may be a no-op.  \sa text() key() invalidate()*/void QListViewItem::setText( int column, const QString &text ){    if ( column < 0 )	return;    QListViewPrivate::ItemColumnInfo * l	= (QListViewPrivate::ItemColumnInfo*) columns;    if ( !l ) {	l = new QListViewPrivate::ItemColumnInfo;	columns = (void*)l;    }    for( int c=0; c<column; c++ ) {	if ( !l->next )	    l->next = new QListViewPrivate::ItemColumnInfo;	l = l->next;    }    if ( l->text == text )	return;    l->dirty = TRUE;    l->text = text;    if ( column == (int)lsc )	lsc = Unsorted;    QListView * lv = listView();    widthChanged( column );    if ( lv ) {	lv->d->useDoubleBuffer = TRUE;	lv->triggerUpdate();    }}/*!  Sets the pixmap in column \a column to \a pm, if \a pm is  non-null and \a column is non-negative.  \sa pixmap() setText()*/void QListViewItem::setPixmap( int column, const QPixmap & pm ){    int oldW = 0;    int oldH = 0;    if ( pixmap( column ) ) {	oldW = pixmap( column )->width();	oldH = pixmap( column )->height();    }    if ( column < 0 )	return;    QListViewPrivate::ItemColumnInfo * l	= (QListViewPrivate::ItemColumnInfo*) columns;    if ( !l ) {	l = new QListViewPrivate::ItemColumnInfo;	columns = (void*)l;    }    for( int c=0; c<column; c++ ) {	if ( !l->next )	    l->next = new QListViewPrivate::ItemColumnInfo;	l = l->next;    }    if ( ( pm.isNull() && ( !l->pm || l->pm->isNull() ) ) ||	 ( l->pm && pm.serialNumber() == l->pm->serialNumber() ) )	return;    if ( pm.isNull() ) {	delete l->pm;	l->pm = 0;    } else {	if ( l->pm )	    *(l->pm) = pm;	else	    l->pm = new QPixmap( pm );    }    int newW = 0;    int newH = 0;    if ( pixmap( column ) ) {	newW = pixmap( column )->width();	newH = pixmap( column )->height();    }    if ( oldW != newW || oldH != newH ) {	setup();	widthChanged( column );	invalidateHeight();    }    QListView *lv = listView();    if ( lv ) {	lv->d->useDoubleBuffer = TRUE;	lv->triggerUpdate();    }}/*!  Returns a pointer to the pixmap for \a column, or a null pointer  if there is no pixmap for \a column.  This function works even if this item is not contained in a list  view, but reimplementations of it are not required to work properly  in that case.  \sa setText() setPixmap()*/const QPixmap * QListViewItem::pixmap( int column ) const{    QListViewPrivate::ItemColumnInfo * l    = (QListViewPrivate::ItemColumnInfo*) columns;    while( column && l ) {	l = l->next;	column--;    }    return (l && l->pm) ? l->pm : 0;}/*!  This virtual function paints the contents of one column of one item.  \a p is a QPainter open on the relevant paint device.  \a p is  translated so 0, 0 is the top left pixel in the cell and \a width-1,  height()-1 is the bottom right pixel \e in the cell.  The other  properties of \a p (pen, brush etc) are undefined.  \a cg is the  color group to use.  \a column is the logical column number within  the item that is to be painted; 0 is the column which may contain a  tree.  This function may use QListView::itemMargin() for readability  spacing on the left and right sides of information such as text,  and should honor isSelected() and QListView::allColumnsShowFocus().  If you reimplement this function, you should also reimplement  width().  The rectangle to be painted is in an undefined state when this  function is called, so you \e must draw on all the pixels.  The  painter \a p has the right font on entry.  \sa paintBranches(), QListView::drawContentsOffset()*/void QListViewItem::paintCell( QPainter * p, const QColorGroup & cg,			       int column, int width, int align ){    // Change width() if you change this.    if ( !p )	return;    QListView *lv = listView();    // had, but we _need_ the column info for the ellipsis thingy!!!    if ( !columns ) {	for ( uint i = 0; i < lv->d->column.size(); ++i ) {	    setText( i, text( i ) );	}    }    QString t = text( column );    if ( columns ) {	QListViewPrivate::ItemColumnInfo *ci = 0;	// try until we have a column info....	while ( !ci ) {	    ci = (QListViewPrivate::ItemColumnInfo*)columns;	    for ( int i = 0; ci && (i < column); ++i )		ci = ci->next;	    if ( !ci ) {		setText( column, t );		ci = 0;	    }	}	// if the column width changed and this item was not painted since this change	if ( ci && ( ci->width != width || ci->text != t || ci->dirty ) ) {	    ci->dirty = FALSE;	    QFontMetrics fm( p->fontMetrics() );	    ci->width = width;	    ci->truncated = FALSE;	    // if we have to do the ellipsis thingy calc the truncated text	    int pw = pixmap( column ) ? pixmap( column )->width() + lv->itemMargin() : lv->itemMargin();	    if ( fm.width( t ) + pw > width ) {		ci->truncated = TRUE;		ci->tmpText = "...";		int i = 0;		while ( fm.width( ci->tmpText + t[ i ] ) + pw < width )		    ci->tmpText += t[ i++ ];		ci->tmpText.remove( 0, 3 );		if ( ci->tmpText.isEmpty() )		    ci->tmpText = t.left( 1 );		ci->tmpText += "...";	    }	}	// if we have to draw the ellipsis thingy, use the truncated text	if ( ci && ci->truncated )	    t = ci->tmpText;    }    int r = lv ? lv->itemMargin() : 1;    const QPixmap * icon = pixmap( column );#ifdef QT_KEYPAD_MODE    if ( qt_modalEditingEnabled && !listView()->isModalEditing() && !qt_singleFocusWidget(listView()) )	p->fillRect( 0, 0, width, height(), cg.brush( QColorGroup::Background ) );    else#endif	p->fillRect( 0, 0, width, height(), cg.brush( QColorGroup::Base ) );    int marg = lv ? lv->itemMargin() : 1;    if ( align != AlignLeft )	marg -= lv->d->minRightBearing;    if ( isSelected() &&	 (column==0 || listView()->allColumnsShowFocus()) ) {	p->fillRect( r - marg, 0, width - r + marg, height(),		     cg.brush( QColorGroup::Highlight ) );	p->setPen( cg.highlightedText() );    } else {	p->setPen( cg.text() );    }    if ( icon ) {	p->drawPixmap( r, (height()-icon->height())/2, *icon );	r += icon->width() + listView()->itemMargin();    }    if ( !t.isEmpty() ) {	if ( ! (align & AlignTop | align & AlignBottom) )            align |= AlignVCenter;        p->drawText( r, 0, width-marg-r, height(),            align, t );    }}/*!  Returns the number of pixels of width required to draw column \a c  of listview \a lv, using the metrics \a fm without cropping.  The list view containing this item may use  this information, depending on the QListView::WidthMode settings  for the column.  The default implementation returns the width of the bounding  rectangle of the text of column \a c.  \sa listView() widthChanged() QListView::setColumnWidthMode()  QListView::itemMargin()*/int QListViewItem::width( const QFontMetrics& fm,			  const QListView* lv, int c ) const{    int w = fm.width( text( c ) ) + lv->itemMargin() * 2	    - lv->d->minLeftBearing - lv->d->minRightBearing;    const QPixmap * pm = pixmap( c );    if ( pm )	w += pm->width() + lv->itemMargin(); // ### correct margin stuff?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -