📄 formwindow.cpp
字号:
if ( !w->parentWidget() || WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout ) w->raise(); if ( ( e->state() & ControlButton ) ) { // with control pressed, always start rubber band selection drawRubber = TRUE; currRect = QRect( 0, 0, -1, -1 ); startRectDraw( mapFromGlobal( e->globalPos() ), e->globalPos(), this, Rubber ); break; } bool sel = isWidgetSelected( w ); if ( !( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) ) ) { // control not pressed... if ( !sel ) { // ...and widget no selectted: unselect all clearSelection( FALSE ); } else { // ...widget selected // only if widget has a layout (it is a layout meta widget or a laid out container!), unselect its childs if ( WidgetFactory::layoutType( w ) != WidgetFactory::NoLayout ) { QObjectList *l = w->queryList( "QWidget" ); setPropertyShowingBlocked( TRUE ); for ( QObject *o = l->first(); o; o = l->next() ) { if ( !o->isWidgetType() ) continue; if ( insertedWidgets.find( (QWidget*)o ) ) selectWidget( (QWidget*)o, FALSE ); } setPropertyShowingBlocked( FALSE ); delete l; } } qApp->processEvents(); } if ( ( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) ) && sel && e->button() == LeftButton ) { // control pressed and selected, unselect widget selectWidget( w, FALSE ); break; } raiseChildSelections( w ); // raise selections and select widget selectWidget( w ); // if widget is laid out, find the first non-laid out super-widget QWidget *realWidget = w; // but store the original one while ( w->parentWidget() && ( WidgetFactory::layoutType( w->parentWidget()) != WidgetFactory::NoLayout || !insertedWidgets.find(w) ) ) w = w->parentWidget(); if ( e->button() == LeftButton ) { // left button: store original geometry and more as the widget might start moving widgetPressed = TRUE; widgetGeom = QRect( w->pos(), w->size() ); oldPressPos = w->mapFromGlobal( e->globalPos() ); origPressPos = oldPressPos; checkedSelectionsForMove = FALSE; moving.clear(); } else if ( e->button() == RightButton ) { // RMB menu mainwindow->popupWidgetMenu( e->globalPos(), this, realWidget); } } else { // press was on the formwindow if ( e->button() == LeftButton ) { // left button: start rubber selection and show formwindow properties drawRubber = TRUE; if ( !( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) ) ) { clearSelection( FALSE ); QWidget *opw = propertyWidget; propertyWidget = mainContainer(); repaintSelection( opw ); } currRect = QRect( 0, 0, -1, -1 ); startRectDraw( mapFromGlobal( e->globalPos() ), e->globalPos(), this, Rubber ); } else if ( e->button() == RightButton ) { // RMB menu clearSelection(); mainwindow->popupFormWindoMenu( e->globalPos(), this ); } } break; case CONNECT_TOOL: if ( e->button() != LeftButton ) break; saveBackground(); mainWindow()->statusBar()->message( tr( "Connect '%1' with..." ).arg( w->name() ) ); connectStartPos = mapFromGlobal( e->globalPos() ); currentConnectPos = mapFromGlobal( e->globalPos() ); connectSender = designerWidget( w ); connectReceiver = designerWidget( w ); beginUnclippedPainter( FALSE ); drawConnectLine(); break; case ORDER_TOOL: if ( !isMainContainer( w ) ) { // press on a child widget orderedWidgets.removeRef( w ); orderedWidgets.append( w ); for ( QWidget *wid = orderedWidgets.last(); wid; wid = orderedWidgets.prev() ) { int i = stackedWidgets.findRef( wid ); if ( i != -1 ) { stackedWidgets.removeRef( wid ); stackedWidgets.insert( 0, wid ); } } QWidgetList oldl = MetaDataBase::tabOrder( this ); TabOrderCommand *cmd = new TabOrderCommand( tr( "Change Tab Order" ), this, oldl, stackedWidgets ); cmd->execute(); commandHistory()->addCommand( cmd, TRUE ); updateOrderIndicators(); } break; default: // any insert widget tool if ( e->button() == LeftButton ) { insertParent = WidgetFactory::containerOfWidget( mainContainer() ); // default parent for new widget is the formwindow if ( !isMainContainer( w ) ) { // press was not on formwindow, check if we can find another parent QWidget *wid = w; for (;;) { int id = WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( wid ) ); if ( ( WidgetDatabase::isContainer( id ) || wid == mainContainer() ) && !wid->inherits( "QLayoutWidget" ) ) { insertParent = WidgetFactory::containerOfWidget( wid ); // found another parent, store it break; } else { wid = wid->parentWidget(); if ( !wid ) break; } } } startRectDraw( w->mapFromGlobal( e->globalPos() ), e->globalPos(), w, Insert ); } break; }}void FormWindow::handleMouseDblClick( QMouseEvent *, QWidget *w ){ switch ( currTool ) { case ORDER_TOOL: if ( !isMainContainer( w ) ) { // press on a child widget orderedWidgets.clear(); orderedWidgets.append( w ); for ( QWidget *wid = orderedWidgets.last(); wid; wid = orderedWidgets.prev() ) { int i = stackedWidgets.findRef( wid ); if ( i != -1 ) { stackedWidgets.removeRef( wid ); stackedWidgets.insert( 0, wid ); } } QWidgetList oldl = MetaDataBase::tabOrder( this ); TabOrderCommand *cmd = new TabOrderCommand( tr( "Change Tab Order" ), this, oldl, stackedWidgets ); cmd->execute(); commandHistory()->addCommand( cmd, TRUE ); updateOrderIndicators(); } default: break; }}void FormWindow::handleMouseMove( QMouseEvent *e, QWidget *w ){ if ( ( e->state() & LeftButton ) != LeftButton ) return; QWidget *newReceiver = (QWidget*)connectReceiver, *oldReceiver = (QWidget*)connectReceiver, *wid; bool drawRecRect; switch ( currTool ) { case POINTER_TOOL: if ( widgetPressed && allowMove( w ) ) { // we are prepated for a move // if widget is laid out, find the first non-laid out super-widget while ( w->parentWidget() && ( WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout || !insertedWidgets.find(w ) ) ) w = w->parentWidget(); // calc correct position QPoint pos = w->mapFromGlobal( e->globalPos() );#if 0 QPoint mpos = w->mapToParent( pos ); // check if we are not outside the visible area, else correct coords if ( mpos.x() < 0 ) pos.setX( w->mapFromParent( QPoint( 0, mpos.y() ) ).x() ); if ( mpos.y() < 0 ) pos.setY( w->mapFromParent( QPoint( mpos.x(), 0 ) ).y() ); if ( mpos.x() > w->parentWidget()->width() ) pos.setX( w->mapFromParent( QPoint( w->parentWidget()->width(), mpos.y() ) ).x() ); if ( mpos.y() > w->parentWidget()->height() ) pos.setY( w->mapFromParent( QPoint( mpos.x(), w->parentWidget()->height() ) ).y() );#endif // calc move distance and store it QPoint d = oldPressPos - pos; if ( QABS( d.x() ) < grid().x() ) d.setX( 0 ); if ( QABS( d.y() ) < grid().y() ) d.setY( 0 ); if ( d.x() == 0 ) pos.setX( oldPressPos.x() ); if ( d.y() == 0 ) pos.setY( oldPressPos.y() ); oldPressPos = pos; // snap to grid int x = widgetGeom.x() - d.x(); widgetGeom.setX( x ); x = ( x / grid().x() ) * grid().x(); int y = widgetGeom.y() - d.y(); widgetGeom.setY( y ); y = ( y / grid().y() ) * grid().y(); QPoint p = w->pos(); if ( x - p.x() != 0 || y - p.y() != 0 ) { // if we actually have to move if ( !checkedSelectionsForMove ) { // if not checked yet, check if the correct widget are selected... if ( !isWidgetSelected( w ) ) { // and unselect others. Only siblings can be moved at the same time setPropertyShowingBlocked( TRUE ); selectWidget( w ); setPropertyShowingBlocked( FALSE ); } checkSelectionsForMove( w ); } // finally move the selected widgets and show/update preview lable moveSelectedWidgets( x - p.x(), y - p.y() ); sizePreviewLabel->setText( tr( "%1/%2" ).arg( w->pos().x() ).arg( w->pos().y() ) ); sizePreviewLabel->adjustSize(); QRect lg( mapFromGlobal( e->globalPos() ) + QPoint( 16, 16 ), sizePreviewLabel->size() ); checkPreviewGeometry( lg ); sizePreviewLabel->setGeometry( lg ); sizePreviewLabel->raise(); sizePreviewLabel->show();#if defined(_WS_WIN32_) windowsRepaintWorkaroundTimer->start( 100, TRUE );#endif } else { // if we don't need to move, do some indication QRect lg( mapFromGlobal( e->globalPos() ) + QPoint( 16, 16 ), sizePreviewLabel->size() ); checkPreviewGeometry( lg ); sizePreviewLabel->move( lg.x(), lg.y() ); } oldPressPos += ( p - w->pos() ); } else if ( drawRubber ) { // draw rubber if we are in rubber-selection mode continueRectDraw( mapFromGlobal( e->globalPos() ), e->globalPos(), this, Rubber ); } break; case CONNECT_TOOL: restoreConnectionLine(); wid = qApp->widgetAt( e->globalPos(), TRUE ); if ( wid ) wid = designerWidget( wid ); if ( wid && ( isMainContainer( wid ) || insertedWidgets.find( wid ) ) && wid->isVisibleTo( this ) ) newReceiver = wid; if ( newReceiver && ( newReceiver->inherits( "QLayoutWidget" ) || newReceiver->inherits( "Spacer" ) ) ) newReceiver = (QWidget*)connectReceiver; drawRecRect = newReceiver != connectReceiver; currentConnectPos = mapFromGlobal( e->globalPos() ); if ( newReceiver && ( isMainContainer( newReceiver ) || insertedWidgets.find( newReceiver ) ) ) connectReceiver = newReceiver; mainWindow()->statusBar()->message( tr( "Connect '%1' with '%2'" ).arg( connectSender->name() ). arg( connectReceiver->name() ) ); qApp->processEvents(); if ( drawRecRect ) restoreRect( QRect( mapToForm( ( (QWidget*)oldReceiver )->parentWidget(), ( (QWidget*)oldReceiver )->pos() ), ( (QWidget*)oldReceiver )->size() ) ); drawConnectLine(); 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 ){ 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; // tell property editor to update if ( propertyWidget && !isMainContainer( propertyWidget ) ) emitUpdateProperties( propertyWidget ); QWidget *oldParent = ( (QWidget*)moving.begin().key() )->parentWidget(); QWidget *newParent = oldParent; // check whether we have to reparent the selection QWidget* wa = containerAt( e->globalPos(), ( (QWidget*)moving.begin().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*)moving.begin().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 laid out Container Widget '%1'.\n" "This is not possible. In order to insert the widget, the layout of '%1'\n" "has to be broken. 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 ( QMap<ulong, QPoint>::Iterator 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: 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(); qApp->processEvents(); if ( connectSender && connectReceiver ) editConnections(); 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 laid out Container Widget '%1'.\n" "This is not possible. In order to insert the widget, the layout of '%1'\n" "has to be broken. 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 ){ e->ignore(); checkSelectionsTimer->stop(); if ( !checkedSelectionsForMove && ( e->key() == Key_Left || e->key() == Key_Right || e->key() == Key_Up || e->key() == Key_Down ) ) checkSelectionsForMove( 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -