formwindow.cpp

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

CPP
2,164
字号
	if ( w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout )	    continue;	w->move( w->x() + dx, w->y() + dy );	s->updateGeometry();	updateChildSelections( w );    }}CommandHistory *FormWindow::commandHistory(){    return &commands;}void FormWindow::undo(){    commandHistory()->undo();}void FormWindow::redo(){    commandHistory()->redo();}void FormWindow::raiseChildSelections( QWidget *w ){    QObjectList *l = w->queryList( "QWidget" );    if ( !l || !l->first() ) {	delete l;	return;    }    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it ) {	if ( l->findRef( it.current()->widget() ) != -1 )	    it.current()->show();    }    delete l;}void FormWindow::updateChildSelections( QWidget *w ){    QObjectList *l = w->queryList( "QWidget" );    if ( l ) {	for ( QObject *o = l->first(); o; o = l->next() ) {	    if ( o->isWidgetType() &&		 insertedWidgets.find( (QWidget*)o ) )		updateSelection( (QWidget*)o );	}	delete l;    }}void FormWindow::checkSelectionsForMove( QWidget *w ){    checkedSelectionsForMove = TRUE;    QObjectList *l = w->parentWidget()->queryList( "QWidget", 0, FALSE, FALSE );    moving.clear();    if ( l ) {	QPtrDictIterator<WidgetSelection> it( usedSelections );	WidgetSelection *sel;	while ( ( sel = it.current() ) != 0 ) {	    if ( it.current()->widget() == mainContainer() )		continue;	    ++it;	    if ( l->find( sel->widget() ) == -1 ) {		if ( WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout )		    sel->setWidget( 0 );	    } else {		if ( WidgetFactory::layoutType( sel->widget()->parentWidget() ) == WidgetFactory::NoLayout ) {		    moving.insert( (ulong)sel->widget(), sel->widget()->pos() );		    sel->widget()->raise();		    raiseChildSelections( sel->widget() );		    raiseSelection( sel->widget() );		}	    }	}	delete l;    }}void FormWindow::deleteWidgets(){    QWidgetList widgets;    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it ) {	QWidget *tb = 0;	if ( !( tb = mainWindow()->isAToolBarChild( it.current()->widget() ) ) )	     widgets.append( it.current()->widget() );	else	    ( (QDesignerToolBar*)tb )->removeWidget( it.current()->widget() );    }    if ( widgets.isEmpty() )	return;    DeleteCommand *cmd = new DeleteCommand( tr( "Delete" ), this, widgets );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::editAdjustSize(){    QPtrList<Command> commands;    QWidgetList widgets = selectedWidgets();    if ( widgets.isEmpty() ) {	QRect oldr = geometry();	mainContainer()->adjustSize();	resize( mainContainer()->size() );	QRect nr = geometry();	if ( oldr != nr ) {	    ResizeCommand *cmd = new ResizeCommand( tr( "Adjust Size" ), this, this, oldr, nr );	    commandHistory()->addCommand( cmd );	}	return;    }    for ( QWidget* w = widgets.first(); w; w = widgets.next() ) {	if ( w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout )	    continue;	QRect oldr = w->geometry();	w->adjustSize();	QRect nr = w->geometry();	if ( oldr != nr )	    commands.append( new ResizeCommand( tr("Adjust Size"), this, w, oldr, nr ) );    }    if ( commands.isEmpty() )	return;    for ( WidgetSelection *s = selections.first(); s; s = selections.next() )	s->updateGeometry();    MacroCommand *cmd = new MacroCommand( tr( "Adjust Size" ), this, commands );    commandHistory()->addCommand( cmd );}QWidgetList FormWindow::selectedWidgets() const{    QWidgetList widgets;    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it )	widgets.append( it.current()->widget() );    return widgets;}void FormWindow::widgetChanged( QObject *w ){    if ( w->isWidgetType() )	updateSelection( (QWidget*)w );    // ########## do QObject stuff}QLabel *FormWindow::sizePreview() const{    if ( !sizePreviewLabel ) {	( (FormWindow*)this )->sizePreviewLabel = new QLabel( (FormWindow*)this );	( (FormWindow*)this )->sizePreviewLabel->hide();	( (FormWindow*)this )->sizePreviewLabel->setBackgroundColor( QColor( 255, 255, 128 ) );	( (FormWindow*)this )->sizePreviewLabel->setFrameStyle( QFrame::Plain | QFrame::Box );    }    return sizePreviewLabel;}void FormWindow::invalidCheckedSelections(){    checkedSelectionsForMove = FALSE;}void FormWindow::checkPreviewGeometry( QRect &r ){    if ( !rect().contains( r ) ) {	if ( r.left() < rect().left() )	    r.moveTopLeft( QPoint( 0, r.top() ) );	if ( r.right() > rect().right()  )	    r.moveBottomRight( QPoint( rect().right(), r.bottom() ) );	if ( r.top() < rect().top() )	    r.moveTopLeft( QPoint( r.left(), rect().top() ) );	if ( r.bottom() > rect().bottom()  )	    r.moveBottomRight( QPoint( r.right(), rect().bottom() ) );    }}void FormWindow::focusInEvent( QFocusEvent * ){}void FormWindow::focusOutEvent( QFocusEvent * ){    if ( propertyWidget && !isMainContainer( propertyWidget ) && !isWidgetSelected( propertyWidget ) ) {	QObject *opw = propertyWidget;	propertyWidget = mainContainer();	if ( opw->isWidgetType() )	    repaintSelection( (QWidget*)opw );    }}void FormWindow::resizeEvent( QResizeEvent *e ){    QWidget::resizeEvent( e );    if ( currTool == ORDER_TOOL )	repositionOrderIndicators();    if ( isVisible() )	formFile()->setModified( TRUE, FormFile::WFormWindow );#if defined(Q_WS_WIN32)    windowsRepaintWorkaroundTimer->start( 100, TRUE );#endif}void FormWindow::windowsRepaintWorkaroundTimerTimeout(){#if defined(Q_WS_WIN32)    QObjectList *l = queryList( "QWidget" );    for ( QObject *o = l->first(); o; o = l->next() ) {	flickerfree_update( (QWidget*)o );    }    flickerfree_update( this );    delete l;#endif}QPtrDict<QWidget> *FormWindow::widgets(){    return &insertedWidgets;}QWidget *FormWindow::designerWidget( QObject *o ) const{    if ( !o || !o->isWidgetType() )	return 0;    QWidget *w = (QWidget*)o;    while ( w && !isMainContainer( w ) && !insertedWidgets[ (void*)w ] || isCentralWidget( w ) )	w = (QWidget*)w->parent();    return w;}void FormWindow::emitShowProperties( QObject *w ){    if ( w ) {	QObject *opw = propertyWidget;	propertyWidget = w;	if ( opw->isWidgetType() )	    repaintSelection( (QWidget*)opw );    }    showPropertiesTimer->stop();    showPropertiesTimer->start( 0, TRUE );}void FormWindow::emitUpdateProperties( QObject *w ){    if ( w == propertyWidget ) {	updatePropertiesTimer->stop();	updatePropertiesTimer->start( 0, TRUE );    }}void FormWindow::emitSelectionChanged(){    selectionChangedTimer->stop();    selectionChangedTimer->start( 0, TRUE );}void FormWindow::updatePropertiesTimerDone(){    if ( propertyWidget && mainWindow()->formWindow() == this )	emit updateProperties( propertyWidget );}void FormWindow::showPropertiesTimerDone(){    if ( propertyWidget && mainWindow()->formWindow() == this )	emit showProperties( propertyWidget );}void FormWindow::selectionChangedTimerDone(){    emit selectionChanged();}void FormWindow::currentToolChanged(){    toolFixed = FALSE;    int t = mainwindow->currentTool();    if ( currTool == t && t != ORDER_TOOL )	return;    // tool cleanup    switch ( currTool ) {    case ORDER_TOOL:	hideOrderIndicators();	break;    case CONNECT_TOOL:	restoreConnectionLine();	if ( connectSender )	    restoreRect( QRect( mapToForm(  ( (QWidget*)connectSender )->parentWidget(),					    ( (QWidget*)connectSender )->pos() ),				( (QWidget*)connectSender )->size() ) );	if ( connectReceiver )	    restoreRect( QRect( mapToForm( ( (QWidget*)connectReceiver )->parentWidget(),					   ( (QWidget*)connectReceiver )->pos() ),				( (QWidget*)connectReceiver )->size() ) );	endUnclippedPainter();	break;    case POINTER_TOOL:	break;    default:	if ( insertParent )	    endRectDraw();	break;    }    connectSender = connectReceiver = 0;    widgetPressed = FALSE;    drawRubber = FALSE;    insertParent = 0;    delete buffer;    buffer = 0;    currTool = t;    if ( hasFocus() )	clearSelection( FALSE );    mainWindow()->statusBar()->clear();    // tool setup    switch ( currTool ) {    case POINTER_TOOL:	if ( propertyWidget && !isMainContainer( propertyWidget ) && !isWidgetSelected( propertyWidget ) )	    emitShowProperties( mainContainer() );	restoreCursors( this, this );	break;    case ORDER_TOOL:	if ( mainWindow()->formWindow() == this ) {	    mainWindow()->statusBar()->message( tr( "Click widgets to change the tab order...") );	    orderedWidgets.clear();	    showOrderIndicators();	    if ( mainWindow()->formWindow() == this )		emitShowProperties( mainContainer() );	    setCursorToAll( ArrowCursor, this );	}	break;    case CONNECT_TOOL:	mainWindow()->statusBar()->message( tr( "Drag a line to create a connection...") );	setCursorToAll( CrossCursor, this );	if ( mainWindow()->formWindow() == this )	    emitShowProperties( mainContainer() );	break;    default:	mainWindow()->statusBar()->message( tr( "Click on the form to insert a %1..." ).arg( WidgetDatabase::toolTip( currTool ).lower() ) );	setCursorToAll( CrossCursor, this );	if ( mainWindow()->formWindow() == this )	    emitShowProperties( mainContainer() );	break;    }}void FormWindow::showOrderIndicators(){    hideOrderIndicators();    orderIndicators.setAutoDelete( TRUE );    QObjectList *l = mainContainer()->queryList( "QWidget" );    stackedWidgets = MetaDataBase::tabOrder( this );    if ( l ) {	int order = 1;	for ( QObject *o = l->first(); o; o = l->next() ) {	    QWidget* w = (QWidget*) o;	    if ( w->isVisibleTo( w->parentWidget() ) &&		 insertedWidgets[ (void*)w ]  &&		 w->focusPolicy() != NoFocus ) {		OrderIndicator* ind = new OrderIndicator( order++, w, this );		orderIndicators.append( ind );		if ( stackedWidgets.findRef( w ) == -1 )		    stackedWidgets.append( w );	    }	}	delete l;    }    updateOrderIndicators();}void FormWindow::hideOrderIndicators(){    orderIndicators.clear();}void FormWindow::updateOrderIndicators(){    int order = 1;    for ( QWidget *w = stackedWidgets.first(); w; w = stackedWidgets.next() ) {	for ( OrderIndicator* i = orderIndicators.first(); i; i = orderIndicators.next() )	    i->setOrder( order, w );	order++;    }}void FormWindow::repositionOrderIndicators(){    for ( OrderIndicator* i = orderIndicators.first(); i; i = orderIndicators.next() )	i->reposition();}void FormWindow::updateUndoInfo(){    commandHistory()->emitUndoRedo();}bool FormWindow::checkCustomWidgets(){    QStringList missingCustomWidgets;    QPtrDictIterator<QWidget> it( insertedWidgets );    for ( ; it.current(); ++it ) {	if ( it.current()->isA( "CustomWidget" ) ) {	    QString className = WidgetFactory::classNameOf( it.current() );	    if ( !MetaDataBase::hasCustomWidget( className ) )		missingCustomWidgets << className;	}    }    if ( !missingCustomWidgets.isEmpty() ) {	QString txt = tr( "The following custom widgets are used in '%1',\n"			  "but are not known to Qt Designer:\n" ).arg( name() );	for ( QStringList::Iterator sit = missingCustomWidgets.begin(); sit != missingCustomWidgets.end(); ++sit )	    txt += "   " + *sit + "\n";	txt += "If you save this form and generate code for it using uic, \n"	       "the generated code will not compile.\n"	       "Do you want to save this form now?";	if ( QMessageBox::information( mainWindow(), tr( "Save Form" ), txt ) == 1 )	    return FALSE;    }    return TRUE;}

⌨️ 快捷键说明

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