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

📄 qpopupmenu.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	while ( n-- ) {	    i = i + dy;	    if ( i == c )		i = 0;	    else if ( i < 0 )		i = c - 1;	    mi = mitems->at( i );	    if ( !mi->isSeparator()		 && ( style() != MotifStyle || mi->isEnabled() ) #ifdef QT_KEYPAD_MODE		 && mi->isEnabled()#endif		)		break;	}	if ( i != actItem )	    setActiveItem( i );    }}/*!\reimp*/void QPopupMenu::timerEvent( QTimerEvent *e ){    QFrame::timerEvent( e );}/*!\reimp*/void  QPopupMenu::styleChange( QStyle& old ){    style().polishPopupMenu( this );    updateSize();    QFrame::styleChange( old );}/*!  If a popup menu does not fit on the screen, it layouts itself in  multiple columns until it fits.  This functions returns in how many.\sa sizeHint() */int QPopupMenu::columns() const{    return ncols;}/*! This private slot handles the delayed submenu effects */void QPopupMenu::subMenuTimer() {    if ( !isVisible() || (actItem < 0 && popupActive < 0) || actItem == popupActive )	return;    if ( popupActive >= 0 ) {	hidePopups();	popupActive = -1;    }    if ( actItem < 0 )	return;    QMenuItem *mi = mitems->at(actItem);    if ( !mi || !mi->isEnabled() )	return;    QPopupMenu *popup = mi->popup();    if ( !popup || !popup->isEnabled() )	return;    //avoid circularity    if ( popup->isVisible() )	return;    if (popup->parentMenu != this ){	// reuse	if (popup->parentMenu)	    popup->parentMenu->menuDelPopup(popup);	menuInsPopup(popup);    }    emit popup->aboutToShow();    supressAboutToShow = TRUE;    QRect r( itemGeometry( actItem ) );    QPoint p( r.right() - motifArrowHMargin, r.top() + motifArrowVMargin );    p = mapToGlobal( p );    QSize ps = popup->sizeHint();    if (p.y() + ps.height() > QApplication::desktop()->height()	&& p.y() - ps.height()	+ (QCOORD)(popup->itemHeight( popup->count()-1)) >= 0)	p.setY( p.y() - ps.height()		+ (QCOORD)(popup->itemHeight( popup->count()-1)));    popupActive = actItem;    bool left = FALSE;    if ( ( parentMenu && parentMenu->isPopupMenu &&	   ((QPopupMenu*)parentMenu)->geometry().x() > geometry().x() ) ||	 p.x() + ps.width() > QApplication::desktop()->width() )	left = TRUE;    if ( left && (ps.width() > mapToGlobal( r.topLeft() ).x() ) )	left = FALSE;    if ( left )	p.setX( mapToGlobal( r.topLeft() ).x() - ps.width() );    popup->popup( p );}void QPopupMenu::allowAnimation(){    preventAnimation = FALSE;}void QPopupMenu::updateRow( int row ){    if ( badSize ){	updateSize();	update();	return;    }    if ( !isVisible() )	return;    QPainter p(this);    QMenuItemListIt it(*mitems);    QMenuItem *mi;    int r = 0;    int x = contentsRect().x();    int y = contentsRect().y();    int itemw = contentsRect().width() / ncols;    while ( (mi=it.current()) ) {	++it;	int itemh = itemHeight( r );	if ( ncols > 1 && y + itemh > contentsRect().bottom() ) {	    y = contentsRect().y();	    x +=itemw;	}	if ( r == row )	    drawItem(&p, tab, mi, r == actItem, x, y, itemw, itemh );	y += itemh;	++r;    }}/*!  Execute this popup synchronously.  Opens the popup menu so that the item number \a indexAtPoint will be  at the specified \e global position \a pos.  To translate a widget's  local coordinates into global coordinates, use QWidget::mapToGlobal().  The return code is the ID of the selected item in either the popup  menu or one of its submenus, or -1 if no item is selected (normally  because the user presses Escape).  Note that all signals are emitted as usual.  If you connect a menu  item to a slot and call the menu's exec(), you get the result both  via the signal-slot connection and in the return value of exec().  Common usage is to position the popup at the current  mouse position:  \code      exec(QCursor::pos());  \endcode  or aligned to a widget:  \code      exec(somewidget.mapToGlobal(QPoint(0,0)));  \endcode  When positioning a popup with exec() or popup(), keep in mind that  you cannot rely on the popup menu's current size(). For performance  reasons, the popup adapts its size only when actually needed. So in  many cases, the size before and after the show is  different. Instead, use sizeHint(). It calculates the proper size  depending on the menu's current contents.  \sa popup(), sizeHint()*/int QPopupMenu::exec( const QPoint & pos, int indexAtPoint ){    if ( !qApp )	return -1;    QPopupMenu* priorSyncMenu = syncMenu;    syncMenu = this;    syncMenuId = -1;    QGuardedPtr<QPopupMenu> that = this;    connectModal( that, TRUE );    popup( pos, indexAtPoint );    qApp->enter_loop();    connectModal( that, FALSE );    syncMenu = priorSyncMenu;    return syncMenuId;}/*  connect the popup and all its submenus to modalActivation() if  \a doConnect is true, otherwise disconnect. */void QPopupMenu::connectModal( QPopupMenu* receiver, bool doConnect ){    if ( !receiver )	return;    connectModalRecursionSafety = doConnect;    if ( doConnect )	connect( this, SIGNAL(activated(int)),		 receiver, SLOT(modalActivation(int)) );    else	disconnect( this, SIGNAL(activated(int)),		    receiver, SLOT(modalActivation(int)) );    QMenuItemListIt it(*mitems);    register QMenuItem *mi;    while ( (mi=it.current()) ) {	++it;	if ( mi->popup() && mi->popup() != receiver	     && (bool)(mi->popup()->connectModalRecursionSafety) != doConnect )	    mi->popup()->connectModal( receiver, doConnect ); //avoid circular    }}/*!  Execute this popup synchronously.  Similar to the above function, but the position of the  popup is not set, so you must choose an appropriate position.  The function move the popup if it is partially off-screen.  More common usage is to position the popup at the current  mouse position:  \code      exec(QCursor::pos());  \endcode  or aligned to a widget:  \code      exec(somewidget.mapToGlobal(QPoint(0,0)));  \endcode*/int QPopupMenu::exec(){    return exec(mapToGlobal(QPoint(0,0)));}/*!  Internal slot used for exec(). */void QPopupMenu::modalActivation( int id ){    syncMenuId = id;}/*!  Sets the currently active item to \a i and repaints as necessary.*/void QPopupMenu::setActiveItem( int i ){    int lastActItem = actItem;    actItem = i;    if ( lastActItem >= 0 )	updateRow( lastActItem );    if ( i >= 0 && i != lastActItem )	updateRow( i );    QMenuItem *mi = mitems->at( actItem );    if ( !mi )	return;    if ( mi->widget() && mi->widget()->isFocusEnabled() )	mi->widget()->setFocus();    else	setFocus();    if ( mi->id() != -1 )	hilitSig( mi->id() );}/*!\reimp */QSize QPopupMenu::sizeHint() const{    constPolish();    if ( badSize ) {	QPopupMenu* that = (QPopupMenu*) this;	that->updateSize();    }    return size().expandedTo( QApplication::globalStrut() );}/*!  Return the id of the item at \e pos, or -1 if there is no item  there, or if it is a separator item. */int QPopupMenu::idAt( const QPoint& pos ) const{    return idAt( itemAtPos( pos ) );}/*!\fn int QPopupMenu::idAt( int index ) const  Returns the identifier of the menu item at position \a index in the internal  list, or -1 if \a index is out of range.  \sa QMenuData::setId(), QMenuData::indexOf()*//*!\reimp */bool QPopupMenu::customWhatsThis() const{    return TRUE;}/*!\reimp */bool QPopupMenu::focusNextPrevChild( bool next ){    register QMenuItem *mi;    int dy = next? 1 : -1;    if ( dy && actItem < 0 ) {	setFirstItemActive();    } else if ( dy ) {				// highlight next/prev	register int i = actItem;	int c = mitems->count();	int n = c;	while ( n-- ) {	    i = i + dy;	    if ( i == c )		i = 0;	    else if ( i < 0 )		i = c - 1;	    mi = mitems->at( i );	    if ( !mi->isSeparator()		 && ( style() != MotifStyle || mi->isEnabled() ) )		break;	}	if ( i != actItem )	    setActiveItem( i );    }    return TRUE;}/*!\reimp */void QPopupMenu::focusInEvent( QFocusEvent * ){}/*!\reimp */void QPopupMenu::focusOutEvent( QFocusEvent * ){}class QTearOffMenuItem : public QCustomMenuItem{public:    QTearOffMenuItem()    {    }    ~QTearOffMenuItem()    {    }    void paint( QPainter* p, const QColorGroup& cg, bool /* act*/,		bool /*enabled*/, int x, int y, int w, int h )    {	p->setPen( QPen( cg.dark(), 1, DashLine ) );	p->drawLine( x+2, y+h/2-1, x+w-4, y+h/2-1 );	p->setPen( QPen( cg.light(), 1, DashLine ) );	p->drawLine( x+2, y+h/2, x+w-4, y+h/2 );    }    bool fullSpan() const    {	return TRUE;    }    QSize sizeHint()    {	return QSize( 20, 6 );    }};/*!  Inserts a tear-off handle into the menu. A tear-off handle is a  special menu item, that - when selected - creates a copy of the  menu. This "torn off" copy lives in a separate window. It contains  the same choices as the original menu, with the exception of the  tear-off handle.  You may also want to set a proper window title for the tear-off menu  with setCaption().  The handle item is assigned the identifier \a id or an automatically  generated identifier if \a id is < 0. The generated identifiers  (negative integers) are guaranteed to be unique within the entire  application.  The \a index specifies the position in the menu.  The tear-off  handle is appended at the end of the list if \a index is negative. */int QPopupMenu::insertTearOffHandle( int id, int index ){    int myid = insertItem( new QTearOffMenuItem, id, index );    connectItem( myid, this, SLOT( toggleTearOff() ) );    QMenuData::d->aInt = myid;    return myid;}/*!\internal  implements tear-off menus */void QPopupMenu::toggleTearOff(){    if ( active_popup_menu && active_popup_menu->tornOff ) {	active_popup_menu->close();    } else  if (QMenuData::d->aWidget ) {	delete (QWidget*) QMenuData::d->aWidget; // delete the old one    } else {	// create a tear off menu	QPopupMenu* p = new QPopupMenu( 0, "tear off menu" );	connect( p, SIGNAL( activated(int) ), this, SIGNAL( activated(int) ) );	p->setCaption( caption() );	p->setCheckable( isCheckable() );	p->reparent( parentWidget(), WType_TopLevel | WStyle_Tool |		     WRepaintNoErase | WDestructiveClose,		     geometry().topLeft(), FALSE );	p->mitems->setAutoDelete( FALSE );	p->tornOff = TRUE;	for ( QMenuItemListIt it( *mitems ); it.current(); ++it ) {	    if ( it.current()->id() != QMenuData::d->aInt && !it.current()->widget() )		p->mitems->append( it.current() );	}	p->show();	QMenuData::d->aWidget = p;    }}/*! \reimp */void QPopupMenu::activateItemAt( int index ){    if ( index >= 0 && index < (int) mitems->count() ) {	QMenuItem *mi = mitems->at( index );	if ( index != actItem )			// new item activated	    setActiveItem( index );	QPopupMenu *popup = mi->popup();	if ( popup ) {	    if ( popup->isVisible() ) {		// sub menu already open		int pactItem = popup->actItem;		popup->actItem = -1;		popup->hidePopups();		popup->updateRow( pactItem );	    } else {				// open sub menu		hidePopups();		actItem = index;		subMenuTimer();		popup->setFirstItemActive();	    }	} else {	    byeMenuBar();			// deactivate menu bar#ifndef QT_NO_WHATSTHIS	    bool b = QWhatsThis::inWhatsThisMode();#else	    const bool b = FALSE;#endif	    if ( !mi->isEnabled() ) {#ifndef QT_NO_WHATSTHIS		if ( b ) {		    actItem = -1;		    updateItem( mi->id() );		    byeMenuBar();		    actSig( mi->id(), b);		}#endif	    } else {		byeMenuBar();			// deactivate menu bar		if ( mi->isEnabled() ) {		    actItem = -1;		    updateItem( mi->id() );		    active_popup_menu = this;		    actSig( mi->id(), b );		    if ( mi->signal() && !b )			mi->signal()->activate();		    active_popup_menu = 0;		}	    }	}    } else {	if ( tornOff ) {	    close();	} else {	    hide();#ifndef QT_NO_MENUBAR	    if ( parentMenu && parentMenu->isMenuBar )		((QMenuBar*) parentMenu)->goodbye( TRUE );#endif	}    }}#endif // QT_NO_POPUPMENU

⌨️ 快捷键说明

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