?? qaction.cpp
字號:
has to be the application window. \sa accel() */void QAction::setAccel( int key ){ d->key = key;#ifndef QT_NO_ACCEL delete d->accel; d->accel = 0;#endif if ( !key ) { d->update(); return; }#ifndef QT_NO_ACCEL QObject* p = parent(); while ( p && !p->isWidgetType() ) { p = p->parent(); } if ( p ) { d->accel = new QAccel( (QWidget*)p, 0, "qt_action_accel" ); d->accelid = d->accel->insertItem( d->key ); d->accel->connectItem( d->accelid, this, SLOT( internalActivation() ) ); if ( !d->whatsthis.isEmpty() ) d->accel->setWhatsThis( d->accelid, d->whatsthis ); }#if defined(CHECK_STATE) else qWarning( "QAction::setAccel() (%s) requires widget in parent chain.", name( "unnamed" ) );#endif#endif d->update();}/*! Returns the acceleration key. \sa setAccel() */int QAction::accel() const{ return d->key;}/*! Makes the action a toggle action if \e enable is TRUE, or a normal action if \e enable is FALSE. You may want to add toggle actions to a QActionGroup for exclusive toggling. \sa isToggleAction() */void QAction::setToggleAction( bool enable ){ if ( enable == (bool)d->toggleaction ) return; d->toggleaction = enable; d->update();}/*! Returns whether the action is a toggle action or not. \sa setToggleAction() */bool QAction::isToggleAction() const{ return d->toggleaction;}/*! Switches a toggle action on if \e enable is TRUE or off if \e enable is FALSE. This function should be called only for toggle actions. \sa isOn(), setToggleAction() */void QAction::setOn( bool enable ){ if ( !isToggleAction() ) {#if defined(CHECK_STATE) qWarning( "QAction::setOn() (%s) Only toggle actions " "may be switched", name( "unnamed" ) );#endif return; } if ( enable == (bool)d->on ) return; d->on = enable; d->update( QActionPrivate::State ); emit toggled( enable );}/*! Returns TRUE if this toggle action is switched on, or FALSE if it is switched off. \sa setOn(), isToggleAction()*/bool QAction::isOn() const{ return d->on;}/*! Enables the action if \a enable is TRUE, otherwise disables it. Menu items and/or tool buttons presenting the action to the user are updated accordingly. \sa isEnabled() */void QAction::setEnabled( bool enable ){ if ( d->enabled != enable ) { d->enabled = enable;#ifndef QT_NO_ACCEL if ( d->accel ) d->accel->setEnabled( enable );#endif d->update( QActionPrivate::State ); }}/*! Returns TRUE if the action is enabled, or FALSE if it is disabled. \sa setEnabled() */bool QAction::isEnabled() const{ return d->enabled;}void QAction::internalActivation(){ if ( isToggleAction() ) setOn( !isOn() ); emit activated();}void QAction::toolButtonToggled( bool on ){ if ( !isToggleAction() ) return; setOn( on );}/*! Adds this action to widget \a w. Currently supported widget types are QToolBar and QPopupMenu. Returns TRUE when the action was added successfully, FALSE otherwise. \sa removeFrom() */bool QAction::addTo( QWidget* w ){#ifndef QT_NO_TOOLBAR if ( w->inherits( "QToolBar" ) ) { QCString bname = name() + QCString( "_action_button" ); QToolButton* btn = new QToolButton( (QToolBar*) w, bname ); btn->setToggleButton( d->toggleaction ); d->toolbuttons.append( btn ); if ( d->iconset ) btn->setIconSet( *d->iconset ); d->update( QActionPrivate::State ); d->update( QActionPrivate::Everything ); connect( btn, SIGNAL( clicked() ), this, SIGNAL( activated() ) ); connect( btn, SIGNAL( toggled(bool) ), this, SLOT( toolButtonToggled(bool) ) ); connect( btn, SIGNAL( destroyed() ), this, SLOT( objectDestroyed() ) );# ifndef QT_NO_TOOLTIP connect( d->tipGroup, SIGNAL(showTip(const QString&)), this, SLOT(showStatusText(const QString&)) ); connect( d->tipGroup, SIGNAL(removeTip()), this, SLOT(clearStatusText()) );# endif } else#endif if ( w->inherits( "QPopupMenu" ) ) { QActionPrivate::MenuItem* mi = new QActionPrivate::MenuItem; mi->popup = (QPopupMenu*) w; QIconSet* diconset = d->iconset; // stupid GCC 2.7.x compiler if ( diconset ) mi->id = mi->popup->insertItem( *diconset, QString::fromLatin1("") ); else mi->id = mi->popup->insertItem( QString::fromLatin1("") ); mi->popup->connectItem( mi->id, this, SLOT(internalActivation()) ); d->menuitems.append( mi ); d->update( QActionPrivate::State ); d->update( QActionPrivate::Everything ); w->topLevelWidget()->className(); connect( mi->popup, SIGNAL(highlighted(int)), this, SLOT(menuStatusText(int)) ); connect( mi->popup, SIGNAL(aboutToHide()), this, SLOT(clearStatusText()) ); connect( mi->popup, SIGNAL( destroyed() ), this, SLOT( objectDestroyed() ) ); } else { qWarning( "QAction::addTo(), unknown object" ); return FALSE; } return TRUE;}/*! Sets the status message to \a text */void QAction::showStatusText( const QString& text ){ QObject* par; if ( ( par = parent() ) && par->inherits( "QActionGroup" ) ) par = par->parent(); if ( !par || !par->isWidgetType() ) return;#ifndef QT_NO_STATUSBAR QObjectList* l = ( (QWidget*)par )->topLevelWidget()->queryList("QStatusBar"); for ( QStatusBar* bar = (QStatusBar*) l->first(); bar; bar = (QStatusBar*)l->next() ) { if ( text.isEmpty() ) bar->clear(); else bar->message( text ); } delete l;#endif}/*! Sets the status message to the menuitem's status text, or to the tooltip, if there is no status text.*/void QAction::menuStatusText( int id ){ QString text; QListIterator<QActionPrivate::MenuItem> it( d->menuitems); QActionPrivate::MenuItem* mi; while ( ( mi = it.current() ) ) { ++it; if ( mi->id == id ) { text = statusTip(); break; } } if ( !text.isEmpty() ) showStatusText( text );}/*! Clears the status text.*/void QAction::clearStatusText(){ showStatusText( QString::null );}/*! Removes the action from widget \a w Returns TRUE when the action was removed successfully, FALSE otherwise. \sa addTo()*/bool QAction::removeFrom( QWidget* w ){ if ( w->inherits( "QToolBar" ) ) { QListIterator<QToolButton> it( d->toolbuttons); QToolButton* btn; while ( ( btn = it.current() ) ) { ++it; if ( btn->parentWidget() == w ) { d->toolbuttons.removeRef( btn ); disconnect( btn, SIGNAL( destroyed() ), this, SLOT( objectDestroyed() ) ); delete btn; // no need to disconnect from statusbar } } } else if ( w->inherits( "QPopupMenu" ) ) { QListIterator<QActionPrivate::MenuItem> it( d->menuitems); QActionPrivate::MenuItem* mi; while ( ( mi = it.current() ) ) { ++it; if ( mi->popup == w ) { disconnect( mi->popup, SIGNAL(highlighted(int)), this, SLOT(menuStatusText(int)) ); disconnect( mi->popup, SIGNAL(aboutToHide()), this, SLOT(clearStatusText()) ); disconnect( mi->popup, SIGNAL( destroyed() ), this, SLOT( objectDestroyed() ) ); mi->popup->removeItem( mi->id ); d->menuitems.removeRef( mi ); } } } else { qWarning( "QAction::removeFrom(), unknown object" ); return FALSE; } return TRUE;}void QAction::objectDestroyed(){ const QObject* obj = sender(); QListIterator<QActionPrivate::MenuItem> it( d->menuitems); QActionPrivate::MenuItem* mi; while ( ( mi = it.current() ) ) { ++it; if ( mi->popup == obj ) d->menuitems.removeRef( mi ); } d->toolbuttons.removeRef( (QToolButton*) obj );}/*! \fn void QAction::activated() This signal is emitted when the action was activated by the user. \sa toggled()*//*! \fn void QAction::toggled(bool) This signal is emitted when a toggle action changes state. \sa activated(), setToggleAction()*/class QActionGroupPrivate{public: uint exclusive: 1; QList<QAction> actions; QAction* selected;};/*! \class QActionGroup qaction.h \brief The QActionGroup class combines actions to a group. An action group makes it easier to deal with groups of actions. It allows to add, remove or activate its children with a single call and provides radio semantics ("one of many" choice) for toggle actions. QActionGroup is an action by its own and thus can be treated as such. Standard action functions like addTo(), removeFrom() and setEnabled() are automatically performed on all members of the group, i.e. for example that adding a group to a toolbar creates a tool button for each child action. Toggle action handling is controlled with the setExclusive() flag, with the default being TRUE. An exclusive group switches off all toggle actions except the one that was activated. This results in a "one of many" choice similar to a group of radio buttons (see QRadioButton). An exclusive group emits the signal selected() whenever the current child action changes.*//*! Constructs an action group with parent \a parent and name \a name. If \a exclusive is TRUE, any toggle action that is a member of this group is toggled off by another action being toggled on. */QActionGroup::QActionGroup( QWidget* parent, const char* name, bool exclusive ) : QAction( parent, name ){ d = new QActionGroupPrivate; d->exclusive = exclusive; d->selected = 0;}/*! Destroys the object and frees any allocated resources. */QActionGroup::~QActionGroup(){ delete d;}/*! Sets the action group to be exclusive if \e enable is TRUE, or to be non-exclusive if \e enable is FALSE. In an exclusive group, any toggle action that is a member of this group is toggled off by another action being toggled on. \sa isExclusive() */void QActionGroup::setExclusive( bool enable ){ d->exclusive = enable;}/*! Returns TRUE if the action group is exclusive, otherwise FALSE. \sa setExclusive()*/bool QActionGroup::isExclusive() const{ return d->exclusive;}/*! Inserts action \a action to the group. It is not necessary to manually insert actions that have this action group as their parent object. */void QActionGroup::insert( QAction* action ){ if ( d->actions.containsRef( action ) ) return; action->setEnabled( isEnabled() ); d->actions.append( action ); connect( action, SIGNAL( destroyed() ), this, SLOT( childDestroyed() ) ); connect( action, SIGNAL( activated() ), this, SIGNAL( activated() ) ); connect( action, SIGNAL( toggled(bool) ), this, SLOT( childToggled(bool) ) );}/*!\reimp */bool QActionGroup::addTo( QWidget* w ){ for ( QListIterator<QAction> it( d->actions); it.current(); ++it ) { it.current()->addTo( w ); } return TRUE;}/*!\reimp */bool QActionGroup::removeFrom( QWidget* w ){ for ( QListIterator<QAction> it( d->actions); it.current(); ++it ) { it.current()->removeFrom( w ); } return TRUE;}void QActionGroup::childToggled( bool b ){ if ( !isExclusive() ) return; QAction* s = (QAction*) sender(); if ( b ) { if ( s != d->selected ) { d->selected = s; for ( QListIterator<QAction> it( d->actions); it.current(); ++it ) { if ( it.current()->isToggleAction() && it.current() != s ) it.current()->setOn( FALSE ); } emit activated(); emit selected( s ); } } else { if ( s == d->selected ) { // at least one has to be selected s->setOn( TRUE ); } }}void QActionGroup::childDestroyed(){ d->actions.removeRef( (QAction*) sender() ); if ( d->selected == sender() ) d->selected = 0;}/*!\reimp */void QActionGroup::setEnabled( bool enable ){ for ( QListIterator<QAction> it( d->actions); it.current(); ++it ) { it.current()->setEnabled( enable ); } QAction::setEnabled( enable );}/*! \fn void QActionGroup::selected(QAction*) This signal is emitted in exclusive groups when the current toggle action changes. \sa setExclusive()*/#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -