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

📄 qgroupbox.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if ( align & AlignHCenter )	    x = rect().width() / 2 - tw / 2;	else if ( align & AlignRight )	    x = rect().width() - tw - 8;	else	    x = 8;	reg = reg.subtract( QRect( 0, 0, x, h / 2 ) );	reg = reg.subtract( QRect( x + tw, 0, rect().width() - ( x + tw ), h / 2 ) );    }    setMask( reg );}/*!  Adds an empty cell at the next free position. If \a size is greater  than 0 then the empty cell has a fixed height or width.  If the groupbox is oriented horizontally then the empty cell has a fixed  height and if oriented vertically it has a fixed width.  Use this method to separate the widgets in the groupbox or to skip  the next free cell. For performance reasons call this method after  calling setColumnLayout(), setColumns() or setOrientation(). It is in  general a good idea to call these methods first (if needed at all) and  insert the widgets and spaces afterwards.*/void QGroupBox::addSpace( int size ){    QApplication::sendPostedEvents( this, QEvent::ChildInserted );    if ( nCols <= 0 || nRows <= 0 )	return;    if ( row >= nRows || col >= nCols )	grid->expand( row+1, col+1 );    if ( size > 0 ) {	QSpacerItem *spacer	    = new QSpacerItem( ( dir == Horizontal ) ? 0 : size,			       ( dir == Vertical ) ? 0 : size,			       QSizePolicy::Fixed, QSizePolicy::Fixed );	grid->addItem( spacer, row, col );    }    skip();}/*!  Returns the numbers of columns in the groupbox as passed to  the constructor, setColumns() or setColumnLayout().*/int QGroupBox::columns() const{    if ( dir == Horizontal )	return nCols;    return nRows;}/*!  Changes the numbers of columns to \a c. Usually it is no good idea  to use the method since it is slow (it does a complete layout).  Better set the numbers of columns directly in the constructor.  \sa column() setColumnLayout()*/void QGroupBox::setColumns( int c ){    setColumnLayout( c, dir );}/*!  \fn Orientation QGroupBox::orientation() const  Returns the current orientation of the groupbox.  \sa setOrientation()*//*!  Changes the orientation of the groupbox. Usually it is no good idea  to use the method since it is slow (it does a complete layout).  Better set the orientation directly in the constructor.  \sa orientation()*/void QGroupBox::setOrientation( Qt::Orientation o ){    setColumnLayout( columns(), o );}/*!  Changes the layout of the group box. This function is only useful in  combination with the default constructor that does not take any  layout information. This function will put all existing children in  the new layout. Nevertheless is is not good programming style to  call this function after children have been inserted.  \sa setOrientation() setColumns() */void QGroupBox::setColumnLayout(int columns, Orientation direction){    if ( layout() )      delete layout();    vbox = 0;    grid = 0;    if ( columns < 0 ) // if 0, we create the vbox but not the grid. See below.	return;    vbox = new QVBoxLayout( this, 11, 0 );    QSpacerItem *spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum,					   QSizePolicy::Fixed );    d = (QGroupBoxPrivate*) spacer;    setTextSpacer();    vbox->addItem( spacer );    nCols = 0;    nRows = 0;    dir = direction;    // Send all child events and ignore them. Otherwise we will end up    // with doubled insertion. This won't do anything because nCols ==    // nRows == 0.    QApplication::sendPostedEvents( this, QEvent::ChildInserted );    // if 0 or smaller , create a vbox-layout but no grid. This allows    // the designer to handle its own grid layout in a group box.    if ( columns <= 0 )	return;    dir = direction;    if ( dir == Horizontal ) {	nCols = columns;	nRows = 1;    } else {	nCols = 1;	nRows = columns;    }    grid = new QGridLayout( nRows, nCols, 5 );    row = col = 0;    grid->setAlignment( AlignTop );    vbox->addLayout( grid );    // Add all children    if ( children() ) {	QObjectListIt it( *children() );	QWidget *w;	while( (w=(QWidget *)it.current()) != 0 ) {	    ++it;	    if ( w->isWidgetType() )		insertWid( w );	}    }}/*! \reimp  */bool QGroupBox::event( QEvent * e ){    if ( e->type() == QEvent::LayoutHint && layout() )	setTextSpacer();    return QFrame::event( e );}/*!\reimp */void QGroupBox::childEvent( QChildEvent *c ){    // Similar to QGrid::childEvent()    if ( !grid || !c->inserted() || !c->child()->isWidgetType() )	return;    QWidget *child = (QWidget*)c->child();    if ( !child->isTopLevel() ) //ignore dialogs etc.	insertWid( child );}void QGroupBox::insertWid( QWidget* w ){    if ( row >= nRows || col >= nCols )	grid->expand( row+1, col+1 );    grid->addWidget( w, row, col );    skip();    QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) );}void QGroupBox::skip(){    // Same as QGrid::skip()    if ( dir == Horizontal ) {	if ( col+1 < nCols ) {	    col++;	} else {	    col = 0;	    row++;	}    } else { //Vertical	if ( row+1 < nRows ) {	    row++;	} else {	    row = 0;	    col++;	}    }}/*!  This private slot finds a nice widget in this group box that canaccept focus, and gives it focus.*/void QGroupBox::fixFocus(){    QFocusData * fd = focusData();    QWidget * orig = fd->focusWidget();    QWidget * best = 0;    QWidget * candidate = 0;    QWidget * w = orig;    do {	QWidget * p = w;	while( p && p != this && !p->isTopLevel() )	    p = p->parentWidget();	if ( p == this && ( w->focusPolicy() & TabFocus ) == TabFocus ) {	    if ( w->hasFocus()#ifndef QT_NO_RADIOBUTTON		 || ( !best &&		   w->inherits( "QRadioButton" ) &&		   ((QRadioButton*)w)->isChecked() )#endif	    )		// we prefer a checked radio button or a widget that		// already has focus, if there is one		best = w;	    else if ( !candidate )		// but we'll accept anything that takes focus		candidate = w;	}	w = fd->next();    } while( w != orig );    if ( best )	best->setFocus();    else if ( candidate )	candidate->setFocus();}/*!  Sets the right framerect depending on the title. Also calculates the  visible part of the title. */void QGroupBox::calculateFrame(){    lenvisible = str.length();    if ( lenvisible ) { // do we have a label?	QFontMetrics fm = fontMetrics();	int h = fm.height();	while ( lenvisible ) {	    int tw = fm.width( str, lenvisible ) + 2*fm.width(QChar(' '));	    if ( tw < width() )		break;	    lenvisible--;	}	if ( lenvisible ) { // but do we also have a visible label?	    QRect r = rect();	    r.setTop( h/2 );				// frame rect should be	    setFrameRect( r );			//   smaller than client rect	    return;	}    }    // no visible label    setFrameRect( QRect(0,0,0,0) );		//  then use client rect}/*! \reimp */void QGroupBox::focusInEvent( QFocusEvent * ){ // note no call to super    fixFocus();}/*!\reimp */void QGroupBox::fontChange( const QFont & oldFont ){    calculateFrame();    setTextSpacer();    QWidget::fontChange( oldFont );}/*!  \reimp*/QSize QGroupBox::sizeHint() const{    QFontMetrics fm( font() );    int tw = fm.width( title() ) + 2 * fm.width( "xx" );    QSize s;    if ( layout() ) {	s = QFrame::sizeHint();	return s.expandedTo( QSize( tw, 0 ) );    } else {	QRect r = childrenRect();	QSize s( 100, 50 );	s = s.expandedTo( QSize( tw, 0 ) );	if ( r.isNull() )	    return s;	return s.expandedTo( QSize( r.width() + 2 * r.x(), r.height()+ 2 * r.y() ) );    }}#endif

⌨️ 快捷键说明

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