| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qmenubar.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | #include <qmenubar.h> | - | ||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||
| 36 | #include <qstyle.h> | - | ||||||||||||||||||||||||
| 37 | #include <qlayout.h> | - | ||||||||||||||||||||||||
| 38 | #include <qapplication.h> | - | ||||||||||||||||||||||||
| 39 | #include <qdesktopwidget.h> | - | ||||||||||||||||||||||||
| 40 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 41 | # include <qaccessible.h> | - | ||||||||||||||||||||||||
| 42 | #endif | - | ||||||||||||||||||||||||
| 43 | #include <qpainter.h> | - | ||||||||||||||||||||||||
| 44 | #include <qstylepainter.h> | - | ||||||||||||||||||||||||
| 45 | #include <qevent.h> | - | ||||||||||||||||||||||||
| 46 | #include <qmainwindow.h> | - | ||||||||||||||||||||||||
| 47 | #include <qtoolbar.h> | - | ||||||||||||||||||||||||
| 48 | #include <qtoolbutton.h> | - | ||||||||||||||||||||||||
| 49 | #include <qwhatsthis.h> | - | ||||||||||||||||||||||||
| 50 | #include <qpa/qplatformtheme.h> | - | ||||||||||||||||||||||||
| 51 | #include "private/qguiapplication_p.h" | - | ||||||||||||||||||||||||
| 52 | #include "qpa/qplatformintegration.h" | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | #include "qmenu_p.h" | - | ||||||||||||||||||||||||
| 58 | #include "qmenubar_p.h" | - | ||||||||||||||||||||||||
| 59 | #include "qdebug.h" | - | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||||||||
| 62 | extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp | - | ||||||||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||
| 65 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | class QMenuBarExtension : public QToolButton | - | ||||||||||||||||||||||||
| 68 | { | - | ||||||||||||||||||||||||
| 69 | public: | - | ||||||||||||||||||||||||
| 70 | explicit QMenuBarExtension(QWidget *parent); | - | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | QSize sizeHint() const Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
| 73 | void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; | - | ||||||||||||||||||||||||
| 74 | }; | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | QMenuBarExtension::QMenuBarExtension(QWidget *parent) | - | ||||||||||||||||||||||||
| 77 | : QToolButton(parent) | - | ||||||||||||||||||||||||
| 78 | { | - | ||||||||||||||||||||||||
| 79 | setObjectName(QLatin1String("qt_menubar_ext_button")); | - | ||||||||||||||||||||||||
| 80 | setAutoRaise(true); | - | ||||||||||||||||||||||||
| 81 | #ifndef QT_NO_MENU | - | ||||||||||||||||||||||||
| 82 | setPopupMode(QToolButton::InstantPopup); | - | ||||||||||||||||||||||||
| 83 | #endif | - | ||||||||||||||||||||||||
| 84 | setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton, 0, parentWidget())); | - | ||||||||||||||||||||||||
| 85 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | void QMenuBarExtension::paintEvent(QPaintEvent *) | - | ||||||||||||||||||||||||
| 88 | { | - | ||||||||||||||||||||||||
| 89 | QStylePainter p(this); | - | ||||||||||||||||||||||||
| 90 | QStyleOptionToolButton opt; | - | ||||||||||||||||||||||||
| 91 | initStyleOption(&opt); | - | ||||||||||||||||||||||||
| 92 | // We do not need to draw both extension arrows | - | ||||||||||||||||||||||||
| 93 | opt.features &= ~QStyleOptionToolButton::HasMenu; | - | ||||||||||||||||||||||||
| 94 | p.drawComplexControl(QStyle::CC_ToolButton, opt); | - | ||||||||||||||||||||||||
| 95 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | QSize QMenuBarExtension::sizeHint() const | - | ||||||||||||||||||||||||
| 99 | { | - | ||||||||||||||||||||||||
| 100 | int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent, 0, parentWidget()); | - | ||||||||||||||||||||||||
| 101 | return QSize(ext, ext); never executed: return QSize(ext, ext); | 0 | ||||||||||||||||||||||||
| 102 | } | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | - | |||||||||||||||||||||||||
| 105 | /*! | - | ||||||||||||||||||||||||
| 106 | \internal | - | ||||||||||||||||||||||||
| 107 | */ | - | ||||||||||||||||||||||||
| 108 | QAction *QMenuBarPrivate::actionAt(QPoint p) const | - | ||||||||||||||||||||||||
| 109 | { | - | ||||||||||||||||||||||||
| 110 | for(int i = 0; i < actions.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 111 | if(actionRect(actions.at(i)).contains(p))
| 0 | ||||||||||||||||||||||||
| 112 | return actions.at(i); never executed: return actions.at(i); | 0 | ||||||||||||||||||||||||
| 113 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 114 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 115 | } | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | QRect QMenuBarPrivate::menuRect(bool extVisible) const | - | ||||||||||||||||||||||||
| 118 | { | - | ||||||||||||||||||||||||
| 119 | Q_Q(const QMenuBar); | - | ||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||
| 121 | int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - | ||||||||||||||||||||||||
| 122 | QRect result = q->rect(); | - | ||||||||||||||||||||||||
| 123 | result.adjust(hmargin, 0, -hmargin, 0); | - | ||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | if (extVisible) {
| 0 | ||||||||||||||||||||||||
| 126 | if (q->isRightToLeft())
| 0 | ||||||||||||||||||||||||
| 127 | result.setLeft(result.left() + extension->sizeHint().width()); never executed: result.setLeft(result.left() + extension->sizeHint().width()); | 0 | ||||||||||||||||||||||||
| 128 | else | - | ||||||||||||||||||||||||
| 129 | result.setWidth(result.width() - extension->sizeHint().width()); never executed: result.setWidth(result.width() - extension->sizeHint().width()); | 0 | ||||||||||||||||||||||||
| 130 | } | - | ||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | if (leftWidget && leftWidget->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 133 | QSize sz = leftWidget->sizeHint(); | - | ||||||||||||||||||||||||
| 134 | if (q->isRightToLeft())
| 0 | ||||||||||||||||||||||||
| 135 | result.setRight(result.right() - sz.width()); never executed: result.setRight(result.right() - sz.width()); | 0 | ||||||||||||||||||||||||
| 136 | else | - | ||||||||||||||||||||||||
| 137 | result.setLeft(result.left() + sz.width()); never executed: result.setLeft(result.left() + sz.width()); | 0 | ||||||||||||||||||||||||
| 138 | } | - | ||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | if (rightWidget && rightWidget->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 141 | QSize sz = rightWidget->sizeHint(); | - | ||||||||||||||||||||||||
| 142 | if (q->isRightToLeft())
| 0 | ||||||||||||||||||||||||
| 143 | result.setLeft(result.left() + sz.width()); never executed: result.setLeft(result.left() + sz.width()); | 0 | ||||||||||||||||||||||||
| 144 | else | - | ||||||||||||||||||||||||
| 145 | result.setRight(result.right() - sz.width()); never executed: result.setRight(result.right() - sz.width()); | 0 | ||||||||||||||||||||||||
| 146 | } | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 149 | } | - | ||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||
| 151 | bool QMenuBarPrivate::isVisible(QAction *action) | - | ||||||||||||||||||||||||
| 152 | { | - | ||||||||||||||||||||||||
| 153 | return !hiddenActions.contains(action); never executed: return !hiddenActions.contains(action); | 0 | ||||||||||||||||||||||||
| 154 | } | - | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | void QMenuBarPrivate::updateGeometries() | - | ||||||||||||||||||||||||
| 157 | { | - | ||||||||||||||||||||||||
| 158 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 159 | if(!itemsDirty)
| 0 | ||||||||||||||||||||||||
| 160 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 161 | int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2); | - | ||||||||||||||||||||||||
| 162 | int q_start = -1; | - | ||||||||||||||||||||||||
| 163 | if(leftWidget || rightWidget) {
| 0 | ||||||||||||||||||||||||
| 164 | int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q) | - | ||||||||||||||||||||||||
| 165 | + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - | ||||||||||||||||||||||||
| 166 | int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q) | - | ||||||||||||||||||||||||
| 167 | + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - | ||||||||||||||||||||||||
| 168 | if (leftWidget && leftWidget->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 169 | QSize sz = leftWidget->sizeHint(); | - | ||||||||||||||||||||||||
| 170 | q_width -= sz.width(); | - | ||||||||||||||||||||||||
| 171 | q_start = sz.width(); | - | ||||||||||||||||||||||||
| 172 | QPoint pos(hmargin, (q->height() - leftWidget->height()) / 2); | - | ||||||||||||||||||||||||
| 173 | QRect vRect = QStyle::visualRect(q->layoutDirection(), q->rect(), QRect(pos, sz)); | - | ||||||||||||||||||||||||
| 174 | leftWidget->setGeometry(vRect); | - | ||||||||||||||||||||||||
| 175 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 176 | if (rightWidget && rightWidget->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 177 | QSize sz = rightWidget->sizeHint(); | - | ||||||||||||||||||||||||
| 178 | q_width -= sz.width(); | - | ||||||||||||||||||||||||
| 179 | QPoint pos(q->width() - sz.width() - hmargin, vmargin); | - | ||||||||||||||||||||||||
| 180 | QRect vRect = QStyle::visualRect(q->layoutDirection(), q->rect(), QRect(pos, sz)); | - | ||||||||||||||||||||||||
| 181 | rightWidget->setGeometry(vRect); | - | ||||||||||||||||||||||||
| 182 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 183 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
| 186 | if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. | - | ||||||||||||||||||||||||
| 187 | itemsDirty = false; | - | ||||||||||||||||||||||||
| 188 | return; | - | ||||||||||||||||||||||||
| 189 | } | - | ||||||||||||||||||||||||
| 190 | #endif | - | ||||||||||||||||||||||||
| 191 | calcActionRects(q_width, q_start); | - | ||||||||||||||||||||||||
| 192 | currentAction = 0; | - | ||||||||||||||||||||||||
| 193 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||
| 194 | if(itemsDirty) {
| 0 | ||||||||||||||||||||||||
| 195 | for(int j = 0; j < shortcutIndexMap.size(); ++j)
| 0 | ||||||||||||||||||||||||
| 196 | q->releaseShortcut(shortcutIndexMap.value(j)); never executed: q->releaseShortcut(shortcutIndexMap.value(j)); | 0 | ||||||||||||||||||||||||
| 197 | shortcutIndexMap.resize(0); // faster than clear | - | ||||||||||||||||||||||||
| 198 | const int actionsCount = actions.count(); | - | ||||||||||||||||||||||||
| 199 | shortcutIndexMap.reserve(actionsCount); | - | ||||||||||||||||||||||||
| 200 | for (int i = 0; i < actionsCount; i++)
| 0 | ||||||||||||||||||||||||
| 201 | shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); never executed: shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); | 0 | ||||||||||||||||||||||||
| 202 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 203 | #endif | - | ||||||||||||||||||||||||
| 204 | itemsDirty = false; | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | hiddenActions.clear(); | - | ||||||||||||||||||||||||
| 207 | //this is the menu rectangle without any extension | - | ||||||||||||||||||||||||
| 208 | QRect menuRect = this->menuRect(false); | - | ||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||
| 210 | //we try to see if the actions will fit there | - | ||||||||||||||||||||||||
| 211 | bool hasHiddenActions = false; | - | ||||||||||||||||||||||||
| 212 | for (int i = 0; i < actions.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 213 | const QRect &rect = actionRects.at(i); | - | ||||||||||||||||||||||||
| 214 | if (rect.isValid() && !menuRect.contains(rect)) {
| 0 | ||||||||||||||||||||||||
| 215 | hasHiddenActions = true; | - | ||||||||||||||||||||||||
| 216 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 217 | } | - | ||||||||||||||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | //...and if not, determine the ones that fit on the menu with the extension visible | - | ||||||||||||||||||||||||
| 221 | if (hasHiddenActions) {
| 0 | ||||||||||||||||||||||||
| 222 | menuRect = this->menuRect(true); | - | ||||||||||||||||||||||||
| 223 | for (int i = 0; i < actions.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 224 | const QRect &rect = actionRects.at(i); | - | ||||||||||||||||||||||||
| 225 | if (rect.isValid() && !menuRect.contains(rect)) {
| 0 | ||||||||||||||||||||||||
| 226 | hiddenActions.append(actions.at(i)); | - | ||||||||||||||||||||||||
| 227 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 228 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 229 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | if (hiddenActions.count() > 0) {
| 0 | ||||||||||||||||||||||||
| 232 | QMenu *pop = extension->menu(); | - | ||||||||||||||||||||||||
| 233 | if (!pop) {
| 0 | ||||||||||||||||||||||||
| 234 | pop = new QMenu(q); | - | ||||||||||||||||||||||||
| 235 | extension->setMenu(pop); | - | ||||||||||||||||||||||||
| 236 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 237 | pop->clear(); | - | ||||||||||||||||||||||||
| 238 | pop->addActions(hiddenActions); | - | ||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||
| 240 | int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q); | - | ||||||||||||||||||||||||
| 241 | int x = q->isRightToLeft()
| 0 | ||||||||||||||||||||||||
| 242 | ? menuRect.left() - extension->sizeHint().width() + 1 | - | ||||||||||||||||||||||||
| 243 | : menuRect.right(); | - | ||||||||||||||||||||||||
| 244 | extension->setGeometry(x, vmargin, extension->sizeHint().width(), menuRect.height() - vmargin*2); | - | ||||||||||||||||||||||||
| 245 | extension->show(); | - | ||||||||||||||||||||||||
| 246 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 247 | extension->hide(); | - | ||||||||||||||||||||||||
| 248 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 249 | q->updateGeometry(); | - | ||||||||||||||||||||||||
| 250 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | QRect QMenuBarPrivate::actionRect(QAction *act) const | - | ||||||||||||||||||||||||
| 253 | { | - | ||||||||||||||||||||||||
| 254 | const int index = actions.indexOf(act); | - | ||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | //makes sure the geometries are up-to-date | - | ||||||||||||||||||||||||
| 257 | const_cast<QMenuBarPrivate*>(this)->updateGeometries(); | - | ||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||
| 259 | if (index < 0 || index >= actionRects.count())
| 0 | ||||||||||||||||||||||||
| 260 | return QRect(); // that can happen in case of native menubar never executed: return QRect(); | 0 | ||||||||||||||||||||||||
| 261 | - | |||||||||||||||||||||||||
| 262 | return actionRects.at(index); never executed: return actionRects.at(index); | 0 | ||||||||||||||||||||||||
| 263 | } | - | ||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||
| 265 | void QMenuBarPrivate::focusFirstAction() | - | ||||||||||||||||||||||||
| 266 | { | - | ||||||||||||||||||||||||
| 267 | if(!currentAction) {
| 0 | ||||||||||||||||||||||||
| 268 | updateGeometries(); | - | ||||||||||||||||||||||||
| 269 | int index = 0; | - | ||||||||||||||||||||||||
| 270 | while (index < actions.count() && actionRects.at(index).isNull()) ++index; never executed: ++index;
| 0 | ||||||||||||||||||||||||
| 271 | if (index < actions.count())
| 0 | ||||||||||||||||||||||||
| 272 | setCurrentAction(actions.at(index)); never executed: setCurrentAction(actions.at(index)); | 0 | ||||||||||||||||||||||||
| 273 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 274 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | void QMenuBarPrivate::setKeyboardMode(bool b) | - | ||||||||||||||||||||||||
| 277 | { | - | ||||||||||||||||||||||||
| 278 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 279 | if (b && !q->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, q)) {
| 0 | ||||||||||||||||||||||||
| 280 | setCurrentAction(0); | - | ||||||||||||||||||||||||
| 281 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 282 | } | - | ||||||||||||||||||||||||
| 283 | keyboardState = b; | - | ||||||||||||||||||||||||
| 284 | if(b) {
| 0 | ||||||||||||||||||||||||
| 285 | QWidget *fw = QApplication::focusWidget(); | - | ||||||||||||||||||||||||
| 286 | if (fw != q)
| 0 | ||||||||||||||||||||||||
| 287 | keyboardFocusWidget = fw; never executed: keyboardFocusWidget = fw; | 0 | ||||||||||||||||||||||||
| 288 | focusFirstAction(); | - | ||||||||||||||||||||||||
| 289 | q->setFocus(Qt::MenuBarFocusReason); | - | ||||||||||||||||||||||||
| 290 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 291 | if(!popupState)
| 0 | ||||||||||||||||||||||||
| 292 | setCurrentAction(0); never executed: setCurrentAction(0); | 0 | ||||||||||||||||||||||||
| 293 | if(keyboardFocusWidget) {
| 0 | ||||||||||||||||||||||||
| 294 | if (QApplication::focusWidget() == q)
| 0 | ||||||||||||||||||||||||
| 295 | keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason); never executed: keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason); | 0 | ||||||||||||||||||||||||
| 296 | keyboardFocusWidget = 0; | - | ||||||||||||||||||||||||
| 297 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 298 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 299 | q->update(); | - | ||||||||||||||||||||||||
| 300 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) | - | ||||||||||||||||||||||||
| 303 | { | - | ||||||||||||||||||||||||
| 304 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 305 | if(!action || !action->menu() || closePopupMode)
| 0 | ||||||||||||||||||||||||
| 306 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 307 | popupState = true; | - | ||||||||||||||||||||||||
| 308 | if (action->isEnabled() && action->menu()->isEnabled()) {
| 0 | ||||||||||||||||||||||||
| 309 | closePopupMode = 0; | - | ||||||||||||||||||||||||
| 310 | activeMenu = action->menu(); | - | ||||||||||||||||||||||||
| 311 | activeMenu->d_func()->causedPopup.widget = q; | - | ||||||||||||||||||||||||
| 312 | activeMenu->d_func()->causedPopup.action = action; | - | ||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||
| 314 | QRect adjustedActionRect = actionRect(action); | - | ||||||||||||||||||||||||
| 315 | QPoint pos(q->mapToGlobal(QPoint(adjustedActionRect.left(), adjustedActionRect.bottom() + 1))); | - | ||||||||||||||||||||||||
| 316 | QSize popup_size = activeMenu->sizeHint(); | - | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | //we put the popup menu on the screen containing the bottom-center of the action rect | - | ||||||||||||||||||||||||
| 319 | QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0)); | - | ||||||||||||||||||||||||
| 320 | pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y())); | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height()); | - | ||||||||||||||||||||||||
| 323 | const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom()); | - | ||||||||||||||||||||||||
| 324 | const bool rtl = q->isRightToLeft(); | - | ||||||||||||||||||||||||
| 325 | const int actionWidth = adjustedActionRect.width(); | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | if (!fitUp && !fitDown) { //we should shift the menu
| 0 | ||||||||||||||||||||||||
| 328 | bool shouldShiftToRight = !rtl; | - | ||||||||||||||||||||||||
| 329 | if (rtl && popup_size.width() > pos.x())
| 0 | ||||||||||||||||||||||||
| 330 | shouldShiftToRight = true; never executed: shouldShiftToRight = true; | 0 | ||||||||||||||||||||||||
| 331 | else if (actionWidth + popup_size.width() + pos.x() > screenRect.right())
| 0 | ||||||||||||||||||||||||
| 332 | shouldShiftToRight = false; never executed: shouldShiftToRight = false; | 0 | ||||||||||||||||||||||||
| 333 | - | |||||||||||||||||||||||||
| 334 | if (shouldShiftToRight) {
| 0 | ||||||||||||||||||||||||
| 335 | pos.rx() += actionWidth + (rtl ? popup_size.width() : 0);
| 0 | ||||||||||||||||||||||||
| 336 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 337 | //shift to left | - | ||||||||||||||||||||||||
| 338 | if (!rtl)
| 0 | ||||||||||||||||||||||||
| 339 | pos.rx() -= popup_size.width(); never executed: pos.rx() -= popup_size.width(); | 0 | ||||||||||||||||||||||||
| 340 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 341 | } else if (rtl) {
| 0 | ||||||||||||||||||||||||
| 342 | pos.rx() += actionWidth; | - | ||||||||||||||||||||||||
| 343 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | if(!defaultPopDown || (fitUp && !fitDown))
| 0 | ||||||||||||||||||||||||
| 346 | pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y())); never executed: pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y())); | 0 | ||||||||||||||||||||||||
| 347 | activeMenu->popup(pos); | - | ||||||||||||||||||||||||
| 348 | if(activateFirst)
| 0 | ||||||||||||||||||||||||
| 349 | activeMenu->d_func()->setFirstActionActive(); never executed: activeMenu->d_func()->setFirstActionActive(); | 0 | ||||||||||||||||||||||||
| 350 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 351 | q->update(actionRect(action)); | - | ||||||||||||||||||||||||
| 352 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 353 | - | |||||||||||||||||||||||||
| 354 | void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst) | - | ||||||||||||||||||||||||
| 355 | { | - | ||||||||||||||||||||||||
| 356 | if(currentAction == action && popup == popupState)
| 0 | ||||||||||||||||||||||||
| 357 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | autoReleaseTimer.stop(); | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | doChildEffects = (popup && !activeMenu);
| 0 | ||||||||||||||||||||||||
| 362 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 363 | QWidget *fw = 0; | - | ||||||||||||||||||||||||
| 364 | if(QMenu *menu = activeMenu) {
| 0 | ||||||||||||||||||||||||
| 365 | activeMenu = 0; | - | ||||||||||||||||||||||||
| 366 | if (popup) {
| 0 | ||||||||||||||||||||||||
| 367 | fw = q->window()->focusWidget(); | - | ||||||||||||||||||||||||
| 368 | q->setFocus(Qt::NoFocusReason); | - | ||||||||||||||||||||||||
| 369 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 370 | menu->hide(); | - | ||||||||||||||||||||||||
| 371 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | if(currentAction)
| 0 | ||||||||||||||||||||||||
| 374 | q->update(actionRect(currentAction)); never executed: q->update(actionRect(currentAction)); | 0 | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | popupState = popup; | - | ||||||||||||||||||||||||
| 377 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||||||||
| 378 | QAction *previousAction = currentAction; | - | ||||||||||||||||||||||||
| 379 | #endif | - | ||||||||||||||||||||||||
| 380 | currentAction = action; | - | ||||||||||||||||||||||||
| 381 | if (action && action->isEnabled()) {
| 0 | ||||||||||||||||||||||||
| 382 | activateAction(action, QAction::Hover); | - | ||||||||||||||||||||||||
| 383 | if(popup)
| 0 | ||||||||||||||||||||||||
| 384 | popupAction(action, activateFirst); never executed: popupAction(action, activateFirst); | 0 | ||||||||||||||||||||||||
| 385 | q->update(actionRect(action)); | - | ||||||||||||||||||||||||
| 386 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||||||||
| 387 | } else if (previousAction) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 388 | QString empty; | - | ||||||||||||||||||||||||
| 389 | QStatusTipEvent tip(empty); | - | ||||||||||||||||||||||||
| 390 | QApplication::sendEvent(q, &tip); | - | ||||||||||||||||||||||||
| 391 | #endif | - | ||||||||||||||||||||||||
| 392 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 393 | if (fw)
| 0 | ||||||||||||||||||||||||
| 394 | fw->setFocus(Qt::NoFocusReason); never executed: fw->setFocus(Qt::NoFocusReason); | 0 | ||||||||||||||||||||||||
| 395 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | void QMenuBarPrivate::calcActionRects(int max_width, int start) const | - | ||||||||||||||||||||||||
| 398 | { | - | ||||||||||||||||||||||||
| 399 | Q_Q(const QMenuBar); | - | ||||||||||||||||||||||||
| 400 | - | |||||||||||||||||||||||||
| 401 | if(!itemsDirty)
| 0 | ||||||||||||||||||||||||
| 402 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | //let's reinitialize the buffer | - | ||||||||||||||||||||||||
| 405 | actionRects.resize(actions.count()); | - | ||||||||||||||||||||||||
| 406 | actionRects.fill(QRect()); | - | ||||||||||||||||||||||||
| 407 | - | |||||||||||||||||||||||||
| 408 | const QStyle *style = q->style(); | - | ||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||
| 410 | const int itemSpacing = style->pixelMetric(QStyle::PM_MenuBarItemSpacing, 0, q); | - | ||||||||||||||||||||||||
| 411 | int max_item_height = 0, separator = -1, separator_start = 0, separator_len = 0; | - | ||||||||||||||||||||||||
| 412 | - | |||||||||||||||||||||||||
| 413 | //calculate size | - | ||||||||||||||||||||||||
| 414 | const QFontMetrics fm = q->fontMetrics(); | - | ||||||||||||||||||||||||
| 415 | const int hmargin = style->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q), | - | ||||||||||||||||||||||||
| 416 | vmargin = style->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q), | - | ||||||||||||||||||||||||
| 417 | icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q); | - | ||||||||||||||||||||||||
| 418 | for(int i = 0; i < actions.count(); i++) {
| 0 | ||||||||||||||||||||||||
| 419 | QAction *action = actions.at(i); | - | ||||||||||||||||||||||||
| 420 | if(!action->isVisible())
| 0 | ||||||||||||||||||||||||
| 421 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | QSize sz; | - | ||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||
| 425 | //calc what I think the size is.. | - | ||||||||||||||||||||||||
| 426 | if(action->isSeparator()) {
| 0 | ||||||||||||||||||||||||
| 427 | if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q))
| 0 | ||||||||||||||||||||||||
| 428 | separator = i; never executed: separator = i; | 0 | ||||||||||||||||||||||||
| 429 | continue; //we don't really position these! never executed: continue; | 0 | ||||||||||||||||||||||||
| 430 | } else { | - | ||||||||||||||||||||||||
| 431 | const QString s = action->text(); | - | ||||||||||||||||||||||||
| 432 | QIcon is = action->icon(); | - | ||||||||||||||||||||||||
| 433 | // If an icon is set, only the icon is visible | - | ||||||||||||||||||||||||
| 434 | if (!is.isNull())
| 0 | ||||||||||||||||||||||||
| 435 | sz = sz.expandedTo(QSize(icone, icone)); never executed: sz = sz.expandedTo(QSize(icone, icone)); | 0 | ||||||||||||||||||||||||
| 436 | else if (!s.isEmpty())
| 0 | ||||||||||||||||||||||||
| 437 | sz = fm.size(Qt::TextShowMnemonic, s); never executed: sz = fm.size(Qt::TextShowMnemonic, s); | 0 | ||||||||||||||||||||||||
| 438 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||
| 440 | //let the style modify the above size.. | - | ||||||||||||||||||||||||
| 441 | QStyleOptionMenuItem opt; | - | ||||||||||||||||||||||||
| 442 | q->initStyleOption(&opt, action); | - | ||||||||||||||||||||||||
| 443 | sz = q->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, q); | - | ||||||||||||||||||||||||
| 444 | - | |||||||||||||||||||||||||
| 445 | if(!sz.isEmpty()) {
| 0 | ||||||||||||||||||||||||
| 446 | { //update the separator state | - | ||||||||||||||||||||||||
| 447 | int iWidth = sz.width() + itemSpacing; | - | ||||||||||||||||||||||||
| 448 | if(separator == -1)
| 0 | ||||||||||||||||||||||||
| 449 | separator_start += iWidth; never executed: separator_start += iWidth; | 0 | ||||||||||||||||||||||||
| 450 | else | - | ||||||||||||||||||||||||
| 451 | separator_len += iWidth; never executed: separator_len += iWidth; | 0 | ||||||||||||||||||||||||
| 452 | } | - | ||||||||||||||||||||||||
| 453 | //maximum height | - | ||||||||||||||||||||||||
| 454 | max_item_height = qMax(max_item_height, sz.height()); | - | ||||||||||||||||||||||||
| 455 | //append | - | ||||||||||||||||||||||||
| 456 | actionRects[i] = QRect(0, 0, sz.width(), sz.height()); | - | ||||||||||||||||||||||||
| 457 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 458 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 459 | - | |||||||||||||||||||||||||
| 460 | //calculate position | - | ||||||||||||||||||||||||
| 461 | const int fw = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - | ||||||||||||||||||||||||
| 462 | int x = fw + ((start == -1) ? hmargin : start) + itemSpacing;
| 0 | ||||||||||||||||||||||||
| 463 | int y = fw + vmargin; | - | ||||||||||||||||||||||||
| 464 | for(int i = 0; i < actions.count(); i++) {
| 0 | ||||||||||||||||||||||||
| 465 | QRect &rect = actionRects[i]; | - | ||||||||||||||||||||||||
| 466 | if (rect.isNull())
| 0 | ||||||||||||||||||||||||
| 467 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 468 | - | |||||||||||||||||||||||||
| 469 | //resize | - | ||||||||||||||||||||||||
| 470 | rect.setHeight(max_item_height); | - | ||||||||||||||||||||||||
| 471 | - | |||||||||||||||||||||||||
| 472 | //move | - | ||||||||||||||||||||||||
| 473 | if(separator != -1 && i >= separator) { //after the separator
| 0 | ||||||||||||||||||||||||
| 474 | int left = (max_width - separator_len - hmargin - itemSpacing) + (x - separator_start - hmargin); | - | ||||||||||||||||||||||||
| 475 | if(left < separator_start) { //wrap
| 0 | ||||||||||||||||||||||||
| 476 | separator_start = x = hmargin; | - | ||||||||||||||||||||||||
| 477 | y += max_item_height; | - | ||||||||||||||||||||||||
| 478 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 479 | rect.moveLeft(left); | - | ||||||||||||||||||||||||
| 480 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 481 | rect.moveLeft(x); | - | ||||||||||||||||||||||||
| 482 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 483 | rect.moveTop(y); | - | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | //keep moving along.. | - | ||||||||||||||||||||||||
| 486 | x += rect.width() + itemSpacing; | - | ||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||
| 488 | //make sure we follow the layout direction | - | ||||||||||||||||||||||||
| 489 | rect = QStyle::visualRect(q->layoutDirection(), q->rect(), rect); | - | ||||||||||||||||||||||||
| 490 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 491 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | void QMenuBarPrivate::activateAction(QAction *action, QAction::ActionEvent action_e) | - | ||||||||||||||||||||||||
| 494 | { | - | ||||||||||||||||||||||||
| 495 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 496 | if (!action || !action->isEnabled())
| 0 | ||||||||||||||||||||||||
| 497 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 498 | action->activate(action_e); | - | ||||||||||||||||||||||||
| 499 | if (action_e == QAction::Hover)
| 0 | ||||||||||||||||||||||||
| 500 | action->showStatusText(q); never executed: action->showStatusText(q); | 0 | ||||||||||||||||||||||||
| 501 | - | |||||||||||||||||||||||||
| 502 | // if(action_e == QAction::Trigger) | - | ||||||||||||||||||||||||
| 503 | // emit q->activated(action); | - | ||||||||||||||||||||||||
| 504 | // else if(action_e == QAction::Hover) | - | ||||||||||||||||||||||||
| 505 | // emit q->highlighted(action); | - | ||||||||||||||||||||||||
| 506 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | void QMenuBarPrivate::_q_actionTriggered() | - | ||||||||||||||||||||||||
| 510 | { | - | ||||||||||||||||||||||||
| 511 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 512 | if (QAction *action = qobject_cast<QAction *>(q->sender())) {
| 0 | ||||||||||||||||||||||||
| 513 | emit q->triggered(action); | - | ||||||||||||||||||||||||
| 514 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 515 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 516 | - | |||||||||||||||||||||||||
| 517 | void QMenuBarPrivate::_q_actionHovered() | - | ||||||||||||||||||||||||
| 518 | { | - | ||||||||||||||||||||||||
| 519 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 520 | if (QAction *action = qobject_cast<QAction *>(q->sender())) {
| 0 | ||||||||||||||||||||||||
| 521 | emit q->hovered(action); | - | ||||||||||||||||||||||||
| 522 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 523 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 524 | int actionIndex = actions.indexOf(action); | - | ||||||||||||||||||||||||
| 525 | QAccessibleEvent focusEvent(q, QAccessible::Focus); | - | ||||||||||||||||||||||||
| 526 | focusEvent.setChild(actionIndex); | - | ||||||||||||||||||||||||
| 527 | QAccessible::updateAccessibility(&focusEvent); | - | ||||||||||||||||||||||||
| 528 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 529 | #endif //QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 530 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 531 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||
| 533 | /*! | - | ||||||||||||||||||||||||
| 534 | Initialize \a option with the values from the menu bar and information from \a action. This method | - | ||||||||||||||||||||||||
| 535 | is useful for subclasses when they need a QStyleOptionMenuItem, but don't want | - | ||||||||||||||||||||||||
| 536 | to fill in all the information themselves. | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | \sa QStyleOption::initFrom(), QMenu::initStyleOption() | - | ||||||||||||||||||||||||
| 539 | */ | - | ||||||||||||||||||||||||
| 540 | void QMenuBar::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const | - | ||||||||||||||||||||||||
| 541 | { | - | ||||||||||||||||||||||||
| 542 | if (!option || !action)
| 0 | ||||||||||||||||||||||||
| 543 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 544 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 545 | option->palette = palette(); | - | ||||||||||||||||||||||||
| 546 | option->state = QStyle::State_None; | - | ||||||||||||||||||||||||
| 547 | if (isEnabled() && action->isEnabled())
| 0 | ||||||||||||||||||||||||
| 548 | option->state |= QStyle::State_Enabled; never executed: option->state |= QStyle::State_Enabled; | 0 | ||||||||||||||||||||||||
| 549 | else | - | ||||||||||||||||||||||||
| 550 | option->palette.setCurrentColorGroup(QPalette::Disabled); never executed: option->palette.setCurrentColorGroup(QPalette::Disabled); | 0 | ||||||||||||||||||||||||
| 551 | option->fontMetrics = fontMetrics(); | - | ||||||||||||||||||||||||
| 552 | if (d->currentAction && d->currentAction == action) {
| 0 | ||||||||||||||||||||||||
| 553 | option->state |= QStyle::State_Selected; | - | ||||||||||||||||||||||||
| 554 | if (d->popupState && !d->closePopupMode)
| 0 | ||||||||||||||||||||||||
| 555 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 | ||||||||||||||||||||||||
| 556 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 557 | if (hasFocus() || d->currentAction)
| 0 | ||||||||||||||||||||||||
| 558 | option->state |= QStyle::State_HasFocus; never executed: option->state |= QStyle::State_HasFocus; | 0 | ||||||||||||||||||||||||
| 559 | option->menuRect = rect(); | - | ||||||||||||||||||||||||
| 560 | option->menuItemType = QStyleOptionMenuItem::Normal; | - | ||||||||||||||||||||||||
| 561 | option->checkType = QStyleOptionMenuItem::NotCheckable; | - | ||||||||||||||||||||||||
| 562 | option->text = action->text(); | - | ||||||||||||||||||||||||
| 563 | option->icon = action->icon(); | - | ||||||||||||||||||||||||
| 564 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | /*! | - | ||||||||||||||||||||||||
| 567 | \class QMenuBar | - | ||||||||||||||||||||||||
| 568 | \brief The QMenuBar class provides a horizontal menu bar. | - | ||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||
| 570 | \ingroup mainwindow-classes | - | ||||||||||||||||||||||||
| 571 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||
| 573 | A menu bar consists of a list of pull-down menu items. You add | - | ||||||||||||||||||||||||
| 574 | menu items with addMenu(). For example, asuming that \c menubar | - | ||||||||||||||||||||||||
| 575 | is a pointer to a QMenuBar and \c fileMenu is a pointer to a | - | ||||||||||||||||||||||||
| 576 | QMenu, the following statement inserts the menu into the menu bar: | - | ||||||||||||||||||||||||
| 577 | \snippet code/src_gui_widgets_qmenubar.cpp 0 | - | ||||||||||||||||||||||||
| 578 | - | |||||||||||||||||||||||||
| 579 | The ampersand in the menu item's text sets Alt+F as a shortcut for | - | ||||||||||||||||||||||||
| 580 | this menu. (You can use "\&\&" to get a real ampersand in the menu | - | ||||||||||||||||||||||||
| 581 | bar.) | - | ||||||||||||||||||||||||
| 582 | - | |||||||||||||||||||||||||
| 583 | There is no need to lay out a menu bar. It automatically sets its | - | ||||||||||||||||||||||||
| 584 | own geometry to the top of the parent widget and changes it | - | ||||||||||||||||||||||||
| 585 | appropriately whenever the parent is resized. | - | ||||||||||||||||||||||||
| 586 | - | |||||||||||||||||||||||||
| 587 | \section1 Usage | - | ||||||||||||||||||||||||
| 588 | - | |||||||||||||||||||||||||
| 589 | In most main window style applications you would use the | - | ||||||||||||||||||||||||
| 590 | \l{QMainWindow::}{menuBar()} function provided in QMainWindow, | - | ||||||||||||||||||||||||
| 591 | adding \l{QMenu}s to the menu bar and adding \l{QAction}s to the | - | ||||||||||||||||||||||||
| 592 | pop-up menus. | - | ||||||||||||||||||||||||
| 593 | - | |||||||||||||||||||||||||
| 594 | Example (from the \l{mainwindows/menus}{Menus} example): | - | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | \snippet mainwindows/menus/mainwindow.cpp 9 | - | ||||||||||||||||||||||||
| 597 | - | |||||||||||||||||||||||||
| 598 | Menu items may be removed with removeAction(). | - | ||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||
| 600 | Widgets can be added to menus by using instances of the QWidgetAction | - | ||||||||||||||||||||||||
| 601 | class to hold them. These actions can then be inserted into menus | - | ||||||||||||||||||||||||
| 602 | in the usual way; see the QMenu documentation for more details. | - | ||||||||||||||||||||||||
| 603 | - | |||||||||||||||||||||||||
| 604 | \section1 Platform Dependent Look and Feel | - | ||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||
| 606 | Different platforms have different requirements for the appearance | - | ||||||||||||||||||||||||
| 607 | of menu bars and their behavior when the user interacts with them. | - | ||||||||||||||||||||||||
| 608 | For example, Windows systems are often configured so that the | - | ||||||||||||||||||||||||
| 609 | underlined character mnemonics that indicate keyboard shortcuts | - | ||||||||||||||||||||||||
| 610 | for items in the menu bar are only shown when the \uicontrol{Alt} key is | - | ||||||||||||||||||||||||
| 611 | pressed. | - | ||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||
| 613 | \section1 QMenuBar on \macos | - | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | QMenuBar on \macos is a wrapper for using the system-wide menu bar. | - | ||||||||||||||||||||||||
| 616 | If you have multiple menu bars in one dialog the outermost menu bar | - | ||||||||||||||||||||||||
| 617 | (normally inside a widget with widget flag Qt::Window) will | - | ||||||||||||||||||||||||
| 618 | be used for the system-wide menu bar. | - | ||||||||||||||||||||||||
| 619 | - | |||||||||||||||||||||||||
| 620 | Qt for \macos also provides a menu bar merging feature to make | - | ||||||||||||||||||||||||
| 621 | QMenuBar conform more closely to accepted \macos menu bar layout. | - | ||||||||||||||||||||||||
| 622 | The merging functionality is based on string matching the title of | - | ||||||||||||||||||||||||
| 623 | a QMenu entry. These strings are translated (using QObject::tr()) | - | ||||||||||||||||||||||||
| 624 | in the "QMenuBar" context. If an entry is moved its slots will still | - | ||||||||||||||||||||||||
| 625 | fire as if it was in the original place. The table below outlines | - | ||||||||||||||||||||||||
| 626 | the strings looked for and where the entry is placed if matched: | - | ||||||||||||||||||||||||
| 627 | - | |||||||||||||||||||||||||
| 628 | \table | - | ||||||||||||||||||||||||
| 629 | \header \li String matches \li Placement \li Notes | - | ||||||||||||||||||||||||
| 630 | \row \li about.* | - | ||||||||||||||||||||||||
| 631 | \li Application Menu | About <application name> | - | ||||||||||||||||||||||||
| 632 | \li The application name is fetched from the \c {Info.plist} file | - | ||||||||||||||||||||||||
| 633 | (see note below). If this entry is not found no About item | - | ||||||||||||||||||||||||
| 634 | will appear in the Application Menu. | - | ||||||||||||||||||||||||
| 635 | \row \li config, options, setup, settings or preferences | - | ||||||||||||||||||||||||
| 636 | \li Application Menu | Preferences | - | ||||||||||||||||||||||||
| 637 | \li If this entry is not found the Settings item will be disabled | - | ||||||||||||||||||||||||
| 638 | \row \li quit or exit | - | ||||||||||||||||||||||||
| 639 | \li Application Menu | Quit <application name> | - | ||||||||||||||||||||||||
| 640 | \li If this entry is not found a default Quit item will be | - | ||||||||||||||||||||||||
| 641 | created to call QCoreApplication::quit() | - | ||||||||||||||||||||||||
| 642 | \endtable | - | ||||||||||||||||||||||||
| 643 | - | |||||||||||||||||||||||||
| 644 | You can override this behavior by using the QAction::menuRole() | - | ||||||||||||||||||||||||
| 645 | property. | - | ||||||||||||||||||||||||
| 646 | - | |||||||||||||||||||||||||
| 647 | If you want all windows in a Mac application to share one menu | - | ||||||||||||||||||||||||
| 648 | bar, you must create a menu bar that does not have a parent. | - | ||||||||||||||||||||||||
| 649 | Create a parent-less menu bar this way: | - | ||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||
| 651 | \snippet code/src_gui_widgets_qmenubar.cpp 1 | - | ||||||||||||||||||||||||
| 652 | - | |||||||||||||||||||||||||
| 653 | \b{Note:} Do \e{not} call QMainWindow::menuBar() to create the | - | ||||||||||||||||||||||||
| 654 | shared menu bar, because that menu bar will have the QMainWindow | - | ||||||||||||||||||||||||
| 655 | as its parent. That menu bar would only be displayed for the | - | ||||||||||||||||||||||||
| 656 | parent QMainWindow. | - | ||||||||||||||||||||||||
| 657 | - | |||||||||||||||||||||||||
| 658 | \b{Note:} The text used for the application name in the menu | - | ||||||||||||||||||||||||
| 659 | bar is obtained from the value set in the \c{Info.plist} file in | - | ||||||||||||||||||||||||
| 660 | the application's bundle. See \l{Qt for macOS - Deployment} | - | ||||||||||||||||||||||||
| 661 | for more information. | - | ||||||||||||||||||||||||
| 662 | - | |||||||||||||||||||||||||
| 663 | \section1 QMenuBar on Windows CE | - | ||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||
| 665 | QMenuBar on Windows CE is a wrapper for using the system-wide menu bar, | - | ||||||||||||||||||||||||
| 666 | similar to the Mac. This feature is activated for Windows Mobile | - | ||||||||||||||||||||||||
| 667 | and integrates QMenuBar with the native soft keys. The left soft | - | ||||||||||||||||||||||||
| 668 | key can be controlled with QMenuBar::setDefaultAction() and the | - | ||||||||||||||||||||||||
| 669 | right soft key can be used to access the menu bar. | - | ||||||||||||||||||||||||
| 670 | - | |||||||||||||||||||||||||
| 671 | The hovered() signal is not supported for the native menu | - | ||||||||||||||||||||||||
| 672 | integration. Also, it is not possible to display an icon in a | - | ||||||||||||||||||||||||
| 673 | native menu on Windows Mobile. | - | ||||||||||||||||||||||||
| 674 | - | |||||||||||||||||||||||||
| 675 | \section1 Examples | - | ||||||||||||||||||||||||
| 676 | - | |||||||||||||||||||||||||
| 677 | The \l{mainwindows/menus}{Menus} example shows how to use QMenuBar | - | ||||||||||||||||||||||||
| 678 | and QMenu. The other \l{Main Window Examples}{main window | - | ||||||||||||||||||||||||
| 679 | application examples} also provide menus using these classes. | - | ||||||||||||||||||||||||
| 680 | - | |||||||||||||||||||||||||
| 681 | \sa QMenu, QShortcut, QAction, | - | ||||||||||||||||||||||||
| 682 | {http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html}{Introduction to Apple Human Interface Guidelines}, | - | ||||||||||||||||||||||||
| 683 | {fowler}{GUI Design Handbook: Menu Bar}, {Menus Example} | - | ||||||||||||||||||||||||
| 684 | */ | - | ||||||||||||||||||||||||
| 685 | - | |||||||||||||||||||||||||
| 686 | - | |||||||||||||||||||||||||
| 687 | void QMenuBarPrivate::init() | - | ||||||||||||||||||||||||
| 688 | { | - | ||||||||||||||||||||||||
| 689 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 690 | q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); | - | ||||||||||||||||||||||||
| 691 | q->setAttribute(Qt::WA_CustomWhatsThis); | - | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | if (!QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar))
| 0 | ||||||||||||||||||||||||
| 694 | platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); never executed: platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); | 0 | ||||||||||||||||||||||||
| 695 | - | |||||||||||||||||||||||||
| 696 | if (platformMenuBar)
| 0 | ||||||||||||||||||||||||
| 697 | q->hide(); never executed: q->hide(); | 0 | ||||||||||||||||||||||||
| 698 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||||||||
| 699 | if (qt_wince_is_mobile()) { | - | ||||||||||||||||||||||||
| 700 | wceCreateMenuBar(q->parentWidget()); | - | ||||||||||||||||||||||||
| 701 | if(wce_menubar) | - | ||||||||||||||||||||||||
| 702 | q->hide(); | - | ||||||||||||||||||||||||
| 703 | } | - | ||||||||||||||||||||||||
| 704 | else { | - | ||||||||||||||||||||||||
| 705 | QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); | - | ||||||||||||||||||||||||
| 706 | } | - | ||||||||||||||||||||||||
| 707 | #endif | - | ||||||||||||||||||||||||
| 708 | q->setBackgroundRole(QPalette::Button); | - | ||||||||||||||||||||||||
| 709 | handleReparent(); | - | ||||||||||||||||||||||||
| 710 | q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q)); | - | ||||||||||||||||||||||||
| 711 | - | |||||||||||||||||||||||||
| 712 | extension = new QMenuBarExtension(q); | - | ||||||||||||||||||||||||
| 713 | extension->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||
| 714 | extension->hide(); | - | ||||||||||||||||||||||||
| 715 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 716 | - | |||||||||||||||||||||||||
| 717 | //Gets the next action for keyboard navigation | - | ||||||||||||||||||||||||
| 718 | QAction *QMenuBarPrivate::getNextAction(const int _start, const int increment) const | - | ||||||||||||||||||||||||
| 719 | { | - | ||||||||||||||||||||||||
| 720 | Q_Q(const QMenuBar); | - | ||||||||||||||||||||||||
| 721 | const_cast<QMenuBarPrivate*>(this)->updateGeometries(); | - | ||||||||||||||||||||||||
| 722 | bool allowActiveAndDisabled = q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q); | - | ||||||||||||||||||||||||
| 723 | const int start = (_start == -1 && increment == -1) ? actions.count() : _start;
| 0 | ||||||||||||||||||||||||
| 724 | const int end = increment == -1 ? 0 : actions.count() - 1;
| 0 | ||||||||||||||||||||||||
| 725 | - | |||||||||||||||||||||||||
| 726 | for (int i = start; i != end;) {
| 0 | ||||||||||||||||||||||||
| 727 | i += increment; | - | ||||||||||||||||||||||||
| 728 | QAction *current = actions.at(i); | - | ||||||||||||||||||||||||
| 729 | if (!actionRects.at(i).isNull() && (allowActiveAndDisabled || current->isEnabled()))
| 0 | ||||||||||||||||||||||||
| 730 | return current; never executed: return current; | 0 | ||||||||||||||||||||||||
| 731 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | if (_start != -1) //let's try from the beginning or the end
| 0 | ||||||||||||||||||||||||
| 734 | return getNextAction(-1, increment); never executed: return getNextAction(-1, increment); | 0 | ||||||||||||||||||||||||
| 735 | - | |||||||||||||||||||||||||
| 736 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 737 | } | - | ||||||||||||||||||||||||
| 738 | - | |||||||||||||||||||||||||
| 739 | /*! | - | ||||||||||||||||||||||||
| 740 | Constructs a menu bar with parent \a parent. | - | ||||||||||||||||||||||||
| 741 | */ | - | ||||||||||||||||||||||||
| 742 | QMenuBar::QMenuBar(QWidget *parent) : QWidget(*new QMenuBarPrivate, parent, 0) | - | ||||||||||||||||||||||||
| 743 | { | - | ||||||||||||||||||||||||
| 744 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 745 | d->init(); | - | ||||||||||||||||||||||||
| 746 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 747 | - | |||||||||||||||||||||||||
| 748 | - | |||||||||||||||||||||||||
| 749 | /*! | - | ||||||||||||||||||||||||
| 750 | Destroys the menu bar. | - | ||||||||||||||||||||||||
| 751 | */ | - | ||||||||||||||||||||||||
| 752 | QMenuBar::~QMenuBar() | - | ||||||||||||||||||||||||
| 753 | { | - | ||||||||||||||||||||||||
| 754 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 755 | delete d->platformMenuBar; | - | ||||||||||||||||||||||||
| 756 | d->platformMenuBar = 0; | - | ||||||||||||||||||||||||
| 757 | - | |||||||||||||||||||||||||
| 758 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||||||||
| 759 | if (qt_wince_is_mobile()) | - | ||||||||||||||||||||||||
| 760 | d->wceDestroyMenuBar(); | - | ||||||||||||||||||||||||
| 761 | #endif | - | ||||||||||||||||||||||||
| 762 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 763 | - | |||||||||||||||||||||||||
| 764 | /*! | - | ||||||||||||||||||||||||
| 765 | \overload | - | ||||||||||||||||||||||||
| 766 | - | |||||||||||||||||||||||||
| 767 | This convenience function creates a new action with \a text. | - | ||||||||||||||||||||||||
| 768 | The function adds the newly created action to the menu's | - | ||||||||||||||||||||||||
| 769 | list of actions, and returns it. | - | ||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||
| 771 | \sa QWidget::addAction(), QWidget::actions() | - | ||||||||||||||||||||||||
| 772 | */ | - | ||||||||||||||||||||||||
| 773 | QAction *QMenuBar::addAction(const QString &text) | - | ||||||||||||||||||||||||
| 774 | { | - | ||||||||||||||||||||||||
| 775 | QAction *ret = new QAction(text, this); | - | ||||||||||||||||||||||||
| 776 | addAction(ret); | - | ||||||||||||||||||||||||
| 777 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 778 | } | - | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | /*! | - | ||||||||||||||||||||||||
| 781 | \overload | - | ||||||||||||||||||||||||
| 782 | - | |||||||||||||||||||||||||
| 783 | This convenience function creates a new action with the given \a | - | ||||||||||||||||||||||||
| 784 | text. The action's triggered() signal is connected to the \a | - | ||||||||||||||||||||||||
| 785 | receiver's \a member slot. The function adds the newly created | - | ||||||||||||||||||||||||
| 786 | action to the menu's list of actions and returns it. | - | ||||||||||||||||||||||||
| 787 | - | |||||||||||||||||||||||||
| 788 | \sa QWidget::addAction(), QWidget::actions() | - | ||||||||||||||||||||||||
| 789 | */ | - | ||||||||||||||||||||||||
| 790 | QAction *QMenuBar::addAction(const QString &text, const QObject *receiver, const char* member) | - | ||||||||||||||||||||||||
| 791 | { | - | ||||||||||||||||||||||||
| 792 | QAction *ret = new QAction(text, this); | - | ||||||||||||||||||||||||
| 793 | QObject::connect(ret, SIGNAL(triggered(bool)), receiver, member); | - | ||||||||||||||||||||||||
| 794 | addAction(ret); | - | ||||||||||||||||||||||||
| 795 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 796 | } | - | ||||||||||||||||||||||||
| 797 | - | |||||||||||||||||||||||||
| 798 | /*! | - | ||||||||||||||||||||||||
| 799 | Appends a new QMenu with \a title to the menu bar. The menu bar | - | ||||||||||||||||||||||||
| 800 | takes ownership of the menu. Returns the new menu. | - | ||||||||||||||||||||||||
| 801 | - | |||||||||||||||||||||||||
| 802 | \sa QWidget::addAction(), QMenu::menuAction() | - | ||||||||||||||||||||||||
| 803 | */ | - | ||||||||||||||||||||||||
| 804 | QMenu *QMenuBar::addMenu(const QString &title) | - | ||||||||||||||||||||||||
| 805 | { | - | ||||||||||||||||||||||||
| 806 | QMenu *menu = new QMenu(title, this); | - | ||||||||||||||||||||||||
| 807 | addAction(menu->menuAction()); | - | ||||||||||||||||||||||||
| 808 | return menu; never executed: return menu; | 0 | ||||||||||||||||||||||||
| 809 | } | - | ||||||||||||||||||||||||
| 810 | - | |||||||||||||||||||||||||
| 811 | /*! | - | ||||||||||||||||||||||||
| 812 | Appends a new QMenu with \a icon and \a title to the menu bar. The menu bar | - | ||||||||||||||||||||||||
| 813 | takes ownership of the menu. Returns the new menu. | - | ||||||||||||||||||||||||
| 814 | - | |||||||||||||||||||||||||
| 815 | \sa QWidget::addAction(), QMenu::menuAction() | - | ||||||||||||||||||||||||
| 816 | */ | - | ||||||||||||||||||||||||
| 817 | QMenu *QMenuBar::addMenu(const QIcon &icon, const QString &title) | - | ||||||||||||||||||||||||
| 818 | { | - | ||||||||||||||||||||||||
| 819 | QMenu *menu = new QMenu(title, this); | - | ||||||||||||||||||||||||
| 820 | menu->setIcon(icon); | - | ||||||||||||||||||||||||
| 821 | addAction(menu->menuAction()); | - | ||||||||||||||||||||||||
| 822 | return menu; never executed: return menu; | 0 | ||||||||||||||||||||||||
| 823 | } | - | ||||||||||||||||||||||||
| 824 | - | |||||||||||||||||||||||||
| 825 | /*! | - | ||||||||||||||||||||||||
| 826 | Appends \a menu to the menu bar. Returns the menu's menuAction(). | - | ||||||||||||||||||||||||
| 827 | - | |||||||||||||||||||||||||
| 828 | \note The returned QAction object can be used to hide the corresponding | - | ||||||||||||||||||||||||
| 829 | menu. | - | ||||||||||||||||||||||||
| 830 | - | |||||||||||||||||||||||||
| 831 | \sa QWidget::addAction(), QMenu::menuAction() | - | ||||||||||||||||||||||||
| 832 | */ | - | ||||||||||||||||||||||||
| 833 | QAction *QMenuBar::addMenu(QMenu *menu) | - | ||||||||||||||||||||||||
| 834 | { | - | ||||||||||||||||||||||||
| 835 | QAction *action = menu->menuAction(); | - | ||||||||||||||||||||||||
| 836 | addAction(action); | - | ||||||||||||||||||||||||
| 837 | return action; never executed: return action; | 0 | ||||||||||||||||||||||||
| 838 | } | - | ||||||||||||||||||||||||
| 839 | - | |||||||||||||||||||||||||
| 840 | /*! | - | ||||||||||||||||||||||||
| 841 | Appends a separator to the menu. | - | ||||||||||||||||||||||||
| 842 | */ | - | ||||||||||||||||||||||||
| 843 | QAction *QMenuBar::addSeparator() | - | ||||||||||||||||||||||||
| 844 | { | - | ||||||||||||||||||||||||
| 845 | QAction *ret = new QAction(this); | - | ||||||||||||||||||||||||
| 846 | ret->setSeparator(true); | - | ||||||||||||||||||||||||
| 847 | addAction(ret); | - | ||||||||||||||||||||||||
| 848 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 849 | } | - | ||||||||||||||||||||||||
| 850 | - | |||||||||||||||||||||||||
| 851 | /*! | - | ||||||||||||||||||||||||
| 852 | This convenience function creates a new separator action, i.e. an | - | ||||||||||||||||||||||||
| 853 | action with QAction::isSeparator() returning true. The function inserts | - | ||||||||||||||||||||||||
| 854 | the newly created action into this menu bar's list of actions before | - | ||||||||||||||||||||||||
| 855 | action \a before and returns it. | - | ||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||
| 857 | \sa QWidget::insertAction(), addSeparator() | - | ||||||||||||||||||||||||
| 858 | */ | - | ||||||||||||||||||||||||
| 859 | QAction *QMenuBar::insertSeparator(QAction *before) | - | ||||||||||||||||||||||||
| 860 | { | - | ||||||||||||||||||||||||
| 861 | QAction *action = new QAction(this); | - | ||||||||||||||||||||||||
| 862 | action->setSeparator(true); | - | ||||||||||||||||||||||||
| 863 | insertAction(before, action); | - | ||||||||||||||||||||||||
| 864 | return action; never executed: return action; | 0 | ||||||||||||||||||||||||
| 865 | } | - | ||||||||||||||||||||||||
| 866 | - | |||||||||||||||||||||||||
| 867 | /*! | - | ||||||||||||||||||||||||
| 868 | This convenience function inserts \a menu before action \a before | - | ||||||||||||||||||||||||
| 869 | and returns the menus menuAction(). | - | ||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||
| 871 | \sa QWidget::insertAction(), addMenu() | - | ||||||||||||||||||||||||
| 872 | */ | - | ||||||||||||||||||||||||
| 873 | QAction *QMenuBar::insertMenu(QAction *before, QMenu *menu) | - | ||||||||||||||||||||||||
| 874 | { | - | ||||||||||||||||||||||||
| 875 | QAction *action = menu->menuAction(); | - | ||||||||||||||||||||||||
| 876 | insertAction(before, action); | - | ||||||||||||||||||||||||
| 877 | return action; never executed: return action; | 0 | ||||||||||||||||||||||||
| 878 | } | - | ||||||||||||||||||||||||
| 879 | - | |||||||||||||||||||||||||
| 880 | /*! | - | ||||||||||||||||||||||||
| 881 | Returns the QAction that is currently highlighted. A null pointer | - | ||||||||||||||||||||||||
| 882 | will be returned if no action is currently selected. | - | ||||||||||||||||||||||||
| 883 | */ | - | ||||||||||||||||||||||||
| 884 | QAction *QMenuBar::activeAction() const | - | ||||||||||||||||||||||||
| 885 | { | - | ||||||||||||||||||||||||
| 886 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 887 | return d->currentAction; never executed: return d->currentAction; | 0 | ||||||||||||||||||||||||
| 888 | } | - | ||||||||||||||||||||||||
| 889 | - | |||||||||||||||||||||||||
| 890 | /*! | - | ||||||||||||||||||||||||
| 891 | \since 4.1 | - | ||||||||||||||||||||||||
| 892 | - | |||||||||||||||||||||||||
| 893 | Sets the currently highlighted action to \a act. | - | ||||||||||||||||||||||||
| 894 | */ | - | ||||||||||||||||||||||||
| 895 | void QMenuBar::setActiveAction(QAction *act) | - | ||||||||||||||||||||||||
| 896 | { | - | ||||||||||||||||||||||||
| 897 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 898 | d->setCurrentAction(act, true, false); | - | ||||||||||||||||||||||||
| 899 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | - | |||||||||||||||||||||||||
| 902 | /*! | - | ||||||||||||||||||||||||
| 903 | Removes all the actions from the menu bar. | - | ||||||||||||||||||||||||
| 904 | - | |||||||||||||||||||||||||
| 905 | \note On \macos, menu items that have been merged to the system | - | ||||||||||||||||||||||||
| 906 | menu bar are not removed by this function. One way to handle this | - | ||||||||||||||||||||||||
| 907 | would be to remove the extra actions yourself. You can set the | - | ||||||||||||||||||||||||
| 908 | \l{QAction::MenuRole}{menu role} on the different menus, so that | - | ||||||||||||||||||||||||
| 909 | you know ahead of time which menu items get merged and which do | - | ||||||||||||||||||||||||
| 910 | not. Then decide what to recreate or remove yourself. | - | ||||||||||||||||||||||||
| 911 | - | |||||||||||||||||||||||||
| 912 | \sa removeAction() | - | ||||||||||||||||||||||||
| 913 | */ | - | ||||||||||||||||||||||||
| 914 | void QMenuBar::clear() | - | ||||||||||||||||||||||||
| 915 | { | - | ||||||||||||||||||||||||
| 916 | QList<QAction*> acts = actions(); | - | ||||||||||||||||||||||||
| 917 | for(int i = 0; i < acts.size(); i++)
| 0 | ||||||||||||||||||||||||
| 918 | removeAction(acts[i]); never executed: removeAction(acts[i]); | 0 | ||||||||||||||||||||||||
| 919 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | /*! | - | ||||||||||||||||||||||||
| 922 | \property QMenuBar::defaultUp | - | ||||||||||||||||||||||||
| 923 | \brief the popup orientation | - | ||||||||||||||||||||||||
| 924 | - | |||||||||||||||||||||||||
| 925 | The default popup orientation. By default, menus pop "down" the | - | ||||||||||||||||||||||||
| 926 | screen. By setting the property to true, the menu will pop "up". | - | ||||||||||||||||||||||||
| 927 | You might call this for menus that are \e below the document to | - | ||||||||||||||||||||||||
| 928 | which they refer. | - | ||||||||||||||||||||||||
| 929 | - | |||||||||||||||||||||||||
| 930 | If the menu would not fit on the screen, the other direction is | - | ||||||||||||||||||||||||
| 931 | used automatically. | - | ||||||||||||||||||||||||
| 932 | */ | - | ||||||||||||||||||||||||
| 933 | void QMenuBar::setDefaultUp(bool b) | - | ||||||||||||||||||||||||
| 934 | { | - | ||||||||||||||||||||||||
| 935 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 936 | d->defaultPopDown = !b; | - | ||||||||||||||||||||||||
| 937 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 938 | - | |||||||||||||||||||||||||
| 939 | bool QMenuBar::isDefaultUp() const | - | ||||||||||||||||||||||||
| 940 | { | - | ||||||||||||||||||||||||
| 941 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 942 | return !d->defaultPopDown; never executed: return !d->defaultPopDown; | 0 | ||||||||||||||||||||||||
| 943 | } | - | ||||||||||||||||||||||||
| 944 | - | |||||||||||||||||||||||||
| 945 | /*! | - | ||||||||||||||||||||||||
| 946 | \reimp | - | ||||||||||||||||||||||||
| 947 | */ | - | ||||||||||||||||||||||||
| 948 | void QMenuBar::resizeEvent(QResizeEvent *) | - | ||||||||||||||||||||||||
| 949 | { | - | ||||||||||||||||||||||||
| 950 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 951 | d->itemsDirty = true; | - | ||||||||||||||||||||||||
| 952 | d->updateGeometries(); | - | ||||||||||||||||||||||||
| 953 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 954 | - | |||||||||||||||||||||||||
| 955 | /*! | - | ||||||||||||||||||||||||
| 956 | \reimp | - | ||||||||||||||||||||||||
| 957 | */ | - | ||||||||||||||||||||||||
| 958 | void QMenuBar::paintEvent(QPaintEvent *e) | - | ||||||||||||||||||||||||
| 959 | { | - | ||||||||||||||||||||||||
| 960 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 961 | QPainter p(this); | - | ||||||||||||||||||||||||
| 962 | QRegion emptyArea(rect()); | - | ||||||||||||||||||||||||
| 963 | - | |||||||||||||||||||||||||
| 964 | //draw the items | - | ||||||||||||||||||||||||
| 965 | for (int i = 0; i < d->actions.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 966 | QAction *action = d->actions.at(i); | - | ||||||||||||||||||||||||
| 967 | QRect adjustedActionRect = d->actionRect(action); | - | ||||||||||||||||||||||||
| 968 | if (adjustedActionRect.isEmpty() || !d->isVisible(action))
| 0 | ||||||||||||||||||||||||
| 969 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 970 | if(!e->rect().intersects(adjustedActionRect))
| 0 | ||||||||||||||||||||||||
| 971 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 972 | - | |||||||||||||||||||||||||
| 973 | emptyArea -= adjustedActionRect; | - | ||||||||||||||||||||||||
| 974 | QStyleOptionMenuItem opt; | - | ||||||||||||||||||||||||
| 975 | initStyleOption(&opt, action); | - | ||||||||||||||||||||||||
| 976 | opt.rect = adjustedActionRect; | - | ||||||||||||||||||||||||
| 977 | p.setClipRect(adjustedActionRect); | - | ||||||||||||||||||||||||
| 978 | style()->drawControl(QStyle::CE_MenuBarItem, &opt, &p, this); | - | ||||||||||||||||||||||||
| 979 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 980 | //draw border | - | ||||||||||||||||||||||||
| 981 | if(int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) {
| 0 | ||||||||||||||||||||||||
| 982 | QRegion borderReg; | - | ||||||||||||||||||||||||
| 983 | borderReg += QRect(0, 0, fw, height()); //left | - | ||||||||||||||||||||||||
| 984 | borderReg += QRect(width()-fw, 0, fw, height()); //right | - | ||||||||||||||||||||||||
| 985 | borderReg += QRect(0, 0, width(), fw); //top | - | ||||||||||||||||||||||||
| 986 | borderReg += QRect(0, height()-fw, width(), fw); //bottom | - | ||||||||||||||||||||||||
| 987 | p.setClipRegion(borderReg); | - | ||||||||||||||||||||||||
| 988 | emptyArea -= borderReg; | - | ||||||||||||||||||||||||
| 989 | QStyleOptionFrame frame; | - | ||||||||||||||||||||||||
| 990 | frame.rect = rect(); | - | ||||||||||||||||||||||||
| 991 | frame.palette = palette(); | - | ||||||||||||||||||||||||
| 992 | frame.state = QStyle::State_None; | - | ||||||||||||||||||||||||
| 993 | frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth); | - | ||||||||||||||||||||||||
| 994 | frame.midLineWidth = 0; | - | ||||||||||||||||||||||||
| 995 | style()->drawPrimitive(QStyle::PE_PanelMenuBar, &frame, &p, this); | - | ||||||||||||||||||||||||
| 996 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 997 | p.setClipRegion(emptyArea); | - | ||||||||||||||||||||||||
| 998 | QStyleOptionMenuItem menuOpt; | - | ||||||||||||||||||||||||
| 999 | menuOpt.palette = palette(); | - | ||||||||||||||||||||||||
| 1000 | menuOpt.state = QStyle::State_None; | - | ||||||||||||||||||||||||
| 1001 | menuOpt.menuItemType = QStyleOptionMenuItem::EmptyArea; | - | ||||||||||||||||||||||||
| 1002 | menuOpt.checkType = QStyleOptionMenuItem::NotCheckable; | - | ||||||||||||||||||||||||
| 1003 | menuOpt.rect = rect(); | - | ||||||||||||||||||||||||
| 1004 | menuOpt.menuRect = rect(); | - | ||||||||||||||||||||||||
| 1005 | style()->drawControl(QStyle::CE_MenuBarEmptyArea, &menuOpt, &p, this); | - | ||||||||||||||||||||||||
| 1006 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1007 | - | |||||||||||||||||||||||||
| 1008 | /*! | - | ||||||||||||||||||||||||
| 1009 | \reimp | - | ||||||||||||||||||||||||
| 1010 | */ | - | ||||||||||||||||||||||||
| 1011 | void QMenuBar::setVisible(bool visible) | - | ||||||||||||||||||||||||
| 1012 | { | - | ||||||||||||||||||||||||
| 1013 | if (isNativeMenuBar()) {
| 0 | ||||||||||||||||||||||||
| 1014 | if (!visible)
| 0 | ||||||||||||||||||||||||
| 1015 | QWidget::setVisible(false); never executed: QWidget::setVisible(false); | 0 | ||||||||||||||||||||||||
| 1016 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1017 | } | - | ||||||||||||||||||||||||
| 1018 | QWidget::setVisible(visible); | - | ||||||||||||||||||||||||
| 1019 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1020 | - | |||||||||||||||||||||||||
| 1021 | /*! | - | ||||||||||||||||||||||||
| 1022 | \reimp | - | ||||||||||||||||||||||||
| 1023 | */ | - | ||||||||||||||||||||||||
| 1024 | void QMenuBar::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
| 1025 | { | - | ||||||||||||||||||||||||
| 1026 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1027 | if(e->button() != Qt::LeftButton)
| 0 | ||||||||||||||||||||||||
| 1028 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1029 | - | |||||||||||||||||||||||||
| 1030 | d->mouseDown = true; | - | ||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||
| 1032 | QAction *action = d->actionAt(e->pos()); | - | ||||||||||||||||||||||||
| 1033 | if (!action || !d->isVisible(action) || !action->isEnabled()) {
| 0 | ||||||||||||||||||||||||
| 1034 | d->setCurrentAction(0); | - | ||||||||||||||||||||||||
| 1035 | #ifndef QT_NO_WHATSTHIS | - | ||||||||||||||||||||||||
| 1036 | if (QWhatsThis::inWhatsThisMode())
| 0 | ||||||||||||||||||||||||
| 1037 | QWhatsThis::showText(e->globalPos(), d->whatsThis, this); never executed: QWhatsThis::showText(e->globalPos(), d->whatsThis, this); | 0 | ||||||||||||||||||||||||
| 1038 | #endif | - | ||||||||||||||||||||||||
| 1039 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1040 | } | - | ||||||||||||||||||||||||
| 1041 | - | |||||||||||||||||||||||||
| 1042 | if(d->currentAction == action && d->popupState) {
| 0 | ||||||||||||||||||||||||
| 1043 | if(QMenu *menu = d->activeMenu) {
| 0 | ||||||||||||||||||||||||
| 1044 | d->activeMenu = 0; | - | ||||||||||||||||||||||||
| 1045 | menu->setAttribute(Qt::WA_NoMouseReplay); | - | ||||||||||||||||||||||||
| 1046 | menu->hide(); | - | ||||||||||||||||||||||||
| 1047 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1048 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1049 | d->setCurrentAction(action, true); | - | ||||||||||||||||||||||||
| 1050 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1051 | } | - | ||||||||||||||||||||||||
| 1052 | - | |||||||||||||||||||||||||
| 1053 | /*! | - | ||||||||||||||||||||||||
| 1054 | \reimp | - | ||||||||||||||||||||||||
| 1055 | */ | - | ||||||||||||||||||||||||
| 1056 | void QMenuBar::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
| 1057 | { | - | ||||||||||||||||||||||||
| 1058 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1059 | if(e->button() != Qt::LeftButton || !d->mouseDown)
| 0 | ||||||||||||||||||||||||
| 1060 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1061 | - | |||||||||||||||||||||||||
| 1062 | d->mouseDown = false; | - | ||||||||||||||||||||||||
| 1063 | QAction *action = d->actionAt(e->pos()); | - | ||||||||||||||||||||||||
| 1064 | if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) {
| 0 | ||||||||||||||||||||||||
| 1065 | //we set the current action before activating | - | ||||||||||||||||||||||||
| 1066 | //so that we let the leave event set the current back to 0 | - | ||||||||||||||||||||||||
| 1067 | d->setCurrentAction(action, false); | - | ||||||||||||||||||||||||
| 1068 | if(action)
| 0 | ||||||||||||||||||||||||
| 1069 | d->activateAction(action, QAction::Trigger); never executed: d->activateAction(action, QAction::Trigger); | 0 | ||||||||||||||||||||||||
| 1070 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1071 | d->closePopupMode = 0; | - | ||||||||||||||||||||||||
| 1072 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1073 | - | |||||||||||||||||||||||||
| 1074 | /*! | - | ||||||||||||||||||||||||
| 1075 | \reimp | - | ||||||||||||||||||||||||
| 1076 | */ | - | ||||||||||||||||||||||||
| 1077 | void QMenuBar::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
| 1078 | { | - | ||||||||||||||||||||||||
| 1079 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1080 | d->updateGeometries(); | - | ||||||||||||||||||||||||
| 1081 | int key = e->key(); | - | ||||||||||||||||||||||||
| 1082 | if(isRightToLeft()) { // in reverse mode open/close key for submenues are reversed
| 0 | ||||||||||||||||||||||||
| 1083 | if(key == Qt::Key_Left)
| 0 | ||||||||||||||||||||||||
| 1084 | key = Qt::Key_Right; never executed: key = Qt::Key_Right; | 0 | ||||||||||||||||||||||||
| 1085 | else if(key == Qt::Key_Right)
| 0 | ||||||||||||||||||||||||
| 1086 | key = Qt::Key_Left; never executed: key = Qt::Key_Left; | 0 | ||||||||||||||||||||||||
| 1087 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1088 | if(key == Qt::Key_Tab) //means right
| 0 | ||||||||||||||||||||||||
| 1089 | key = Qt::Key_Right; never executed: key = Qt::Key_Right; | 0 | ||||||||||||||||||||||||
| 1090 | else if(key == Qt::Key_Backtab) //means left
| 0 | ||||||||||||||||||||||||
| 1091 | key = Qt::Key_Left; never executed: key = Qt::Key_Left; | 0 | ||||||||||||||||||||||||
| 1092 | - | |||||||||||||||||||||||||
| 1093 | bool key_consumed = false; | - | ||||||||||||||||||||||||
| 1094 | switch(key) { | - | ||||||||||||||||||||||||
| 1095 | case Qt::Key_Up: never executed: case Qt::Key_Up: | 0 | ||||||||||||||||||||||||
| 1096 | case Qt::Key_Down: never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||||||||
| 1097 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||||||||
| 1098 | case Qt::Key_Space: never executed: case Qt::Key_Space: | 0 | ||||||||||||||||||||||||
| 1099 | case Qt::Key_Return: { never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||||||||
| 1100 | if(!style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this) || !d->currentAction)
| 0 | ||||||||||||||||||||||||
| 1101 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1102 | if(d->currentAction->menu()) {
| 0 | ||||||||||||||||||||||||
| 1103 | d->popupAction(d->currentAction, true); | - | ||||||||||||||||||||||||
| 1104 | } else if(key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Space) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1105 | d->activateAction(d->currentAction, QAction::Trigger); | - | ||||||||||||||||||||||||
| 1106 | d->setCurrentAction(d->currentAction, false); | - | ||||||||||||||||||||||||
| 1107 | d->setKeyboardMode(false); | - | ||||||||||||||||||||||||
| 1108 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1109 | key_consumed = true; | - | ||||||||||||||||||||||||
| 1110 | break; } never executed: break; | 0 | ||||||||||||||||||||||||
| 1111 | - | |||||||||||||||||||||||||
| 1112 | case Qt::Key_Right: never executed: case Qt::Key_Right: | 0 | ||||||||||||||||||||||||
| 1113 | case Qt::Key_Left: { never executed: case Qt::Key_Left: | 0 | ||||||||||||||||||||||||
| 1114 | if(d->currentAction) {
| 0 | ||||||||||||||||||||||||
| 1115 | int index = d->actions.indexOf(d->currentAction); | - | ||||||||||||||||||||||||
| 1116 | if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) {
| 0 | ||||||||||||||||||||||||
| 1117 | d->setCurrentAction(nextAction, d->popupState, true); | - | ||||||||||||||||||||||||
| 1118 | key_consumed = true; | - | ||||||||||||||||||||||||
| 1119 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1120 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1121 | break; } never executed: break; | 0 | ||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||
| 1123 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1124 | key_consumed = false; | - | ||||||||||||||||||||||||
| 1125 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1126 | - | |||||||||||||||||||||||||
| 1127 | if (!key_consumed && e->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||||||||||||||
| 1128 | d->setCurrentAction(0); | - | ||||||||||||||||||||||||
| 1129 | d->setKeyboardMode(false); | - | ||||||||||||||||||||||||
| 1130 | key_consumed = true; | - | ||||||||||||||||||||||||
| 1131 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1132 | - | |||||||||||||||||||||||||
| 1133 | if(!key_consumed &&
| 0 | ||||||||||||||||||||||||
| 1134 | (!e->modifiers() ||
| 0 | ||||||||||||||||||||||||
| 1135 | (e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) {
| 0 | ||||||||||||||||||||||||
| 1136 | int clashCount = 0; | - | ||||||||||||||||||||||||
| 1137 | QAction *first = 0, *currentSelected = 0, *firstAfterCurrent = 0; | - | ||||||||||||||||||||||||
| 1138 | { | - | ||||||||||||||||||||||||
| 1139 | QChar c = e->text()[0].toUpper(); | - | ||||||||||||||||||||||||
| 1140 | for(int i = 0; i < d->actions.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 1141 | if (d->actionRects.at(i).isNull())
| 0 | ||||||||||||||||||||||||
| 1142 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1143 | QAction *act = d->actions.at(i); | - | ||||||||||||||||||||||||
| 1144 | QString s = act->text(); | - | ||||||||||||||||||||||||
| 1145 | if(!s.isEmpty()) {
| 0 | ||||||||||||||||||||||||
| 1146 | int ampersand = s.indexOf(QLatin1Char('&')); | - | ||||||||||||||||||||||||
| 1147 | if(ampersand >= 0) {
| 0 | ||||||||||||||||||||||||
| 1148 | if(s[ampersand+1].toUpper() == c) {
| 0 | ||||||||||||||||||||||||
| 1149 | clashCount++; | - | ||||||||||||||||||||||||
| 1150 | if(!first)
| 0 | ||||||||||||||||||||||||
| 1151 | first = act; never executed: first = act; | 0 | ||||||||||||||||||||||||
| 1152 | if(act == d->currentAction)
| 0 | ||||||||||||||||||||||||
| 1153 | currentSelected = act; never executed: currentSelected = act; | 0 | ||||||||||||||||||||||||
| 1154 | else if (!firstAfterCurrent && currentSelected)
| 0 | ||||||||||||||||||||||||
| 1155 | firstAfterCurrent = act; never executed: firstAfterCurrent = act; | 0 | ||||||||||||||||||||||||
| 1156 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1157 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1158 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1159 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1160 | } | - | ||||||||||||||||||||||||
| 1161 | QAction *next_action = 0; | - | ||||||||||||||||||||||||
| 1162 | if(clashCount >= 1) {
| 0 | ||||||||||||||||||||||||
| 1163 | if(clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent))
| 0 | ||||||||||||||||||||||||
| 1164 | next_action = first; never executed: next_action = first; | 0 | ||||||||||||||||||||||||
| 1165 | else | - | ||||||||||||||||||||||||
| 1166 | next_action = firstAfterCurrent; never executed: next_action = firstAfterCurrent; | 0 | ||||||||||||||||||||||||
| 1167 | } | - | ||||||||||||||||||||||||
| 1168 | if(next_action) {
| 0 | ||||||||||||||||||||||||
| 1169 | key_consumed = true; | - | ||||||||||||||||||||||||
| 1170 | d->setCurrentAction(next_action, true, true); | - | ||||||||||||||||||||||||
| 1171 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1172 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1173 | if(key_consumed)
| 0 | ||||||||||||||||||||||||
| 1174 | e->accept(); never executed: e->accept(); | 0 | ||||||||||||||||||||||||
| 1175 | else | - | ||||||||||||||||||||||||
| 1176 | e->ignore(); never executed: e->ignore(); | 0 | ||||||||||||||||||||||||
| 1177 | } | - | ||||||||||||||||||||||||
| 1178 | - | |||||||||||||||||||||||||
| 1179 | /*! | - | ||||||||||||||||||||||||
| 1180 | \reimp | - | ||||||||||||||||||||||||
| 1181 | */ | - | ||||||||||||||||||||||||
| 1182 | void QMenuBar::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
| 1183 | { | - | ||||||||||||||||||||||||
| 1184 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1185 | if (!(e->buttons() & Qt::LeftButton))
| 0 | ||||||||||||||||||||||||
| 1186 | d->mouseDown = false; never executed: d->mouseDown = false; | 0 | ||||||||||||||||||||||||
| 1187 | bool popupState = d->popupState || d->mouseDown;
| 0 | ||||||||||||||||||||||||
| 1188 | QAction *action = d->actionAt(e->pos()); | - | ||||||||||||||||||||||||
| 1189 | if ((action && d->isVisible(action)) || !popupState)
| 0 | ||||||||||||||||||||||||
| 1190 | d->setCurrentAction(action, popupState); never executed: d->setCurrentAction(action, popupState); | 0 | ||||||||||||||||||||||||
| 1191 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1192 | - | |||||||||||||||||||||||||
| 1193 | /*! | - | ||||||||||||||||||||||||
| 1194 | \reimp | - | ||||||||||||||||||||||||
| 1195 | */ | - | ||||||||||||||||||||||||
| 1196 | void QMenuBar::leaveEvent(QEvent *) | - | ||||||||||||||||||||||||
| 1197 | { | - | ||||||||||||||||||||||||
| 1198 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1199 | if((!hasFocus() && !d->popupState) ||
| 0 | ||||||||||||||||||||||||
| 1200 | (d->currentAction && d->currentAction->menu() == 0))
| 0 | ||||||||||||||||||||||||
| 1201 | d->setCurrentAction(0); never executed: d->setCurrentAction(0); | 0 | ||||||||||||||||||||||||
| 1202 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1203 | - | |||||||||||||||||||||||||
| 1204 | QPlatformMenu *getPlatformMenu(QAction *action) | - | ||||||||||||||||||||||||
| 1205 | { | - | ||||||||||||||||||||||||
| 1206 | if (!action || !action->menu())
| 0 | ||||||||||||||||||||||||
| 1207 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1208 | - | |||||||||||||||||||||||||
| 1209 | return action->menu()->platformMenu(); never executed: return action->menu()->platformMenu(); | 0 | ||||||||||||||||||||||||
| 1210 | } | - | ||||||||||||||||||||||||
| 1211 | - | |||||||||||||||||||||||||
| 1212 | /*! | - | ||||||||||||||||||||||||
| 1213 | \reimp | - | ||||||||||||||||||||||||
| 1214 | */ | - | ||||||||||||||||||||||||
| 1215 | void QMenuBar::actionEvent(QActionEvent *e) | - | ||||||||||||||||||||||||
| 1216 | { | - | ||||||||||||||||||||||||
| 1217 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1218 | d->itemsDirty = true; | - | ||||||||||||||||||||||||
| 1219 | - | |||||||||||||||||||||||||
| 1220 | if (d->platformMenuBar) {
| 0 | ||||||||||||||||||||||||
| 1221 | #if !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 1222 | QPlatformMenuBar *nativeMenuBar = d->platformMenuBar; | - | ||||||||||||||||||||||||
| 1223 | #else | - | ||||||||||||||||||||||||
| 1224 | QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar; | - | ||||||||||||||||||||||||
| 1225 | #endif | - | ||||||||||||||||||||||||
| 1226 | if (!nativeMenuBar)
| 0 | ||||||||||||||||||||||||
| 1227 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1228 | - | |||||||||||||||||||||||||
| 1229 | if (e->type() == QEvent::ActionAdded) {
| 0 | ||||||||||||||||||||||||
| 1230 | QPlatformMenu *menu = getPlatformMenu(e->action()); | - | ||||||||||||||||||||||||
| 1231 | if (menu) {
| 0 | ||||||||||||||||||||||||
| 1232 | QPlatformMenu* beforeMenu = NULL; | - | ||||||||||||||||||||||||
| 1233 | for (int beforeIndex = d->indexOf(e->action()) + 1; | - | ||||||||||||||||||||||||
| 1234 | !beforeMenu && (beforeIndex < actions().size());
| 0 | ||||||||||||||||||||||||
| 1235 | ++beforeIndex) | - | ||||||||||||||||||||||||
| 1236 | { | - | ||||||||||||||||||||||||
| 1237 | beforeMenu = getPlatformMenu(actions().at(beforeIndex)); | - | ||||||||||||||||||||||||
| 1238 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1239 | - | |||||||||||||||||||||||||
| 1240 | menu->setTag(reinterpret_cast<quintptr>(e->action())); | - | ||||||||||||||||||||||||
| 1241 | menu->setText(e->action()->text()); | - | ||||||||||||||||||||||||
| 1242 | d->platformMenuBar->insertMenu(menu, beforeMenu); | - | ||||||||||||||||||||||||
| 1243 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1244 | } else if (e->type() == QEvent::ActionRemoved) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1245 | QPlatformMenu *menu = getPlatformMenu(e->action()); | - | ||||||||||||||||||||||||
| 1246 | if (menu)
| 0 | ||||||||||||||||||||||||
| 1247 | d->platformMenuBar->removeMenu(menu); never executed: d->platformMenuBar->removeMenu(menu); | 0 | ||||||||||||||||||||||||
| 1248 | } else if (e->type() == QEvent::ActionChanged) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1249 | QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast<quintptr>(e->action())); | - | ||||||||||||||||||||||||
| 1250 | QPlatformMenu *menu = getPlatformMenu(e->action()); | - | ||||||||||||||||||||||||
| 1251 | - | |||||||||||||||||||||||||
| 1252 | // the menu associated with the action can change, need to | - | ||||||||||||||||||||||||
| 1253 | // remove and/or insert the new platform menu | - | ||||||||||||||||||||||||
| 1254 | if (menu != cur) {
| 0 | ||||||||||||||||||||||||
| 1255 | if (cur)
| 0 | ||||||||||||||||||||||||
| 1256 | d->platformMenuBar->removeMenu(cur); never executed: d->platformMenuBar->removeMenu(cur); | 0 | ||||||||||||||||||||||||
| 1257 | if (menu) {
| 0 | ||||||||||||||||||||||||
| 1258 | menu->setTag(reinterpret_cast<quintptr>(e->action())); | - | ||||||||||||||||||||||||
| 1259 | - | |||||||||||||||||||||||||
| 1260 | QPlatformMenu* beforeMenu = NULL; | - | ||||||||||||||||||||||||
| 1261 | for (int beforeIndex = d->indexOf(e->action()) + 1; | - | ||||||||||||||||||||||||
| 1262 | !beforeMenu && (beforeIndex < actions().size());
| 0 | ||||||||||||||||||||||||
| 1263 | ++beforeIndex) | - | ||||||||||||||||||||||||
| 1264 | { | - | ||||||||||||||||||||||||
| 1265 | beforeMenu = getPlatformMenu(actions().at(beforeIndex)); | - | ||||||||||||||||||||||||
| 1266 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1267 | d->platformMenuBar->insertMenu(menu, beforeMenu); | - | ||||||||||||||||||||||||
| 1268 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1269 | } else if (menu) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1270 | menu->setText(e->action()->text()); | - | ||||||||||||||||||||||||
| 1271 | menu->setVisible(e->action()->isVisible()); | - | ||||||||||||||||||||||||
| 1272 | menu->setEnabled(e->action()->isEnabled()); | - | ||||||||||||||||||||||||
| 1273 | d->platformMenuBar->syncMenu(menu); | - | ||||||||||||||||||||||||
| 1274 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1275 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1276 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1277 | - | |||||||||||||||||||||||||
| 1278 | if(e->type() == QEvent::ActionAdded) {
| 0 | ||||||||||||||||||||||||
| 1279 | connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); | - | ||||||||||||||||||||||||
| 1280 | connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered())); | - | ||||||||||||||||||||||||
| 1281 | } else if(e->type() == QEvent::ActionRemoved) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1282 | e->action()->disconnect(this); | - | ||||||||||||||||||||||||
| 1283 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1284 | if (isVisible()) {
| 0 | ||||||||||||||||||||||||
| 1285 | d->updateGeometries(); | - | ||||||||||||||||||||||||
| 1286 | update(); | - | ||||||||||||||||||||||||
| 1287 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1288 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1289 | - | |||||||||||||||||||||||||
| 1290 | /*! | - | ||||||||||||||||||||||||
| 1291 | \reimp | - | ||||||||||||||||||||||||
| 1292 | */ | - | ||||||||||||||||||||||||
| 1293 | void QMenuBar::focusInEvent(QFocusEvent *) | - | ||||||||||||||||||||||||
| 1294 | { | - | ||||||||||||||||||||||||
| 1295 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1296 | if(d->keyboardState)
| 0 | ||||||||||||||||||||||||
| 1297 | d->focusFirstAction(); never executed: d->focusFirstAction(); | 0 | ||||||||||||||||||||||||
| 1298 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1299 | - | |||||||||||||||||||||||||
| 1300 | /*! | - | ||||||||||||||||||||||||
| 1301 | \reimp | - | ||||||||||||||||||||||||
| 1302 | */ | - | ||||||||||||||||||||||||
| 1303 | void QMenuBar::focusOutEvent(QFocusEvent *) | - | ||||||||||||||||||||||||
| 1304 | { | - | ||||||||||||||||||||||||
| 1305 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1306 | if(!d->popupState) {
| 0 | ||||||||||||||||||||||||
| 1307 | d->setCurrentAction(0); | - | ||||||||||||||||||||||||
| 1308 | d->setKeyboardMode(false); | - | ||||||||||||||||||||||||
| 1309 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1310 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1311 | - | |||||||||||||||||||||||||
| 1312 | /*! | - | ||||||||||||||||||||||||
| 1313 | \reimp | - | ||||||||||||||||||||||||
| 1314 | */ | - | ||||||||||||||||||||||||
| 1315 | void QMenuBar::timerEvent (QTimerEvent *e) | - | ||||||||||||||||||||||||
| 1316 | { | - | ||||||||||||||||||||||||
| 1317 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1318 | if (e->timerId() == d->autoReleaseTimer.timerId()) {
| 0 | ||||||||||||||||||||||||
| 1319 | d->autoReleaseTimer.stop(); | - | ||||||||||||||||||||||||
| 1320 | d->setCurrentAction(0); | - | ||||||||||||||||||||||||
| 1321 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1322 | QWidget::timerEvent(e); | - | ||||||||||||||||||||||||
| 1323 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1324 | - | |||||||||||||||||||||||||
| 1325 | - | |||||||||||||||||||||||||
| 1326 | void QMenuBarPrivate::handleReparent() | - | ||||||||||||||||||||||||
| 1327 | { | - | ||||||||||||||||||||||||
| 1328 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 1329 | QWidget *newParent = q->parentWidget(); | - | ||||||||||||||||||||||||
| 1330 | - | |||||||||||||||||||||||||
| 1331 | //Note: if parent is reparented, then window may change even if parent doesn't. | - | ||||||||||||||||||||||||
| 1332 | // We need to install an avent filter on each parent up to the parent that is | - | ||||||||||||||||||||||||
| 1333 | // also a window (for shortcuts) | - | ||||||||||||||||||||||||
| 1334 | QWidget *newWindow = newParent ? newParent->window() : Q_NULLPTR;
| 0 | ||||||||||||||||||||||||
| 1335 | - | |||||||||||||||||||||||||
| 1336 | QVector<QPointer<QWidget> > newParents; | - | ||||||||||||||||||||||||
| 1337 | // Remove event filters on ex-parents, keep them on still-parents | - | ||||||||||||||||||||||||
| 1338 | // The parents are always ordered in the vector | - | ||||||||||||||||||||||||
| 1339 | foreach (const QPointer<QWidget> &w, oldParents) { | - | ||||||||||||||||||||||||
| 1340 | if (w) {
| 0 | ||||||||||||||||||||||||
| 1341 | if (newParent == w) {
| 0 | ||||||||||||||||||||||||
| 1342 | newParents.append(w); | - | ||||||||||||||||||||||||
| 1343 | if (newParent != newWindow) //stop at the window
| 0 | ||||||||||||||||||||||||
| 1344 | newParent = newParent->parentWidget(); never executed: newParent = newParent->parentWidget(); | 0 | ||||||||||||||||||||||||
| 1345 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1346 | w->removeEventFilter(q); | - | ||||||||||||||||||||||||
| 1347 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1348 | } | - | ||||||||||||||||||||||||
| 1349 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1350 | - | |||||||||||||||||||||||||
| 1351 | // At this point, newParent is the next one to be added to newParents | - | ||||||||||||||||||||||||
| 1352 | while (newParent && newParent != newWindow) {
| 0 | ||||||||||||||||||||||||
| 1353 | //install event filters all the way up to (excluding) the window | - | ||||||||||||||||||||||||
| 1354 | newParents.append(newParent); | - | ||||||||||||||||||||||||
| 1355 | newParent->installEventFilter(q); | - | ||||||||||||||||||||||||
| 1356 | newParent = newParent->parentWidget(); | - | ||||||||||||||||||||||||
| 1357 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1358 | - | |||||||||||||||||||||||||
| 1359 | if (newParent && newWindow) {
| 0 | ||||||||||||||||||||||||
| 1360 | // Install the event filter on the window | - | ||||||||||||||||||||||||
| 1361 | newParents.append(newParent); | - | ||||||||||||||||||||||||
| 1362 | newParent->installEventFilter(q); | - | ||||||||||||||||||||||||
| 1363 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1364 | oldParents = newParents; | - | ||||||||||||||||||||||||
| 1365 | - | |||||||||||||||||||||||||
| 1366 | if (platformMenuBar) {
| 0 | ||||||||||||||||||||||||
| 1367 | if (newWindow) {
| 0 | ||||||||||||||||||||||||
| 1368 | // force the underlying platform window to be created, since | - | ||||||||||||||||||||||||
| 1369 | // the platform menubar needs it (and we have no other way to | - | ||||||||||||||||||||||||
| 1370 | // discover when the platform window is created) | - | ||||||||||||||||||||||||
| 1371 | newWindow->createWinId(); | - | ||||||||||||||||||||||||
| 1372 | platformMenuBar->handleReparent(newWindow->windowHandle()); | - | ||||||||||||||||||||||||
| 1373 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1374 | platformMenuBar->handleReparent(0); | - | ||||||||||||||||||||||||
| 1375 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1376 | } | - | ||||||||||||||||||||||||
| 1377 | - | |||||||||||||||||||||||||
| 1378 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||||||||
| 1379 | if (qt_wince_is_mobile() && wce_menubar) | - | ||||||||||||||||||||||||
| 1380 | wce_menubar->rebuild(); | - | ||||||||||||||||||||||||
| 1381 | #endif | - | ||||||||||||||||||||||||
| 1382 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1383 | - | |||||||||||||||||||||||||
| 1384 | /*! | - | ||||||||||||||||||||||||
| 1385 | \reimp | - | ||||||||||||||||||||||||
| 1386 | */ | - | ||||||||||||||||||||||||
| 1387 | void QMenuBar::changeEvent(QEvent *e) | - | ||||||||||||||||||||||||
| 1388 | { | - | ||||||||||||||||||||||||
| 1389 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1390 | if(e->type() == QEvent::StyleChange) {
| 0 | ||||||||||||||||||||||||
| 1391 | d->itemsDirty = true; | - | ||||||||||||||||||||||||
| 1392 | setMouseTracking(style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, this)); | - | ||||||||||||||||||||||||
| 1393 | if(parentWidget())
| 0 | ||||||||||||||||||||||||
| 1394 | resize(parentWidget()->width(), heightForWidth(parentWidget()->width())); never executed: resize(parentWidget()->width(), heightForWidth(parentWidget()->width())); | 0 | ||||||||||||||||||||||||
| 1395 | d->updateGeometries(); | - | ||||||||||||||||||||||||
| 1396 | } else if (e->type() == QEvent::ParentChange) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1397 | d->handleReparent(); | - | ||||||||||||||||||||||||
| 1398 | } else if (e->type() == QEvent::FontChange never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1399 | || e->type() == QEvent::ApplicationFontChange) {
| 0 | ||||||||||||||||||||||||
| 1400 | d->itemsDirty = true; | - | ||||||||||||||||||||||||
| 1401 | d->updateGeometries(); | - | ||||||||||||||||||||||||
| 1402 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1403 | - | |||||||||||||||||||||||||
| 1404 | QWidget::changeEvent(e); | - | ||||||||||||||||||||||||
| 1405 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1406 | - | |||||||||||||||||||||||||
| 1407 | /*! | - | ||||||||||||||||||||||||
| 1408 | \reimp | - | ||||||||||||||||||||||||
| 1409 | */ | - | ||||||||||||||||||||||||
| 1410 | bool QMenuBar::event(QEvent *e) | - | ||||||||||||||||||||||||
| 1411 | { | - | ||||||||||||||||||||||||
| 1412 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1413 | switch (e->type()) { | - | ||||||||||||||||||||||||
| 1414 | case QEvent::KeyPress: { never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 1415 | QKeyEvent *ke = (QKeyEvent*)e; | - | ||||||||||||||||||||||||
| 1416 | #if 0 | - | ||||||||||||||||||||||||
| 1417 | if(!d->keyboardState) { //all keypresses.. | - | ||||||||||||||||||||||||
| 1418 | d->setCurrentAction(0); | - | ||||||||||||||||||||||||
| 1419 | return ; | - | ||||||||||||||||||||||||
| 1420 | } | - | ||||||||||||||||||||||||
| 1421 | #endif | - | ||||||||||||||||||||||||
| 1422 | if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
| 0 | ||||||||||||||||||||||||
| 1423 | keyPressEvent(ke); | - | ||||||||||||||||||||||||
| 1424 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1425 | } | - | ||||||||||||||||||||||||
| 1426 | - | |||||||||||||||||||||||||
| 1427 | } break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1428 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||||||||
| 1429 | case QEvent::Shortcut: { never executed: case QEvent::Shortcut: | 0 | ||||||||||||||||||||||||
| 1430 | QShortcutEvent *se = static_cast<QShortcutEvent *>(e); | - | ||||||||||||||||||||||||
| 1431 | int shortcutId = se->shortcutId(); | - | ||||||||||||||||||||||||
| 1432 | for(int j = 0; j < d->shortcutIndexMap.size(); ++j) {
| 0 | ||||||||||||||||||||||||
| 1433 | if (shortcutId == d->shortcutIndexMap.value(j))
| 0 | ||||||||||||||||||||||||
| 1434 | d->_q_internalShortcutActivated(j); never executed: d->_q_internalShortcutActivated(j); | 0 | ||||||||||||||||||||||||
| 1435 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1436 | } break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1437 | #endif | - | ||||||||||||||||||||||||
| 1438 | case QEvent::Show: never executed: case QEvent::Show: | 0 | ||||||||||||||||||||||||
| 1439 | d->_q_updateLayout(); | - | ||||||||||||||||||||||||
| 1440 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1441 | case QEvent::ShortcutOverride: { never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||||||||
| 1442 | QKeyEvent *kev = static_cast<QKeyEvent*>(e); | - | ||||||||||||||||||||||||
| 1443 | //we only filter out escape if there is a current action | - | ||||||||||||||||||||||||
| 1444 | if (kev->matches(QKeySequence::Cancel) && d->currentAction) {
| 0 | ||||||||||||||||||||||||
| 1445 | e->accept(); | - | ||||||||||||||||||||||||
| 1446 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1447 | } | - | ||||||||||||||||||||||||
| 1448 | } | - | ||||||||||||||||||||||||
| 1449 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1450 | - | |||||||||||||||||||||||||
| 1451 | - | |||||||||||||||||||||||||
| 1452 | #ifndef QT_NO_WHATSTHIS | - | ||||||||||||||||||||||||
| 1453 | case QEvent::QueryWhatsThis: never executed: case QEvent::QueryWhatsThis: | 0 | ||||||||||||||||||||||||
| 1454 | e->setAccepted(d->whatsThis.size()); | - | ||||||||||||||||||||||||
| 1455 | if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) {
| 0 | ||||||||||||||||||||||||
| 1456 | if (action->whatsThis().size() || action->menu())
| 0 | ||||||||||||||||||||||||
| 1457 | e->accept(); never executed: e->accept(); | 0 | ||||||||||||||||||||||||
| 1458 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1459 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1460 | #endif | - | ||||||||||||||||||||||||
| 1461 | case QEvent::LayoutDirectionChange: never executed: case QEvent::LayoutDirectionChange: | 0 | ||||||||||||||||||||||||
| 1462 | d->_q_updateLayout(); | - | ||||||||||||||||||||||||
| 1463 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1464 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1465 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1466 | } | - | ||||||||||||||||||||||||
| 1467 | return QWidget::event(e); never executed: return QWidget::event(e); | 0 | ||||||||||||||||||||||||
| 1468 | } | - | ||||||||||||||||||||||||
| 1469 | - | |||||||||||||||||||||||||
| 1470 | /*! | - | ||||||||||||||||||||||||
| 1471 | \reimp | - | ||||||||||||||||||||||||
| 1472 | */ | - | ||||||||||||||||||||||||
| 1473 | bool QMenuBar::eventFilter(QObject *object, QEvent *event) | - | ||||||||||||||||||||||||
| 1474 | { | - | ||||||||||||||||||||||||
| 1475 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1476 | if (object && (event->type() == QEvent::ParentChange)) //GrandparentChange
| 0 | ||||||||||||||||||||||||
| 1477 | d->handleReparent(); never executed: d->handleReparent(); | 0 | ||||||||||||||||||||||||
| 1478 | - | |||||||||||||||||||||||||
| 1479 | if (object == d->leftWidget || object == d->rightWidget) {
| 0 | ||||||||||||||||||||||||
| 1480 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 1481 | case QEvent::ShowToParent: never executed: case QEvent::ShowToParent: | 0 | ||||||||||||||||||||||||
| 1482 | case QEvent::HideToParent: never executed: case QEvent::HideToParent: | 0 | ||||||||||||||||||||||||
| 1483 | d->_q_updateLayout(); | - | ||||||||||||||||||||||||
| 1484 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1485 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1486 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1487 | } | - | ||||||||||||||||||||||||
| 1488 | } | - | ||||||||||||||||||||||||
| 1489 | - | |||||||||||||||||||||||||
| 1490 | if (style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this)) {
| 0 | ||||||||||||||||||||||||
| 1491 | if (d->altPressed) {
| 0 | ||||||||||||||||||||||||
| 1492 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 1493 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 1494 | case QEvent::KeyRelease: never executed: case QEvent::KeyRelease: | 0 | ||||||||||||||||||||||||
| 1495 | { | - | ||||||||||||||||||||||||
| 1496 | QKeyEvent *kev = static_cast<QKeyEvent*>(event); | - | ||||||||||||||||||||||||
| 1497 | if (kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta) {
| 0 | ||||||||||||||||||||||||
| 1498 | if (event->type() == QEvent::KeyPress) // Alt-press does not interest us, we have the shortcut-override event
| 0 | ||||||||||||||||||||||||
| 1499 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1500 | d->setKeyboardMode(!d->keyboardState); | - | ||||||||||||||||||||||||
| 1501 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1502 | } | - | ||||||||||||||||||||||||
| 1503 | // fall through | - | ||||||||||||||||||||||||
| 1504 | case QEvent::MouseButtonPress: code before this statement never executed: case QEvent::MouseButtonPress:never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
| 1505 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
| 1506 | case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||||||||
| 1507 | case QEvent::FocusIn: never executed: case QEvent::FocusIn: | 0 | ||||||||||||||||||||||||
| 1508 | case QEvent::FocusOut: never executed: case QEvent::FocusOut: | 0 | ||||||||||||||||||||||||
| 1509 | case QEvent::ActivationChange: never executed: case QEvent::ActivationChange: | 0 | ||||||||||||||||||||||||
| 1510 | d->altPressed = false; | - | ||||||||||||||||||||||||
| 1511 | qApp->removeEventFilter(this); | - | ||||||||||||||||||||||||
| 1512 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1513 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1514 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1515 | } | - | ||||||||||||||||||||||||
| 1516 | } else if (isVisible()) {
| 0 | ||||||||||||||||||||||||
| 1517 | if (event->type() == QEvent::ShortcutOverride) {
| 0 | ||||||||||||||||||||||||
| 1518 | QKeyEvent *kev = static_cast<QKeyEvent*>(event); | - | ||||||||||||||||||||||||
| 1519 | if ((kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta)
| 0 | ||||||||||||||||||||||||
| 1520 | && kev->modifiers() == Qt::AltModifier) {
| 0 | ||||||||||||||||||||||||
| 1521 | d->altPressed = true; | - | ||||||||||||||||||||||||
| 1522 | qApp->installEventFilter(this); | - | ||||||||||||||||||||||||
| 1523 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1524 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1525 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1526 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1527 | - | |||||||||||||||||||||||||
| 1528 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1529 | } | - | ||||||||||||||||||||||||
| 1530 | - | |||||||||||||||||||||||||
| 1531 | /*! | - | ||||||||||||||||||||||||
| 1532 | Returns the QAction at \a pt. Returns 0 if there is no action at \a pt or if | - | ||||||||||||||||||||||||
| 1533 | the location has a separator. | - | ||||||||||||||||||||||||
| 1534 | - | |||||||||||||||||||||||||
| 1535 | \sa addAction(), addSeparator() | - | ||||||||||||||||||||||||
| 1536 | */ | - | ||||||||||||||||||||||||
| 1537 | QAction *QMenuBar::actionAt(const QPoint &pt) const | - | ||||||||||||||||||||||||
| 1538 | { | - | ||||||||||||||||||||||||
| 1539 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1540 | return d->actionAt(pt); never executed: return d->actionAt(pt); | 0 | ||||||||||||||||||||||||
| 1541 | } | - | ||||||||||||||||||||||||
| 1542 | - | |||||||||||||||||||||||||
| 1543 | /*! | - | ||||||||||||||||||||||||
| 1544 | Returns the geometry of action \a act as a QRect. | - | ||||||||||||||||||||||||
| 1545 | - | |||||||||||||||||||||||||
| 1546 | \sa actionAt() | - | ||||||||||||||||||||||||
| 1547 | */ | - | ||||||||||||||||||||||||
| 1548 | QRect QMenuBar::actionGeometry(QAction *act) const | - | ||||||||||||||||||||||||
| 1549 | { | - | ||||||||||||||||||||||||
| 1550 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1551 | return d->actionRect(act); never executed: return d->actionRect(act); | 0 | ||||||||||||||||||||||||
| 1552 | } | - | ||||||||||||||||||||||||
| 1553 | - | |||||||||||||||||||||||||
| 1554 | /*! | - | ||||||||||||||||||||||||
| 1555 | \reimp | - | ||||||||||||||||||||||||
| 1556 | */ | - | ||||||||||||||||||||||||
| 1557 | QSize QMenuBar::minimumSizeHint() const | - | ||||||||||||||||||||||||
| 1558 | { | - | ||||||||||||||||||||||||
| 1559 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1560 | const bool as_gui_menubar = !isNativeMenuBar(); | - | ||||||||||||||||||||||||
| 1561 | - | |||||||||||||||||||||||||
| 1562 | ensurePolished(); | - | ||||||||||||||||||||||||
| 1563 | QSize ret(0, 0); | - | ||||||||||||||||||||||||
| 1564 | const_cast<QMenuBarPrivate*>(d)->updateGeometries(); | - | ||||||||||||||||||||||||
| 1565 | const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); | - | ||||||||||||||||||||||||
| 1566 | const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); | - | ||||||||||||||||||||||||
| 1567 | int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); | - | ||||||||||||||||||||||||
| 1568 | int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); | - | ||||||||||||||||||||||||
| 1569 | if(as_gui_menubar) {
| 0 | ||||||||||||||||||||||||
| 1570 | int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
| 0 | ||||||||||||||||||||||||
| 1571 | d->calcActionRects(w - (2 * fw), 0); | - | ||||||||||||||||||||||||
| 1572 | for (int i = 0; ret.isNull() && i < d->actions.count(); ++i)
| 0 | ||||||||||||||||||||||||
| 1573 | ret = d->actionRects.at(i).size(); never executed: ret = d->actionRects.at(i).size(); | 0 | ||||||||||||||||||||||||
| 1574 | if (!d->extension->isHidden())
| 0 | ||||||||||||||||||||||||
| 1575 | ret += QSize(d->extension->sizeHint().width(), 0); never executed: ret += QSize(d->extension->sizeHint().width(), 0); | 0 | ||||||||||||||||||||||||
| 1576 | ret += QSize(2*fw + hmargin, 2*fw + vmargin); | - | ||||||||||||||||||||||||
| 1577 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1578 | int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; | - | ||||||||||||||||||||||||
| 1579 | if(d->leftWidget) {
| 0 | ||||||||||||||||||||||||
| 1580 | QSize sz = d->leftWidget->minimumSizeHint(); | - | ||||||||||||||||||||||||
| 1581 | ret.setWidth(ret.width() + sz.width()); | - | ||||||||||||||||||||||||
| 1582 | if(sz.height() + margin > ret.height())
| 0 | ||||||||||||||||||||||||
| 1583 | ret.setHeight(sz.height() + margin); never executed: ret.setHeight(sz.height() + margin); | 0 | ||||||||||||||||||||||||
| 1584 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1585 | if(d->rightWidget) {
| 0 | ||||||||||||||||||||||||
| 1586 | QSize sz = d->rightWidget->minimumSizeHint(); | - | ||||||||||||||||||||||||
| 1587 | ret.setWidth(ret.width() + sz.width()); | - | ||||||||||||||||||||||||
| 1588 | if(sz.height() + margin > ret.height())
| 0 | ||||||||||||||||||||||||
| 1589 | ret.setHeight(sz.height() + margin); never executed: ret.setHeight(sz.height() + margin); | 0 | ||||||||||||||||||||||||
| 1590 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1591 | if(as_gui_menubar) {
| 0 | ||||||||||||||||||||||||
| 1592 | QStyleOptionMenuItem opt; | - | ||||||||||||||||||||||||
| 1593 | opt.rect = rect(); | - | ||||||||||||||||||||||||
| 1594 | opt.menuRect = rect(); | - | ||||||||||||||||||||||||
| 1595 | opt.state = QStyle::State_None; | - | ||||||||||||||||||||||||
| 1596 | opt.menuItemType = QStyleOptionMenuItem::Normal; | - | ||||||||||||||||||||||||
| 1597 | opt.checkType = QStyleOptionMenuItem::NotCheckable; | - | ||||||||||||||||||||||||
| 1598 | opt.palette = palette(); | - | ||||||||||||||||||||||||
| 1599 | return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this)); | 0 | ||||||||||||||||||||||||
| 1600 | ret.expandedTo(QApplication::globalStrut()), never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this)); | 0 | ||||||||||||||||||||||||
| 1601 | this)); never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this)); | 0 | ||||||||||||||||||||||||
| 1602 | } | - | ||||||||||||||||||||||||
| 1603 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 1604 | } | - | ||||||||||||||||||||||||
| 1605 | - | |||||||||||||||||||||||||
| 1606 | /*! | - | ||||||||||||||||||||||||
| 1607 | \reimp | - | ||||||||||||||||||||||||
| 1608 | */ | - | ||||||||||||||||||||||||
| 1609 | QSize QMenuBar::sizeHint() const | - | ||||||||||||||||||||||||
| 1610 | { | - | ||||||||||||||||||||||||
| 1611 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1612 | const bool as_gui_menubar = !isNativeMenuBar(); | - | ||||||||||||||||||||||||
| 1613 | - | |||||||||||||||||||||||||
| 1614 | ensurePolished(); | - | ||||||||||||||||||||||||
| 1615 | QSize ret(0, 0); | - | ||||||||||||||||||||||||
| 1616 | const_cast<QMenuBarPrivate*>(d)->updateGeometries(); | - | ||||||||||||||||||||||||
| 1617 | const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); | - | ||||||||||||||||||||||||
| 1618 | const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); | - | ||||||||||||||||||||||||
| 1619 | int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); | - | ||||||||||||||||||||||||
| 1620 | int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); | - | ||||||||||||||||||||||||
| 1621 | if(as_gui_menubar) {
| 0 | ||||||||||||||||||||||||
| 1622 | const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
| 0 | ||||||||||||||||||||||||
| 1623 | d->calcActionRects(w - (2 * fw), 0); | - | ||||||||||||||||||||||||
| 1624 | for (int i = 0; i < d->actionRects.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 1625 | const QRect &actionRect = d->actionRects.at(i); | - | ||||||||||||||||||||||||
| 1626 | ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height())); | - | ||||||||||||||||||||||||
| 1627 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1628 | //the action geometries already contain the top and left | - | ||||||||||||||||||||||||
| 1629 | //margins. So we only need to add those from right and bottom. | - | ||||||||||||||||||||||||
| 1630 | ret += QSize(fw + hmargin, fw + vmargin); | - | ||||||||||||||||||||||||
| 1631 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1632 | int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; | - | ||||||||||||||||||||||||
| 1633 | if(d->leftWidget) {
| 0 | ||||||||||||||||||||||||
| 1634 | QSize sz = d->leftWidget->sizeHint(); | - | ||||||||||||||||||||||||
| 1635 | sz.rheight() += margin; | - | ||||||||||||||||||||||||
| 1636 | ret = ret.expandedTo(sz); | - | ||||||||||||||||||||||||
| 1637 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1638 | if(d->rightWidget) {
| 0 | ||||||||||||||||||||||||
| 1639 | QSize sz = d->rightWidget->sizeHint(); | - | ||||||||||||||||||||||||
| 1640 | ret.setWidth(ret.width() + sz.width()); | - | ||||||||||||||||||||||||
| 1641 | if(sz.height() + margin > ret.height())
| 0 | ||||||||||||||||||||||||
| 1642 | ret.setHeight(sz.height() + margin); never executed: ret.setHeight(sz.height() + margin); | 0 | ||||||||||||||||||||||||
| 1643 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1644 | if(as_gui_menubar) {
| 0 | ||||||||||||||||||||||||
| 1645 | QStyleOptionMenuItem opt; | - | ||||||||||||||||||||||||
| 1646 | opt.rect = rect(); | - | ||||||||||||||||||||||||
| 1647 | opt.menuRect = rect(); | - | ||||||||||||||||||||||||
| 1648 | opt.state = QStyle::State_None; | - | ||||||||||||||||||||||||
| 1649 | opt.menuItemType = QStyleOptionMenuItem::Normal; | - | ||||||||||||||||||||||||
| 1650 | opt.checkType = QStyleOptionMenuItem::NotCheckable; | - | ||||||||||||||||||||||||
| 1651 | opt.palette = palette(); | - | ||||||||||||||||||||||||
| 1652 | return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this)); | 0 | ||||||||||||||||||||||||
| 1653 | ret.expandedTo(QApplication::globalStrut()), never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this)); | 0 | ||||||||||||||||||||||||
| 1654 | this)); never executed: return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, ret.expandedTo(QApplication::globalStrut()), this)); | 0 | ||||||||||||||||||||||||
| 1655 | } | - | ||||||||||||||||||||||||
| 1656 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 1657 | } | - | ||||||||||||||||||||||||
| 1658 | - | |||||||||||||||||||||||||
| 1659 | /*! | - | ||||||||||||||||||||||||
| 1660 | \reimp | - | ||||||||||||||||||||||||
| 1661 | */ | - | ||||||||||||||||||||||||
| 1662 | int QMenuBar::heightForWidth(int) const | - | ||||||||||||||||||||||||
| 1663 | { | - | ||||||||||||||||||||||||
| 1664 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1665 | const bool as_gui_menubar = !isNativeMenuBar(); | - | ||||||||||||||||||||||||
| 1666 | - | |||||||||||||||||||||||||
| 1667 | const_cast<QMenuBarPrivate*>(d)->updateGeometries(); | - | ||||||||||||||||||||||||
| 1668 | int height = 0; | - | ||||||||||||||||||||||||
| 1669 | const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); | - | ||||||||||||||||||||||||
| 1670 | int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); | - | ||||||||||||||||||||||||
| 1671 | int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); | - | ||||||||||||||||||||||||
| 1672 | if(as_gui_menubar) {
| 0 | ||||||||||||||||||||||||
| 1673 | for (int i = 0; i < d->actionRects.count(); ++i)
| 0 | ||||||||||||||||||||||||
| 1674 | height = qMax(height, d->actionRects.at(i).height()); never executed: height = qMax(height, d->actionRects.at(i).height()); | 0 | ||||||||||||||||||||||||
| 1675 | if (height) //there is at least one non-null item
| 0 | ||||||||||||||||||||||||
| 1676 | height += spaceBelowMenuBar; never executed: height += spaceBelowMenuBar; | 0 | ||||||||||||||||||||||||
| 1677 | height += 2*fw; | - | ||||||||||||||||||||||||
| 1678 | height += 2*vmargin; | - | ||||||||||||||||||||||||
| 1679 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1680 | int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; | - | ||||||||||||||||||||||||
| 1681 | if(d->leftWidget)
| 0 | ||||||||||||||||||||||||
| 1682 | height = qMax(d->leftWidget->sizeHint().height() + margin, height); never executed: height = qMax(d->leftWidget->sizeHint().height() + margin, height); | 0 | ||||||||||||||||||||||||
| 1683 | if(d->rightWidget)
| 0 | ||||||||||||||||||||||||
| 1684 | height = qMax(d->rightWidget->sizeHint().height() + margin, height); never executed: height = qMax(d->rightWidget->sizeHint().height() + margin, height); | 0 | ||||||||||||||||||||||||
| 1685 | if(as_gui_menubar) {
| 0 | ||||||||||||||||||||||||
| 1686 | QStyleOptionMenuItem opt; | - | ||||||||||||||||||||||||
| 1687 | opt.init(this); | - | ||||||||||||||||||||||||
| 1688 | opt.menuRect = rect(); | - | ||||||||||||||||||||||||
| 1689 | opt.state = QStyle::State_None; | - | ||||||||||||||||||||||||
| 1690 | opt.menuItemType = QStyleOptionMenuItem::Normal; | - | ||||||||||||||||||||||||
| 1691 | opt.checkType = QStyleOptionMenuItem::NotCheckable; | - | ||||||||||||||||||||||||
| 1692 | return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); //not pretty.. never executed: return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); | 0 | ||||||||||||||||||||||||
| 1693 | } | - | ||||||||||||||||||||||||
| 1694 | return height; never executed: return height; | 0 | ||||||||||||||||||||||||
| 1695 | } | - | ||||||||||||||||||||||||
| 1696 | - | |||||||||||||||||||||||||
| 1697 | /*! | - | ||||||||||||||||||||||||
| 1698 | \internal | - | ||||||||||||||||||||||||
| 1699 | */ | - | ||||||||||||||||||||||||
| 1700 | void QMenuBarPrivate::_q_internalShortcutActivated(int id) | - | ||||||||||||||||||||||||
| 1701 | { | - | ||||||||||||||||||||||||
| 1702 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 1703 | QAction *act = actions.at(id); | - | ||||||||||||||||||||||||
| 1704 | setCurrentAction(act, true, true); | - | ||||||||||||||||||||||||
| 1705 | if (act && !act->menu()) {
| 0 | ||||||||||||||||||||||||
| 1706 | activateAction(act, QAction::Trigger); | - | ||||||||||||||||||||||||
| 1707 | //100 is the same as the default value in QPushButton::animateClick | - | ||||||||||||||||||||||||
| 1708 | autoReleaseTimer.start(100, q); | - | ||||||||||||||||||||||||
| 1709 | } else if (act && q->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, q)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1710 | // When we open a menu using a shortcut, we should end up in keyboard state | - | ||||||||||||||||||||||||
| 1711 | setKeyboardMode(true); | - | ||||||||||||||||||||||||
| 1712 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1713 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1714 | - | |||||||||||||||||||||||||
| 1715 | void QMenuBarPrivate::_q_updateLayout() | - | ||||||||||||||||||||||||
| 1716 | { | - | ||||||||||||||||||||||||
| 1717 | Q_Q(QMenuBar); | - | ||||||||||||||||||||||||
| 1718 | itemsDirty = true; | - | ||||||||||||||||||||||||
| 1719 | if (q->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 1720 | updateGeometries(); | - | ||||||||||||||||||||||||
| 1721 | q->update(); | - | ||||||||||||||||||||||||
| 1722 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1723 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1724 | - | |||||||||||||||||||||||||
| 1725 | /*! | - | ||||||||||||||||||||||||
| 1726 | \fn void QMenuBar::setCornerWidget(QWidget *widget, Qt::Corner corner) | - | ||||||||||||||||||||||||
| 1727 | - | |||||||||||||||||||||||||
| 1728 | This sets the given \a widget to be shown directly on the left of the first | - | ||||||||||||||||||||||||
| 1729 | menu item, or on the right of the last menu item, depending on \a corner. | - | ||||||||||||||||||||||||
| 1730 | - | |||||||||||||||||||||||||
| 1731 | The menu bar takes ownership of \a widget, reparenting it into the menu bar. | - | ||||||||||||||||||||||||
| 1732 | However, if the \a corner already contains a widget, this previous widget | - | ||||||||||||||||||||||||
| 1733 | will no longer be managed and will still be a visible child of the menu bar. | - | ||||||||||||||||||||||||
| 1734 | - | |||||||||||||||||||||||||
| 1735 | \note Using a corner other than Qt::TopRightCorner or Qt::TopLeftCorner | - | ||||||||||||||||||||||||
| 1736 | will result in a warning. | - | ||||||||||||||||||||||||
| 1737 | */ | - | ||||||||||||||||||||||||
| 1738 | void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner) | - | ||||||||||||||||||||||||
| 1739 | { | - | ||||||||||||||||||||||||
| 1740 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1741 | switch (corner) { | - | ||||||||||||||||||||||||
| 1742 | case Qt::TopLeftCorner: never executed: case Qt::TopLeftCorner: | 0 | ||||||||||||||||||||||||
| 1743 | if (d->leftWidget)
| 0 | ||||||||||||||||||||||||
| 1744 | d->leftWidget->removeEventFilter(this); never executed: d->leftWidget->removeEventFilter(this); | 0 | ||||||||||||||||||||||||
| 1745 | d->leftWidget = w; | - | ||||||||||||||||||||||||
| 1746 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1747 | case Qt::TopRightCorner: never executed: case Qt::TopRightCorner: | 0 | ||||||||||||||||||||||||
| 1748 | if (d->rightWidget)
| 0 | ||||||||||||||||||||||||
| 1749 | d->rightWidget->removeEventFilter(this); never executed: d->rightWidget->removeEventFilter(this); | 0 | ||||||||||||||||||||||||
| 1750 | d->rightWidget = w; | - | ||||||||||||||||||||||||
| 1751 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1752 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1753 | qWarning("QMenuBar::setCornerWidget: Only TopLeftCorner and TopRightCorner are supported"); | - | ||||||||||||||||||||||||
| 1754 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1755 | } | - | ||||||||||||||||||||||||
| 1756 | - | |||||||||||||||||||||||||
| 1757 | if (w) {
| 0 | ||||||||||||||||||||||||
| 1758 | w->setParent(this); | - | ||||||||||||||||||||||||
| 1759 | w->installEventFilter(this); | - | ||||||||||||||||||||||||
| 1760 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1761 | - | |||||||||||||||||||||||||
| 1762 | d->_q_updateLayout(); | - | ||||||||||||||||||||||||
| 1763 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1764 | - | |||||||||||||||||||||||||
| 1765 | /*! | - | ||||||||||||||||||||||||
| 1766 | Returns the widget on the left of the first or on the right of the last menu | - | ||||||||||||||||||||||||
| 1767 | item, depending on \a corner. | - | ||||||||||||||||||||||||
| 1768 | - | |||||||||||||||||||||||||
| 1769 | \note Using a corner other than Qt::TopRightCorner or Qt::TopLeftCorner | - | ||||||||||||||||||||||||
| 1770 | will result in a warning. | - | ||||||||||||||||||||||||
| 1771 | */ | - | ||||||||||||||||||||||||
| 1772 | QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const | - | ||||||||||||||||||||||||
| 1773 | { | - | ||||||||||||||||||||||||
| 1774 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1775 | QWidget *w = 0; | - | ||||||||||||||||||||||||
| 1776 | switch(corner) { | - | ||||||||||||||||||||||||
| 1777 | case Qt::TopLeftCorner: never executed: case Qt::TopLeftCorner: | 0 | ||||||||||||||||||||||||
| 1778 | w = d->leftWidget; | - | ||||||||||||||||||||||||
| 1779 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1780 | case Qt::TopRightCorner: never executed: case Qt::TopRightCorner: | 0 | ||||||||||||||||||||||||
| 1781 | w = d->rightWidget; | - | ||||||||||||||||||||||||
| 1782 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1783 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1784 | qWarning("QMenuBar::cornerWidget: Only TopLeftCorner and TopRightCorner are supported"); | - | ||||||||||||||||||||||||
| 1785 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1786 | } | - | ||||||||||||||||||||||||
| 1787 | - | |||||||||||||||||||||||||
| 1788 | return w; never executed: return w; | 0 | ||||||||||||||||||||||||
| 1789 | } | - | ||||||||||||||||||||||||
| 1790 | - | |||||||||||||||||||||||||
| 1791 | /*! | - | ||||||||||||||||||||||||
| 1792 | \property QMenuBar::nativeMenuBar | - | ||||||||||||||||||||||||
| 1793 | \brief Whether or not a menubar will be used as a native menubar on platforms that support it | - | ||||||||||||||||||||||||
| 1794 | \since 4.6 | - | ||||||||||||||||||||||||
| 1795 | - | |||||||||||||||||||||||||
| 1796 | This property specifies whether or not the menubar should be used as a native menubar on platforms | - | ||||||||||||||||||||||||
| 1797 | that support it. The currently supported platforms are \macos and Windows CE. On these platforms | - | ||||||||||||||||||||||||
| 1798 | if this property is \c true, the menubar is used in the native menubar and is not in the window of | - | ||||||||||||||||||||||||
| 1799 | its parent, if false the menubar remains in the window. On other platforms the value of this | - | ||||||||||||||||||||||||
| 1800 | attribute has no effect. | - | ||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||
| 1802 | The default is to follow whether the Qt::AA_DontUseNativeMenuBar attribute | - | ||||||||||||||||||||||||
| 1803 | is set for the application. Explicitly settings this property overrides | - | ||||||||||||||||||||||||
| 1804 | the presence (or abscence) of the attribute. | - | ||||||||||||||||||||||||
| 1805 | */ | - | ||||||||||||||||||||||||
| 1806 | - | |||||||||||||||||||||||||
| 1807 | void QMenuBar::setNativeMenuBar(bool nativeMenuBar) | - | ||||||||||||||||||||||||
| 1808 | { | - | ||||||||||||||||||||||||
| 1809 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1810 | if (nativeMenuBar != bool(d->platformMenuBar)) {
| 0 | ||||||||||||||||||||||||
| 1811 | if (!nativeMenuBar) {
| 0 | ||||||||||||||||||||||||
| 1812 | delete d->platformMenuBar; | - | ||||||||||||||||||||||||
| 1813 | d->platformMenuBar = 0; | - | ||||||||||||||||||||||||
| 1814 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1815 | if (!d->platformMenuBar)
| 0 | ||||||||||||||||||||||||
| 1816 | d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); never executed: d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); | 0 | ||||||||||||||||||||||||
| 1817 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1818 | - | |||||||||||||||||||||||||
| 1819 | updateGeometry(); | - | ||||||||||||||||||||||||
| 1820 | if (!nativeMenuBar && parentWidget())
| 0 | ||||||||||||||||||||||||
| 1821 | setVisible(true); never executed: setVisible(true); | 0 | ||||||||||||||||||||||||
| 1822 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1823 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1824 | - | |||||||||||||||||||||||||
| 1825 | bool QMenuBar::isNativeMenuBar() const | - | ||||||||||||||||||||||||
| 1826 | { | - | ||||||||||||||||||||||||
| 1827 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1828 | return bool(d->platformMenuBar); never executed: return bool(d->platformMenuBar); | 0 | ||||||||||||||||||||||||
| 1829 | } | - | ||||||||||||||||||||||||
| 1830 | - | |||||||||||||||||||||||||
| 1831 | /*! | - | ||||||||||||||||||||||||
| 1832 | \internal | - | ||||||||||||||||||||||||
| 1833 | */ | - | ||||||||||||||||||||||||
| 1834 | QPlatformMenuBar *QMenuBar::platformMenuBar() | - | ||||||||||||||||||||||||
| 1835 | { | - | ||||||||||||||||||||||||
| 1836 | Q_D(const QMenuBar); | - | ||||||||||||||||||||||||
| 1837 | return d->platformMenuBar; never executed: return d->platformMenuBar; | 0 | ||||||||||||||||||||||||
| 1838 | } | - | ||||||||||||||||||||||||
| 1839 | - | |||||||||||||||||||||||||
| 1840 | /*! | - | ||||||||||||||||||||||||
| 1841 | \since 4.4 | - | ||||||||||||||||||||||||
| 1842 | - | |||||||||||||||||||||||||
| 1843 | Sets the default action to \a act. | - | ||||||||||||||||||||||||
| 1844 | - | |||||||||||||||||||||||||
| 1845 | The default action is assigned to the left soft key. The menu is assigned | - | ||||||||||||||||||||||||
| 1846 | to the right soft key. | - | ||||||||||||||||||||||||
| 1847 | - | |||||||||||||||||||||||||
| 1848 | Currently there is only support for the default action on Windows | - | ||||||||||||||||||||||||
| 1849 | Mobile. On all other platforms this method is not available. | - | ||||||||||||||||||||||||
| 1850 | - | |||||||||||||||||||||||||
| 1851 | \sa defaultAction() | - | ||||||||||||||||||||||||
| 1852 | */ | - | ||||||||||||||||||||||||
| 1853 | - | |||||||||||||||||||||||||
| 1854 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||||||||
| 1855 | void QMenuBar::setDefaultAction(QAction *act) | - | ||||||||||||||||||||||||
| 1856 | { | - | ||||||||||||||||||||||||
| 1857 | Q_D(QMenuBar); | - | ||||||||||||||||||||||||
| 1858 | if (d->defaultAction == act) | - | ||||||||||||||||||||||||
| 1859 | return; | - | ||||||||||||||||||||||||
| 1860 | if (qt_wince_is_mobile()) | - | ||||||||||||||||||||||||
| 1861 | if (d->defaultAction) { | - | ||||||||||||||||||||||||
| 1862 | disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); | - | ||||||||||||||||||||||||
| 1863 | disconnect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); | - | ||||||||||||||||||||||||
| 1864 | } | - | ||||||||||||||||||||||||
| 1865 | d->defaultAction = act; | - | ||||||||||||||||||||||||
| 1866 | if (qt_wince_is_mobile()) | - | ||||||||||||||||||||||||
| 1867 | if (d->defaultAction) { | - | ||||||||||||||||||||||||
| 1868 | connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); | - | ||||||||||||||||||||||||
| 1869 | connect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); | - | ||||||||||||||||||||||||
| 1870 | } | - | ||||||||||||||||||||||||
| 1871 | if (d->wce_menubar) { | - | ||||||||||||||||||||||||
| 1872 | d->wce_menubar->rebuild(); | - | ||||||||||||||||||||||||
| 1873 | } | - | ||||||||||||||||||||||||
| 1874 | } | - | ||||||||||||||||||||||||
| 1875 | - | |||||||||||||||||||||||||
| 1876 | /*! | - | ||||||||||||||||||||||||
| 1877 | \since 4.4 | - | ||||||||||||||||||||||||
| 1878 | - | |||||||||||||||||||||||||
| 1879 | Returns the current default action. | - | ||||||||||||||||||||||||
| 1880 | - | |||||||||||||||||||||||||
| 1881 | \sa setDefaultAction() | - | ||||||||||||||||||||||||
| 1882 | */ | - | ||||||||||||||||||||||||
| 1883 | QAction *QMenuBar::defaultAction() const | - | ||||||||||||||||||||||||
| 1884 | { | - | ||||||||||||||||||||||||
| 1885 | return d_func()->defaultAction; | - | ||||||||||||||||||||||||
| 1886 | } | - | ||||||||||||||||||||||||
| 1887 | #endif | - | ||||||||||||||||||||||||
| 1888 | - | |||||||||||||||||||||||||
| 1889 | /*! | - | ||||||||||||||||||||||||
| 1890 | \fn void QMenuBar::triggered(QAction *action) | - | ||||||||||||||||||||||||
| 1891 | - | |||||||||||||||||||||||||
| 1892 | This signal is emitted when an action in a menu belonging to this menubar | - | ||||||||||||||||||||||||
| 1893 | is triggered as a result of a mouse click; \a action is the action that | - | ||||||||||||||||||||||||
| 1894 | caused the signal to be emitted. | - | ||||||||||||||||||||||||
| 1895 | - | |||||||||||||||||||||||||
| 1896 | \note QMenuBar has to have ownership of the QMenu in order this signal to work. | - | ||||||||||||||||||||||||
| 1897 | - | |||||||||||||||||||||||||
| 1898 | Normally, you connect each menu action to a single slot using | - | ||||||||||||||||||||||||
| 1899 | QAction::triggered(), but sometimes you will want to connect | - | ||||||||||||||||||||||||
| 1900 | several items to a single slot (most often if the user selects | - | ||||||||||||||||||||||||
| 1901 | from an array). This signal is useful in such cases. | - | ||||||||||||||||||||||||
| 1902 | - | |||||||||||||||||||||||||
| 1903 | \sa hovered(), QAction::triggered() | - | ||||||||||||||||||||||||
| 1904 | */ | - | ||||||||||||||||||||||||
| 1905 | - | |||||||||||||||||||||||||
| 1906 | /*! | - | ||||||||||||||||||||||||
| 1907 | \fn void QMenuBar::hovered(QAction *action) | - | ||||||||||||||||||||||||
| 1908 | - | |||||||||||||||||||||||||
| 1909 | This signal is emitted when a menu action is highlighted; \a action | - | ||||||||||||||||||||||||
| 1910 | is the action that caused the event to be sent. | - | ||||||||||||||||||||||||
| 1911 | - | |||||||||||||||||||||||||
| 1912 | Often this is used to update status information. | - | ||||||||||||||||||||||||
| 1913 | - | |||||||||||||||||||||||||
| 1914 | \sa triggered(), QAction::hovered() | - | ||||||||||||||||||||||||
| 1915 | */ | - | ||||||||||||||||||||||||
| 1916 | - | |||||||||||||||||||||||||
| 1917 | // for private slots | - | ||||||||||||||||||||||||
| 1918 | - | |||||||||||||||||||||||||
| 1919 | - | |||||||||||||||||||||||||
| 1920 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 1921 | - | |||||||||||||||||||||||||
| 1922 | #include <moc_qmenubar.cpp> | - | ||||||||||||||||||||||||
| 1923 | - | |||||||||||||||||||||||||
| 1924 | #endif // QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |