?? qtableview.cpp
字號:
if ( testWState(WState_GlobalBrushOrigin) ) repaint(contentsRect(), FALSE); else QWidget::scroll( -xPixels, -yPixels, contentsRect() );}/*! Returns the leftmost pixel of the table view in \e view coordinates. This excludes the frame and any header. \sa maxViewY(), viewWidth(), contentsRect()*/int QTableView::minViewX() const{ return frameWidth();}/*! Returns the top pixel of the table view in \e view coordinates. This excludes the frame and any header. \sa maxViewX(), viewHeight(), contentsRect()*/int QTableView::minViewY() const{ return frameWidth();}/*! Returns the rightmost pixel of the table view in \e view coordinates. This excludes the frame and any scroll bar, but includes blank pixels to the right of the visible table data. \sa maxViewY(), viewWidth(), contentsRect()*/int QTableView::maxViewX() const{ return width() - 1 - frameWidth() - (tFlags & Tbl_vScrollBar ? VSBEXT : 0);}/*! Returns the bottom pixel of the table view in \e view coordinates. This excludes the frame and any scroll bar, but includes blank pixels below the visible table data. \sa maxViewX(), viewHeight(), contentsRect()*/int QTableView::maxViewY() const{ return height() - 1 - frameWidth() - (tFlags & Tbl_hScrollBar ? HSBEXT : 0);}/*! Returns the width of the table view, as such, in \e view coordinates. This does not include any header, scroll bar or frame, but does include background pixels to the right of the table data. \sa minViewX() maxViewX(), viewHeight(), contentsRect() viewRect()*/int QTableView::viewWidth() const{ return maxViewX() - minViewX() + 1;}/*! Returns the height of the table view, as such, in \e view coordinates. This does not include any header, scroll bar or frame, but does include background pixels below the table data. \sa minViewY() maxViewY() viewWidth() contentsRect() viewRect()*/int QTableView::viewHeight() const{ return maxViewY() - minViewY() + 1;}void QTableView::doAutoScrollBars(){ int viewW = width() - frameWidth() - minViewX(); int viewH = height() - frameWidth() - minViewY(); bool vScrollOn = testTableFlags(Tbl_vScrollBar); bool hScrollOn = testTableFlags(Tbl_hScrollBar); int w = 0; int h = 0; int i; if ( testTableFlags(Tbl_autoHScrollBar) ) { if ( cellW ) { w = cellW*nCols; } else { i = 0; while ( i < nCols && w <= viewW ) w += cellWidth( i++ ); } if ( w > viewW ) hScrollOn = TRUE; else hScrollOn = FALSE; } if ( testTableFlags(Tbl_autoVScrollBar) ) { if ( cellH ) { h = cellH*nRows; } else { i = 0; while ( i < nRows && h <= viewH ) h += cellHeight( i++ ); } if ( h > viewH ) vScrollOn = TRUE; else vScrollOn = FALSE; } if ( testTableFlags(Tbl_autoHScrollBar) && vScrollOn && !hScrollOn ) if ( w > viewW - VSBEXT ) hScrollOn = TRUE; if ( testTableFlags(Tbl_autoVScrollBar) && hScrollOn && !vScrollOn ) if ( h > viewH - HSBEXT ) vScrollOn = TRUE; setHorScrollBar( hScrollOn, FALSE ); setVerScrollBar( vScrollOn, FALSE ); updateFrameSize();}/*! \fn void QTableView::updateScrollBars() Updates the scroll bars' contents and presence to match the table's state. Generally you should not need to call this. \sa setTableFlags()*//*! Updates the scroll bars' contents and presence to match the table's state \c or \e f. \sa setTableFlags()*/void QTableView::updateScrollBars( uint f ){ sbDirty = sbDirty | f; if ( inSbUpdate ) return; inSbUpdate = TRUE; if ( testTableFlags(Tbl_autoHScrollBar) && (sbDirty & horRange) || testTableFlags(Tbl_autoVScrollBar) && (sbDirty & verRange) ) // if range change and auto doAutoScrollBars(); // turn scroll bars on/off if needed if ( !autoUpdate() ) { inSbUpdate = FALSE; return; } if ( yOffset() > 0 && testTableFlags( Tbl_autoVScrollBar ) && !testTableFlags( Tbl_vScrollBar ) ) { setYOffset( 0 ); } if ( xOffset() > 0 && testTableFlags( Tbl_autoHScrollBar ) && !testTableFlags( Tbl_hScrollBar ) ) { setXOffset( 0 ); } if ( !isVisible() ) { inSbUpdate = FALSE; return; } if ( testTableFlags(Tbl_hScrollBar) && (sbDirty & horMask) != 0 ) { if ( sbDirty & horGeometry ) hScrollBar->setGeometry( 0, height() - HSBEXT, viewWidth()+2*frameWidth(), HSBEXT); if ( sbDirty & horSteps ) { if ( cellW ) hScrollBar->setSteps( QMIN(cellW,viewWidth()/2), viewWidth() ); else hScrollBar->setSteps( 16, viewWidth() ); } if ( sbDirty & horRange ) hScrollBar->setRange( 0, maxXOffset() ); if ( sbDirty & horValue ) hScrollBar->setValue( xOffs ); // show scrollbar only when it has a sane geometry if ( !hScrollBar->isVisible() ) hScrollBar->show(); } if ( testTableFlags(Tbl_vScrollBar) && (sbDirty & verMask) != 0 ) { if ( sbDirty & verGeometry ) vScrollBar->setGeometry( width() - VSBEXT, 0, VSBEXT, viewHeight()+2*frameWidth()); if ( sbDirty & verSteps ) { if ( cellH ) vScrollBar->setSteps( QMIN(cellH,viewHeight()/2), viewHeight() ); else vScrollBar->setSteps( 16, viewHeight() ); // fttb! ### } if ( sbDirty & verRange ) vScrollBar->setRange( 0, maxYOffset() ); if ( sbDirty & verValue ) vScrollBar->setValue( yOffs ); // show scrollbar only when it has a sane geometry if ( !vScrollBar->isVisible() ) vScrollBar->show(); } if ( coveringCornerSquare && ( (sbDirty & verGeometry ) || (sbDirty & horGeometry)) ) cornerSquare->move( maxViewX() + 1 + frameWidth(), maxViewY() + 1 + frameWidth()); sbDirty = 0; inSbUpdate = FALSE;}void QTableView::updateFrameSize(){ int rw = width() - ( testTableFlags(Tbl_vScrollBar) ? VSBEXT : 0 ); int rh = height() - ( testTableFlags(Tbl_hScrollBar) ? HSBEXT : 0 ); if ( rw < 0 ) rw = 0; if ( rh < 0 ) rh = 0; if ( autoUpdate() ) { setFrameRect( QRect(0,0,rw,rh) ); update(); }}/*! Returns the maximum horizontal offset within the table of the view's left edge, in \e table coordinates. This is used mainly to set the horizontal scroll bar's range. \sa maxColOffset(), maxYOffset(), totalWidth()*/int QTableView::maxXOffset(){ int tw = totalWidth(); int maxOffs; if ( testTableFlags(Tbl_scrollLastHCell) ) { if ( nCols != 1) maxOffs = tw - ( cellW ? cellW : cellWidth( nCols - 1 ) ); else maxOffs = tw - viewWidth(); } else { if ( testTableFlags(Tbl_snapToHGrid) ) { if ( cellW ) { maxOffs = tw - (viewWidth()/cellW)*cellW; } else { int goal = tw - viewWidth(); int pos = tw; int nextCol = nCols - 1; int nextCellWidth = cellWidth( nextCol ); while( nextCol > 0 && pos > goal + nextCellWidth ) { pos -= nextCellWidth; nextCellWidth = cellWidth( --nextCol ); } if ( goal + nextCellWidth == pos ) maxOffs = goal; else if ( goal < pos ) maxOffs = pos; else maxOffs = 0; } } else { maxOffs = tw - viewWidth(); } } return maxOffs > 0 ? maxOffs : 0;}/*! Returns the maximum vertical offset within the table of the view's top edge, in \e table coordinates. This is used mainly to set the vertical scroll bar's range. \sa maxRowOffset(), maxXOffset(), totalHeight()*/int QTableView::maxYOffset(){ int th = totalHeight(); int maxOffs; if ( testTableFlags(Tbl_scrollLastVCell) ) { if ( nRows != 1) maxOffs = th - ( cellH ? cellH : cellHeight( nRows - 1 ) ); else maxOffs = th - viewHeight(); } else { if ( testTableFlags(Tbl_snapToVGrid) ) { if ( cellH ) { maxOffs = th - (viewHeight()/cellH)*cellH; } else { int goal = th - viewHeight(); int pos = th; int nextRow = nRows - 1; int nextCellHeight = cellHeight( nextRow ); while( nextRow > 0 && pos > goal + nextCellHeight ) { pos -= nextCellHeight; nextCellHeight = cellHeight( --nextRow ); } if ( goal + nextCellHeight == pos ) maxOffs = goal; else if ( goal < pos ) maxOffs = pos; else maxOffs = 0; } } else { maxOffs = th - viewHeight(); } } return maxOffs > 0 ? maxOffs : 0;}/*! Returns the index of the last column which may be at the left edge of the view. Depending on the \link setTableFlags Tbl_scrollLastHCell\endlink flag, this may or may not be the last column. \sa maxXOffset(), maxRowOffset()*/int QTableView::maxColOffset(){ int mx = maxXOffset(); if ( cellW ) return mx/cellW; else { int xcd=0, col=0; while ( col < nCols && mx > (xcd=cellWidth(col)) ) { mx -= xcd; col++; } return col; }}/*! Returns the index of the last row which may be at the top edge of the view. Depending on the \link setTableFlags Tbl_scrollLastVCell\endlink flag, this may or may not be the last row. \sa maxYOffset(), maxColOffset()*/int QTableView::maxRowOffset(){ int my = maxYOffset(); if ( cellH ) return my/cellH; else { int ycd=0, row=0; while ( row < nRows && my > (ycd=cellHeight(row)) ) { my -= ycd; row++; } return row; }}void QTableView::showOrHideScrollBars(){ if ( !autoUpdate() ) return; if ( vScrollBar ) { if ( testTableFlags(Tbl_vScrollBar) ) { if ( !vScrollBar->isVisible() ) sbDirty = sbDirty | verMask; } else { if ( vScrollBar->isVisible() ) vScrollBar->hide(); } } if ( hScrollBar ) { if ( testTableFlags(Tbl_hScrollBar) ) { if ( !hScrollBar->isVisible() ) sbDirty = sbDirty | horMask; } else { if ( hScrollBar->isVisible() ) hScrollBar->hide(); } } if ( cornerSquare ) { if ( testTableFlags(Tbl_hScrollBar) && testTableFlags(Tbl_vScrollBar) ) { if ( !cornerSquare->isVisible() ) cornerSquare->show(); } else { if ( cornerSquare->isVisible() ) cornerSquare->hide(); } }}/*! Updates the scroll bars and internal state. Call this function when the table view's total size is changed; typically because the result of cellHeight() or cellWidth() have changed. This function does not repaint the widget.*/void QTableView::updateTableSize(){ bool updateOn = autoUpdate(); setAutoUpdate( FALSE ); int xofs = xOffset(); xOffs++; //so that setOffset will not return immediately setOffset(xofs,yOffset(),FALSE); //to calculate internal state correctly setAutoUpdate(updateOn); updateScrollBars( horSteps | horRange | verSteps | verRange ); showOrHideScrollBars();}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -