?? qmenudata.cpp
字號:
else parent->menuContentsChanged(); }}/*! Changes the icon and text of the menu item \a id. \sa pixmap()*/void QMenuData::changeItem( int id, const QIconSet &icon, const QString &text ){ changeItem(id, text); changeItemIconSet(id, icon);}/*! Changes the icon and pixmap of the menu item \a id. \sa pixmap()*/void QMenuData::changeItem( int id, const QIconSet &icon, const QPixmap &pixmap ){ changeItem(id, pixmap); changeItemIconSet(id, icon);}/*! Changes the icon of the menu item \a id. \sa pixmap()*/void QMenuData::changeItemIconSet( int id, const QIconSet &icon ){ QMenuData *parent; QMenuItem *mi = findItem( id, &parent ); if ( mi ) { // item found register QIconSet *i = mi->iconset_data; bool fast_refresh = i != 0; mi->iconset_data = new QIconSet( icon ); delete i; // old mi->iconset_data, could be &icon if ( fast_refresh ) parent->updateItem( id ); else parent->menuContentsChanged(); }}/*! Returns TRUE if the item with identifier \a id is enabled or FALSE if it is disabled. \sa setItemEnabled()*/bool QMenuData::isItemEnabled( int id ) const{ QMenuItem *mi = findItem( id ); return mi ? mi->isEnabled() : FALSE;}/*! Enables the menu item with identifier \a id if \a enable is TRUE, or disables the item if \a enable is FALSE. \sa isItemEnabled()*/void QMenuData::setItemEnabled( int id, bool enable ){ QMenuData *parent; QMenuItem *mi = findItem( id, &parent ); if ( mi && (bool)mi->is_enabled != enable ) { mi->is_enabled = enable;#ifndef QT_NO_ACCEL if ( mi->popup() ) mi->popup()->enableAccel( enable );#endif parent->menuStateChanged(); }}/*! Returns TRUE if the menu item has been checked, otherwise FALSE. \sa setItemChecked()*/bool QMenuData::isItemChecked( int id ) const{ QMenuItem *mi = findItem( id ); return mi ? mi->isChecked() : FALSE;}/*! Checks the menu item with id \a id if \a check is TRUE, or unchecks it if \a check is FALSE, and calls QPopupMenu::setCheckable( TRUE ) if necessary. \sa isItemChecked()*/void QMenuData::setItemChecked( int id, bool check ){ QMenuData *parent; QMenuItem *mi = findItem( id, &parent ); if ( mi && (bool)mi->is_checked != check ) { mi->is_checked = check; if ( parent->isPopupMenu && !((QPopupMenu *)parent)->isCheckable() ) ((QPopupMenu *)parent)->setCheckable( TRUE ); parent->menuStateChanged(); }}/*! Returns a pointer to the menu item with identifier \a id, or 0 if there is no item with such an identifier. \sa indexOf()*/QMenuItem *QMenuData::findItem( int id ) const{ return findItem( id, 0 );}/*! Returns a pointer to the menu item with identifier \a id, or 0 if there is no item with such an identifier, and changes \a parent to point to the parent of the return value. \sa indexOf()*/QMenuItem * QMenuData::findItem( int id, QMenuData ** parent ) const{ if ( parent ) *parent = (QMenuData *)this; // ### if ( id == -1 ) // bad identifier return 0; QMenuItemListIt it( *mitems ); QMenuItem *mi; while ( (mi=it.current()) ) { // search this menu ++it; if ( mi->ident == id ) // found item return mi; } it.toFirst(); while ( (mi=it.current()) ) { // search submenus ++it; if ( mi->popup_menu ) { mi = mi->popup_menu->findItem( id, parent ); if ( mi ) // found item return mi; } } return 0; // not found}/*! Returns the index of the menu item with identifier \a id, or -1 if there is no item with such an identifier. \sa idAt(), findItem()*/int QMenuData::indexOf( int id ) const{ if ( id == -1 ) // bad identifier return -1; QMenuItemListIt it( *mitems ); QMenuItem *mi; int index = 0; while ( (mi=it.current()) ) { if ( mi->ident == id ) // this one? return index; ++index; ++it; } return -1; // not found}/*! 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 setId(), indexOf()*/int QMenuData::idAt( int index ) const{ return index < (int)mitems->count() && index >= 0 ? mitems->at(index)->id() : -1;}/*! Sets the menu identifier of the item at \a index to \a id. If index is out of range the operation is ignored. \sa idAt()*/void QMenuData::setId( int index, int id ){ if ( index < (int)mitems->count() ) mitems->at(index)->ident = id;}/*! Sets the parameter of the activation signal of item \a id to \a param. If any receiver takes an integer parameter, this value is passed. \sa connectItem(), disconnectItem(), itemParameter() */bool QMenuData::setItemParameter( int id, int param ) { QMenuItem *mi = findItem( id ); if ( !mi ) // no such identifier return FALSE; if ( !mi->signal_data ) { // create new signal mi->signal_data = new QSignal; CHECK_PTR( mi->signal_data ); } mi->signal_data->setParameter( param ); return TRUE;}/*! Returns the parameter of the activation signal of item \a id. If no parameter has been specified for this item with setItemParameter(), the value defaults to \a id. \sa connectItem(), disconnectItem(), setItemParameter() */int QMenuData::itemParameter( int id ) const{ QMenuItem *mi = findItem( id ); if ( !mi || !mi->signal_data ) return id; return mi->signal_data->parameter();}/*! Connects a menu item to a receiver and a slot or signal. The receiver's slot/signal is activated when the menu item is activated. \sa disconnectItem(), setItemParameter()*/bool QMenuData::connectItem( int id, const QObject *receiver, const char* member ){ QMenuItem *mi = findItem( id ); if ( !mi ) // no such identifier return FALSE; if ( !mi->signal_data ) { // create new signal mi->signal_data = new QSignal; CHECK_PTR( mi->signal_data ); mi->signal_data->setParameter( id ); } return mi->signal_data->connect( receiver, member );}/*! Disconnects a receiver/member from a menu item. All connections are removed when the menu data object is destroyed. \sa connectItem(), setItemParameter()*/bool QMenuData::disconnectItem( int id, const QObject *receiver, const char* member ){ QMenuItem *mi = findItem( id ); if ( !mi || !mi->signal_data ) // no identifier or no signal return FALSE; return mi->signal_data->disconnect( receiver, member );}/*! Sets a Whats This help for a certain menu item. \arg \e id is the menu item id. \arg \e text is the Whats This help text in rich text format ( see QStyleSheet) \sa whatsThis() */void QMenuData::setWhatsThis( int id, const QString& text ){ QMenuData *parent; QMenuItem *mi = findItem( id, &parent ); if ( mi ) { mi->setWhatsThis( text ); parent->menuContentsChanged(); }}/*! Returns the Whats This help text for the specified item \e id or QString::null if no text has been defined yet. \sa setWhatsThis() */QString QMenuData::whatsThis( int id ) const{ QMenuItem *mi = findItem( id ); return mi? mi->whatsThis() : QString::null;}// NOT REVISED/*! \class QCustomMenuItem qmenudata.h \brief The QCustomMenuItem class is an abstract base class for custom menu items in popup menus. A custom menu item is a menu item that is defined by two purely virtual functions, paint() and sizeHint(). The size hint tells the menu how much space it needs to reserve for this item, whereas paint is called whenever the item needs painting. This simply mechanism gives applications the possibility to create all kinds of application specific menu items. Examples are items showing different fonts in a word processor, or menus that allow the selection of drawing utilities in a vector drawing program. A custom item is inserted into a popup menu with QPopupMenu::insertItem(). Per default, a custom item can also have an icon set and/or an accelerator key. You can, however, reimplement fullSpan() to return TRUE if you want the item to span the entire popup menu width. This is in particular useful for labels. If you want the custom item to be treated as a separator only, reimplement isSeparator() to return TRUE. Note that you can also insert pixmaps or bitmaps as items into a popup menu. A custom menu item, however, offers even more flexibility and - which is especially important under windows style - the possibility to draw the item with a different color when it is highlighted. menu/menu.cpp shows a simply example how custom menu items can beused. Please note: QCustomMenu items will not recognize menu shortcuts (text with ampersands in it). <img src=qpopmenu-fancy.png> \sa QMenuData, QPopupMenu*//*! Constructs a QCustomMenuItem */QCustomMenuItem::QCustomMenuItem(){}/*! Destructs a QCustomMenuItem */QCustomMenuItem::~QCustomMenuItem(){}/*! Sets the font of the custom menu item. This function is called whenever the font in the popup menu changes. For menu items that show their own individual font entry, you want to ignore this. */void QCustomMenuItem::setFont( const QFont& ){}/*! Returns whether this item wants to span the entire popup menu width. The default is FALSE, meaning that the menu may show an icon and/or an accelerator key for this item as well. */bool QCustomMenuItem::fullSpan() const{ return FALSE;}/*! Returns whether this item is just a separator. */bool QCustomMenuItem::isSeparator() const{ return FALSE;}/*! \fn void QCustomMenuItem::paint( QPainter* p, const QColorGroup& cg, bool act, bool enabled, int x, int y, int w, int h ); Paints this item. When this function is invoked, the painter \a p is set to the right font and the right foreground color suitable for a menu item text. The item is active according to \a act and enabled/disabled according to \a enabled. The geometry values \a x, \a y, \a w and h specify where to draw the item. Do not draw any background, this has already been done by the popup menu according to the current gui style. *//*! \fn QSize QCustomMenuItem::sizeHint(); Returns the size hint of this item. *//*! Activates the menu item at index \a index. If the index is invalid (for example -1), the object itself is deactivated. */void QMenuData::activateItemAt( int index ){#ifndef QT_NO_MENUBAR if ( isMenuBar ) ( (QMenuBar*)this )->activateItemAt( index ); else#endif if ( isPopupMenu ) ( (QPopupMenu*)this )->activateItemAt( index );}#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -