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

📄 qlistview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  \sa QHeader::setSortIndicator()*/void QListView::setShowSortIndicator( bool show ){    if ( show == d->sortIndicator )	return;    d->sortIndicator = show;    if ( d->sortcolumn != Unsorted && d->sortIndicator )	d->h->setSortIndicator( d->sortcolumn, d->ascending );    else	d->h->setSortIndicator( -1 );}/*!  Returns TRUE, if the sort order and column are indicated  in the header, else FALSE.  \sa QListView::setSortIndicator()*/bool QListView::showSortIndicator() const{    return d->sortIndicator;}/*!  Destructs the listview, deleting all items in it, and frees up all  allocated resources.*/QListView::~QListView(){    if ( d->iterators ) {	QListViewItemIterator *i = d->iterators->first();	while ( i ) {	    i->listView = 0;	    i = d->iterators->next();	}	delete d->iterators;    }    d->focusItem = 0;    delete d->r;    d->r = 0;    delete d->dirtyItems;    d->dirtyItems = 0;    delete d->drawables;    d->drawables = 0;    delete d->vci;    d->vci = 0;    delete d;    d = 0;}/*!  Calls QListViewItem::paintCell() and/or  QListViewItem::paintBranches() for all list view items that  require repainting.  See the documentation for those functions for  details.*/void QListView::drawContentsOffset( QPainter * p, int ox, int oy,				    int cx, int cy, int cw, int ch ){    if ( !d->drawables ||	 d->drawables->isEmpty() ||	 d->topPixel > cy ||	 d->bottomPixel < cy + ch - 1 ||	 d->r->maybeTotalHeight < 0 )	buildDrawableList();    if ( d->dirtyItems ) {	QRect br( cx - ox, cy - oy, cw, ch );	QPtrDictIterator<void> it( *(d->dirtyItems) );	QListViewItem * i;	while( (i=(QListViewItem *)(it.currentKey())) != 0 ) {	    ++it;	    QRect ir = itemRect( i ).intersect( viewport()->rect() );	    if ( ir.isEmpty() || br.contains( ir ) )		// we're painting this one, or it needs no painting: forget it		d->dirtyItems->remove( (void *)i );	}	if ( d->dirtyItems->count() ) {	    // there are still items left that need repainting	    d->dirtyItemTimer->start( 0, TRUE );	} else {	    // we're painting all items that need to be painted	    delete d->dirtyItems;	    d->dirtyItems = 0;	    d->dirtyItemTimer->stop();	}    }    p->setFont( font() );    QListIterator<QListViewPrivate::DrawableItem> it( *(d->drawables) );    QRect r;    int fx = -1, x, fc = 0, lc = 0;    int tx = -1;    QListViewPrivate::DrawableItem * current;    while ( (current = it.current()) != 0 ) {	++it;	int ih = current->i->height();	int ith = current->i->totalHeight();	int c;	int cs;	// need to paint current?	if ( ih > 0 && current->y < cy+ch && current->y+ih >= cy ) {	    if ( fx < 0 ) {		// find first interesting column, once		x = 0;		c = 0;		cs = d->h->cellSize( 0 );		while ( x + cs <= cx && c < d->h->count() ) {		    x += cs;		    c++;		    if ( c < d->h->count() )			cs = d->h->cellSize( c );		}		fx = x;		fc = c;		while( x < cx + cw && c < d->h->count() ) {		    x += cs;		    c++;		    if ( c < d->h->count() )			cs = d->h->cellSize( c );		}		lc = c;	    }	    x = fx;	    c = fc;	    // draw to last interesting column	    while ( c < lc && d->drawables ) {		int i = d->h->mapToLogical( c );		cs = d->h->cellSize( c );		r.setRect( x - ox, current->y - oy, cs, ih );		if ( i==0 && current->i->parentItem )		    r.setLeft( r.left() + current->l * treeStepSize() );		p->save();		p->translate( r.left(), r.top() );		int ac = d->h->mapToLogical( c );		if ( d->useDoubleBuffer ) {		    QSize ps( r.width(), current->i->height() );		    QPixmap *pm = getCacheBuffer( ps );		    QPainter dp( pm );		    dp.translate( -r.left(), -r.top() );		    paintEmptyArea( &dp, r );		    dp.translate( r.left(), r.top() );		    dp.setFont( p->font() );		    dp.setPen( p->pen() );		    dp.setBrush( p->brush() );                    if ( testWState(WState_GlobalBrushOrigin) )                        dp.setBrushOrigin(p->brushOrigin() - r.topLeft());		    current->i->paintCell( &dp, colorGroup(), ac, r.width(),					   columnAlignment( ac ) );		    dp.end();		    p->drawPixmap( QPoint( 0, 0 ), *pm, QRect( 0, 0, ps.width(), ps.height() ) );		} else {		    current->i->paintCell( p, colorGroup(), ac, r.width(),					   columnAlignment( ac ) );		}		p->restore();		x += cs;		c++;	    }	    if ( current->i == d->focusItem && hasFocus() &&		 !d->allColumnsShowFocus ) {		p->save();		int c = d->h->mapToActual( 0 );		QRect r( d->h->cellPos( c ) - ox, current->y - oy, d->h->cellSize( c ), ih );		if ( current->i->parentItem )		    r.setLeft( r.left() + current->l * treeStepSize() );		current->i->paintFocus( p, colorGroup(), r );		p->restore();	    }	}	// does current need focus indication?	if ( current->i == d->focusItem && hasFocus() &&	     d->allColumnsShowFocus ) {	    p->save();	    int x = -contentsX();	    int w = header()->cellPos( header()->count() - 1 ) +		    header()->cellSize( header()->count() - 1 );	    r.setRect( x, current->y - oy, w, ih );	    if ( d->h->mapToActual( 0 ) == 0 || ( current->l == 0 && !rootIsDecorated() ) ) {		r.setLeft( r.left() + current->l * treeStepSize() );		current->i->paintFocus( p, colorGroup(), r );	    } else {		int xdepth = treeStepSize() * ( current->i->depth() + ( rootIsDecorated() ? 1 : 0) )			     + itemMargin();		xdepth += d->h->cellPos( d->h->mapToActual( 0 ) );		QRect r1( r );		r1.setRight( d->h->cellPos( d->h->mapToActual( 0 ) ) - 1 );		QRect r2( r );		r2.setLeft( xdepth - 1 ); 		current->i->paintFocus( p, colorGroup(), r1 ); 		current->i->paintFocus( p, colorGroup(), r2 );	    }	    p->restore();	}	if ( tx < 0 )	    tx = d->h->cellPos( d->h->mapToActual( 0 ) );	// do any children of current need to be painted?	if ( ih != ith &&	     (current->i != d->r || d->rootIsExpandable) &&	     current->y + ith > cy &&	     current->y + ih < cy + ch &&	     tx + current->l * treeStepSize() < cx + cw &&	     tx + (current->l+1) * treeStepSize() > cx ) {	    // compute the clip rectangle the safe way	    int rtop = current->y + ih;	    int rbottom = current->y + ith;	    int rleft = tx + current->l*treeStepSize();	    int rright = rleft + treeStepSize();	    int crtop = QMAX( rtop, cy );	    int crbottom = QMIN( rbottom, cy+ch );	    int crleft = QMAX( rleft, cx );	    int crright = QMIN( rright, cx+cw );	    r.setRect( crleft-ox, crtop-oy,		       crright-crleft, crbottom-crtop );	    if ( r.isValid() ) {		p->save();		p->translate( rleft-ox, crtop-oy );		current->i->paintBranches( p, colorGroup(), treeStepSize(),					   rtop - crtop, r.height(), style() );		p->restore();	    }	}    }    if ( d->r->totalHeight() < cy + ch )	paintEmptyArea( p, QRect( cx - ox, d->r->totalHeight() - oy,				  cw, cy + ch - d->r->totalHeight() ) );    int c = d->h->count()-1;    if ( c >= 0 &&	 d->h->cellPos( c ) + d->h->cellSize( c ) < cx + cw ) {	c = d->h->cellPos( c ) + d->h->cellSize( c );	paintEmptyArea( p, QRect( c - ox, cy - oy, cx + cw - c, ch ) );    }}/*!  Paints \a rect so that it looks like empty background using  painter p.  \a rect is is widget coordinates, ready to be fed to \a  p.  The default function fills \a rect with colorGroup().brush( QColorGroup::Base ).*/void QListView::paintEmptyArea( QPainter * p, const QRect & rect ){#ifdef QT_KEYPAD_MODE    if ( qt_modalEditingEnabled && !isModalEditing() && !qt_singleFocusWidget(this) )	p->fillRect( rect, colorGroup().brush( QColorGroup::Background ) );    else#endif	p->fillRect( rect, colorGroup().brush( QColorGroup::Base ) );}/*! Rebuilds the list of drawable QListViewItems.  This function is  const so that const functions can call it without requiring  d->drawables to be mutable */void QListView::buildDrawableList() const{    d->r->enforceSortOrder();    QStack<QListViewPrivate::Pending> stack;    stack.push( new QListViewPrivate::Pending( ((int)d->rootIsExpandable)-1,					       0, d->r ) );    // could mess with cy and ch in order to speed up vertical    // scrolling    int cy = contentsY();    int ch = ((QListView *)this)->visibleHeight();    // ### hack to help sizeHint().  if not visible, assume that we'll    // ### use 200 pixels rather than whatever QScrollView thinks.    // ### this lets sizeHint() base its width on a more realistic    // ### number of items.    if ( !isVisible() && ch < 200 )	ch = 200;    d->topPixel = cy + ch; // one below bottom    d->bottomPixel = cy - 1; // one above top    QListViewPrivate::Pending * cur;    // used to work around lack of support for mutable    QList<QListViewPrivate::DrawableItem> * dl;    dl = new QList<QListViewPrivate::DrawableItem>;    dl->setAutoDelete( TRUE );    if ( d->drawables )	delete ((QListView *)this)->d->drawables;    ((QListView *)this)->d->drawables = dl;    while ( !stack.isEmpty() ) {	cur = stack.pop();	int ih = cur->i->height();	int ith = cur->i->totalHeight();	// is this item, or its branch symbol, inside the viewport?	if ( cur->y + ith >= cy && cur->y < cy + ch ) {	    dl->append( new QListViewPrivate::DrawableItem(cur));	    // perhaps adjust topPixel up to this item?  may be adjusted	    // down again if any children are not to be painted	    if ( cur->y < d->topPixel )		d->topPixel = cur->y;	    // bottompixel is easy: the bottom item drawn contains it	    d->bottomPixel = cur->y + ih - 1;	}	// push younger sibling of cur on the stack?	if ( cur->y + ith < cy+ch && cur->i->siblingItem )	    stack.push( new QListViewPrivate::Pending(cur->l,						      cur->y + ith,						      cur->i->siblingItem));	// do any children of cur need to be painted?	if ( cur->i->isOpen() && cur->i->childCount() &&	     cur->y + ith > cy &&	     cur->y + ih < cy + ch ) {	    cur->i->enforceSortOrder();	    QListViewItem * c = cur->i->childItem;	    int y = cur->y + ih;	    // if any of the children are not to be painted, skip them	    // and invalidate topPixel	    while ( c && y + c->totalHeight() <= cy ) {		y += c->totalHeight();		c = c->siblingItem;		d->topPixel = cy + ch;	    }	    // push one child on the stack, if there is at least one	    // needing to be painted	    if ( c && y < cy+ch )		stack.push( new QListViewPrivate::Pending( cur->l + 1,							   y, c ) );	}	delete cur;    }}/*!  Returns the number of pixels a child is offset from its parent.  This number has meaning only for tree views.  The default is 20.  \sa setTreeStepSize()*/int QListView::treeStepSize() const{    return d->levelWidth;}/*!  Sets the the number of pixels a child is offset from its parent,  in a tree view to \a l.  The default is 20.  \sa treeStepSize()*/void QListView::setTreeStepSize( int l ){    if ( l != d->levelWidth ) {	d->levelWidth = l;	// update    }}/*!  Inserts \a i into the list view as a top-level item.  You do not  need to call this unless you've called takeItem( \a i ) or  QListViewItem::takeItem( i ) and need to reinsert \a i elsewhere.  \sa QListViewItem::takeItem() (important) takeItem()*/void QListView::insertItem( QListViewItem * i ){    if ( d->r ) // not for d->r itself	d->r->insertItem( i );}/*!  Remove and delete all the items in this list view, and trigger an  update. \sa triggerUpdate() */void QListView::clear(){    bool block = signalsBlocked();    blockSignals( TRUE );    d->clearing = TRUE;    clearSelection();    if ( d->iterators ) {	QListViewItemIterator *i = d->iterators->first();	while ( i ) {	    i->curr = 0;	    i = d->iterators->next();	}    }    if ( d->drawables )	d->drawables->clear();    delete d->dirtyItems;    d->dirtyItems = 0;    d->dirtyItemTimer->stop();    d->focusItem = 0;    d->selectAnchor = 0;    // if it's down its downness makes no sense, so undown it    d->buttonDown = FALSE;    QListViewItem *c = (QListViewItem *)d->r->firstChild();    QListViewItem *n;    while( c ) {	n = (QListViewItem *)c->nextSibling();	delete c;	c = n;    }    resizeContents( d->h->sizeHint().width(), contentsHeight() );    delete d->r;    d->r = 0;    QListViewPrivate::Root * r = new QListViewPrivate::Root( this );    r->is_root = TRUE;    d->r = r;    d->r->setSelectable( FALSE );    blockSignals( block );    triggerUpdate();    d->clearing = FALSE;}/*!  \reimp*/void QListView::setContentsPos( int x, int y ){    updateGeometries();    QScrollView::setContentsPos( x, y );}/*!  Adds a new column at the right end of the widget, with the header \a  label, and returns the index of the column.  If \a width is negative, the new column will have WidthMode Maximum,  otherwise it will be Manual at \a width pixels wide.  \sa setColumnText() setColumnWidth

⌨️ 快捷键说明

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