formwindow.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 2,164 行 · 第 1/5 页

CPP
2,164
字号
void FormWindow::setPropertyShowingBlocked( bool b ){    propShowBlocked = b;}bool FormWindow::isPropertyShowingBlocked() const{    return propShowBlocked;}int FormWindow::numSelectedWidgets() const{    return usedSelections.count();}QString FormWindow::copy(){    Resource resource( mainWindow() );    resource.setWidget( this );    return resource.copy();}void FormWindow::lowerWidgets(){    QWidgetList widgets;    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it )	widgets.append( it.current()->widget() );    LowerCommand *cmd = new LowerCommand( tr( "Lower" ), this, widgets );    cmd->execute();    commandHistory()->addCommand( cmd );}static void find_accel( const QString &txt, QMap<QChar, QWidgetList > &accels, QWidget *w ){    int i = txt.find( "&" );    if ( i == -1 )	return;    QChar c = txt[ i + 1 ];    if ( c.isNull() || c == '&' )	return;    c = c.lower();    QMap<QChar, QWidgetList >::Iterator it = accels.find( c );    if ( it == accels.end() ) {	QWidgetList wl;	wl.append( w );	accels.insert( c, wl );    } else {	QWidgetList *wl = &*it;	wl->append( w );    }}void FormWindow::checkAccels(){    QMap<QChar, QWidgetList > accels;    QObjectList *l = mainContainer()->queryList( "QWidget" );    if ( l ) {	for ( QObject *o = l->first(); o; o = l->next() ) {	    if ( ( (QWidget*)o )->isVisibleTo( this ) &&		 insertedWidgets[ (void*)o ] ) {		QWidget *w = (QWidget*)o;		const QMetaProperty* text =		    w->metaObject()->property( w->metaObject()->findProperty( "text", TRUE ), TRUE );		const QMetaProperty* title =		    w->metaObject()->property( w->metaObject()->findProperty( "title", TRUE ), TRUE );		const QMetaProperty* pageTitle =		    w->metaObject()->property( w->metaObject()->findProperty( "pageTitle", TRUE ), TRUE );		if ( text )		    find_accel( w->property( "text" ).toString(), accels, w );		if ( title )		    find_accel( w->property( "title" ).toString(), accels, w );		if ( pageTitle )		    find_accel( w->property( "pageTitle" ).toString(), accels, w );	    }	}	delete l;    }    bool ok = TRUE;    QWidget *wid;    for ( QMap<QChar, QWidgetList >::Iterator it = accels.begin(); it != accels.end(); ++it ) {	if ( (*it).count() > 1 ) {	    ok = FALSE;	    switch ( QMessageBox::information( mainWindow(), tr( "Check Accelerators" ),					       tr( "Accelerator '%1' is used %2 times."						   ).arg( it.key().upper() ).arg( (*it).count() ),					       tr( "&Select" ),					       tr( "&Cancel" ), 0, 2 ) ) {	    case 0: // select		clearSelection( FALSE );		for ( wid = (*it).first(); wid; wid = (*it).next() )		    selectWidget( wid, TRUE );		return;	    case 1: // cancel		return;	    }	}    }    if ( ok )	QMessageBox::information( mainWindow(), tr( "Check Accelerators" ),				  tr( "No accelerator is used more than once." ) );}void FormWindow::raiseWidgets(){    QWidgetList widgets;    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it )	widgets.append( it.current()->widget() );    RaiseCommand *cmd = new RaiseCommand( tr( "Raise" ), this, widgets );    cmd->execute();    commandHistory()->addCommand( cmd );}void FormWindow::paste( const QString &cb, QWidget *parent ){    Resource resource( mainWindow() );    resource.setWidget( this );    resource.paste( cb, parent );}void FormWindow::selectAll(){    checkedSelectionsForMove = FALSE;    blockSignals( TRUE );    QObjectList *l = mainContainer()->queryList( "QWidget" );    if ( l ) {	for ( QObject *o = l->first(); o; o = l->next() ) {	    if ( ( (QWidget*)o )->isVisibleTo( this ) &&		 insertedWidgets[ (void*)o ] ) {		selectWidget( (QWidget*)o );	    }	}	delete l;    }    blockSignals( FALSE );    emitSelectionChanged();    if ( propertyWidget )	emitShowProperties( propertyWidget );    emitSelectionChanged();}void FormWindow::layoutHorizontal(){    QWidgetList widgets( selectedWidgets() );    LayoutHorizontalCommand *cmd = new LayoutHorizontalCommand( tr( "Lay out horizontally" ),								this, mainContainer(), 0, widgets );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::layoutVertical(){    QWidgetList widgets( selectedWidgets() );    LayoutVerticalCommand *cmd = new LayoutVerticalCommand( tr( "Lay out vertically" ),							    this, mainContainer(), 0, widgets );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::layoutHorizontalSplit(){    QWidgetList widgets( selectedWidgets() );    LayoutHorizontalSplitCommand *cmd = new LayoutHorizontalSplitCommand( tr( "Lay out horizontally (in splitter)" ),									  this, mainContainer(), 0, widgets );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::layoutVerticalSplit(){    QWidgetList widgets( selectedWidgets() );    LayoutVerticalSplitCommand *cmd = new LayoutVerticalSplitCommand( tr( "Lay out vertically (in splitter)" ),								      this, mainContainer(), 0, widgets );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::layoutGrid(){    int xres = grid().x();    int yres = grid().y();    QWidgetList widgets( selectedWidgets() );    LayoutGridCommand *cmd = new LayoutGridCommand( tr( "Lay out in a grid" ),						    this, mainContainer(), 0, widgets, xres, yres );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::layoutHorizontalContainer( QWidget *w ){    if ( w == this )	w = mainContainer();    QObjectList *l = (QObjectList*)WidgetFactory::containerOfWidget(w)->children();    if ( !l )	return;    QWidgetList widgets;    for ( QObject *o = l->first(); o; o = l->next() ) {	if ( o->isWidgetType() &&	     ( (QWidget*)o )->isVisibleTo( this ) &&	     insertedWidgets.find( (QWidget*)o ) )	    widgets.append( (QWidget*)o );    }    LayoutHorizontalCommand *cmd = new LayoutHorizontalCommand( tr( "Lay out children horizontally" ),								this, mainContainer(), w, widgets );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::layoutVerticalContainer( QWidget *w ){    if ( w == this )	w = mainContainer();    QObjectList *l = (QObjectList*)WidgetFactory::containerOfWidget(w)->children();    if ( !l )	return;    QWidgetList widgets;    for ( QObject *o = l->first(); o; o = l->next() ) {	if ( o->isWidgetType() &&	     ( (QWidget*)o )->isVisibleTo( this ) &&	     insertedWidgets.find( (QWidget*)o ) )	    widgets.append( (QWidget*)o );    }    LayoutVerticalCommand *cmd = new LayoutVerticalCommand( tr( "Lay out children vertically" ),							    this, mainContainer(), w, widgets );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::layoutGridContainer( QWidget *w ){    if ( w == this )	w = mainContainer();    int xres = grid().x();    int yres = grid().y();    QObjectList *l = (QObjectList*)WidgetFactory::containerOfWidget(w)->children();    if ( !l )	return;    QWidgetList widgets;    for ( QObject *o = l->first(); o; o = l->next() ) {	if ( o->isWidgetType() &&	     ( (QWidget*)o )->isVisibleTo( this ) &&	     insertedWidgets.find( (QWidget*)o ) )	    widgets.append( (QWidget*)o );    }    LayoutGridCommand *cmd = new LayoutGridCommand( tr( "Lay out children in a grid" ),						    this, mainContainer(), w, widgets, xres, yres );    clearSelection( FALSE );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::breakLayout( QWidget *w ){    if ( w == this )	w = mainContainer();    w = WidgetFactory::containerOfWidget( w );    QPtrList<Command> commands;    for (;;) {	if ( !w || w == this )	    break;	if ( WidgetFactory::layoutType( w ) != WidgetFactory::NoLayout ) {	    Command *cmd = breakLayoutCommand( w );	    if ( cmd )		commands.insert( 0, cmd );	    if ( !w->inherits( "QLayoutWidget" ) && !w->inherits( "QSplitter" ) )		break;	}	w = w->parentWidget();    }    if ( commands.isEmpty() )	return;    clearSelection( FALSE );    MacroCommand *cmd = new MacroCommand( tr( "Break Layout" ), this, commands );    commandHistory()->addCommand( cmd );    cmd->execute();}BreakLayoutCommand *FormWindow::breakLayoutCommand( QWidget *w ){    QObjectList *l = (QObjectList*)w->children();    if ( !l )	return 0;    QWidgetList widgets;    for ( QObject *o = l->first(); o; o = l->next() ) {	if ( o->isWidgetType() &&	     !mainWindow()->isAToolBarChild( (QWidget*)o ) &&	     ( (QWidget*)o )->isVisibleTo( this ) &&	     insertedWidgets.find( (QWidget*)o ) )	    widgets.append( (QWidget*)o );    }    return new BreakLayoutCommand( tr( "Break Layout" ), this, WidgetFactory::widgetOfContainer( w ), widgets );}int FormWindow::numVisibleWidgets() const{    QPtrDictIterator<QWidget> it( insertedWidgets );    int visible = 0;    for ( ; it.current(); ++it ) {	if ( it.current()->isVisibleTo( (FormWindow*)this ) )	    visible++;    }    return visible;}bool FormWindow::hasInsertedChildren( QWidget *w ) const{    if ( !w )	return FALSE;    w = WidgetFactory::containerOfWidget( w );    if ( !w )	return FALSE;    QObjectList *l = w->queryList( "QWidget" );    if ( !l || !l->first() ) {	delete l;	return FALSE;    }    for ( QObject *o = l->first(); o; o = l->next() ) {	if ( o->isWidgetType() &&	     ( (QWidget*)o )->isVisibleTo( (FormWindow*)this ) &&	     insertedWidgets.find( (QWidget*)o ) ) {	    delete l;	    return TRUE;	}    }    delete l;    return FALSE;}bool FormWindow::allowMove( QWidget *w ){    w = w->parentWidget();    while ( w ) {	if ( ( isMainContainer( w ) || insertedWidgets.find( w ) ) && WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout )	    return TRUE;	w = w->parentWidget();    }    return FALSE;}void FormWindow::editConnections(){    buffer = 0;    if ( !connectSender || !connectReceiver )	return;    mainWindow()->statusBar()->clear();    ConnectionEditor editor( mainwindow, connectSender, connectReceiver, this );    mainWindow()->statusBar()->message( tr( "Edit connections...") );    editor.exec();    mainWindow()->statusBar()->clear();    if ( !toolFixed )	mainwindow->resetTool();    connectSender = connectReceiver = 0;}void FormWindow::saveBackground(){    if ( buffer )	delete buffer;    buffer = new QPixmap( width(), height() );    *buffer = QPixmap::grabWindow( winId() );}void FormWindow::restoreConnectionLine(){    if (!unclippedPainter)	return;    int a =QABS( connectStartPos.x() - currentConnectPos.x() );    int b = QABS( connectStartPos.y() - currentConnectPos.y() );    QRect r( connectStartPos, currentConnectPos );    if ( a < 32 || b < 32 ) { // special case: vertical or horizontal line	r = r.normalize();	unclippedPainter->drawPixmap( r.x() - 2, r.y() - 2, *buffer,				      r.x() - 2, r.y() - 2, r.width() + 4, r.height() + 4 );	return;    }    if ( a <= 0 )	a = 1;    if ( b <= 0 )	b = 1;    int w, h;    if ( b > a ) {	h = 64;	w = ( a * h ) / b;    } else {	w = 64;	h = ( b * w ) / a;    }    int dx = 2 * w / 3;    int dy = 2 * h / 3;    QPoint p( connectStartPos );    if ( r.x() > r.right() ) {	dx = dx * -1;	p.setX( p.x() - 64 );	r.moveBy( -64, 0 );    }    if ( r.y() > r.bottom() ) {	dy = dy * -1;	p.setY( p.y() - 64 );	r.moveBy( 0, -64 );    }    w = h = 64;    r = r.normalize();

⌨️ 快捷键说明

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