📄 formwindow.cpp
字号:
#if defined(_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 ] ) w = (QWidget*)w->parent(); return w;}void FormWindow::emitShowProperties( QWidget *w ){ if ( w ) { QWidget *opw = propertyWidget; propertyWidget = w; repaintSelection( opw ); } showPropertiesTimer->stop(); showPropertiesTimer->start( 0, TRUE );}void FormWindow::emitUpdateProperties( QWidget *w ){ if ( w == propertyWidget ) { updatePropertiesTimer->stop(); updatePropertiesTimer->start( 0, TRUE ); }}void FormWindow::emitSelectionChanged(){ selectionChangedTimer->stop(); selectionChangedTimer->start( 0, TRUE );}void FormWindow::updatePropertiesTimerDone(){ if ( propertyWidget ) emit updateProperties( propertyWidget );}void FormWindow::showPropertiesTimerDone(){ if ( propertyWidget ) emit showProperties( propertyWidget );}void FormWindow::selectionChangedTimerDone(){ emit selectionChanged();}void FormWindow::currentToolChanged(){ toolFixed = FALSE; int t = mainwindow->currentTool(); if ( currTool == t ) return; // tool cleanup switch ( currTool ) { case ORDER_TOOL: hideOrderIndicators(); 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(); break; case POINTER_TOOL: break; default: if ( insertParent ) endRectDraw(); break; } connectSender = connectReceiver = 0; widgetPressed = FALSE; drawRubber = FALSE; insertParent = 0; delete buffer; buffer = 0; currTool = t; if ( hasFocus() ) clearSelection( FALSE ); mainWindow()->statusBar()->clear(); // tool setup switch ( currTool ) { case POINTER_TOOL: if ( propertyWidget && !isMainContainer( propertyWidget ) && !isWidgetSelected( propertyWidget ) ) emitShowProperties( mainContainer() ); restoreCursors( this, this ); break; case ORDER_TOOL: mainWindow()->statusBar()->message( tr( "Click widgets to change tab order...") ); orderedWidgets.clear(); showOrderIndicators(); if ( mainWindow()->formWindow() == this ) emitShowProperties( mainContainer() ); setCursorToAll( ArrowCursor, this ); break; case CONNECT_TOOL: mainWindow()->statusBar()->message( tr( "Drag a line to create a connection...") ); setCursorToAll( CrossCursor, this ); if ( mainWindow()->formWindow() == this ) emitShowProperties( mainContainer() ); break; default: mainWindow()->statusBar()->message( tr( "Click on the form to insert a %1..." ).arg( WidgetDatabase::toolTip( currTool ).lower() ) ); setCursorToAll( CrossCursor, this ); if ( mainWindow()->formWindow() == this ) emitShowProperties( mainContainer() ); break; }}void FormWindow::showOrderIndicators(){ hideOrderIndicators(); orderIndicators.setAutoDelete( TRUE ); QObjectList *l = mainContainer()->queryList( "QWidget" ); stackedWidgets = MetaDataBase::tabOrder( this ); if ( l ) { int order = 1; for ( QObject *o = l->first(); o; o = l->next() ) { QWidget* w = (QWidget*) o; if ( w->isVisibleTo( w->parentWidget() ) && insertedWidgets[ (void*)w ] && w->focusPolicy() != NoFocus ) { OrderIndicator* ind = new OrderIndicator( order++, w, this ); orderIndicators.append( ind ); if ( stackedWidgets.findRef( w ) == -1 ) stackedWidgets.append( w ); } } delete l; } updateOrderIndicators();}void FormWindow::hideOrderIndicators(){ orderIndicators.clear();}void FormWindow::updateOrderIndicators(){ int order = 1; for ( QWidget *w = stackedWidgets.first(); w; w = stackedWidgets.next() ) { for ( OrderIndicator* i = orderIndicators.first(); i; i = orderIndicators.next() ) i->setOrder( order, w ); order++; }}void FormWindow::repositionOrderIndicators(){ for ( OrderIndicator* i = orderIndicators.first(); i; i = orderIndicators.next() ) i->reposition();}void FormWindow::updateUndoInfo(){ commandHistory()->emitUndoRedo();}MainWindow *FormWindow::mainWindow() const{ return mainwindow;}void FormWindow::save( const QString &filename ){ mainWindow()->statusBar()->message( tr( "Saving file %1..." ).arg(filename) ); QStringList missingCustomWidgets; QPtrDictIterator<QWidget> it( insertedWidgets ); for ( ; it.current(); ++it ) { if ( it.current()->isA( "CustomWidget" ) ) { QString className = WidgetFactory::classNameOf( it.current() ); if ( !MetaDataBase::hasCustomWidget( className ) ) missingCustomWidgets << className; } } if ( !missingCustomWidgets.isEmpty() ) { QString txt = tr( "Following custom widgets are used in '%1',\n" "but they are not known to the designer:" ).arg( name() ); for ( QStringList::Iterator sit = missingCustomWidgets.begin(); sit != missingCustomWidgets.end(); ++sit ) txt += " " + *sit + "\n"; txt += "If you save this form and generate code for it by the UIC, \n" "the generated code will not compile. Do you really want to save\n" "this form now?"; if ( QMessageBox::information( mainWindow(), tr( "Save Form" ), txt ) == 1 ) return; } fname = filename; Resource resource( mainWindow() ); resource.setWidget( this ); if ( !resource.save( fname ) ) { mainWindow()->statusBar()->message( tr( "Failed to save file %1.").arg( filename ), 5000 ); QMessageBox::warning( mainWindow(), tr( "Save" ), tr( "Couldn't save file %1" ).arg( fname ) ); } else { mainWindow()->statusBar()->message( tr( "%1 saved.").arg( filename ), 3000 ); commandHistory()->setModified( FALSE ); }}void FormWindow::setPropertyShowingBlocked( bool b ){ propShowBlocked = b;}bool FormWindow::isPropertyShowingBlocked() const{ return propShowBlocked;}int FormWindow::numSelectedWidgets() const{ return usedSelections.count();}QString FormWindow::copy(){ Resource resource( mainWindow() ); resource.setWidget( this ); return resource.copy();}void FormWindow::lowerWidgets(){ QWidgetList widgets; QPtrDictIterator<WidgetSelection> it( usedSelections ); for ( ; it.current(); ++it ) widgets.append( it.current()->widget() ); LowerCommand *cmd = new LowerCommand( tr( "Lower" ), this, widgets ); cmd->execute(); commandHistory()->addCommand( cmd ); }static void find_accel( const QString &txt, QMap<QChar, QWidgetList > &accels, QWidget *w ){ int i = txt.find( "&" ); if ( i == -1 ) return; QChar c = txt[ i + 1 ]; if ( c.isNull() || c == '&' ) return; c = c.lower(); QMap<QChar, QWidgetList >::Iterator it = accels.find( c ); if ( it == accels.end() ) { QWidgetList wl; wl.append( w ); accels.insert( c, wl ); } else { QWidgetList *wl = &*it;; wl->append( w ); }}void FormWindow::checkAccels(){ QMap<QChar, QWidgetList > accels; QObjectList *l = mainContainer()->queryList( "QWidget" ); if ( l ) { for ( QObject *o = l->first(); o; o = l->next() ) { if ( ( (QWidget*)o )->isVisibleTo( this ) && insertedWidgets[ (void*)o ] ) { QWidget *w = (QWidget*)o; const QMetaProperty* text = w->metaObject()->property( "text", TRUE ); const QMetaProperty* title = w->metaObject()->property( "title", TRUE ); const QMetaProperty* pageTitle = w->metaObject()->property( "pageTitle", TRUE ); if ( text ) find_accel( w->property( "text" ).toString(), accels, w ); if ( title ) find_accel( w->property( "title" ).toString(), accels, w ); if ( pageTitle ) find_accel( w->property( "pageTitle" ).toString(), accels, w ); } } } delete l; bool ok = TRUE; QWidget *wid; for ( QMap<QChar, QWidgetList >::Iterator it = accels.begin(); it != accels.end(); ++it ) { if ( (*it).count() > 1 ) { ok = FALSE; switch ( QMessageBox::information( mainWindow(), tr( "Check Accelerators" ), tr( "The accelerator '%1' is used %2 times. What do you " "want to do?" ).arg( it.key() ).arg( (*it).count() ), tr( "&Select widgets using it" ), tr( "&Ignore" ), tr( "&Cancel" ), 0, 2 ) ) { case 0: // select clearSelection( FALSE ); for ( wid = (*it).first(); wid; wid = (*it).next() ) selectWidget( wid, TRUE ); return; case 1: // ignore break; case 2: // cancel return; } } } if ( ok ) QMessageBox::information( mainWindow(), tr( "Check Accelerators" ), tr( "No accelerator is used more that once!" ) );}void FormWindow::raiseWidgets(){ QWidgetList widgets; QPtrDictIterator<WidgetSelection> it( usedSelections ); for ( ; it.current(); ++it ) widgets.append( it.current()->widget() ); RaiseCommand *cmd = new RaiseCommand( tr( "Raise" ), this, widgets ); cmd->execute(); commandHistory()->addCommand( cmd ); }void FormWindow::paste( const QString &cb, QWidget *parent ){ Resource resource( mainWindow() ); resource.setWidget( this ); resource.paste( cb, parent );}void FormWindow::selectAll(){ checkedSelectionsForMove = FALSE; blockSignals( TRUE ); QObjectList *l = mainContainer()->queryList( "QWidget" ); if ( l ) { for ( QObject *o = l->first(); o; o = l->next() ) { if ( ( (QWidget*)o )->isVisibleTo( this ) && insertedWidgets[ (void*)o ] ) { selectWidget( (QWidget*)o ); } } } delete l; blockSignals( FALSE ); emitSelectionChanged(); if ( propertyWidget ) emitShowProperties( propertyWidget ); emitSelectionChanged();}void FormWindow::layoutHorizontal(){ QWidgetList widgets( selectedWidgets() ); LayoutHorizontalCommand *cmd = new LayoutHorizontalCommand( tr( "Layout horizontally" ), this, mainContainer(), 0, widgets ); clearSelection( FALSE ); commandHistory()->addCommand( cmd ); cmd->execute();}void FormWindow::layoutVertical(){ QWidgetList widgets( selectedWidgets() ); LayoutVerticalCommand *cmd = new LayoutVerticalCommand( tr( "Layout vertically" ), this, mainContainer(), 0, widgets ); clearSelection( FALSE ); commandHistory()->addCommand( cmd ); cmd->execute();}void FormWindow::layoutGrid(){ int xres = grid().x(); int yres = grid().y(); QWidgetList widgets( selectedWidgets() ); LayoutGridCommand *cmd = new LayoutGridCommand( tr( "Layout in a grid" ), this, mainContainer(), 0, widgets, xres, yres ); clearSelection( FALSE ); commandHistory()->addCommand( cmd ); cmd->execute();}void FormWindow::layoutHorizontalContainer( QWidget *w ){ if ( w == this ) 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 ); } LayoutHorizontalCommand *cmd = new LayoutHorizontalCommand( tr( "Layout children horizontally" ), this, mainContainer(), w, widgets ); clearSelection( FALSE ); commandHistory()->addCommand( cmd ); cmd->execute();}void FormWindow::layoutVerticalContainer( QWidget *w ){ if ( w == this )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -