📄 formwindow.cpp
字号:
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( QObject *w ){ if ( w->isWidgetType() ) return usedSelections.find( (QWidget*)w ) != 0; return FALSE; // #### do stuff for QObjects}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 || !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(){ CHECK_MAINWINDOW; 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() ); // check whether our own size constraint hit us if ( size() != mainContainer()->size() ) mainContainer()->resize( 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(){ CHECK_MAINWINDOW; if ( propertyWidget && mainWindow()->formWindow() == this ) emit updateProperties( propertyWidget );}void FormWindow::showPropertiesTimerDone(){ CHECK_MAINWINDOW; if ( propertyWidget && mainWindow()->formWindow() == this ) emit showProperties( propertyWidget );}void FormWindow::selectionChangedTimerDone(){ emit selectionChanged();}void FormWindow::currentToolChanged(){ CHECK_MAINWINDOW; 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: case BUDDY_TOOL: restoreConnectionLine(); if ( startWidget ) restoreRect( QRect( mapToForm( ( (QWidget*)startWidget )->parentWidget(), ( (QWidget*)startWidget )->pos() ), ( (QWidget*)startWidget )->size() ) ); if ( endWidget ) restoreRect( QRect( mapToForm( ( (QWidget*)endWidget )->parentWidget(), ( (QWidget*)endWidget )->pos() ), ( (QWidget*)endWidget )->size() ) ); endUnclippedPainter(); break; case POINTER_TOOL: break; default: if ( insertParent ) endRectDraw(); break; } startWidget = endWidget = 0; widgetPressed = FALSE; drawRubber = FALSE; insertParent = 0; delete buffer; buffer = 0; currTool = t; if ( hasFocus() ) clearSelection( FALSE ); mainWindow()->statusBar()->clear(); // tool setup switch ( currTool ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -