📄 formwindow.cpp
字号:
( (QWidget*)oldendWidget )->size() ) ); drawConnectionLine(); break; case BUDDY_TOOL: if ( !validForBuddy ) break; restoreConnectionLine(); wid = qApp->widgetAt( e->globalPos(), TRUE ); if ( wid ) wid = designerWidget( wid ); if ( wid && canBeBuddy( wid ) && wid->isVisibleTo( this ) ) newendWidget = wid; else newendWidget = 0; if ( newendWidget && ( newendWidget->inherits( "QLayoutWidget" ) || newendWidget->inherits( "Spacer" ) ) ) newendWidget = (QWidget*)endWidget; drawRecRect = newendWidget != endWidget; if ( !newendWidget ) endWidget = newendWidget; else if ( insertedWidgets.find( newendWidget ) && !isCentralWidget( newendWidget ) ) endWidget = newendWidget; if ( endWidget ) mainWindow()->statusBar()->message( tr( "Set buddy '%1' to '%2'" ).arg( startWidget->name() ). arg( endWidget->name() ) ); else mainWindow()->statusBar()->message( tr( "Set buddy '%1' to ..." ).arg( startWidget->name() ) ); currentPos = mapFromGlobal( e->globalPos() ); qApp->processEvents(); if ( drawRecRect && oldendWidget ) restoreRect( QRect( mapToForm( ( (QWidget*)oldendWidget )->parentWidget(), ( (QWidget*)oldendWidget )->pos() ), ( (QWidget*)oldendWidget )->size() ) ); drawConnectionLine(); break; case ORDER_TOOL: break; default: // we are in an insert-widget tool if ( insertParent ) // draw insert rect continueRectDraw( w->mapFromGlobal( e->globalPos() ), e->globalPos(), w, Insert ); break; }}void FormWindow::handleMouseRelease( QMouseEvent *e, QWidget *w ){ CHECK_MAINWINDOW; if ( e->button() != LeftButton ) return; switch ( currTool ) { case POINTER_TOOL: if ( widgetPressed && allowMove( w ) ) { // we moved the widget sizePreviewLabel->hide(); if ( moving.isEmpty() || w->pos() == *moving.find( (ulong)w ) ) break; // restore targetContainer if ( targetContainer ) { if( hadOwnPalette ) targetContainer->setPalette( restorePalette ); else targetContainer->unsetPalette(); } // tell property editor to update if ( propertyWidget && propertyWidget->isWidgetType() && !isMainContainer( propertyWidget ) ) emitUpdateProperties( propertyWidget ); QMapConstIterator<ulong,QPoint> it = moving.begin(); QWidget *oldParent = ( (QWidget*)it.key() )->parentWidget(); QWidget *newParent = oldParent; // check whether we have to reparent the selection QWidget* wa = containerAt( e->globalPos(), ( (QWidget*)it.key() ) ); if ( wa ) { wa = WidgetFactory::containerOfWidget( wa ); // ok, looks like we moved onto a container // check whether we really have different parents. if ( wa == ( (QWidget*)it.key() )->parentWidget() ) goto make_move_command; // break layout if necessary if ( WidgetFactory::layoutType( wa ) != WidgetFactory::NoLayout ) { if ( QMessageBox::information( mainWindow(), tr( "Inserting a Widget" ), tr( "You tried to insert a widget into the " "layout Container Widget '%1'.\n" "This is not possible. " "In order to insert the widget, the layout of '%1'\n" "must first be broken.\n" "Break the layout or cancel the operation?" ). arg( wa->name() ). arg( wa->name() ), tr( "&Break Layout" ), tr( "&Cancel" ) ) ) goto make_move_command; // cancel breakLayout( wa ); } // doesn't need to be a command, the MoveCommand does reparenting too bool emitSelChanged = FALSE; for ( QMap<ulong, QPoint>::Iterator it = moving.begin(); it != moving.end(); ++it ) { QWidget *i = (QWidget*)it.key(); if ( !emitSelChanged && i->inherits( "QButton" ) ) { if ( i->parentWidget() && i->parentWidget()->inherits( "QButtonGroup" ) || wa->inherits( "QButtonGroup" ) ) emitSelChanged = TRUE; if ( !wa->inherits( "QButtonGroup" ) ) { MetaDataBase::setPropertyChanged( i, "buttonGroupId", FALSE ); if ( i->parentWidget() && i->parentWidget()->inherits( "QButtonGroup" ) ) ( (QButtonGroup*)i->parentWidget() )->remove( (QButton*)i ); } } QPoint pos = wa->mapFromGlobal( i->mapToGlobal( QPoint(0,0) ) ); i->reparent( wa, pos, TRUE ); raiseSelection( i ); raiseChildSelections( i ); widgetChanged( i ); mainWindow()->objectHierarchy()->widgetRemoved( i ); mainWindow()->objectHierarchy()->widgetInserted( i ); } if ( emitSelChanged ) { emit showProperties( wa ); emit showProperties( propertyWidget ); } newParent = wa; } make_move_command: QWidgetList widgets; // collect the widgets and its old and new positions which have been moved QValueList<QPoint> oldPos, newPos; for ( it = moving.begin(); it != moving.end(); ++it ) { widgets.append( (QWidget*)it.key() ); oldPos.append( *it ); newPos.append( ( (QWidget*)it.key() )->pos() ); } // add move command, don't execute it, this is just a summary of the operations we did during the move-event handling commandHistory()->addCommand( new MoveCommand( tr( "Move" ), this, widgets, oldPos, newPos, oldParent, newParent ) ); } else if ( drawRubber ) { // we were drawing a rubber selection endRectDraw(); // get rid of the rectangle blockSignals( TRUE ); selectWidgets(); // select widgets which intersect the rect blockSignals( FALSE ); emitSelectionChanged(); // inform about selection changes if ( propertyWidget ) emitShowProperties( propertyWidget ); } 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(); qApp->processEvents(); if ( startWidget && endWidget ) { if ( currTool == CONNECT_TOOL ) editConnections(); else if ( currTool == BUDDY_TOOL && validForBuddy && startWidget != endWidget ) { QString oldBuddy = startWidget->property( "buddy" ).toString(); if ( oldBuddy.isNull() ) oldBuddy = ""; SetPropertyCommand *cmd = new SetPropertyCommand( tr( "Set buddy for " + QString( startWidget->name() ) ), this, startWidget, mainWindow()->propertyeditor(), "buddy", startWidget->property( "buddy" ), endWidget->name(), endWidget->name(), oldBuddy ); commandHistory()->addCommand( cmd, TRUE ); cmd->execute(); emitUpdateProperties( startWidget ); } } if ( !toolFixed ) mainwindow->resetTool(); startWidget = endWidget = 0; mainWindow()->statusBar()->clear(); break; case ORDER_TOOL: break; default: // any insert widget tool is active if ( insertParent ) { // we should insert the new widget now endRectDraw(); if ( WidgetFactory::layoutType( insertParent ) != WidgetFactory::NoLayout ) { if ( QMessageBox::information( mainWindow(), tr( "Inserting a Widget" ), tr( "You tried to insert a widget into the " "layout Container Widget '%1'.\n" "This is not possible. " "In order to insert the widget, the layout of '%1'\n" "must first be broken.\n" "Break the layout or cancel the operation?" ). arg( insertParent->name() ). arg( insertParent->name() ), tr( "&Break Layout" ), tr( "&Cancel" ) ) == 0 ) { breakLayout( insertParent ); } else { if ( !toolFixed ) mainWindow()->resetTool(); break; } } insertWidget(); // so do it } break; } widgetPressed = FALSE; drawRubber = FALSE; insertParent = 0; delete buffer; buffer = 0;}void FormWindow::handleKeyPress( QKeyEvent *e, QWidget *w ){ CHECK_MAINWINDOW; e->ignore(); checkSelectionsTimer->stop(); if ( !checkedSelectionsForMove && ( e->key() == Key_Left || e->key() == Key_Right || e->key() == Key_Up || e->key() == Key_Down ) && propertyWidget->isWidgetType() ) checkSelectionsForMove( (QWidget*)propertyWidget ); checkSelectionsTimer->start( 1000, TRUE ); if ( e->key() == Key_Left || e->key() == Key_Right || e->key() == Key_Up || e->key() == Key_Down ) { QWidgetList widgets; QValueList<QPoint> oldPos, newPos; for ( WidgetSelection *s = selections.first(); s; s = selections.next() ) { if ( s->isUsed() ) { int dx = 0, dy = 0; bool control = e->state() & ControlButton; switch ( e->key() ) { case Key_Left: { e->accept(); if ( control ) dx = -1; else dx = -grid().x(); } break; case Key_Right: { e->accept(); if ( control ) dx = 1; else dx = grid().x(); } break; 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( QObject *o, bool select ){ CHECK_MAINWINDOW; if ( !o->isWidgetType() ) { // ########### do QObject stuff return; } QWidget *w = (QWidget*)o; if ( isMainContainer( w ) ) { QObject *opw = propertyWidget; propertyWidget = mainContainer(); if ( opw->isWidgetType() ) repaintSelection( (QWidget*)opw ); emitShowProperties( propertyWidget ); return; } if ( mainContainer()->inherits( "QMainWindow" ) && w == ( (QMainWindow*)mainContainer() )->centralWidget() ) { QObject *opw = propertyWidget; propertyWidget = mainContainer(); if ( opw->isWidgetType() ) repaintSelection( (QWidget*)opw ); emitShowProperties( propertyWidget ); return; } if ( o->inherits( "QDesignerToolBar" ) || o->inherits( "QDesignerMenuBar" ) ) return; if ( select ) { QObject *opw = propertyWidget; propertyWidget = w; if ( opw->isWidgetType() ) repaintSelection( (QWidget*)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 ); QObject *opw = propertyWidget; if ( !usedSelections.isEmpty() ) propertyWidget = QPtrDictIterator<WidgetSelection>( usedSelections ).current()->widget(); else propertyWidget = mainContainer(); if ( opw->isWidgetType() ) repaintSelection( (QWidget*)opw ); if ( !isPropertyShowingBlocked() ) emitShowProperties( propertyWidget ); emitSelectionChanged(); }}QPoint FormWindow::grid() const{ if ( !mainWindow() || !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 ) { QObject *opw = propertyWidget; propertyWidget = mainContainer(); if ( opw->isWidgetType() ) repaintSelection( (QWidget*)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 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -