src/gui/widgets/qmenu.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   115         // make the torn-off menu a sibling of p (instead of a child)
   115         // make the torn-off menu a sibling of p (instead of a child)
   116         QWidget *parentWidget = d->causedStack.isEmpty() ? p : d->causedStack.last();
   116         QWidget *parentWidget = d->causedStack.isEmpty() ? p : d->causedStack.last();
   117         if (parentWidget->parentWidget())
   117         if (parentWidget->parentWidget())
   118             parentWidget = parentWidget->parentWidget();
   118             parentWidget = parentWidget->parentWidget();
   119         setParent(parentWidget, Qt::Window | Qt::Tool);
   119         setParent(parentWidget, Qt::Window | Qt::Tool);
   120 	setAttribute(Qt::WA_DeleteOnClose, true);
   120         setAttribute(Qt::WA_DeleteOnClose, true);
   121         setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true);
   121         setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true);
   122         setWindowTitle(p->windowTitle());
   122         setWindowTitle(p->windowTitle());
   123         setEnabled(p->isEnabled());
   123         setEnabled(p->isEnabled());
   124         //QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*)));
   124         //QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*)));
   125         //QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*)));
   125         //QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*)));
  1224     if (action->menu())
  1224     if (action->menu())
  1225         option->menuItemType = QStyleOptionMenuItem::SubMenu;
  1225         option->menuItemType = QStyleOptionMenuItem::SubMenu;
  1226     else if (action->isSeparator())
  1226     else if (action->isSeparator())
  1227         option->menuItemType = QStyleOptionMenuItem::Separator;
  1227         option->menuItemType = QStyleOptionMenuItem::Separator;
  1228     else if (d->defaultAction == action)
  1228     else if (d->defaultAction == action)
  1229 	    option->menuItemType = QStyleOptionMenuItem::DefaultItem;
  1229         option->menuItemType = QStyleOptionMenuItem::DefaultItem;
  1230     else
  1230     else
  1231         option->menuItemType = QStyleOptionMenuItem::Normal;
  1231         option->menuItemType = QStyleOptionMenuItem::Normal;
  1232     if (action->isIconVisibleInMenu())
  1232     if (action->isIconVisibleInMenu())
  1233         option->icon = action->icon();
  1233         option->icon = action->icon();
  1234     QString textAndAccel = action->text();
  1234     QString textAndAccel = action->text();
  1586     insertAction(before, action);
  1586     insertAction(before, action);
  1587     return action;
  1587     return action;
  1588 }
  1588 }
  1589 
  1589 
  1590 /*!
  1590 /*!
  1591   This will set the default action to \a act. The default action may
  1591   This sets the default action to \a act. The default action may have
  1592   have a visual queue depending on the current QStyle. A default
  1592   a visual cue, depending on the current QStyle. A default action
  1593   action is usually meant to indicate what will defaultly happen on a
  1593   usually indicates what will happen by default when a drop occurs.
  1594   drop, as shown in a context menu.
       
  1595 
  1594 
  1596   \sa defaultAction()
  1595   \sa defaultAction()
  1597 */
  1596 */
  1598 void QMenu::setDefaultAction(QAction *act)
  1597 void QMenu::setDefaultAction(QAction *act)
  1599 {
  1598 {
  1718     \sa removeAction()
  1717     \sa removeAction()
  1719 */
  1718 */
  1720 void QMenu::clear()
  1719 void QMenu::clear()
  1721 {
  1720 {
  1722     QList<QAction*> acts = actions();
  1721     QList<QAction*> acts = actions();
       
  1722 
  1723     for(int i = 0; i < acts.size(); i++) {
  1723     for(int i = 0; i < acts.size(); i++) {
       
  1724 #ifdef QT_SOFTKEYS_ENABLED
       
  1725         Q_D(QMenu);
       
  1726         // Lets not touch to our internal softkey actions
       
  1727         if(acts[i] == d->selectAction || acts[i] == d->cancelAction)
       
  1728             continue;
       
  1729 #endif
  1724         removeAction(acts[i]);
  1730         removeAction(acts[i]);
  1725         if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty())
  1731         if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty())
  1726             delete acts[i];
  1732             delete acts[i];
  1727     }
  1733     }
  1728 }
  1734 }
  2406         if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) {
  2412         if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) {
  2407             if (action->whatsThis().size() || action->menu())
  2413             if (action->whatsThis().size() || action->menu())
  2408                 e->accept();
  2414                 e->accept();
  2409         }
  2415         }
  2410         return true;
  2416         return true;
       
  2417 #endif
       
  2418 #ifdef QT_SOFTKEYS_ENABLED
       
  2419     case QEvent::LanguageChange: {
       
  2420         d->selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey));
       
  2421         d->cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey));
       
  2422         }
       
  2423         break;
  2411 #endif
  2424 #endif
  2412     default:
  2425     default:
  2413         break;
  2426         break;
  2414     }
  2427     }
  2415     return QWidget::event(e);
  2428     return QWidget::event(e);
  2918     else if (e->type() == QEvent::ActionChanged)
  2931     else if (e->type() == QEvent::ActionChanged)
  2919         d->symbian_menu->syncAction(e->action());
  2932         d->symbian_menu->syncAction(e->action());
  2920 #endif
  2933 #endif
  2921     if (isVisible()) {
  2934     if (isVisible()) {
  2922         d->updateActionRects();
  2935         d->updateActionRects();
  2923 	resize(sizeHint());
  2936         resize(sizeHint());
  2924         update();
  2937         update();
  2925     }
  2938     }
  2926 }
  2939 }
  2927 
  2940 
  2928 /*!
  2941 /*!