Esempio n. 1
0
void MenuManager::kmenuAccelActivated()
{
    if(m_kmenu->isVisible())
    {
        m_kmenu->hide();
        return;
    }

    m_kmenu->initialize();

    if(m_kbuttons.isEmpty())
    {
        // no button to use, make it behave like a desktop menu
        QPoint p;
        // Popup the K-menu at the center of the screen.
        QDesktopWidget *desktop = KApplication::desktop();
        QRect r = desktop->screenGeometry(desktop->screenNumber(QCursor::pos()));
        // kMenu->rect() is not valid before showing, use sizeHint()
        p = r.center() - QRect(QPoint(0, 0), m_kmenu->sizeHint()).center();
        m_kmenu->popup(p);

        // when the cursor is in the area where the menu pops up,
        // the item under the cursor gets selected. The single shot
        // avoids this from happening by allowing the item to be selected
        // when the event loop is enterred, and then resetting it.
        QTimer::singleShot(0, this, SLOT(slotSetKMenuItemActive()));
    }
    else
    {
        // We need the kmenu's size to place it at the right position.
        // We cannot rely on the popup menu's current size(), if it wasn't
        // shown before, so we resize it here according to its sizeHint().
        const QSize size = m_kmenu->sizeHint();
        m_kmenu->resize(size.width(), size.height());

        PanelPopupButton *button = findKButtonFor(m_kmenu);

        // let's unhide the panel while we're at it. traverse the widget
        // hierarchy until we find the panel, if any
        QObject *menuParent = button->parent();
        while(menuParent)
        {
            ExtensionContainer *ext = dynamic_cast< ExtensionContainer * >(menuParent);

            if(ext)
            {
                ext->unhideIfHidden();
                // make sure it's unhidden before we use it to figure out
                // where to popup
                qApp->processEvents();
                break;
            }

            menuParent = menuParent->parent();
        }

        button->showMenu();
    }
}
Esempio n. 2
0
void PanelKMenu::showMenu()
{
    kdDebug( 1210 ) << "PanelKMenu::showMenu()" << endl;
    PanelPopupButton *kButton = MenuManager::the()->findKButtonFor(this);
    if (kButton)
    {
        adjustSize();
        kButton->showMenu();
    }
    else
    {
        show();
    }
}