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

📄 actiondnd.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	 e->provides( "application/x-designer-submenu" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();    else	return;    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-submenu" ) ||	 e->provides( "application/x-designer-separator" ) ) {	int item = itemAtPos( e->pos() );	bool uieffect = QApplication::isEffectEnabled( UI_AnimateMenu );	QApplication::setEffectEnabled( UI_AnimateMenu, FALSE );	if ( !qApp->activePopupWidget() )	    actItem = -1;	activateItemAt( item );	QApplication::setEffectEnabled( UI_AnimateMenu, uieffect );	if ( item == -1 )	    hidePopups();    } else {	drawIndicator( calcIndicatorPos( e->pos() ) );    }}void QDesignerMenuBar::dragLeaveEvent( QDragLeaveEvent * ){    mousePressed = FALSE;    lastIndicatorPos = QPoint( -1, -1 );    insertAt = -1;}void QDesignerMenuBar::dropEvent( QDropEvent *e ){    mousePressed = FALSE;    if ( !e->provides( "application/x-designer-menuitem" ) )	return;    e->accept();    QString s( e->encodedData( "application/x-designer-menuitem" ) );    QString s1 = s.left( s.find( "/" ) );    QString s2 = s.mid( s.find( "/" ) + 1 );    QPopupMenu *popup = (QPopupMenu*)s1.toLong();  // #### huha, that is evil    QString txt = s2;    insertItem( txt, popup, -1, insertAt );    MoveMenuCommand *cmd = new MoveMenuCommand( tr( "Move Menu '%1'" ).arg( txt ), formWindow,				this, (QDesignerPopupMenu*)popup, oldPos, insertAt, txt );    // do not execute, we did the work already    formWindow->commandHistory()->addCommand( cmd );    formWindow->mainWindow()->objectHierarchy()->rebuild();    indicator->hide();}#endifQPoint QDesignerMenuBar::calcIndicatorPos( const QPoint &pos ){    int w = frameWidth();    insertAt = count();    for ( int i = 0; i < (int)count(); ++i ) {	QRect r = itemRect( i );	if ( pos.x() < w + r.width() / 2 ) {	    insertAt = i;	    break;	}	w += r.width();    }    return QPoint( w, 0 );}void QDesignerMenuBar::drawIndicator( const QPoint &pos ){    if ( lastIndicatorPos == pos )	return;    bool wasVsisible = indicator->isVisible();    indicator->resize( 3, height() );    indicator->move( pos.x() - 1, 0 );    indicator->show();    indicator->raise();    lastIndicatorPos = pos;    if ( !wasVsisible )	QApplication::sendPostedEvents();}void QDesignerMenuBar::setItemNumber( int num ){    itemNum = num;}int QDesignerMenuBar::itemNumber() const{    return itemNum;}void QDesignerMenuBar::setItemText( const QString &s ){    if ( itemNum < 0 || itemNum >= (int)count() )	return;    changeItem( idAt( itemNum ), s );}QString QDesignerMenuBar::itemText() const{    if ( itemNum < 0 || (int)itemNum >= (int)count() )	return QString::null;    return text( idAt( itemNum ) );}void QDesignerMenuBar::setItemName( const QCString &s ){    if ( itemNum < 0 || itemNum >= (int)count() )	return;    findItem( idAt( itemNum ) )->popup()->setName( s );}QCString QDesignerMenuBar::itemName() const{    if ( itemNum < 0 || itemNum >= (int)count() )	return "";    return findItem( idAt( itemNum ) )->popup()->name();}QDesignerPopupMenu::QDesignerPopupMenu( QWidget *w )    : QPopupMenu( w, 0 ),      popupMenu( 0 ){    findFormWindow();    setAcceptDrops( TRUE );    insertAt = -1;    mousePressed = FALSE;    lastIndicatorPos = QPoint( -1, -1 );    indicator = new QDesignerIndicatorWidget( this );    indicator->hide();}void QDesignerPopupMenu::contextMenuEvent( QContextMenuEvent *e ){#if defined( Q_WS_MAC ) //the mac needs us to use context menu rather than right click    e->accept();    QMouseEvent me( QEvent::MouseButtonPress, e->pos(), e->globalPos(), RightButton, RightButton );    mousePressEvent(&me);#else    Q_UNUSED( e );#endif}void QDesignerPopupMenu::mousePressEvent( QMouseEvent *e ){    if ( e->button() == MidButton )	return;    if ( e->button() == RightButton ) {	// A popup for a popup, we only need one, so make sure that	// we don't show multiple.	popupPos = e->globalPos();	popupLocalPos = e->pos();	if ( popupMenu ) {	    popupMenu->close();	    popupMenu = 0;	}	e->accept();	createPopupMenu();	return;    }    mousePressed = TRUE;    dragStartPos = e->pos();    QPopupMenu::mousePressEvent( e );}void QDesignerPopupMenu::createPopupMenu(){    QPopupMenu *oldPopup = popupMenu;    // actually creates our popup for the popupmenu.    QPopupMenu menu( 0 );    popupMenu = &menu;    int itm;    const int ID_DELETE = 1;    const int ID_SEP = 2;    const int ID_SUB = 3;    itm = itemAtPos( popupLocalPos, FALSE );    if ( itm == -1 )	return;    QAction *a = actionList.at( itm );    if ( a && a->inherits( "QSeparatorAction" ) )	menu.insertItem( tr( "Delete Separator" ), ID_DELETE );    else	menu.insertItem( tr( "Delete Item" ), ID_DELETE );    menu.insertItem( tr( "Insert Separator" ), ID_SEP );#if 0    menu.insertItem( tr( "Insert Sub Menu Item" ), ID_SUB );#endif    int res = menu.exec( popupPos );    if ( res == ID_DELETE ) {	QAction *a = actionList.at( itm );	if ( !a )	    return;	RemoveActionFromPopupCommand *cmd =	    new RemoveActionFromPopupCommand(					     tr( "Delete Action '%1' from Popup Menu '%2'" ).					     arg( a->name() ).arg( caption() ),					     formWindow, a, this, itm );	formWindow->commandHistory()->addCommand( cmd );	cmd->execute();    } else if ( res == ID_SEP ) {	QPoint p( pos() );	calcIndicatorPos( mapFromGlobal( popupPos ) );	QAction *a = new QSeparatorAction( 0 );	AddActionToPopupCommand *cmd =	    new AddActionToPopupCommand(					tr( "Add Separator to Popup Menu '%1'" ).					arg( name() ),					formWindow, a, this, insertAt );	formWindow->commandHistory()->addCommand( cmd );	cmd->execute();	( (QDesignerMenuBar*)( (QMainWindow*)parentWidget() )->menuBar() )->hidePopups();	( (QDesignerMenuBar*)( (QMainWindow*)parentWidget() )->menuBar() )->activateItemAt( -1 );	popup( p );    } else if ( res == ID_SUB ) {	QPoint p( pos() );	calcIndicatorPos( mapFromGlobal( popupPos ) );	QAction *a = new QSubMenuAction( 0 );	AddActionToPopupCommand *cmd =	    new AddActionToPopupCommand(					tr( "Add Sub Menu Item to Popup Menu '%1'" ).					arg( name() ),					formWindow, a, this, insertAt );	formWindow->commandHistory()->addCommand( cmd );	cmd->execute();	( (QDesignerMenuBar*)( (QMainWindow*)parentWidget() )->menuBar() )->hidePopups();	( (QDesignerMenuBar*)( (QMainWindow*)parentWidget() )->menuBar() )->activateItemAt( -1 );	popup( p );    }    // set this back to old one so we know a popup (will soon) not exist.    popupMenu = oldPopup;}void QDesignerPopupMenu::mouseMoveEvent( QMouseEvent *e ){    if ( !mousePressed || e->state() == NoButton ) {	QPopupMenu::mouseMoveEvent( e );	return;    }    if ( QABS( QPoint( dragStartPos - e->pos() ).manhattanLength() ) < QApplication::startDragDistance() ) {	QPopupMenu::mouseMoveEvent( e );	return;    }    int itm = itemAtPos( dragStartPos, FALSE );    if ( itm == -1 )	return;    QAction *a = actionList.at( itm );    if ( !a )	return;    RemoveActionFromPopupCommand *cmd =	new RemoveActionFromPopupCommand( tr( "Delete Action '%1' from Popup Menu '%2'" ).					  arg( a->name() ).arg( caption() ),					  formWindow, a, this, itm );    formWindow->commandHistory()->addCommand( cmd );    cmd->execute();    QString type;    if ( a->inherits( "QActionGroup" ) )	type = "application/x-designer-actiongroup";    else if ( a->inherits( "QSeparatorAction" ) )	type = "application/x-designer-separator";    else if ( a->inherits( "QSubMenuAction" ) )	type = "application/x-designer-submenu";    else	type = "application/x-designer-actions";    // ### to hide my sub menus here!!!    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 ( !drag->drag() ) {	AddActionToPopupCommand *cmd =	    new AddActionToPopupCommand( tr( "Add Action '%1' to Popup Menu '%2'" ).					 arg( a->name() ).arg( name() ),					 formWindow, a, this, itm );	formWindow->commandHistory()->addCommand( cmd );	cmd->execute();    }    indicator->hide();    lastIndicatorPos = QPoint( -1, -1 );    mousePressed = FALSE;}void QDesignerPopupMenu::mouseReleaseEvent( QMouseEvent *e ){    mousePressed = FALSE;    QPopupMenu::mouseReleaseEvent( e );}#ifndef QT_NO_DRAGANDDROPvoid QDesignerPopupMenu::dragEnterEvent( QDragEnterEvent *e ){    mousePressed = FALSE;    lastIndicatorPos = QPoint( -1, -1 );    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-submenu" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();}void QDesignerPopupMenu::dragMoveEvent( QDragMoveEvent *e ){    mousePressed = FALSE;    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-submenu" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();    else	return;    drawIndicator( calcIndicatorPos( e->pos() ) );}void QDesignerPopupMenu::dragLeaveEvent( QDragLeaveEvent * ){    mousePressed = FALSE;    indicator->hide();    insertAt = -1;}void QDesignerPopupMenu::dropEvent( QDropEvent *e ){    mousePressed = FALSE;    if ( e->provides( "application/x-designer-actions" ) ||	 e->provides( "application/x-designer-actiongroup" ) ||	 e->provides( "application/x-designer-submenu" ) ||	 e->provides( "application/x-designer-separator" ) )	e->accept();    else	return;    QPoint p = pos();    QAction *a = 0;    if ( e->provides( "application/x-designer-actiongroup" ) ) {	QString s( e->encodedData( "application/x-designer-actiongroup" ) );	a = (QDesignerActionGroup*)s.toLong();    } else {	QString s;	if ( e->provides( "application/x-designer-separator" ) ) {	    s = QString( e->encodedData( "application/x-designer-separator" ) );	    a = (QSeparatorAction*)s.toLong();	} else if ( e->provides( "application/x-designer-submenu" ) ) {	    s = QString( e->encodedData( "application/x-designer-submenu" ) );	    a = (QSubMenuAction*)s.toLong();	} else {	    s = QString( e->encodedData( "application/x-designer-actions" ) );	    a = (QDesignerAction*)s.toLong();	}    }    if ( actionList.findRef( a ) != -1 ) {	QMessageBox::warning( MainWindow::self, tr( "Insert/Move Action" ),			      tr( "Action '%1' has already been added to this menu.\n"				  "An Action may only occur once in a given menu." ).			      arg( a->name() ) );	return;    }    AddActionToPopupCommand *cmd =	new AddActionToPopupCommand( tr( "Add Action '%1' to Popup Menu '%2'" ).				     arg( a->name() ).arg( name() ),				     formWindow, a, this, insertAt );    formWindow->commandHistory()->addCommand( cmd );    cmd->execute();    ( (QDesignerMenuBar*)( (QMainWindow*)parentWidget() )->menuBar() )->hidePopups();    ( (QDesignerMenuBar*)( (QMainWindow*)parentWidget() )->menuBar() )->activateItemAt( -1 );    indicator->hide();    popup( p );}#endifvoid QDesignerPopupMenu::reInsert(){    clear();    for ( QAction *a = actionList.first(); a; a = actionList.next() )	a->addTo( this );}void QDesignerPopupMenu::drawIndicator( const QPoint &pos ){    if ( lastIndicatorPos == pos )	return;    bool wasVsisible = indicator->isVisible();    indicator->resize( width(), 3 );    indicator->move( 0, pos.y() - 1 );    indicator->show();    indicator->raise();    lastIndicatorPos = pos;    if ( !wasVsisible )	QApplication::sendPostedEvents();}QPoint QDesignerPopupMenu::calcIndicatorPos( const QPoint &pos ){    int h = frameWidth();    insertAt = count();    for ( int i = 0; i < (int)count(); ++i ) {	QRect r = itemGeometry( i );	if ( pos.y() < h + r.height() / 2 ) {	    insertAt = i;	    break;	}	h += r.height();    }    return QPoint( 0, h );}void QDesignerPopupMenu::addAction( QAction *a ){    actionList.append( a );    connect( a, SIGNAL( destroyed() ), this, SLOT( actionRemoved() ) );}void QDesignerPopupMenu::actionRemoved(){    actionList.removeRef( (QAction*)sender() );}void QDesignerPopupMenu::paintEvent( QPaintEvent *e ){    QPopupMenu::paintEvent( e );    if ( e->rect() != rect() )	return;    lastIndicatorPos = QPoint( -1, -1 );}void QDesignerPopupMenu::findFormWindow(){    QWidget *w = this;    while ( w ) {	if ( w->inherits( "FormWindow" ) )	    formWindow = (FormWindow*)w;	w = w->parentWidget();    }}#include "actiondnd.moc"

⌨️ 快捷键说明

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