Source Code (Use browser search to find items of interest.)

Class Index

kdelibs'KContextMenuManager (./kdelibs/kdeui/kcmenumngr.h:78)

class KContextMenuManager : public QObject
{
    Q_OBJECT
public:
    
    /**
       Makes @p popup a context popup menu for widget @p widget.
       
       Ownership of the popup menu is not transferred to the context
       menu manager.
    */
    static void insert( QWidget* widget, QPopupMenu* popup );

    /**
     * Use this method to get information about when a popup menu 
     * should be activated. This can be useful if the popup menu is
     * to be activated from a listview.
     *
     * @return true if the menu should be made visible on a button press
     *         or false after a button press-release sequence.
     */
     static bool showOnButtonPress( void );
    
private slots:
    void widgetDestroyed();
private:
    KContextMenuManager( QObject* parent = 0, const char* name  = 0);
    ~KContextMenuManager();
    bool eventFilter( QObject *, QEvent * );
    QPtrDict<QPopupMenu> menus;
    bool showOnPress;
    int menuKey;
    static KContextMenuManager* manager;
    friend I_really_like_this_class; // avoid warning

    KContextMenuManagerPrivate *d;
};

kdelibs'KContextMenuManager::KContextMenuManager() (./kdelibs/kdeui/kcmenumngr.cpp:35)

KContextMenuManager::KContextMenuManager( QObject* parent, const char* name )
    : QObject( parent, name)
{
    KConfigGroupSaver saver ( KGlobal::config(), QString::fromLatin1("Keys") ) ;
    menuKey = KAccel::stringToKey( saver.config()->readEntry(QString::fromLatin1("PopupContextMenu"), QString::fromLatin1("Menu") ) );
    saver.config()->setGroup( QString::fromLatin1("ContextMenus") ) ;
    showOnPress = saver.config()->readBoolEntry(QString::fromLatin1("ShowOnPress"), TRUE );
}


kdelibs'KContextMenuManager::~KContextMenuManager() (./kdelibs/kdeui/kcmenumngr.cpp:44)

KContextMenuManager::~KContextMenuManager()
{
}



kdelibs'KContextMenuManager::showOnButtonPress() (./kdelibs/kdeui/kcmenumngr.cpp:49)

bool KContextMenuManager::showOnButtonPress( void )
{
  if ( !manager )
	manager = new KContextMenuManager;
  return( manager->showOnPress );
}



kdelibs'KContextMenuManager::insert() (./kdelibs/kdeui/kcmenumngr.cpp:57)

void KContextMenuManager::insert( QWidget* widget, QPopupMenu* popup )
{
    if ( !manager )
	manager = new KContextMenuManager;
    
    manager->connect( widget, SIGNAL( destroyed() ), manager, SLOT( widgetDestroyed() ) );
    manager->menus.insert( widget, popup );
    widget->installEventFilter( manager );
}


kdelibs'KContextMenuManager::eventFilter() (./kdelibs/kdeui/kcmenumngr.cpp:67)

bool KContextMenuManager::eventFilter( QObject *o, QEvent * e)
{
    QPopupMenu* popup = 0;
    QPoint pos;
    switch ( e->type() ) {
    case QEvent::MouseButtonPress:
	if (((QMouseEvent*) e )->button() != RightButton )
	    break;
	if ( !showOnPress )
	    return TRUE; // eat event for safety
	popup = menus[o];
	pos = ((QMouseEvent*) e )->globalPos();
	break;
    case QEvent::MouseButtonRelease:
	if ( showOnPress  || ((QMouseEvent*) e )->button() != RightButton )
	    break;
	popup = menus[o];	
	pos = ((QMouseEvent*) e )->globalPos();
	break;
    case QEvent::KeyPress:
	{
	    if ( !o->isWidgetType() )
		break;
	    QKeyEvent *k = (QKeyEvent *)e;
	    int key = k->key();
	    if ( k->state() & ShiftButton )
		key |= SHIFT;
	    if ( k->state() & ControlButton )
		key |= CTRL;
	    if ( k->state() & AltButton )
		key |= ALT;
	    if ( key != menuKey )
		break;
	    popup = menus[o];
	    if ( popup ) {
		QWidget* w = (QWidget*) o ;
	    
		// ### workaround
		pos = w->mapToGlobal( w->rect().center() );
		// with later Qt snapshot 
		// pos = w->mapToGlobal( w->microFocusHint().center() );
	    }
	}
	break;
    default: 
	break;
    }
    
    if ( popup ) {
	popup->popup( pos );
	return TRUE;
    }
	
    return FALSE;
}


kdelibs'KContextMenuManager::widgetDestroyed() (./kdelibs/kdeui/kcmenumngr.cpp:123)

void KContextMenuManager::widgetDestroyed()
{
    if ( menus.find( (QObject*)sender() ) )
	menus.remove( (QObject*)sender() );
}