⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actiondnd.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    if ( e->button() == LeftButton &&	 MainWindow::self->currentTool() != POINTER_TOOL &&	 MainWindow::self->currentTool() != ORDER_TOOL ) {	if ( MainWindow::self->currentTool() == CONNECT_TOOL ) {	} else {	    widgetInserting = TRUE;	}	return;    }    dragStartPos = e->pos();}void QDesignerToolBar::removeWidget( QWidget *w ){    QMap<QWidget*, QAction*>::Iterator it = actionMap.find( w );    if ( it == actionMap.end() )	return;    QAction *a = *it;    int index = actionList.find( a );    RemoveActionFromToolBarCommand *cmd =	new RemoveActionFromToolBarCommand( tr( "Delete Action '%1' from Toolbar '%2'" ).					    arg( a->name() ).arg( caption() ),					    formWindow, a, this, index );    formWindow->commandHistory()->addCommand( cmd );    cmd->execute();    QApplication::sendPostedEvents();    adjustSize();}void QDesignerToolBar::buttonMouseMoveEvent( QMouseEvent *e, QObject *o ){    if ( widgetInserting || ( e->state() & LeftButton ) == 0 )	return;    if ( QABS( QPoint( dragStartPos - e->pos() ).manhattanLength() ) < QApplication::startDragDistance() )	return;    QMap<QWidget*, QAction*>::Iterator it = actionMap.find( (QWidget*)o );    if ( it == actionMap.end() )	return;    QAction *a = *it;    if ( !a )	return;    int index = actionList.find( a );    RemoveActionFromToolBarCommand *cmd =	new RemoveActionFromToolBarCommand( tr( "Delete Action '%1' from Toolbar '%2'" ).					    arg( a->name() ).arg( caption() ),					    formWindow, a, this, index );    formWindow->commandHistory()->addCommand( cmd );    cmd->execute();    QApplication::sendPostedEvents();    adjustSize();    QString type = a->inherits( "QActionGroup" ) ? QString( "application/x-designer-actiongroup" ) :	a->inherits( "QSeparatorAction" ) ? QString( "application/x-designer-separator" ) : QString( "application/x-designer-actions" );    QStoredDrag *drag = new QStoredDrag( type, this );    QString s = QString::number( (long)a ); // #### huha, that is evil    drag->setEncodedData( QCString( s.latin1() ) );    drag->setPixmap( a->iconSet().pixmap() );    if ( a->inherits( "QDesignerAction" ) ) {	if ( formWindow->widgets()->find( ( (QDesignerAction*)a )->widget() ) )	    formWindow->selectWidget( ( (QDesignerAction*)a )->widget(), FALSE );    }    if ( !drag->drag() ) {	AddActionToToolBarCommand *cmd = new AddActionToToolBarCommand( tr( "Add Action '%1' to Toolbar '%2'" ).									arg( a->name() ).arg( caption() ),									formWindow, a, this, index );	formWindow->commandHistory()->addCommand( cmd );	cmd->execute();    }    lastIndicatorPos = QPoint( -1, -1 );    indicator->hide();}#ifndef QT_NO_DRAGANDDROPvoid QDesignerToolBar::dragEnterEvent( QDragEnterEvent *e ){    widgetInserting = FALSE;    lastIndicatorPos = QPoint( -1, -1 );    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();}void QDesignerToolBar::dragMoveEvent( QDragMoveEvent *e ){    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();    else	return;    drawIndicator( calcIndicatorPos( e->pos() ) );}void QDesignerToolBar::dragLeaveEvent( QDragLeaveEvent * ){    indicator->hide();    insertAnchor = 0;    afterAnchor = TRUE;}void QDesignerToolBar::dropEvent( QDropEvent *e ){    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();    else	return;    QString s;    if ( e->provides( "application/x-designer-actiongroup" ) )	s = QString( e->encodedData( "application/x-designer-actiongroup" ) );    else if ( e->provides( "application/x-designer-separator" ) )	s = QString( e->encodedData( "application/x-designer-separator" ) );    else	s = QString( e->encodedData( "application/x-designer-actions" ) );    indicator->hide();    QAction *a = 0;    int index = actionList.findRef( *actionMap.find( insertAnchor ) );    if ( index != -1 && afterAnchor )	++index;    if ( !insertAnchor )	index = 0;    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-separator" ) ) {	if ( e->provides( "application/x-designer-actions" ) )	    a = (QDesignerAction*)s.toLong();	else	    a = (QSeparatorAction*)s.toLong();    } else {	a = (QDesignerActionGroup*)s.toLong();    }    if ( actionList.findRef( a ) != -1 ) {	QMessageBox::warning( MainWindow::self, tr( "Insert/Move Action" ),			      tr( "Action '%1' has already been added to this toolbar.\n"				  "An Action may only occur once in a given toolbar." ).			      arg( a->name() ) );	return;    }    AddActionToToolBarCommand *cmd = new AddActionToToolBarCommand( tr( "Add Action '%1' to Toolbar '%2'" ).								    arg( a->name() ).arg( caption() ),								    formWindow, a, this, index );    formWindow->commandHistory()->addCommand( cmd );    cmd->execute();    lastIndicatorPos = QPoint( -1, -1 );}#endifvoid QDesignerToolBar::reInsert(){    QAction *a = 0;    actionMap.clear();    clear();    for ( a = actionList.first(); a; a = actionList.next() ) {	a->addTo( this );	if ( a->inherits( "QActionGroup" ) ) {	    actionMap.insert( ( (QDesignerActionGroup*)a )->widget(), a );	    if ( ( (QDesignerActionGroup*)a )->widget() )		( (QDesignerActionGroup*)a )->widget()->installEventFilter( this );	} else if ( a->inherits( "QDesignerAction" ) ) {	    actionMap.insert( ( (QDesignerAction*)a )->widget(), a );	    ( (QDesignerAction*)a )->widget()->installEventFilter( this );	} else if ( a->inherits( "QSeparatorAction" ) ) {	    actionMap.insert( ( (QSeparatorAction*)a )->widget(), a );	    ( (QSeparatorAction*)a )->widget()->installEventFilter( this );	}    }    QApplication::sendPostedEvents();    adjustSize();}void QDesignerToolBar::actionRemoved(){    actionList.removeRef( (QAction*)sender() );}QPoint QDesignerToolBar::calcIndicatorPos( const QPoint &pos ){    if ( orientation() == Horizontal ) {	QPoint pnt( width() - 2, 0 );	insertAnchor = 0;	afterAnchor = TRUE;	if ( !children() )	    return pnt;	pnt = QPoint( 13, 0 );	QObjectListIt it( *children() );	QObject * obj;	while( (obj=it.current()) != 0 ) {	    ++it;	    if ( obj->isWidgetType() &&		 qstrcmp( "qt_dockwidget_internal", obj->name() ) != 0 ) {		QWidget *w = (QWidget*)obj;		if ( w->x() < pos.x() ) {		    pnt.setX( w->x() + w->width() + 1 );		    insertAnchor = w;		    afterAnchor = TRUE;		}	    }	}	return pnt;    } else {	QPoint pnt( 0, height() - 2 );	insertAnchor = 0;	afterAnchor = TRUE;	if ( !children() )	    return pnt;	pnt = QPoint( 0, 13 );	QObjectListIt it( *children() );	QObject * obj;	while( (obj=it.current()) != 0 ) {	    ++it;	    if ( obj->isWidgetType() &&		 qstrcmp( "qt_dockwidget_internal", obj->name() ) != 0 ) {		QWidget *w = (QWidget*)obj;		if ( w->y() < pos.y() ) {		    pnt.setY( w->y() + w->height() + 1 );		    insertAnchor = w;		    afterAnchor = TRUE;		}	    }	}	return pnt;    }}void QDesignerToolBar::drawIndicator( const QPoint &pos ){    if ( lastIndicatorPos == pos )	return;    bool wasVsisible = indicator->isVisible();    if ( orientation() == Horizontal ) {	indicator->resize( 3, height() );	if ( pos != QPoint( -1, -1 ) )	     indicator->move( pos.x() - 1, 0 );	indicator->show();	indicator->raise();	lastIndicatorPos = pos;    } else {	indicator->resize( width(), 3 );	if ( pos != QPoint( -1, -1 ) )	     indicator->move( 0, pos.y() - 1 );	indicator->show();	indicator->raise();	lastIndicatorPos = pos;    }    if ( !wasVsisible )	QApplication::sendPostedEvents();}void QDesignerToolBar::doInsertWidget( const QPoint &p ){    if ( formWindow != MainWindow::self->formWindow() )	return;    calcIndicatorPos( p );    QWidget *w = WidgetFactory::create( MainWindow::self->currentTool(), this, 0, TRUE );    installEventFilters( w );    MainWindow::self->formWindow()->insertWidget( w, TRUE );    QDesignerAction *a = new QDesignerAction( w, parent() );    int index = actionList.findRef( *actionMap.find( insertAnchor ) );    if ( index != -1 && afterAnchor )	++index;    if ( !insertAnchor )	index = 0;    AddActionToToolBarCommand *cmd = new AddActionToToolBarCommand( tr( "Add Widget '%1' to Toolbar '%2'" ).								    arg( w->name() ).arg( caption() ),								    formWindow, a, this, index );    formWindow->commandHistory()->addCommand( cmd );    cmd->execute();    MainWindow::self->resetTool();}void QDesignerToolBar::clear(){    for ( QAction *a = actionList.first(); a; a = actionList.next() ) {	if ( a->inherits( "QDesignerAction" ) )	    ( (QDesignerAction*)a )->remove();    }    QToolBar::clear();}void QDesignerToolBar::installEventFilters( QWidget *w ){    if ( !w )	return;    QObjectList *l = w->queryList( "QWidget" );    for ( QObject *o = l->first(); o; o = l->next() )	o->installEventFilter( this );    delete l;}QDesignerMenuBar::QDesignerMenuBar( QWidget *mw )    : QMenuBar( mw, 0 ){    show();    setAcceptDrops( TRUE );    MetaDataBase::addEntry( this );    itemNum = 0;    mousePressed = FALSE;    lastIndicatorPos = QPoint( -1, -1 );    insertAt = -1;    indicator = new QDesignerIndicatorWidget( this );    indicator->hide();    findFormWindow();}void QDesignerMenuBar::findFormWindow(){    QWidget *w = this;    while ( w ) {	if ( w->inherits( "FormWindow" ) )	    formWindow = (FormWindow*)w;	w = w->parentWidget();    }}void QDesignerMenuBar::contextMenuEvent( QContextMenuEvent *e ){    e->accept();    int itm = itemAtPos( e->pos() );    if ( itm == -1 ) {	if ( formWindow )	    formWindow->mainWindow()->popupFormWindowMenu( e->globalPos(), formWindow );	return;    }    QPopupMenu menu( this );    menu.insertItem( tr( "Delete Item" ), 1 );    menu.insertItem( tr( "Rename Item..." ), 2 );    int res = menu.exec( e->globalPos() );    if ( res == 1 ) {	QMenuItem *item = findItem( idAt( itm ) );	RemoveMenuCommand *cmd = new RemoveMenuCommand( tr( "Delete Menu '%1'" ).arg( item->text() ),							formWindow,							(QMainWindow*)parentWidget(), this,							(QDesignerPopupMenu*)item->popup(),							idAt( itm ), itm, item->text() );	formWindow->commandHistory()->addCommand( cmd );	cmd->execute();	// #### need to do a proper invalidate and re-layout	parentWidget()->layout()->invalidate();	parentWidget()->layout()->activate();    } else if ( res == 2 ) {	bool ok;	QString old = text( idAt( itm ) );	QString txt = QInputDialog::getText( tr( "Rename Menu Item" ), tr( "Menu Text" ),					     QLineEdit::Normal, text( idAt( itm ) ), &ok, 0 );	if ( ok ) {	    RenameMenuCommand *cmd = new RenameMenuCommand(		tr( "Rename Menu '%1' to '%2'" ).arg( old ).arg( txt ),		formWindow, this, idAt( itm ), old, txt );	    formWindow->commandHistory()->addCommand( cmd );	    cmd->execute();	}    }}void QDesignerMenuBar::mousePressEvent( QMouseEvent *e ){    lastIndicatorPos = QPoint( -1, -1 );    insertAt = -1;    mousePressed = TRUE;    if ( e->button() == MidButton || e->button() == RightButton )	return;    dragStartPos = e->pos();    QMenuBar::mousePressEvent( e );}void QDesignerMenuBar::mouseMoveEvent( QMouseEvent *e ){    if ( !mousePressed || e->state() == NoButton ) {	QMenuBar::mouseMoveEvent( e );	return;    }    if ( QABS( QPoint( dragStartPos - e->pos() ).manhattanLength() ) < QApplication::startDragDistance() )	return;    hidePopups();    activateItemAt( -1 );    int itm = itemAtPos( dragStartPos );    if ( itm == -1 )	return;    QPopupMenu *popup = findItem( idAt( itm ) )->popup();    QString txt = findItem( idAt( itm ) )->text();    removeItemAt( itm );    QStoredDrag *drag = new QStoredDrag( "application/x-designer-menuitem", this );    QString s = QString::number( (long)popup );    s += "/" + txt;    drag->setEncodedData( QCString( s.latin1() ) );    QSize sz( fontMetrics().boundingRect( txt ).size() );    QPixmap pix( sz.width() + 20, sz.height() * 2 );    pix.fill( white );    QPainter p( &pix, this );    p.drawText( 2, 0, pix.width(), pix.height(), 0, txt );    p.end();    QBitmap bm( pix.size() );    bm.fill( color0 );    p.begin( &bm );    p.setPen( color1 );    p.drawText( 2, 0, pix.width(), pix.height(), 0, txt );    p.end();    pix.setMask( bm );    drag->setPixmap( pix );    oldPos = itm;    if ( !drag->drag() ) {	insertItem( txt, popup, -1, itm );    }    lastIndicatorPos = QPoint( -1, -1 );    indicator->hide();    mousePressed = FALSE;}void QDesignerMenuBar::mouseReleaseEvent( QMouseEvent *e ){    QMenuBar::mouseReleaseEvent( e );    mousePressed = FALSE;}#ifndef QT_NO_DRAGANDDROPvoid QDesignerMenuBar::dragEnterEvent( QDragEnterEvent *e ){    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();    if ( e->provides( "application/x-designer-menuitem" ) ||	 e->provides( "application/x-designer-submenu" ) )	e->accept();    lastIndicatorPos = QPoint( -1, -1 );    insertAt = -1;}void QDesignerMenuBar::dragMoveEvent( QDragMoveEvent *e ){    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-menuitem" ) ||

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -