void QGroupBox::fixFocus()
{
    QFocusData * fd = focusData();
    QWidget * orig = fd->home();
    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
                && w->isVisibleTo(this) ) {
            if ( w->hasFocus()
#ifndef QT_NO_RADIOBUTTON
                    || ( !best && ::qt_cast<QRadioButton*>(w)
                         && ((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();
}
示例#2
0
void QwtPlot::updateTabOrder()
{
    // Depending on the position of the legend the 
    // tab order will be changed that the canvas is
    // next to the last legend item, or directly before
    // the first one. The following code seems much too
    // complicated but is there a better implementation ?

    if ( d_canvas->focusPolicy() == QWidget::NoFocus || focusData() == NULL )
        return;

    // move the cursor to the canvas

    for ( int i = 0; i < focusData()->count(); i++ )
    {
        if ( focusData()->next() == d_canvas )
            break;
    }

    const bool canvasFirst = d_layout->legendPosition() == QwtPlot::Bottom ||
        d_layout->legendPosition() == QwtPlot::Right;

    for ( int j = 0; j < focusData()->count(); j++ )
    {
        QWidget *w = canvasFirst ? focusData()->next() : focusData()->prev();

        if ( w->focusPolicy() != QWidget::NoFocus 
            && w->parent() && w->parent() == d_legend->contentsWidget() )
        {
            if ( canvasFirst )
            {
                do // go back to last non legend item
                {
                    w = focusData()->prev(); // before the first legend item
                } while ( w->focusPolicy() == QWidget::NoFocus );
            }

            if ( w != d_canvas )
                setTabOrder(w, d_canvas);
            break;
        }
    }
}
示例#3
0
void QWidgetStack::raiseWidget( QWidget *w )
{
    if ( !w || w == invisible || w->parent() != this || w == topWidget )
	return;

    if ( id(w) == -1 )
	addWidget( w );
    if ( !isVisible() ) {
	topWidget = w;
	return;
    }

    if (w->maximumSize().width() < invisible->width()
        || w->maximumSize().height() < invisible->height())
        invisible->setBackgroundMode(backgroundMode());
    else if (invisible->backgroundMode() != NoBackground)
        invisible->setBackgroundMode(NoBackground);

    if ( invisible->isHidden() ) {
	invisible->setGeometry( contentsRect() );
	invisible->lower();
	invisible->show();
	QApplication::sendPostedEvents( invisible, QEvent::ShowWindowRequest );
    }

    // try to move focus onto the incoming widget if focus
    // was somewhere on the outgoing widget.
    if ( topWidget ) {
	QWidget * fw = focusWidget();
	QWidget* p = fw;
	while ( p && p != topWidget )
	    p = p->parentWidget();
	if ( p == topWidget ) { // focus was on old page
	    if ( !focusWidgets )
		focusWidgets = new QPtrDict<QWidget>( 17 );
	    focusWidgets->replace( topWidget, fw );
	    fw->clearFocus();
	    // look for the best focus widget we can find
	    // best == what we had (which may be deleted)
	    fw = focusWidgets->take( w );
	    if ( isChildOf( fw, w ) ) {
		fw->setFocus();
	    } else {
		// second best == first child widget in the focus chain
		QFocusData *f = focusData();
		QWidget* home = f->home();
		QWidget *i = home;
		do {
		    if ( ( ( i->focusPolicy() & TabFocus ) == TabFocus )
			 && !i->focusProxy() && i->isVisibleTo(w) && i->isEnabled() ) {
			p = i;
			while ( p && p != w )
			    p = p->parentWidget();
			if ( p == w ) {
			    i->setFocus();
			    break;
			}
		    }
		    i = f->next();
		} while( i != home );
	    }
	}
    }

    if ( isVisible() ) {
	emit aboutToShow( w );
	int i = id( w );
	if ( i != -1 )
	    emit aboutToShow( i );
    }

    topWidget = w;

    const QObjectList * c = children();
    QObjectListIt it( *c );
    QObject * o;

    while( (o=it.current()) != 0 ) {
	++it;
	if ( o->isWidgetType() && o != w && o != invisible )
	    ((QWidget *)o)->hide();
    }

    w->setGeometry( invisible->geometry() );
    w->show();
}