?? qheader.cpp
字號(hào):
*/int QHeader::pPos( int i ) const{ if ( i == count() ) return d->positions[i-1] + d->sizes[ d->i2s[i-1] ] - offset(); return d->positions[i] - offset();}/*! Returns the size of actual section \a i. */int QHeader::pSize( int i ) const{ return d->sizes[ d->i2s[i] ];}/*! Returns the height of actual section \a i if orientation() is horizontal , returns the width if vertical.*/int QHeader::pHeight( int i ) const{ int section = mapToSection(i); if ( section < 0 ) return 0; return d->heights[section];}/*! Sets the height of actual section \a i to \a h if orientation() is horizontal. Sets the width if vertical.*/void QHeader::setPHeight( int i, int h ){ int section = mapToSection(i); if ( section < 0 ) return; d->heights[section] = h;}/*! Returns the leftmost (or uppermost for vertical headers) visible pixel. */int QHeader::offset() const{ return offs;}/*! \obsolete Use mapToSection() instead! Translates from actual index \a a (index at which the section is displayed) to logical index of the section. Returns -1 if \a a is outside the legal range. \sa mapToActual()*/int QHeader::mapToLogical( int a ) const{ return mapToSection( a );}/*! \obsolete Use mapToIndex() instead! Translates from logical index \a l to actual index (index, at which the section \a l is displayed) . Returns -1 if \a l is outside the legal range. \sa mapToLogical()*/int QHeader::mapToActual( int l ) const{ return mapToIndex( l );}/*! \obsolete Use resizeSection() instead! Sets the size of the section \a section to \a s pixels. \warning does not repaint or send out signals*/void QHeader::setCellSize( int section, int s ){ if ( section < 0 || section >= count() ) return; d->sizes[ section ] = s; if ( isUpdatesEnabled() ) d->calculatePositions();}/*! Enable user resizing of the section \a section if \a enable is TRUE, disable otherwise. If \a section is negative (as it is by default), resizing is enabled/disabled for all current and new sections. If the user resizes a section (because this feature enabled it), a sizeChange() signal is emitted. \sa setMovingEnabled(), setClickEnabled()*/void QHeader::setResizeEnabled( bool enable, int section ){ if ( section < 0 ) { d->resize.fill( enable ); // and future ones... d->resize_default = enable; } else if ( section < count() ) { d->resize[ section ] = enable; }}/*! Enable the user to exchange sections if \a enable is TRUE, disable otherwise. If you enable moving here, the indexChange() signal is emitted if the user moves a section. \sa setClickEnabled(), setResizeEnabled()*/void QHeader::setMovingEnabled( bool enable ){ d->move = enable;}/*! Enable clicking in section \a section if \a enable is TRUE, disable otherwise. If \a section is negative (as it is by default), clicking is enabled/disabled for all current and new sections. If enabled, the clicked() signal is emitted when the user clicks. \sa setMovingEnabled(), setResizeEnabled()*/void QHeader::setClickEnabled( bool enable, int section ){ if ( section < 0 ) { d->clicks.fill( enable ); // and future ones... d->clicks_default = enable; } else if ( section < count() ) { d->clicks[ section ] = enable; }}/*! Paints actual section \a index of the header, inside rectangle \a fr in widget coordinates. Calls paintSectionLabel().*/void QHeader::paintSection( QPainter *p, int index, QRect fr ){ int section = mapToSection( index ); if ( section < 0 ) return; bool down = (index==handleIdx) && ( state == Pressed || state == Moving ); p->setBrushOrigin( fr.topLeft() ); if ( d->clicks[section] ) { style().drawBevelButton( p, fr.x(), fr.y(), fr.width(), fr.height(), colorGroup(), down ); } else { // ##### should be somhow styled in 3.0 if ( orientation() == Horizontal ) { p->save(); // ### Hack to keep styles working p->setClipRect( fr ); style().drawBevelButton( p, fr.x() - 2, fr.y() - 2, fr.width() + 4, fr.height() + 4, colorGroup(), down ); p->setPen( colorGroup().color( QColorGroup::Mid ) ); p->drawLine( fr.x(), fr.y() + fr.height() - 1, fr.x() + fr.width() - 1, fr.y() + fr.height() - 1 ); p->drawLine( fr.x() + fr.width() - 1, fr.y(), fr.x() + fr.width() - 1, fr.y() + fr.height() - 1 ); p->setPen( colorGroup().color( QColorGroup::Light ) ); if ( index > 0 ) p->drawLine( fr.x(), fr.y(), fr.x(), fr.y() + fr.height() - 1 ); if ( index == count() - 1 ) { p->drawLine( fr.x() + fr.width() - 1, fr.y(), fr.x() + fr.width() - 1, fr.y() + fr.height() - 1 ); p->setPen( colorGroup().color( QColorGroup::Mid ) ); p->drawLine( fr.x() + fr.width() - 2, fr.y(), fr.x() + fr.width() - 2, fr.y() + fr.height() - 1 ); } p->restore(); } else { p->save(); // ### Hack to keep styles working p->setClipRect( fr ); style().drawBevelButton( p, fr.x() - 2, fr.y() - 2, fr.width() + 4, fr.height() + 4, colorGroup(), down ); p->setPen( colorGroup().color( QColorGroup::Mid ) ); p->drawLine( fr.x() + width() - 1, fr.y(), fr.x() + fr.width() - 1, fr.y() + fr.height() - 1 ); p->drawLine( fr.x(), fr.y() + fr.height() - 1, fr.x() + fr.width() - 1, fr.y() + fr.height() - 1 ); p->setPen( colorGroup().color( QColorGroup::Light ) ); if ( index > 0 ) p->drawLine( fr.x(), fr.y(), fr.x() + fr.width() - 1, fr.y() ); if ( index == count() - 1 ) { p->drawLine( fr.x(), fr.y() + fr.height() - 1, fr.x() + fr.width() - 1, fr.y() + fr.height() - 1 ); p->setPen( colorGroup().color( QColorGroup::Mid ) ); p->drawLine( fr.x(), fr.y() + fr.height() - 2, fr.x() + fr.width() - 1, fr.y() + fr.height() - 2 ); } p->restore(); } } paintSectionLabel( p, index, fr );}/*! Paints the label of actual section \a index of the header, inside rectangle \a fr in widget coordinates. Called by paintSection()*/void QHeader::paintSectionLabel( QPainter *p, int index, const QRect& fr ){ int section = mapToSection( index ); if ( section < 0 ) return; QString s; if ( d->labels[section] ) s = *(d->labels[section]); else if ( orient == Horizontal ) s = tr("Col %1").arg(section); else s = tr("Row %1").arg(section); int m = 0; if ( style() == WindowsStyle && index==handleIdx && ( state == Pressed || state == Moving ) ) m = 1; QRect r( fr.x() + QH_MARGIN+m, fr.y() + 2+m, fr.width() - 6, fr.height() - 4 ); int pw = 0; if ( d->iconsets[section] ) { QIconSet::Mode mode = isEnabled()?QIconSet::Normal:QIconSet::Disabled; QPixmap pixmap = d->iconsets[section]->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); pw = pixw; int pixh = pixmap.height(); p->drawPixmap( r.left(), r.center().y()-pixh/2, pixmap ); r.setLeft( r.left() + pixw + 2 ); } p->drawText ( r, AlignLeft|AlignVCenter|SingleLine, s ); int arrowWidth = orient == Qt::Horizontal ? height() / 2 : width() / 2; int arrowHeight = fr.height() - 6; int tw = p->fontMetrics().width( s ) + 16; if ( d->sortColumn == section && pw + tw + arrowWidth + 2 < fr.width() ) { p->save(); if ( d->sortDirection ) { QPointArray pa( 3 ); int x = fr.x() + pw + tw; p->setPen( colorGroup().light() ); p->drawLine( x + arrowWidth, 4, x + arrowWidth / 2, arrowHeight ); p->setPen( colorGroup().dark() ); pa.setPoint( 0, x + arrowWidth / 2, arrowHeight ); pa.setPoint( 1, x, 4 ); pa.setPoint( 2, x + arrowWidth, 4 ); p->drawPolyline( pa ); } else { QPointArray pa( 3 ); int x = fr.x() + pw + tw; p->setPen( colorGroup().light() ); pa.setPoint( 0, x, arrowHeight ); pa.setPoint( 1, x + arrowWidth, arrowHeight ); pa.setPoint( 2, x + arrowWidth / 2, 4 ); p->drawPolyline( pa ); p->setPen( colorGroup().dark() ); p->drawLine( x, arrowHeight, x + arrowWidth / 2, 4 ); } p->restore(); }}/*!\reimp*/void QHeader::paintEvent( QPaintEvent *e ){ QPainter p( this ); p.setPen( colorGroup().buttonText() ); int pos = orient == Horizontal ? e->rect().left() : e->rect().top(); int id = mapToIndex( sectionAt( pos + offset() ) ); if ( id < 0 ) if ( pos > 0 ) return; else id = 0; for ( int i = id; i < count(); i++ ) { QRect r = sRect( i ); paintSection( &p, i, r ); if ( orient == Horizontal && r. right() >= e->rect().right() || orient == Vertical && r. bottom() >= e->rect().bottom() ) return; }}/*! As often the QHeader is used together with a list widget, QHeader can indicate a sort order. This is done using an arrow at the right edge of a section which points up or down. \a section specifies in which section this arrow should be drawn, and \a increasing, if the arrow should point to the bottom (TRUE) or the the top (FALSE). If \a section is -1, no arrow is drawn. \sa QListView::setShowSortIndicator()*/void QHeader::setSortIndicator( int section, bool increasing ){ d->sortColumn = section; d->sortDirection = increasing; update(); updateGeometry();}/*! Resizes the section \a section to \a s pixels.*/void QHeader::resizeSection( int section, int s ){ if ( section < 0 || section >= count() ) return; d->sizes[ section ] = s; if ( isUpdatesEnabled() ) { d->calculatePositions(); update(); }}/*! Returns the size of the \a section in pixels.*/int QHeader::sectionSize( int section ) const{ if ( section < 0 || section >= count() ) return 0; return d->sizes[section];}/*! Returns the position (in pixels) at which the \a section starts. \sa offset()*/int QHeader::sectionPos( int section ) const{ if ( d->positionsDirty ) d->calculatePositions(); if ( section < 0 || section >= count() ) return 0; return d->positions[ d->s2i[section] ];}/*! Returns the section which contains the position \a pos given in pixels. \sa offset()*/int QHeader::sectionAt( int pos ) const{ return d->sectionAt( pos );}/*! Returns the section which is displayed at the index \a index.*/int QHeader::mapToSection( int index ) const{ return ( index >= 0 && index < count() ) ? d->i2s[ index ] : -1;}/*! Returns the index at which the section \a section is currently displayed.*/int QHeader::mapToIndex( int section ) const{ return ( section >= 0 && section < count() ) ? d->s2i[ section ] : -1;}/*! Moves the section \a section to be displayed at the index \a toIndex.*/void QHeader::moveSection( int section, int toIndex ){ int fromIndex = mapToIndex( section ); if ( fromIndex == toIndex || fromIndex < 0 || fromIndex > count() || toIndex < 0 || toIndex > count() ) return; int i; int idx = d->i2s[fromIndex]; if ( fromIndex < toIndex ) { for ( i = fromIndex; i < toIndex - 1; i++ ) { int t; d->i2s[i] = t = d->i2s[i+1]; d->s2i[t] = i; } d->i2s[toIndex-1] = idx; d->s2i[idx] = toIndex-1; } else { for ( i = fromIndex; i > toIndex ; i-- ) { int t; d->i2s[i] = t = d->i2s[i-1]; d->s2i[t] = i; } d->i2s[toIndex] = idx; d->s2i[idx] = toIndex; } d->calculatePositions();}/*! Returns whether the section \a section is clickable or not. If \a section is out of range (negative or larger than count() - 1), TRUE is returned if all sections are clickable, else FALSE. \sa setClickEnabled()*/bool QHeader::isClickEnabled( int section ) const{ if ( section >= 0 && section < count() ) { return (bool)d->clicks[ section ]; } for ( int i = 0; i < count(); ++i ) { if ( !d->clicks[ i ] ) return FALSE; } return TRUE;}/*! Returns whether the section \a section is resizeable or not. If \a section is out of range (negative or larger than count() - 1), TRUE is returned if all sections are resizeable, else FALSE. \sa setResizeEnabled()*/bool QHeader::isResizeEnabled( int section ) const{ if ( section >= 0 && section < count() ) { return (bool)d->resize[ section ]; } for ( int i = 0; i < count();++i ) { if ( !d->resize[ i ] ) return FALSE; } return TRUE;}/*! Returns TRUE if the sections of the header can be moved around be the user, otherwise FALSE. \sa setMovingEnabled()*/bool QHeader::isMovingEnabled() const{ return d->move;}/*! reimp */void QHeader::setUpdatesEnabled( bool enable ){ if ( enable ) d->calculatePositions(); QWidget::setUpdatesEnabled( enable );}//#### what about lastSectionCoversAll?#endif // QT_NO_HEADER
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -