示例#1
0
void Menu::closeAllMenus()
{
    QMenu* parentMenu = this;

    while (parentMenu) {
        parentMenu->close();
        parentMenu = qobject_cast<QMenu*>(parentMenu->parentWidget());
    }
}
示例#2
0
文件: KxMenuItem.cpp 项目: lihw/glf
bool KxMenuItem::saveToShelf(int whichAction)
{
    // First check that this is not a submenu item or separator
    if(menu() != NULL || isSeparator()) return false;

    // Only menu items from main menu bar are allowed to be saved to shelf.

    // Get topmost parent menu
    QMenu *menu = qobject_cast<QMenu *>(parent());
    QMenu *parentMenu = qobject_cast<QMenu *>(menu->parentWidget());
    while(parentMenu) {
        menu = parentMenu;
        parentMenu = qobject_cast<QMenu *>(menu->parentWidget());
    }

    // Now get the menu bar
    QMenuBar *mbar = qobject_cast<QMenuBar *>(menu->parentWidget());

    // Bail if parentWidget() is not a QMenuBar
    //
    if( mbar != NULL ){
        // Check if this is main menu bar
        QVariant v = qApp->property("mainWindow");
        if(v.isValid()) {
            QWidget *mainWindow = (QWidget *)(v.value<void *>());
            if(mbar->parentWidget() == mainWindow) {
                //QString menuName;
                //QString cmdStr(kShelfMenuItemCmd);
                QAction *a = whichAction == kMainAction ? this : this->optionBoxAction();
                if(NULL != a) {
                   // gUIInventory->fullName(a, menuName);
                    //cmdStr.append(menuName);
                   // cmdStr.appendChar(kBackSlashDoubleQuote);
                    //theCommandEngine->executeCommand( cmdStr );
                    return true;
                }
            }
        }
    }

    return false;
}
bool DlgExpressionInput::eventFilter(QObject *obj, QEvent *ev)
{
    // if the user clicks on a widget different to this
    if (ev->type() == QEvent::MouseButtonPress && obj != this) {
        // Since the widget has a transparent background we cannot rely
        // on the size of the widget. Instead, it must be checked if the
        // cursor is on this or an underlying widget or outside.
        if (!underMouse()) {
            // if the expression fields context-menu is open do not close the dialog
            QMenu* menu = qobject_cast<QMenu*>(obj);
            if (menu && menu->parentWidget() == ui->expression) {
                return false;
            }
            bool on = ui->expression->completerActive();
            // Do this only if the completer is not shown
            if (!on) {
                qApp->removeEventFilter(this);
                reject();
            }
        }
    }

    return false;
}