📄 formwindow.cpp
字号:
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( "Layout 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( "Layout 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 ); QList<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" ) ) 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() && ( (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(); QWidgetList selection = selectedWidgets(); 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(); while ( r.contains( p ) ) { unclippedPainter->drawPixmap( p, *buffer, QRect( p, QSize( w, h ) ) ); unclippedPainter->setPen( red ); p.setX( p.x() + dx ); p.setY( p.y() + dy ); } unclippedPainter->drawPixmap( connectStartPos.x() - 10, connectStartPos.y() - 10, *buffer, connectStartPos.x() - 10, connectStartPos.y() - 10, 20, 20 );}void FormWindow::restoreRect( const QRect &rect ){ if (!unclippedPainter) return; QRect r( rect ); r = r.normalize(); r = QRect( r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4 ); unclippedPainter->drawPixmap( r.x() - 2, r.y() - 2, *buffer, r.x() - 2, r.y() - 2, r.width() + 4, 4 ); unclippedPainter->drawPixmap( r.x() - 2, r.y() - 2, *buffer, r.x() - 2, r.y() - 2, 4, r.height() + 4 ); unclippedPainter->drawPixmap( r.x() - 2, r.y() + r.height() - 3, *buffer, r.x() - 2, r.y() + r.height() - 3, r.width() + 4, 5 ); unclippedPainter->drawPixmap( r.x() + r.width() - 2, r.y(), *buffer, r.x() + r.width() - 2, r.y(), 4, r.height() + 4 );}void FormWindow::drawConnectLine(){ if ( !unclippedPainter ) return; unclippedPainter->setPen( QPen( white, 2 ) ); unclippedPainter->drawLine( connectStartPos, currentConnectPos ); unclippedPainter->setPen( QPen( darkCyan, 1 ) ); unclippedPainter->drawLine( connectStartPos, currentConnectPos ); unclippedPainter->setPen( QPen( magenta, 1 ) ); if ( connectSender ) { QWidget *w = (QWidget*)connectSender; QPoint p = mapToForm( w, QPoint(0,0) ); unclippedPainter->drawRect( QRect( p + QPoint( 2, 2 ), w->size() - QSize( 4, 4 ) ) ); } if ( connectReceiver ) { QWidget *w = (QWidget*)connectReceiver; QPoint p = mapToForm( w, QPoint(0,0) ); unclippedPainter->drawRect( QRect( p + QPoint( 2, 2 ), w->size() - QSize( 4, 4 ) ) ); }}QString FormWindow::fileName() const{ return filename;}void FormWindow::setFileName( const QString &fn ){ filename = fn; emit fileNameChanged( filename, this );}void FormWindow::modificationChanged( bool m ){ emit modificationChanged( m, this );}bool FormWindow::unify( QWidget *w, QString &s, bool changeIt ){ bool found = !isMainContainer( w ) && qstrcmp( name(), s.latin1() ) == 0; if ( !found ) { QString orig = s; int num = 1; QPtrDictIterator<QWidget> it( insertedWidgets ); for ( ; it.current(); ++it ) { if ( it.current() != w && qstrcmp( it.current()->name(), s.latin1() ) == 0 ) { found = TRUE; if ( !changeIt ) break; s = orig + "_" + QString::number( ++num ); it.toFirst(); } } } if ( !found ) return TRUE; return FALSE;}bool FormWindow::isCustomWidgetUsed( MetaDataBase::CustomWidget *w ){ QPtrDictIterator<QWidget> it( insertedWidgets ); for ( ; it.current(); ++it ) { if ( it.current()->isA( "CustomWidget" ) ) { if ( qstrcmp( WidgetFactory::classNameOf( it.current() ), w->className.utf8() ) == 0 ) return TRUE; } } return FALSE;}void FormWindow::visibilityChanged(){ if ( currTool != ORDER_TOOL ) { emitUpdateProperties( currentWidget() ); } else { updateOrderIndicators(); repositionOrderIndicators(); }}/*! Maps \a pos in \a w's coordinates to the form's coordinate system. This is the equivalent to mapFromGlobal(w->mapToGlobal(pos) ) but avoids the two roundtrips to the X-Server on Unix/X11. */QPoint FormWindow::mapToForm( const QWidget* w, const QPoint& pos ) const{ QPoint p = pos; const QWidget* i = w; while ( i && !i->isTopLevel() && !isMainContainer( (QWidget*)i ) ) { p = i->mapToParent( p ); i = i->parentWidget(); } return mapFromGlobal( w->mapToGlobal( pos ) );}static int widgetDepth( QWidget *w ){ int d = -1; while ( w && !w->isTopLevel() ) { d++; w = w->parentWidget(); } return d;}static bool isChildOf( QWidget *c, QWidget *p ){ while ( c && !c->isTopLevel() ) { if ( c == p ) return TRUE; c = c->parentWidget(); } return FALSE;}QWidget *FormWindow::containerAt( const QPoint &pos, QWidget *notParentOf ){ QPtrDictIterator<QWidget> it( insertedWidgets ); QWidget *container = 0; int depth = -1; QWidgetList selected = selectedWidgets(); if ( rect().contains( mapFromGlobal( pos ) ) ) { container = mainContainer(); depth = widgetDepth( container ); } for ( ; it.current(); ++it ) { if ( it.current()->inherits( "QLayoutWidget" ) ) continue; if ( !it.current()->isVisibleTo( this ) ) continue; if ( selected.find( it.current() ) != -1 ) continue; if ( !WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( it.current() ) ) ) && it.current() != mainContainer() ) continue; if ( !it.current()->rect().contains( it.current()->mapFromGlobal( pos ) ) ) continue; int wd = widgetDepth( it.current() ); if ( wd == depth && container ) { if ( ( (QObjectList*)it.current()->parentWidget()->children() )->find( it.current() ) > ( (QObjectList*)container->parentWidget()->children() )->find( container ) ) wd++; } if ( wd > depth && !isChildOf( it.current(), notParentOf ) ) { depth = wd; container = it.current(); } } return container;}bool FormWindow::isMainContainer( QWidget *w ) const{ return w == (QWidget*)this || w == mainContainer();}void FormWindow::setMainContainer( QWidget *w ){ bool resetPropertyWidget = isMainContainer( propertyWidget ); if ( mContainer ) insertedWidgets.remove( mContainer ); delete mContainer; mContainer = w; insertedWidgets.insert( mContainer, mContainer ); delete layout(); QHBoxLayout *l = new QHBoxLayout( this ); l->addWidget( w ); if ( resetPropertyWidget ) { QWidget *opw = propertyWidget; propertyWidget = mContainer; repaintSelection( opw ); }}bool FormWindow::savePixmapInline() const{ return pixInline;}QString FormWindow::pixmapLoaderFunction() const{ return pixLoader;}void FormWindow::setSavePixmapInline( bool b ){ pixInline = b;}void FormWindow::setPixmapLoaderFunction( const QString &func ){ pixLoader = func;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -