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

📄 qtableview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		matrix.translate( xPos, yPos );		paint.setWorldMatrix( matrix );		if ( testTableFlags(Tbl_clipCellPainting) ||		     frameWidth() > 0 && !winR.contains( cellR ) ) { //##arnt		    paint.setClipRect( cellUR );		    paintCell( &paint, row, col );		    paint.setClipping( FALSE );		} else {		    paintCell( &paint, row, col );		}		matrix.reset();		paint.setWorldMatrix( matrix );#else		paint.translate( xPos, yPos );		if ( testTableFlags(Tbl_clipCellPainting) ||		     frameWidth() > 0 && !winR.contains( cellR ) ) { //##arnt		    paint.setClipRect( cellUR );		    paintCell( &paint, row, col );		    paint.setClipping( FALSE );		} else {		    paintCell( &paint, row, col );		}		paint.translate( -xPos, -yPos );#endif	    }	    col++;	    xPos = nextX;	}	row++;	yPos = nextY;    }    // while painting we have to erase any areas in the view that    // are not covered by cells but are covered by the paint event    // rectangle these must be erased. We know that xPos is the last    // x pixel updated + 1 and that yPos is the last y pixel updated + 1.    // Note that this needs to be done regardless whether we do    // eraseInPaint or not. Reason: a subclass (for example    // QMultiLineEdit) may implement flicker-freeness and encourage    // the use of repaint(FALSE). The subclass, however, cannot draw    // all pixels, just those inside the cells. So QTableView is    // reponsible for all pixels outside the cells.    QRect viewR = viewRect();    const QColorGroup g = colorGroup();        if ( xPos <= maxX ) {	QRect r = viewR;	r.setLeft( xPos );	r.setBottom( yPos<maxY?yPos:maxY );	if ( inherits( "QMultiLineEdit" ) )#ifdef QT_KEYPAD_MODE	    if ( qt_modalEditingEnabled && !isModalEditing() )		paint.fillRect( r.intersect( updateR ), g.brush(QColorGroup::Background) );	    else#endif	    paint.fillRect( r.intersect( updateR ), g.brush(QColorGroup::Base) );	else	    paint.eraseRect( r.intersect( updateR ) );    }    if ( yPos <= maxY ) {	QRect r = viewR;	r.setTop( yPos );	if ( inherits( "QMultiLineEdit" ) )#ifdef QT_KEYPAD_MODE	    if ( qt_modalEditingEnabled && !isModalEditing() )		paint.fillRect( r.intersect( updateR ), g.brush(QColorGroup::Background) );	    else#endif	    paint.fillRect( r.intersect( updateR ), g.brush(QColorGroup::Base) );	else	    paint.eraseRect( r.intersect( updateR ) );    }}/*!\reimp*/void QTableView::resizeEvent( QResizeEvent * /* e */){    updateScrollBars( horValue | verValue | horSteps | horGeometry | horRange |		      verSteps | verGeometry | verRange );    showOrHideScrollBars();    updateFrameSize();    int maxX = QMIN( xOffs, maxXOffset() );			// ### can be slow    int maxY = QMIN( yOffs, maxYOffset() );    setOffset( maxX, maxY );    if ( testWState(WState_AutoMask) )	updateMask();}/*!  Redraws all visible cells in the table view.*/void QTableView::updateView(){    repaint( viewRect() );}/*!  Returns a pointer to the vertical scroll bar, mainly so you can  connect() to its signals.  Note that the scroll bar works in pixel  values, use findRow() to translate to cell numbers.*/QScrollBar *QTableView::verticalScrollBar() const{    QTableView *that = (QTableView*)this; // semantic const    if ( !vScrollBar ) {	QScrollBar *sb = new QScrollBar( QScrollBar::Vertical, that );#ifndef QT_NO_CURSOR	sb->setCursor( arrowCursor );#endif        sb->resize( sb->sizeHint() ); // height is irrelevant	CHECK_PTR(sb);	sb->setTracking( FALSE );	sb->setFocusPolicy( NoFocus );	connect( sb, SIGNAL(valueChanged(int)),		 SLOT(verSbValue(int)));	connect( sb, SIGNAL(sliderMoved(int)),		 SLOT(verSbSliding(int)));	connect( sb, SIGNAL(sliderReleased()),		 SLOT(verSbSlidingDone()));	sb->hide();	that->vScrollBar = sb;	return sb;    }    return vScrollBar;}/*!  Returns a pointer to the horizontal scroll bar, mainly so you can  connect() to its signals. Note that the scroll bar works in pixel  values, use findCol() to translate to cell numbers.*/QScrollBar *QTableView::horizontalScrollBar() const{    QTableView *that = (QTableView*)this; // semantic const    if ( !hScrollBar ) {	QScrollBar *sb = new QScrollBar( QScrollBar::Horizontal, that );#ifndef QT_NO_CURSOR	sb->setCursor( arrowCursor );#endif	sb->resize( sb->sizeHint() ); // width is irrelevant	sb->setFocusPolicy( NoFocus );	CHECK_PTR(sb);	sb->setTracking( FALSE );	connect( sb, SIGNAL(valueChanged(int)),		 SLOT(horSbValue(int)));	connect( sb, SIGNAL(sliderMoved(int)),		 SLOT(horSbSliding(int)));	connect( sb, SIGNAL(sliderReleased()),		 SLOT(horSbSlidingDone()));	sb->hide();	that->hScrollBar = sb;	return sb;    }    return hScrollBar;}/*!  Enables or disables the horizontal scroll bar, as required by  setAutoUpdate() and the \link setTableFlags() table flags\endlink.*/void QTableView::setHorScrollBar( bool on, bool update ){    if ( on ) {	tFlags |= Tbl_hScrollBar;	horizontalScrollBar(); // created	if ( update )	    updateScrollBars( horMask | verMask );	else	    sbDirty = sbDirty | (horMask | verMask);	if ( testTableFlags( Tbl_vScrollBar ) )	    coverCornerSquare( TRUE );	if ( autoUpdate() )	    sbDirty = sbDirty | horMask;    } else {	tFlags &= ~Tbl_hScrollBar;	if ( !hScrollBar )	    return;	coverCornerSquare( FALSE );	bool hideScrollBar = autoUpdate() && hScrollBar->isVisible();	if ( hideScrollBar )	    hScrollBar->hide();	if ( update )	    updateScrollBars( verMask );	else	    sbDirty = sbDirty | verMask;	if ( hideScrollBar && isVisible() )	    repaint( hScrollBar->x(), hScrollBar->y(),		     width() - hScrollBar->x(), hScrollBar->height() );    }    if ( update )	updateFrameSize();}/*!  Enables or disables the vertical scroll bar, as required by  setAutoUpdate() and the \link setTableFlags() table flags\endlink.*/void QTableView::setVerScrollBar( bool on, bool update ){    if ( on ) {	tFlags |= Tbl_vScrollBar;	verticalScrollBar(); // created	if ( update )	    updateScrollBars( verMask | horMask );	else	    sbDirty = sbDirty | (horMask | verMask);	if ( testTableFlags( Tbl_hScrollBar ) )	    coverCornerSquare( TRUE );	if ( autoUpdate() )	    sbDirty = sbDirty | verMask;    } else {	tFlags &= ~Tbl_vScrollBar;	if ( !vScrollBar )	    return;	coverCornerSquare( FALSE );	bool hideScrollBar = autoUpdate() && vScrollBar->isVisible();	if ( hideScrollBar )	    vScrollBar->hide();	if ( update )	    updateScrollBars( horMask );	else	    sbDirty = sbDirty | horMask;	if ( hideScrollBar && isVisible() )	    repaint( vScrollBar->x(), vScrollBar->y(),		     vScrollBar->width(), height() - vScrollBar->y() );    }    if ( update )	updateFrameSize();}int QTableView::findRawRow( int yPos, int *cellMaxY, int *cellMinY,			    bool goOutsideView ) const{    int r = -1;    if ( nRows == 0 )	return r;    if ( goOutsideView || yPos >= minViewY() && yPos <= maxViewY() ) {	if ( yPos < minViewY() ) {#if defined(CHECK_RANGE)	    qWarning( "QTableView::findRawRow: (%s) internal error: "		     "yPos < minViewY() && goOutsideView "		     "not supported. (%d,%d)",		     name( "unnamed" ), yPos, yOffs );#endif	    return -1;	}	if ( cellH ) {				     // uniform cell height	    r = (yPos - minViewY() + yCellDelta)/cellH; // cell offs from top	    if ( cellMaxY )		*cellMaxY = (r + 1)*cellH + minViewY() - yCellDelta - 1;	    if ( cellMinY )		*cellMinY = r*cellH + minViewY() - yCellDelta;	    r += yCellOffs;			     // absolute cell index	} else {				     // variable cell height	    QTableView *tw = (QTableView *)this;	    r	     = yCellOffs;	    int h    = minViewY() - yCellDelta; //##arnt3	    int oldH = h;	    ASSERT( r < nRows );	    while ( r < nRows ) {		oldH = h;		h += tw->cellHeight( r );	     // Start of next cell		if ( yPos < h )		    break;		r++;	    }	    if ( cellMaxY )		*cellMaxY = h - 1;	    if ( cellMinY )		*cellMinY = oldH;	}    }    return r;}int QTableView::findRawCol( int xPos, int *cellMaxX, int *cellMinX ,			    bool goOutsideView ) const{    int c = -1;    if ( nCols == 0 )	return c;    if ( goOutsideView || xPos >= minViewX() && xPos <= maxViewX() ) {	if ( xPos < minViewX() ) {#if defined(CHECK_RANGE)	    qWarning( "QTableView::findRawCol: (%s) internal error: "		     "xPos < minViewX() && goOutsideView "		     "not supported. (%d,%d)",		     name( "unnamed" ), xPos, xOffs );#endif	    return -1;	}	if ( cellW ) {				// uniform cell width	    c = (xPos - minViewX() + xCellDelta)/cellW; //cell offs from left	    if ( cellMaxX )		*cellMaxX = (c + 1)*cellW + minViewX() - xCellDelta - 1;	    if ( cellMinX )		*cellMinX = c*cellW + minViewX() - xCellDelta;	    c += xCellOffs;			// absolute cell index	} else {				// variable cell width	    QTableView *tw = (QTableView *)this;	    c	     = xCellOffs;	    int w    = minViewX() - xCellDelta; //##arnt3	    int oldW = w;	    ASSERT( c < nCols );	    while ( c < nCols ) {		oldW = w;		w += tw->cellWidth( c );	// Start of next cell		if ( xPos < w )		    break;		c++;	    }	    if ( cellMaxX )		*cellMaxX = w - 1;	    if ( cellMinX )		*cellMinX = oldW;	}    }    return c;}/*!  Returns the index of the row at position \e yPos, where \e yPos is in  \e widget coordinates.  Returns -1 if \e yPos is outside the valid  range.  \sa findCol(), rowYPos()*/int QTableView::findRow( int yPos ) const{    int cellMaxY;    int row = findRawRow( yPos, &cellMaxY );    if ( testTableFlags(Tbl_cutCellsV) && cellMaxY > maxViewY() )	row = - 1;				//  cell cut by bottom margin    if ( row >= nRows )	row = -1;    return row;}/*!  Returns the index of the column at position \e xPos, where \e xPos is  in \e widget coordinates.  Returns -1 if \e xPos is outside the valid  range.  \sa findRow(), colXPos()*/int QTableView::findCol( int xPos ) const{    int cellMaxX;    int col = findRawCol( xPos, &cellMaxX );    if ( testTableFlags(Tbl_cutCellsH) && cellMaxX > maxViewX() )	col = - 1;				//  cell cut by right margin    if ( col >= nCols )	col = -1;    return col;}/*!  Computes the position in the widget of row \e row.  Returns TRUE and stores the result in \e *yPos (in \e widget  coordinates) if the row is visible.  Returns FALSE and does not modify  \e *yPos if \e row is invisible or invalid.  \sa colXPos(), findRow()*/bool QTableView::rowYPos( int row, int *yPos ) const{    int y;    if ( row >= yCellOffs ) {	if ( cellH ) {	    int lastVisible = lastRowVisible();	    if ( row > lastVisible || lastVisible == -1 )		return FALSE;	    y = (row - yCellOffs)*cellH + minViewY() - yCellDelta;	} else {	    //##arnt3	    y = minViewY() - yCellDelta;	// y of leftmost cell in view	    int r = yCellOffs;	    QTableView *tw = (QTableView *)this;	    int maxY = maxViewY();	    while ( r < row && y <= maxY )		y += tw->cellHeight( r++ );	    if ( y > maxY )		return FALSE;	}    } else {	return FALSE;    }    if ( yPos )	*yPos = y;    return TRUE;}/*!  Computes the position in the widget of column \e column.  Returns TRUE and stores the result in \e *xPos (in \e widget  coordinates) if the column is visible.  Returns FALSE and does not  modify \e *xPos if \e col is invisible or invalid.  \sa rowYPos(), findCol()*/bool QTableView::colXPos( int col, int *xPos ) const{    int x;    if ( col >= xCellOffs ) {	if ( cellW ) {	    int lastVisible = lastColVisible();	    if ( col > lastVisible || lastVisible == -1 )		return FALSE;	    x = (col - xCellOffs)*cellW + minViewX() - xCellDelta;	} else {	    //##arnt3	    x = minViewX() - xCellDelta;	// x of uppermost cell in view	    int c = xCellOffs;	    QTableView *tw = (QTableView *)this;	    int maxX = maxViewX();	    while ( c < col && x <= maxX )		x += tw->cellWidth( c++ );	    if ( x > maxX )		return FALSE;	}    } else {	return FALSE;    }    if ( xPos )	*xPos = x;    return TRUE;}/*!  Moves the visible area of the table rightwards by \e xPixels and  downwards by \e yPixels pixels.  Both may be negative.  \warning You might find that QScrollView offers a higher-level of	functionality than using QTableView and this function.  This function is \e not the same as QWidget::scroll(), in particular,  the signs of \a xPixels and \a yPixels have the reverse semantics.  \sa setXOffset(), setYOffset(), setOffset(), setTopCell(),  setLeftCell(), setTopLeftOffset()*/void QTableView::scroll( int xPixels, int yPixels ){

⌨️ 快捷键说明

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