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

📄 formwindow.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		case Key_Up: {		    e->accept();		    if ( control )			dy = -1;		    else			dy = -grid().y();		} break;		case Key_Down: {		    e->accept();		    if ( control )			dy = 1;		    else			dy = grid().y();		} break;		default:		    break;		}				widgets.append( s->widget() );		oldPos.append( s->widget()->pos() );		newPos.append( s->widget()->pos() + QPoint( dx, dy ) );	    }	}	if ( !widgets.isEmpty() ) {	    MoveCommand *cmd = new MoveCommand( tr( "Move" ), this,						widgets, oldPos, newPos, 0, 0 );	    commandHistory()->addCommand( cmd, TRUE );	    cmd->execute();	}    }    if ( !e->isAccepted() ) {	QObjectList *l = queryList( "QWidget" );	if ( !l )	    return;	if ( l->find( w ) != -1 )	    e->accept();	delete l;    }}void FormWindow::handleKeyRelease( QKeyEvent *e, QWidget * ){    e->ignore();}void FormWindow::selectWidget( QWidget *w, bool select ){    if ( isMainContainer( w ) ) {	QWidget *opw = propertyWidget;	propertyWidget = mainContainer();	repaintSelection( opw );	emitShowProperties( propertyWidget );	return;    }    if ( select ) {	QWidget *opw = propertyWidget;	propertyWidget = w;	repaintSelection( opw );	if ( !isPropertyShowingBlocked() )	    emitShowProperties( propertyWidget );	WidgetSelection *s = usedSelections.find( w );	if ( s ) {	    s->show();	    return;	}	for ( WidgetSelection *s2 = selections.first(); s2; s2 = selections.next() ) {	    if ( !s2->isUsed() ) {		s = s2;	    }	}	if ( !s ) {	    s = new WidgetSelection( this, &usedSelections );	    selections.append( s );	}	s->setWidget( w );	emitSelectionChanged();    } else {	WidgetSelection *s = usedSelections.find( w );	if ( s )	    s->setWidget( 0 );	QWidget *opw = propertyWidget;	if ( !usedSelections.isEmpty() )	    propertyWidget = QPtrDictIterator<WidgetSelection>( usedSelections ).current()->widget();	else	    propertyWidget = mainContainer();	repaintSelection( opw );	if ( !isPropertyShowingBlocked() )	    emitShowProperties( propertyWidget );	emitSelectionChanged();    }}QPoint FormWindow::grid() const{    if ( !mainWindow()->snapGrid() )	return QPoint( 1, 1 );    return mainWindow()->grid();}void FormWindow::updateSelection( QWidget *w ){    WidgetSelection *s = usedSelections.find( w );    if ( !w->isVisibleTo( this ) )	selectWidget( w, FALSE );    else if ( s )	s->updateGeometry();}void FormWindow::raiseSelection( QWidget *w ){    WidgetSelection *s = usedSelections.find( w );    if ( s )	s->show();}void FormWindow::repaintSelection( QWidget *w ){    WidgetSelection *s = usedSelections.find( w );    if ( s )	s->update();}void FormWindow::clearSelection( bool changePropertyDisplay ){    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it )	it.current()->setWidget( 0, FALSE );    usedSelections.clear();    if ( changePropertyDisplay ) {	QWidget *opw = propertyWidget;	propertyWidget = mainContainer();	repaintSelection( opw );	emitShowProperties( propertyWidget );    }    emitSelectionChanged();}void FormWindow::startRectDraw( const QPoint &p, const QPoint &global, QWidget *, RectType t ){    QPoint pos( p );    pos = mapFromGlobal( global );    oldRectValid = FALSE;    beginUnclippedPainter( TRUE );    if ( t == Rubber )	unclippedPainter->setPen( QPen( color0, 1 ) );    if ( t == Insert )	rectAnchor = gridPoint( pos );    else if ( t == Rubber )	rectAnchor = pos;    currRect = QRect( rectAnchor, QPoint( 0, 0 ) );    if ( t == Insert )	drawSizePreview( pos, tr("Use Size Hint") );}void FormWindow::continueRectDraw( const QPoint &p, const QPoint &global, QWidget *, RectType t ){    QPoint pos =p;    pos = mapFromGlobal( global );    QPoint p2;    if ( t == Insert )	p2 = gridPoint( pos );    else if ( t == Rubber )	p2 = pos;    QRect r( rectAnchor, p2 );    r = r.normalize();    if ( currRect == r ) {	QString t = tr( "%1/%2" );	t = t.arg( r.width() - 1 ).arg( r.height() - 1 );	drawSizePreview( pos, t );	return;    }    if ( oldRectValid )	unclippedPainter->drawRect( currRect );    if ( r.width() > 1 || r.height() > 1 ) {	oldRectValid = TRUE;	currRect = r;	if ( t == Insert ) {	    QString t = tr( "%1/%2" );	    t = t.arg( r.width() - 1 ).arg( r.height() - 1 );	    drawSizePreview( pos, t );	}	unclippedPainter->setClipRegion( QRegion( rect() ).subtract( QRect( sizePreviewPos, sizePreviewPixmap.size() ) ) );	unclippedPainter->drawRect( currRect );	unclippedPainter->setClipping( FALSE );    } else {	oldRectValid = FALSE;	if ( t == Insert )	    drawSizePreview( pos, tr("Use Size Hint") );    }}void FormWindow::endRectDraw(){    if ( !unclippedPainter )	return;    if ( oldRectValid )	unclippedPainter->drawRect( currRect );    drawSizePreview( QPoint(-1,-1), QString::null );    endUnclippedPainter();}void FormWindow::selectWidgets(){    QObjectList *l = mainContainer()->queryList( "QWidget" );    if ( l ) {	for ( QObject *o = l->first(); o; o = l->next() ) {	    if ( ( (QWidget*)o )->isVisibleTo( this ) &&		 insertedWidgets[ (void*)o ] ) {		QPoint p = ( (QWidget*)o )->mapToGlobal( QPoint(0,0) );		p = mapFromGlobal( p );		QRect r( p, ( (QWidget*)o )->size() );		if ( r.intersects( currRect ) && !r.contains( currRect ) )		    selectWidget( (QWidget*)o );	    }	}    }    delete l;    emitSelectionChanged();}bool FormWindow::isWidgetSelected( QWidget *w ){    return usedSelections.find( w ) != 0;}void FormWindow::moveSelectedWidgets( int dx, int dy ){    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it ) {	WidgetSelection *s = it.current();	QWidget *w = s->widget();	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 )	return;    if ( !l->first() ) {	delete l;	return;    }    QPtrDictIterator<WidgetSelection> it( usedSelections );    for ( ; it.current(); ++it ) {	if ( l->findRef( it.current()->widget() ) != -1 )	    it.current()->show();    }}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 )	widgets.append( it.current()->widget() );    DeleteCommand *cmd = new DeleteCommand( tr( "Delete" ), this, widgets );    commandHistory()->addCommand( cmd );    cmd->execute();}void FormWindow::editAdjustSize(){    QList<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( QWidget *w ){    updateSelection( w );}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 ) ) {	QWidget *opw = propertyWidget;	propertyWidget = mainContainer();	repaintSelection( opw );    }}void FormWindow::resizeEvent( QResizeEvent *e ){    QWidget::resizeEvent( e );    if ( currTool == ORDER_TOOL )	repositionOrderIndicators();#if defined(_WS_WIN32_)    windowsRepaintWorkaroundTimer->start( 100, TRUE );#endif}void FormWindow::windowsRepaintWorkaroundTimerTimeout(){

⌨️ 快捷键说明

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