| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | #include <qmenubar.h> | - |
| 41 | | - |
| 42 | #include <qstyle.h> | - |
| 43 | #include <qlayout.h> | - |
| 44 | #include <qapplication.h> | - |
| 45 | #include <qdesktopwidget.h> | - |
| 46 | #ifndef QT_NO_ACCESSIBILITY | - |
| 47 | # include <qaccessible.h> | - |
| 48 | #endif | - |
| 49 | #include <qpainter.h> | - |
| 50 | #include <qstylepainter.h> | - |
| 51 | #include <qevent.h> | - |
| 52 | #include <qmainwindow.h> | - |
| 53 | #include <qtoolbar.h> | - |
| 54 | #include <qtoolbutton.h> | - |
| 55 | #include <qwhatsthis.h> | - |
| 56 | #include <qpa/qplatformtheme.h> | - |
| 57 | #include "private/qguiapplication_p.h" | - |
| 58 | #include "qpa/qplatformintegration.h" | - |
| 59 | | - |
| 60 | #ifndef QT_NO_MENUBAR | - |
| 61 | | - |
| 62 | | - |
| 63 | #include "qmenu_p.h" | - |
| 64 | #include "qmenubar_p.h" | - |
| 65 | #include "qdebug.h" | - |
| 66 | | - |
| 67 | #ifdef Q_OS_WINCE | - |
| 68 | extern bool qt_wince_is_mobile(); | - |
| 69 | #endif | - |
| 70 | | - |
| 71 | QT_BEGIN_NAMESPACE | - |
| 72 | | - |
| 73 | class QMenuBarExtension : public QToolButton | - |
| 74 | { | - |
| 75 | public: | - |
| 76 | explicit QMenuBarExtension(QWidget *parent); | - |
| 77 | | - |
| 78 | QSize sizeHint() const Q_DECL_OVERRIDE; | - |
| 79 | void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; | - |
| 80 | }; | - |
| 81 | | - |
| 82 | QMenuBarExtension::QMenuBarExtension(QWidget *parent) | - |
| 83 | : QToolButton(parent) | - |
| 84 | { | - |
| 85 | setObjectName(QLatin1String("qt_menubar_ext_button")); | - |
| 86 | setAutoRaise(true); | - |
| 87 | #ifndef QT_NO_MENU | - |
| 88 | setPopupMode(QToolButton::InstantPopup); | - |
| 89 | #endif | - |
| 90 | setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton, 0, parentWidget())); | - |
| 91 | } | - |
| 92 | | - |
| 93 | void QMenuBarExtension::paintEvent(QPaintEvent *) | - |
| 94 | { | - |
| 95 | QStylePainter p(this); | - |
| 96 | QStyleOptionToolButton opt; | - |
| 97 | initStyleOption(&opt); | - |
| 98 | | - |
| 99 | opt.features &= ~QStyleOptionToolButton::HasMenu; | - |
| 100 | p.drawComplexControl(QStyle::CC_ToolButton, opt); | - |
| 101 | } | - |
| 102 | | - |
| 103 | | - |
| 104 | QSize QMenuBarExtension::sizeHint() const | - |
| 105 | { | - |
| 106 | int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent, 0, parentWidget()); | - |
| 107 | return QSize(ext, ext); | - |
| 108 | } | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | QAction *QMenuBarPrivate::actionAt(QPoint p) const | - |
| 115 | { | - |
| 116 | for(int i = 0; i < actions.size(); ++i) { | - |
| 117 | if(actionRect(actions.at(i)).contains(p)) | - |
| 118 | return actions.at(i); | - |
| 119 | } | - |
| 120 | return 0; | - |
| 121 | } | - |
| 122 | | - |
| 123 | QRect QMenuBarPrivate::menuRect(bool extVisible) const | - |
| 124 | { | - |
| 125 | Q_Q(const QMenuBar); | - |
| 126 | | - |
| 127 | int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - |
| 128 | QRect result = q->rect(); | - |
| 129 | result.adjust(hmargin, 0, -hmargin, 0); | - |
| 130 | | - |
| 131 | if (extVisible) { | - |
| 132 | if (q->isRightToLeft()) | - |
| 133 | result.setLeft(result.left() + extension->sizeHint().width()); | - |
| 134 | else | - |
| 135 | result.setWidth(result.width() - extension->sizeHint().width()); | - |
| 136 | } | - |
| 137 | | - |
| 138 | if (leftWidget && leftWidget->isVisible()) { | - |
| 139 | QSize sz = leftWidget->sizeHint(); | - |
| 140 | if (q->isRightToLeft()) | - |
| 141 | result.setRight(result.right() - sz.width()); | - |
| 142 | else | - |
| 143 | result.setLeft(result.left() + sz.width()); | - |
| 144 | } | - |
| 145 | | - |
| 146 | if (rightWidget && rightWidget->isVisible()) { | - |
| 147 | QSize sz = rightWidget->sizeHint(); | - |
| 148 | if (q->isRightToLeft()) | - |
| 149 | result.setLeft(result.left() + sz.width()); | - |
| 150 | else | - |
| 151 | result.setRight(result.right() - sz.width()); | - |
| 152 | } | - |
| 153 | | - |
| 154 | return result; | - |
| 155 | } | - |
| 156 | | - |
| 157 | bool QMenuBarPrivate::isVisible(QAction *action) | - |
| 158 | { | - |
| 159 | return !hiddenActions.contains(action); | - |
| 160 | } | - |
| 161 | | - |
| 162 | void QMenuBarPrivate::updateGeometries() | - |
| 163 | { | - |
| 164 | Q_Q(QMenuBar); | - |
| 165 | if(!itemsDirty)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 166 | return; never executed: return; | 0 |
| 167 | int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2); | - |
| 168 | int q_start = -1; | - |
| 169 | if(leftWidget || rightWidget) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 170 | int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q) | - |
| 171 | + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - |
| 172 | int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q) | - |
| 173 | + q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - |
| 174 | if (leftWidget && leftWidget->isVisible()) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 175 | QSize sz = leftWidget->sizeHint(); | - |
| 176 | q_width -= sz.width(); | - |
| 177 | q_start = sz.width(); | - |
| 178 | QPoint pos(hmargin, (q->height() - leftWidget->height()) / 2); | - |
| 179 | QRect vRect = QStyle::visualRect(q->layoutDirection(), q->rect(), QRect(pos, sz)); | - |
| 180 | leftWidget->setGeometry(vRect); | - |
| 181 | } never executed: end of block | 0 |
| 182 | if (rightWidget && rightWidget->isVisible()) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 183 | QSize sz = rightWidget->sizeHint(); | - |
| 184 | q_width -= sz.width(); | - |
| 185 | QPoint pos(q->width() - sz.width() - hmargin, vmargin); | - |
| 186 | QRect vRect = QStyle::visualRect(q->layoutDirection(), q->rect(), QRect(pos, sz)); | - |
| 187 | rightWidget->setGeometry(vRect); | - |
| 188 | } never executed: end of block | 0 |
| 189 | } never executed: end of block | 0 |
| 190 | | - |
| 191 | #ifdef Q_OS_MAC | - |
| 192 | if(q->isNativeMenuBar()) { | - |
| 193 | itemsDirty = false; | - |
| 194 | return; | - |
| 195 | } | - |
| 196 | #endif | - |
| 197 | calcActionRects(q_width, q_start); | - |
| 198 | currentAction = 0; | - |
| 199 | #ifndef QT_NO_SHORTCUT | - |
| 200 | if(itemsDirty) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 201 | for(int j = 0; j < shortcutIndexMap.size(); ++j)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 202 | q->releaseShortcut(shortcutIndexMap.value(j)); never executed: q->releaseShortcut(shortcutIndexMap.value(j)); | 0 |
| 203 | shortcutIndexMap.resize(0); clear(); | - |
| 204 | const int actionsCount = actions.count(); | - |
| 205 | shortcutIndexMap.reserve(actionsCount); | - |
| 206 | for (int i = 0; i < actionsCount; i++)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 207 | shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); never executed: shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); | 0 |
| 208 | } never executed: end of block | 0 |
| 209 | #endif | - |
| 210 | itemsDirty = false; | - |
| 211 | | - |
| 212 | hiddenActions.clear(); | - |
| 213 | | - |
| 214 | QRect menuRect = this->menuRect(false); | - |
| 215 | | - |
| 216 | | - |
| 217 | bool hasHiddenActions = false; | - |
| 218 | for (int i = 0; i < actions.count(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 219 | const QRect &rect = actionRects.at(i); | - |
| 220 | if (rect.isValid() && !menuRect.contains(rect)) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 221 | hasHiddenActions = true; | - |
| 222 | break; never executed: break; | 0 |
| 223 | } | - |
| 224 | } never executed: end of block | 0 |
| 225 | | - |
| 226 | | - |
| 227 | if (hasHiddenActions) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 228 | menuRect = this->menuRect(true); | - |
| 229 | for (int i = 0; i < actions.count(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 230 | const QRect &rect = actionRects.at(i); | - |
| 231 | if (rect.isValid() && !menuRect.contains(rect)) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 232 | hiddenActions.append(actions.at(i)); | - |
| 233 | } never executed: end of block | 0 |
| 234 | } never executed: end of block | 0 |
| 235 | } never executed: end of block | 0 |
| 236 | | - |
| 237 | if (hiddenActions.count() > 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 238 | QMenu *pop = extension->menu(); | - |
| 239 | if (!pop) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 240 | pop = new QMenu(q); | - |
| 241 | extension->setMenu(pop); | - |
| 242 | } never executed: end of block | 0 |
| 243 | pop->clear(); | - |
| 244 | pop->addActions(hiddenActions); | - |
| 245 | | - |
| 246 | int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q); | - |
| 247 | int x = q->isRightToLeft()| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 248 | ? menuRect.left() - extension->sizeHint().width() + 1 | - |
| 249 | : menuRect.right(); | - |
| 250 | extension->setGeometry(x, vmargin, extension->sizeHint().width(), menuRect.height() - vmargin*2); | - |
| 251 | extension->show(); | - |
| 252 | } else { never executed: end of block | 0 |
| 253 | extension->hide(); | - |
| 254 | } never executed: end of block | 0 |
| 255 | q->updateGeometry(); | - |
| 256 | } never executed: end of block | 0 |
| 257 | | - |
| 258 | QRect QMenuBarPrivate::actionRect(QAction *act) const | - |
| 259 | { | - |
| 260 | const int index = actions.indexOf(act); | - |
| 261 | | - |
| 262 | | - |
| 263 | const_cast<QMenuBarPrivate*>(this)->updateGeometries(); | - |
| 264 | | - |
| 265 | if (index < 0 || index >= actionRects.count()) | - |
| 266 | return QRect(); | - |
| 267 | | - |
| 268 | return actionRects.at(index); | - |
| 269 | } | - |
| 270 | | - |
| 271 | void QMenuBarPrivate::focusFirstAction() | - |
| 272 | { | - |
| 273 | if(!currentAction) { | - |
| 274 | updateGeometries(); | - |
| 275 | int index = 0; | - |
| 276 | while (index < actions.count() && actionRects.at(index).isNull()) ++index; | - |
| 277 | if (index < actions.count()) | - |
| 278 | setCurrentAction(actions.at(index)); | - |
| 279 | } | - |
| 280 | } | - |
| 281 | | - |
| 282 | void QMenuBarPrivate::setKeyboardMode(bool b) | - |
| 283 | { | - |
| 284 | Q_Q(QMenuBar); | - |
| 285 | if (b && !q->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, q)) { | - |
| 286 | setCurrentAction(0); | - |
| 287 | return; | - |
| 288 | } | - |
| 289 | keyboardState = b; | - |
| 290 | if(b) { | - |
| 291 | QWidget *fw = QApplication::focusWidget(); | - |
| 292 | if (fw != q) | - |
| 293 | keyboardFocusWidget = fw; | - |
| 294 | focusFirstAction(); | - |
| 295 | q->setFocus(Qt::MenuBarFocusReason); | - |
| 296 | } else { | - |
| 297 | if(!popupState) | - |
| 298 | setCurrentAction(0); | - |
| 299 | if(keyboardFocusWidget) { | - |
| 300 | if (QApplication::focusWidget() == q) | - |
| 301 | keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason); | - |
| 302 | keyboardFocusWidget = 0; | - |
| 303 | } | - |
| 304 | } | - |
| 305 | q->update(); | - |
| 306 | } | - |
| 307 | | - |
| 308 | void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) | - |
| 309 | { | - |
| 310 | Q_Q(QMenuBar); | - |
| 311 | if(!action || !action->menu() || closePopupMode) | - |
| 312 | return; | - |
| 313 | popupState = true; | - |
| 314 | if (action->isEnabled() && action->menu()->isEnabled()) { | - |
| 315 | closePopupMode = 0; | - |
| 316 | activeMenu = action->menu(); | - |
| 317 | activeMenu->d_func()->causedPopup.widget = q; | - |
| 318 | activeMenu->d_func()->causedPopup.action = action; | - |
| 319 | | - |
| 320 | QRect adjustedActionRect = actionRect(action); | - |
| 321 | QPoint pos(q->mapToGlobal(QPoint(adjustedActionRect.left(), adjustedActionRect.bottom() + 1))); | - |
| 322 | QSize popup_size = activeMenu->sizeHint(); | - |
| 323 | | - |
| 324 | | - |
| 325 | QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0)); | - |
| 326 | pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y())); | - |
| 327 | | - |
| 328 | const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height()); | - |
| 329 | const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom()); | - |
| 330 | const bool rtl = q->isRightToLeft(); | - |
| 331 | const int actionWidth = adjustedActionRect.width(); | - |
| 332 | | - |
| 333 | if (!fitUp && !fitDown) { | - |
| 334 | bool shouldShiftToRight = !rtl; | - |
| 335 | if (rtl && popup_size.width() > pos.x()) | - |
| 336 | shouldShiftToRight = true; | - |
| 337 | else if (actionWidth + popup_size.width() + pos.x() > screenRect.right()) | - |
| 338 | shouldShiftToRight = false; | - |
| 339 | | - |
| 340 | if (shouldShiftToRight) { | - |
| 341 | pos.rx() += actionWidth + (rtl ? popup_size.width() : 0); | - |
| 342 | } else { | - |
| 343 | | - |
| 344 | if (!rtl) | - |
| 345 | pos.rx() -= popup_size.width(); | - |
| 346 | } | - |
| 347 | } else if (rtl) { | - |
| 348 | pos.rx() += actionWidth; | - |
| 349 | } | - |
| 350 | | - |
| 351 | if(!defaultPopDown || (fitUp && !fitDown)) | - |
| 352 | pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y())); | - |
| 353 | activeMenu->popup(pos); | - |
| 354 | if(activateFirst) | - |
| 355 | activeMenu->d_func()->setFirstActionActive(); | - |
| 356 | } | - |
| 357 | q->update(actionRect(action)); | - |
| 358 | } | - |
| 359 | | - |
| 360 | void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst) | - |
| 361 | { | - |
| 362 | if(currentAction == action && popup == popupState) | - |
| 363 | return; | - |
| 364 | | - |
| 365 | autoReleaseTimer.stop(); | - |
| 366 | | - |
| 367 | doChildEffects = (popup && !activeMenu); | - |
| 368 | Q_Q(QMenuBar); | - |
| 369 | QWidget *fw = 0; | - |
| 370 | if(QMenu *menu = activeMenu) { | - |
| 371 | activeMenu = 0; | - |
| 372 | if (popup) { | - |
| 373 | fw = q->window()->focusWidget(); | - |
| 374 | q->setFocus(Qt::NoFocusReason); | - |
| 375 | } | - |
| 376 | menu->hide(); | - |
| 377 | } | - |
| 378 | | - |
| 379 | if(currentAction) | - |
| 380 | q->update(actionRect(currentAction)); | - |
| 381 | | - |
| 382 | popupState = popup; | - |
| 383 | #ifndef QT_NO_STATUSTIP | - |
| 384 | QAction *previousAction = currentAction; | - |
| 385 | #endif | - |
| 386 | currentAction = action; | - |
| 387 | if (action && action->isEnabled()) { | - |
| 388 | activateAction(action, QAction::Hover); | - |
| 389 | if(popup) | - |
| 390 | popupAction(action, activateFirst); | - |
| 391 | q->update(actionRect(action)); | - |
| 392 | #ifndef QT_NO_STATUSTIP | - |
| 393 | } else if (previousAction) { | - |
| 394 | QString empty; | - |
| 395 | QStatusTipEvent tip(empty); | - |
| 396 | QApplication::sendEvent(q, &tip); | - |
| 397 | #endif | - |
| 398 | } | - |
| 399 | if (fw) | - |
| 400 | fw->setFocus(Qt::NoFocusReason); | - |
| 401 | } | - |
| 402 | | - |
| 403 | void QMenuBarPrivate::calcActionRects(int max_width, int start) const | - |
| 404 | { | - |
| 405 | Q_Q(const QMenuBar); | - |
| 406 | | - |
| 407 | if(!itemsDirty) | - |
| 408 | return; | - |
| 409 | | - |
| 410 | | - |
| 411 | actionRects.resize(actions.count()); | - |
| 412 | actionRects.fill(QRect()); | - |
| 413 | | - |
| 414 | const QStyle *style = q->style(); | - |
| 415 | | - |
| 416 | const int itemSpacing = style->pixelMetric(QStyle::PM_MenuBarItemSpacing, 0, q); | - |
| 417 | int max_item_height = 0, separator = -1, separator_start = 0, separator_len = 0; | - |
| 418 | | - |
| 419 | | - |
| 420 | const QFontMetrics fm = q->fontMetrics(); | - |
| 421 | const int hmargin = style->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q), | - |
| 422 | vmargin = style->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q), | - |
| 423 | icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q); | - |
| 424 | for(int i = 0; i < actions.count(); i++) { | - |
| 425 | QAction *action = actions.at(i); | - |
| 426 | if(!action->isVisible()) | - |
| 427 | continue; | - |
| 428 | | - |
| 429 | QSize sz; | - |
| 430 | | - |
| 431 | | - |
| 432 | if(action->isSeparator()) { | - |
| 433 | if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q)) | - |
| 434 | separator = i; | - |
| 435 | continue; | - |
| 436 | } else { | - |
| 437 | const QString s = action->text(); | - |
| 438 | QIcon is = action->icon(); | - |
| 439 | | - |
| 440 | if (!is.isNull()) | - |
| 441 | sz = sz.expandedTo(QSize(icone, icone)); | - |
| 442 | else if (!s.isEmpty()) | - |
| 443 | sz = fm.size(Qt::TextShowMnemonic, s); | - |
| 444 | } | - |
| 445 | | - |
| 446 | | - |
| 447 | QStyleOptionMenuItem opt; | - |
| 448 | q->initStyleOption(&opt, action); | - |
| 449 | sz = q->style()->sizeFromContents(QStyle::CT_MenuBarItem, &opt, sz, q); | - |
| 450 | | - |
| 451 | if(!sz.isEmpty()) { | - |
| 452 | { | - |
| 453 | int iWidth = sz.width() + itemSpacing; | - |
| 454 | if(separator == -1) | - |
| 455 | separator_start += iWidth; | - |
| 456 | else | - |
| 457 | separator_len += iWidth; | - |
| 458 | } | - |
| 459 | | - |
| 460 | max_item_height = qMax(max_item_height, sz.height()); | - |
| 461 | | - |
| 462 | actionRects[i] = QRect(0, 0, sz.width(), sz.height()); | - |
| 463 | } | - |
| 464 | } | - |
| 465 | | - |
| 466 | | - |
| 467 | const int fw = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); | - |
| 468 | int x = fw + ((start == -1) ? hmargin : start) + itemSpacing; | - |
| 469 | int y = fw + vmargin; | - |
| 470 | for(int i = 0; i < actions.count(); i++) { | - |
| 471 | QRect &rect = actionRects[i]; | - |
| 472 | if (rect.isNull()) | - |
| 473 | continue; | - |
| 474 | | - |
| 475 | | - |
| 476 | rect.setHeight(max_item_height); | - |
| 477 | | - |
| 478 | | - |
| 479 | if(separator != -1 && i >= separator) { | - |
| 480 | int left = (max_width - separator_len - hmargin - itemSpacing) + (x - separator_start - hmargin); | - |
| 481 | if(left < separator_start) { | - |
| 482 | separator_start = x = hmargin; | - |
| 483 | y += max_item_height; | - |
| 484 | } | - |
| 485 | rect.moveLeft(left); | - |
| 486 | } else { | - |
| 487 | rect.moveLeft(x); | - |
| 488 | } | - |
| 489 | rect.moveTop(y); | - |
| 490 | | - |
| 491 | | - |
| 492 | x += rect.width() + itemSpacing; | - |
| 493 | | - |
| 494 | | - |
| 495 | rect = QStyle::visualRect(q->layoutDirection(), q->rect(), rect); | - |
| 496 | } | - |
| 497 | } | - |
| 498 | | - |
| 499 | void QMenuBarPrivate::activateAction(QAction *action, QAction::ActionEvent action_e) | - |
| 500 | { | - |
| 501 | Q_Q(QMenuBar); | - |
| 502 | if (!action || !action->isEnabled()) | - |
| 503 | return; | - |
| 504 | action->activate(action_e); | - |
| 505 | if (action_e == QAction::Hover) | - |
| 506 | action->showStatusText(q); | - |
| 507 | | - |
| 508 | | - |
| 509 | | - |
| 510 | | - |
| 511 | | - |
| 512 | } | - |
| 513 | | - |
| 514 | | - |
| 515 | void QMenuBarPrivate::_q_actionTriggered() | - |
| 516 | { | - |
| 517 | Q_Q(QMenuBar); | - |
| 518 | if (QAction *action = qobject_cast<QAction *>(q->sender())) { | - |
| 519 | emit q->triggered(action); | - |
| 520 | } | - |
| 521 | } | - |
| 522 | | - |
| 523 | void QMenuBarPrivate::_q_actionHovered() | - |
| 524 | { | - |
| 525 | Q_Q(QMenuBar); | - |
| 526 | if (QAction *action = qobject_cast<QAction *>(q->sender())) { | - |
| 527 | emit q->hovered(action); | - |
| 528 | #ifndef QT_NO_ACCESSIBILITY | - |
| 529 | if (QAccessible::isActive()) { | - |
| 530 | int actionIndex = actions.indexOf(action); | - |
| 531 | QAccessibleEvent focusEvent(q, QAccessible::Focus); | - |
| 532 | focusEvent.setChild(actionIndex); | - |
| 533 | QAccessible::updateAccessibility(&focusEvent); | - |
| 534 | } | - |
| 535 | #endif //QT_NO_ACCESSIBILITY | - |
| 536 | } | - |
| 537 | } | - |
| 538 | | - |
| 539 | | - |
| 540 | | - |
| 541 | | - |
| 542 | | - |
| 543 | | - |
| 544 | | - |
| 545 | | - |
| 546 | void QMenuBar::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const | - |
| 547 | { | - |
| 548 | if (!option || !action) | - |
| 549 | return; | - |
| 550 | Q_D(const QMenuBar); | - |
| 551 | option->palette = palette(); | - |
| 552 | option->state = QStyle::State_None; | - |
| 553 | if (isEnabled() && action->isEnabled()) | - |
| 554 | option->state |= QStyle::State_Enabled; | - |
| 555 | else | - |
| 556 | option->palette.setCurrentColorGroup(QPalette::Disabled); | - |
| 557 | option->fontMetrics = fontMetrics(); | - |
| 558 | if (d->currentAction && d->currentAction == action) { | - |
| 559 | option->state |= QStyle::State_Selected; | - |
| 560 | if (d->popupState && !d->closePopupMode) | - |
| 561 | option->state |= QStyle::State_Sunken; | - |
| 562 | } | - |
| 563 | if (hasFocus() || d->currentAction) | - |
| 564 | option->state |= QStyle::State_HasFocus; | - |
| 565 | option->menuRect = rect(); | - |
| 566 | option->menuItemType = QStyleOptionMenuItem::Normal; | - |
| 567 | option->checkType = QStyleOptionMenuItem::NotCheckable; | - |
| 568 | option->text = action->text(); | - |
| 569 | option->icon = action->icon(); | - |
| 570 | } | - |
| 571 | | - |
| 572 | | - |
| 573 | | - |
| 574 | | - |
| 575 | | - |
| 576 | | - |
| 577 | | - |
| 578 | | - |
| 579 | | - |
| 580 | | - |
| 581 | | - |
| 582 | | - |
| 583 | | - |
| 584 | | - |
| 585 | | - |
| 586 | | - |
| 587 | | - |
| 588 | | - |
| 589 | | - |
| 590 | | - |
| 591 | | - |
| 592 | | - |
| 593 | | - |
| 594 | | - |
| 595 | | - |
| 596 | | - |
| 597 | | - |
| 598 | | - |
| 599 | | - |
| 600 | | - |
| 601 | | - |
| 602 | | - |
| 603 | | - |
| 604 | | - |
| 605 | | - |
| 606 | | - |
| 607 | | - |
| 608 | | - |
| 609 | | - |
| 610 | | - |
| 611 | | - |
| 612 | | - |
| 613 | | - |
| 614 | | - |
| 615 | | - |
| 616 | | - |
| 617 | | - |
| 618 | | - |
| 619 | | - |
| 620 | | - |
| 621 | | - |
| 622 | | - |
| 623 | | - |
| 624 | | - |
| 625 | | - |
| 626 | | - |
| 627 | | - |
| 628 | | - |
| 629 | | - |
| 630 | | - |
| 631 | | - |
| 632 | | - |
| 633 | | - |
| 634 | | - |
| 635 | | - |
| 636 | | - |
| 637 | | - |
| 638 | | - |
| 639 | | - |
| 640 | | - |
| 641 | | - |
| 642 | | - |
| 643 | | - |
| 644 | | - |
| 645 | | - |
| 646 | | - |
| 647 | | - |
| 648 | | - |
| 649 | | - |
| 650 | | - |
| 651 | | - |
| 652 | | - |
| 653 | | - |
| 654 | | - |
| 655 | | - |
| 656 | | - |
| 657 | | - |
| 658 | | - |
| 659 | | - |
| 660 | | - |
| 661 | | - |
| 662 | | - |
| 663 | | - |
| 664 | | - |
| 665 | | - |
| 666 | | - |
| 667 | | - |
| 668 | | - |
| 669 | | - |
| 670 | | - |
| 671 | | - |
| 672 | | - |
| 673 | | - |
| 674 | | - |
| 675 | | - |
| 676 | | - |
| 677 | | - |
| 678 | | - |
| 679 | | - |
| 680 | | - |
| 681 | | - |
| 682 | | - |
| 683 | | - |
| 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)) | - |
| 694 | platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); | - |
| 695 | | - |
| 696 | if (platformMenuBar) | - |
| 697 | q->hide(); | - |
| 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 | } | - |
| 716 | | - |
| 717 | | - |
| 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; | - |
| 724 | const int end = increment == -1 ? 0 : actions.count() - 1; | - |
| 725 | | - |
| 726 | for (int i = start; i != end;) { | - |
| 727 | i += increment; | - |
| 728 | QAction *current = actions.at(i); | - |
| 729 | if (!actionRects.at(i).isNull() && (allowActiveAndDisabled || current->isEnabled())) | - |
| 730 | return current; | - |
| 731 | } | - |
| 732 | | - |
| 733 | if (_start != -1) | - |
| 734 | return getNextAction(-1, increment); | - |
| 735 | | - |
| 736 | return 0; | - |
| 737 | } | - |
| 738 | | - |
| 739 | | - |
| 740 | | - |
| 741 | | - |
| 742 | QMenuBar::QMenuBar(QWidget *parent) : QWidget(*new QMenuBarPrivate, parent, 0) | - |
| 743 | { | - |
| 744 | Q_D(QMenuBar); | - |
| 745 | d->init(); | - |
| 746 | } | - |
| 747 | | - |
| 748 | | - |
| 749 | | - |
| 750 | | - |
| 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 | } | - |
| 763 | | - |
| 764 | | - |
| 765 | | - |
| 766 | | - |
| 767 | | - |
| 768 | | - |
| 769 | | - |
| 770 | | - |
| 771 | | - |
| 772 | | - |
| 773 | QAction *QMenuBar::addAction(const QString &text) | - |
| 774 | { | - |
| 775 | QAction *ret = new QAction(text, this); | - |
| 776 | addAction(ret); | - |
| 777 | return ret; | - |
| 778 | } | - |
| 779 | | - |
| 780 | | - |
| 781 | | - |
| 782 | | - |
| 783 | | - |
| 784 | | - |
| 785 | | - |
| 786 | | - |
| 787 | | - |
| 788 | | - |
| 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; | - |
| 796 | } | - |
| 797 | | - |
| 798 | | - |
| 799 | | - |
| 800 | | - |
| 801 | | - |
| 802 | | - |
| 803 | | - |
| 804 | QMenu *QMenuBar::addMenu(const QString &title) | - |
| 805 | { | - |
| 806 | QMenu *menu = new QMenu(title, this); | - |
| 807 | addAction(menu->menuAction()); | - |
| 808 | return menu; | - |
| 809 | } | - |
| 810 | | - |
| 811 | | - |
| 812 | | - |
| 813 | | - |
| 814 | | - |
| 815 | | - |
| 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; | - |
| 823 | } | - |
| 824 | | - |
| 825 | | - |
| 826 | | - |
| 827 | | - |
| 828 | | - |
| 829 | | - |
| 830 | | - |
| 831 | | - |
| 832 | | - |
| 833 | QAction *QMenuBar::addMenu(QMenu *menu) | - |
| 834 | { | - |
| 835 | QAction *action = menu->menuAction(); | - |
| 836 | addAction(action); | - |
| 837 | return action; | - |
| 838 | } | - |
| 839 | | - |
| 840 | | - |
| 841 | | - |
| 842 | | - |
| 843 | QAction *QMenuBar::addSeparator() | - |
| 844 | { | - |
| 845 | QAction *ret = new QAction(this); | - |
| 846 | ret->setSeparator(true); | - |
| 847 | addAction(ret); | - |
| 848 | return ret; | - |
| 849 | } | - |
| 850 | | - |
| 851 | | - |
| 852 | | - |
| 853 | | - |
| 854 | | - |
| 855 | | - |
| 856 | | - |
| 857 | | - |
| 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; | - |
| 865 | } | - |
| 866 | | - |
| 867 | | - |
| 868 | | - |
| 869 | | - |
| 870 | | - |
| 871 | | - |
| 872 | | - |
| 873 | QAction *QMenuBar::insertMenu(QAction *before, QMenu *menu) | - |
| 874 | { | - |
| 875 | QAction *action = menu->menuAction(); | - |
| 876 | insertAction(before, action); | - |
| 877 | return action; | - |
| 878 | } | - |
| 879 | | - |
| 880 | | - |
| 881 | | - |
| 882 | | - |
| 883 | | - |
| 884 | QAction *QMenuBar::activeAction() const | - |
| 885 | { | - |
| 886 | Q_D(const QMenuBar); | - |
| 887 | return d->currentAction; | - |
| 888 | } | - |
| 889 | | - |
| 890 | | - |
| 891 | | - |
| 892 | | - |
| 893 | | - |
| 894 | | - |
| 895 | void QMenuBar::setActiveAction(QAction *act) | - |
| 896 | { | - |
| 897 | Q_D(QMenuBar); | - |
| 898 | d->setCurrentAction(act, true, false); | - |
| 899 | } | - |
| 900 | | - |
| 901 | | - |
| 902 | | - |
| 903 | | - |
| 904 | | - |
| 905 | | - |
| 906 | | - |
| 907 | | - |
| 908 | | - |
| 909 | | - |
| 910 | | - |
| 911 | | - |
| 912 | | - |
| 913 | | - |
| 914 | void QMenuBar::clear() | - |
| 915 | { | - |
| 916 | QList<QAction*> acts = actions(); | - |
| 917 | for(int i = 0; i < acts.size(); i++) | - |
| 918 | removeAction(acts[i]); | - |
| 919 | } | - |
| 920 | | - |
| 921 | | - |
| 922 | | - |
| 923 | | - |
| 924 | | - |
| 925 | | - |
| 926 | | - |
| 927 | | - |
| 928 | | - |
| 929 | | - |
| 930 | | - |
| 931 | | - |
| 932 | | - |
| 933 | void QMenuBar::setDefaultUp(bool b) | - |
| 934 | { | - |
| 935 | Q_D(QMenuBar); | - |
| 936 | d->defaultPopDown = !b; | - |
| 937 | } | - |
| 938 | | - |
| 939 | bool QMenuBar::isDefaultUp() const | - |
| 940 | { | - |
| 941 | Q_D(const QMenuBar); | - |
| 942 | return !d->defaultPopDown; | - |
| 943 | } | - |
| 944 | | - |
| 945 | | - |
| 946 | | - |
| 947 | | - |
| 948 | void QMenuBar::resizeEvent(QResizeEvent *) | - |
| 949 | { | - |
| 950 | Q_D(QMenuBar); | - |
| 951 | d->itemsDirty = true; | - |
| 952 | d->updateGeometries(); | - |
| 953 | } | - |
| 954 | | - |
| 955 | | - |
| 956 | | - |
| 957 | | - |
| 958 | void QMenuBar::paintEvent(QPaintEvent *e) | - |
| 959 | { | - |
| 960 | Q_D(QMenuBar); | - |
| 961 | QPainter p(this); | - |
| 962 | QRegion emptyArea(rect()); | - |
| 963 | | - |
| 964 | | - |
| 965 | for (int i = 0; i < d->actions.count(); ++i) { | - |
| 966 | QAction *action = d->actions.at(i); | - |
| 967 | QRect adjustedActionRect = d->actionRect(action); | - |
| 968 | if (adjustedActionRect.isEmpty() || !d->isVisible(action)) | - |
| 969 | continue; | - |
| 970 | if(!e->rect().intersects(adjustedActionRect)) | - |
| 971 | continue; | - |
| 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 | } | - |
| 980 | | - |
| 981 | if(int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this)) { | - |
| 982 | QRegion borderReg; | - |
| 983 | borderReg += QRect(0, 0, fw, height()); | - |
| 984 | borderReg += QRect(width()-fw, 0, fw, height()); | - |
| 985 | borderReg += QRect(0, 0, width(), fw); | - |
| 986 | borderReg += QRect(0, height()-fw, width(), fw); | - |
| 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 | } | - |
| 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 | } | - |
| 1007 | | - |
| 1008 | | - |
| 1009 | | - |
| 1010 | | - |
| 1011 | void QMenuBar::setVisible(bool visible) | - |
| 1012 | { | - |
| 1013 | if (isNativeMenuBar()) { | - |
| 1014 | if (!visible) | - |
| 1015 | QWidget::setVisible(false); | - |
| 1016 | return; | - |
| 1017 | } | - |
| 1018 | QWidget::setVisible(visible); | - |
| 1019 | } | - |
| 1020 | | - |
| 1021 | | - |
| 1022 | | - |
| 1023 | | - |
| 1024 | void QMenuBar::mousePressEvent(QMouseEvent *e) | - |
| 1025 | { | - |
| 1026 | Q_D(QMenuBar); | - |
| 1027 | if(e->button() != Qt::LeftButton) | - |
| 1028 | return; | - |
| 1029 | | - |
| 1030 | d->mouseDown = true; | - |
| 1031 | | - |
| 1032 | QAction *action = d->actionAt(e->pos()); | - |
| 1033 | if (!action || !d->isVisible(action) || !action->isEnabled()) { | - |
| 1034 | d->setCurrentAction(0); | - |
| 1035 | #ifndef QT_NO_WHATSTHIS | - |
| 1036 | if (QWhatsThis::inWhatsThisMode()) | - |
| 1037 | QWhatsThis::showText(e->globalPos(), d->whatsThis, this); | - |
| 1038 | #endif | - |
| 1039 | return; | - |
| 1040 | } | - |
| 1041 | | - |
| 1042 | if(d->currentAction == action && d->popupState) { | - |
| 1043 | if(QMenu *menu = d->activeMenu) { | - |
| 1044 | d->activeMenu = 0; | - |
| 1045 | menu->setAttribute(Qt::WA_NoMouseReplay); | - |
| 1046 | menu->hide(); | - |
| 1047 | } | - |
| 1048 | } else { | - |
| 1049 | d->setCurrentAction(action, true); | - |
| 1050 | } | - |
| 1051 | } | - |
| 1052 | | - |
| 1053 | | - |
| 1054 | | - |
| 1055 | | - |
| 1056 | void QMenuBar::mouseReleaseEvent(QMouseEvent *e) | - |
| 1057 | { | - |
| 1058 | Q_D(QMenuBar); | - |
| 1059 | if(e->button() != Qt::LeftButton || !d->mouseDown) | - |
| 1060 | return; | - |
| 1061 | | - |
| 1062 | d->mouseDown = false; | - |
| 1063 | QAction *action = d->actionAt(e->pos()); | - |
| 1064 | if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) { | - |
| 1065 | | - |
| 1066 | | - |
| 1067 | d->setCurrentAction(action, false); | - |
| 1068 | if(action) | - |
| 1069 | d->activateAction(action, QAction::Trigger); | - |
| 1070 | } | - |
| 1071 | d->closePopupMode = 0; | - |
| 1072 | } | - |
| 1073 | | - |
| 1074 | | - |
| 1075 | | - |
| 1076 | | - |
| 1077 | void QMenuBar::keyPressEvent(QKeyEvent *e) | - |
| 1078 | { | - |
| 1079 | Q_D(QMenuBar); | - |
| 1080 | d->updateGeometries(); | - |
| 1081 | int key = e->key(); | - |
| 1082 | if(isRightToLeft()) { | - |
| 1083 | if(key == Qt::Key_Left) | - |
| 1084 | key = Qt::Key_Right; | - |
| 1085 | else if(key == Qt::Key_Right) | - |
| 1086 | key = Qt::Key_Left; | - |
| 1087 | } | - |
| 1088 | if(key == Qt::Key_Tab) | - |
| 1089 | key = Qt::Key_Right; | - |
| 1090 | else if(key == Qt::Key_Backtab) | - |
| 1091 | key = Qt::Key_Left; | - |
| 1092 | | - |
| 1093 | bool key_consumed = false; | - |
| 1094 | switch(key) { | - |
| 1095 | case Qt::Key_Up: | - |
| 1096 | case Qt::Key_Down: | - |
| 1097 | case Qt::Key_Enter: | - |
| 1098 | case Qt::Key_Space: | - |
| 1099 | case Qt::Key_Return: { | - |
| 1100 | if(!style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this) || !d->currentAction) | - |
| 1101 | break; | - |
| 1102 | if(d->currentAction->menu()) { | - |
| 1103 | d->popupAction(d->currentAction, true); | - |
| 1104 | } else if(key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Space) { | - |
| 1105 | d->activateAction(d->currentAction, QAction::Trigger); | - |
| 1106 | d->setCurrentAction(d->currentAction, false); | - |
| 1107 | d->setKeyboardMode(false); | - |
| 1108 | } | - |
| 1109 | key_consumed = true; | - |
| 1110 | break; } | - |
| 1111 | | - |
| 1112 | case Qt::Key_Right: | - |
| 1113 | case Qt::Key_Left: { | - |
| 1114 | if(d->currentAction) { | - |
| 1115 | int index = d->actions.indexOf(d->currentAction); | - |
| 1116 | if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) { | - |
| 1117 | d->setCurrentAction(nextAction, d->popupState, true); | - |
| 1118 | key_consumed = true; | - |
| 1119 | } | - |
| 1120 | } | - |
| 1121 | break; } | - |
| 1122 | | - |
| 1123 | default: | - |
| 1124 | key_consumed = false; | - |
| 1125 | } | - |
| 1126 | | - |
| 1127 | if (!key_consumed && e->matches(QKeySequence::Cancel)) { | - |
| 1128 | d->setCurrentAction(0); | - |
| 1129 | d->setKeyboardMode(false); | - |
| 1130 | key_consumed = true; | - |
| 1131 | } | - |
| 1132 | | - |
| 1133 | if(!key_consumed && | - |
| 1134 | (!e->modifiers() || | - |
| 1135 | (e->modifiers()&(Qt::MetaModifier|Qt::AltModifier))) && e->text().length()==1 && !d->popupState) { | - |
| 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) { | - |
| 1141 | if (d->actionRects.at(i).isNull()) | - |
| 1142 | continue; | - |
| 1143 | QAction *act = d->actions.at(i); | - |
| 1144 | QString s = act->text(); | - |
| 1145 | if(!s.isEmpty()) { | - |
| 1146 | int ampersand = s.indexOf(QLatin1Char('&')); | - |
| 1147 | if(ampersand >= 0) { | - |
| 1148 | if(s[ampersand+1].toUpper() == c) { | - |
| 1149 | clashCount++; | - |
| 1150 | if(!first) | - |
| 1151 | first = act; | - |
| 1152 | if(act == d->currentAction) | - |
| 1153 | currentSelected = act; | - |
| 1154 | else if (!firstAfterCurrent && currentSelected) | - |
| 1155 | firstAfterCurrent = act; | - |
| 1156 | } | - |
| 1157 | } | - |
| 1158 | } | - |
| 1159 | } | - |
| 1160 | } | - |
| 1161 | QAction *next_action = 0; | - |
| 1162 | if(clashCount >= 1) { | - |
| 1163 | if(clashCount == 1 || !d->currentAction || (currentSelected && !firstAfterCurrent)) | - |
| 1164 | next_action = first; | - |
| 1165 | else | - |
| 1166 | next_action = firstAfterCurrent; | - |
| 1167 | } | - |
| 1168 | if(next_action) { | - |
| 1169 | key_consumed = true; | - |
| 1170 | d->setCurrentAction(next_action, true, true); | - |
| 1171 | } | - |
| 1172 | } | - |
| 1173 | if(key_consumed) | - |
| 1174 | e->accept(); | - |
| 1175 | else | - |
| 1176 | e->ignore(); | - |
| 1177 | } | - |
| 1178 | | - |
| 1179 | | - |
| 1180 | | - |
| 1181 | | - |
| 1182 | void QMenuBar::mouseMoveEvent(QMouseEvent *e) | - |
| 1183 | { | - |
| 1184 | Q_D(QMenuBar); | - |
| 1185 | if (!(e->buttons() & Qt::LeftButton)) | - |
| 1186 | d->mouseDown = false; | - |
| 1187 | bool popupState = d->popupState || d->mouseDown; | - |
| 1188 | QAction *action = d->actionAt(e->pos()); | - |
| 1189 | if ((action && d->isVisible(action)) || !popupState) | - |
| 1190 | d->setCurrentAction(action, popupState); | - |
| 1191 | } | - |
| 1192 | | - |
| 1193 | | - |
| 1194 | | - |
| 1195 | | - |
| 1196 | void QMenuBar::leaveEvent(QEvent *) | - |
| 1197 | { | - |
| 1198 | Q_D(QMenuBar); | - |
| 1199 | if((!hasFocus() && !d->popupState) || | - |
| 1200 | (d->currentAction && d->currentAction->menu() == 0)) | - |
| 1201 | d->setCurrentAction(0); | - |
| 1202 | } | - |
| 1203 | | - |
| 1204 | QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) | - |
| 1205 | { | - |
| 1206 | if (!action || !action->menu())| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1207 | return 0; never executed: return 0; | 0 |
| 1208 | | - |
| 1209 | returnQPlatformMenu *platformMenu = action->menu()->platformMenu(); | - |
| 1210 | if (!platformMenu && platformMenuBar) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1211 | platformMenu = platformMenuBar->createMenu(); | - |
| 1212 | if (platformMenu)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1213 | action->menu()->setPlatformMenu(platformMenu); never executed: action->menu()->setPlatformMenu(platformMenu); | 0 |
| 1214 | } never executed: end of block | 0 |
| 1215 | | - |
| 1216 | return platformMenu; never executed: return platformMenu; | 0 |
| 1217 | } | - |
| 1218 | | - |
| 1219 | | - |
| 1220 | | - |
| 1221 | | - |
| 1222 | void QMenuBar::actionEvent(QActionEvent *e) | - |
| 1223 | { | - |
| 1224 | Q_D(QMenuBar); | - |
| 1225 | d->itemsDirty = true; | - |
| 1226 | | - |
| 1227 | if (d->platformMenuBar) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1228 | #if !defined(Q_OS_WINCE) | - |
| 1229 | QPlatformMenuBar *nativeMenuBar = d->platformMenuBar; | - |
| 1230 | #else | - |
| 1231 | QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar; | - |
| 1232 | #endif | - |
| 1233 | if (!nativeMenuBar)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1234 | return; never executed: return; | 0 |
| 1235 | | - |
| 1236 | if (e->type() == QEvent::ActionAdded) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1237 | QPlatformMenu *menu = d->getPlatformMenu(e->action()); | - |
| 1238 | if (menu) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1239 | QPlatformMenu* beforeMenu = NULL; | - |
| 1240 | for (int beforeIndex = d->indexOf(e->action()) + 1; | - |
| 1241 | !beforeMenu && (beforeIndex < actions().size());| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1242 | ++beforeIndex) | - |
| 1243 | { | - |
| 1244 | beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); | - |
| 1245 | } never executed: end of block | 0 |
| 1246 | | - |
| 1247 | menu->setTag(reinterpret_cast<quintptr>(e->action())); | - |
| 1248 | menu->setText(e->action()->text()); | - |
| 1249 | d->platformMenuBar->insertMenu(menu, beforeMenu); | - |
| 1250 | } never executed: end of block | 0 |
| 1251 | } else if (e->type() == QEvent::ActionRemoved) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1252 | QPlatformMenu *menu = d->getPlatformMenu(e->action()); | - |
| 1253 | if (menu)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1254 | d->platformMenuBar->removeMenu(menu); never executed: d->platformMenuBar->removeMenu(menu); | 0 |
| 1255 | } else if (e->type() == QEvent::ActionChanged) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1256 | QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast<quintptr>(e->action())); | - |
| 1257 | QPlatformMenu *menu = d->getPlatformMenu(e->action()); | - |
| 1258 | | - |
| 1259 | | - |
| 1260 | | - |
| 1261 | if (menu != cur) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1262 | if (cur)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1263 | d->platformMenuBar->removeMenu(cur); never executed: d->platformMenuBar->removeMenu(cur); | 0 |
| 1264 | if (menu) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1265 | menu->setTag(reinterpret_cast<quintptr>(e->action())); | - |
| 1266 | | - |
| 1267 | QPlatformMenu* beforeMenu = NULL; | - |
| 1268 | for (int beforeIndex = d->indexOf(e->action()) + 1; | - |
| 1269 | !beforeMenu && (beforeIndex < actions().size());| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1270 | ++beforeIndex) | - |
| 1271 | { | - |
| 1272 | beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); | - |
| 1273 | } never executed: end of block | 0 |
| 1274 | d->platformMenuBar->insertMenu(menu, beforeMenu); | - |
| 1275 | } never executed: end of block | 0 |
| 1276 | } else if (menu) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1277 | menu->setText(e->action()->text()); | - |
| 1278 | menu->setVisible(e->action()->isVisible()); | - |
| 1279 | menu->setEnabled(e->action()->isEnabled()); | - |
| 1280 | d->platformMenuBar->syncMenu(menu); | - |
| 1281 | } never executed: end of block | 0 |
| 1282 | } never executed: end of block | 0 |
| 1283 | } never executed: end of block | 0 |
| 1284 | | - |
| 1285 | if(e->type() == QEvent::ActionAdded) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1286 | connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); | - |
| 1287 | connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered())); | - |
| 1288 | } else if(e->type() == QEvent::ActionRemoved) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1289 | e->action()->disconnect(this); | - |
| 1290 | } never executed: end of block | 0 |
| 1291 | if (isVisible()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1292 | d->updateGeometries(); | - |
| 1293 | update(); | - |
| 1294 | } never executed: end of block | 0 |
| 1295 | } never executed: end of block | 0 |
| 1296 | | - |
| 1297 | | - |
| 1298 | | - |
| 1299 | | - |
| 1300 | void QMenuBar::focusInEvent(QFocusEvent *) | - |
| 1301 | { | - |
| 1302 | Q_D(QMenuBar); | - |
| 1303 | if(d->keyboardState) | - |
| 1304 | d->focusFirstAction(); | - |
| 1305 | } | - |
| 1306 | | - |
| 1307 | | - |
| 1308 | | - |
| 1309 | | - |
| 1310 | void QMenuBar::focusOutEvent(QFocusEvent *) | - |
| 1311 | { | - |
| 1312 | Q_D(QMenuBar); | - |
| 1313 | if(!d->popupState) { | - |
| 1314 | d->setCurrentAction(0); | - |
| 1315 | d->setKeyboardMode(false); | - |
| 1316 | } | - |
| 1317 | } | - |
| 1318 | | - |
| 1319 | | - |
| 1320 | | - |
| 1321 | | - |
| 1322 | void QMenuBar::timerEvent (QTimerEvent *e) | - |
| 1323 | { | - |
| 1324 | Q_D(QMenuBar); | - |
| 1325 | if (e->timerId() == d->autoReleaseTimer.timerId()) { | - |
| 1326 | d->autoReleaseTimer.stop(); | - |
| 1327 | d->setCurrentAction(0); | - |
| 1328 | } | - |
| 1329 | QWidget::timerEvent(e); | - |
| 1330 | } | - |
| 1331 | | - |
| 1332 | | - |
| 1333 | void QMenuBarPrivate::handleReparent() | - |
| 1334 | { | - |
| 1335 | Q_Q(QMenuBar); | - |
| 1336 | QWidget *newParent = q->parentWidget(); | - |
| 1337 | | - |
| 1338 | | - |
| 1339 | | - |
| 1340 | | - |
| 1341 | QWidget *newWindow = newParent ? newParent->window() : Q_NULLPTR; | - |
| 1342 | | - |
| 1343 | QVector<QPointer<QWidget> > newParents; | - |
| 1344 | | - |
| 1345 | | - |
| 1346 | foreach (const QPointer<QWidget> &w, oldParents) { | - |
| 1347 | if (w) { | - |
| 1348 | if (newParent == w) { | - |
| 1349 | newParents.append(w); | - |
| 1350 | if (newParent != newWindow) | - |
| 1351 | newParent = newParent->parentWidget(); | - |
| 1352 | } else { | - |
| 1353 | w->removeEventFilter(q); | - |
| 1354 | } | - |
| 1355 | } | - |
| 1356 | } | - |
| 1357 | | - |
| 1358 | | - |
| 1359 | while (newParent && newParent != newWindow) { | - |
| 1360 | | - |
| 1361 | newParents.append(newParent); | - |
| 1362 | newParent->installEventFilter(q); | - |
| 1363 | newParent = newParent->parentWidget(); | - |
| 1364 | } | - |
| 1365 | | - |
| 1366 | if (newParent && newWindow) { | - |
| 1367 | | - |
| 1368 | newParents.append(newParent); | - |
| 1369 | newParent->installEventFilter(q); | - |
| 1370 | } | - |
| 1371 | oldParents = newParents; | - |
| 1372 | | - |
| 1373 | if (platformMenuBar) { | - |
| 1374 | if (newWindow) { | - |
| 1375 | | - |
| 1376 | | - |
| 1377 | | - |
| 1378 | newWindow->createWinId(); | - |
| 1379 | platformMenuBar->handleReparent(newWindow->windowHandle()); | - |
| 1380 | } else { | - |
| 1381 | platformMenuBar->handleReparent(0); | - |
| 1382 | } | - |
| 1383 | } | - |
| 1384 | | - |
| 1385 | #ifdef Q_OS_WINCE | - |
| 1386 | if (qt_wince_is_mobile() && wce_menubar) | - |
| 1387 | wce_menubar->rebuild(); | - |
| 1388 | #endif | - |
| 1389 | } | - |
| 1390 | | - |
| 1391 | | - |
| 1392 | | - |
| 1393 | | - |
| 1394 | void QMenuBar::changeEvent(QEvent *e) | - |
| 1395 | { | - |
| 1396 | Q_D(QMenuBar); | - |
| 1397 | if(e->type() == QEvent::StyleChange) { | - |
| 1398 | d->itemsDirty = true; | - |
| 1399 | setMouseTracking(style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, this)); | - |
| 1400 | if(parentWidget()) | - |
| 1401 | resize(parentWidget()->width(), heightForWidth(parentWidget()->width())); | - |
| 1402 | d->updateGeometries(); | - |
| 1403 | } else if (e->type() == QEvent::ParentChange) { | - |
| 1404 | d->handleReparent(); | - |
| 1405 | } else if (e->type() == QEvent::FontChange | - |
| 1406 | || e->type() == QEvent::ApplicationFontChange) { | - |
| 1407 | d->itemsDirty = true; | - |
| 1408 | d->updateGeometries(); | - |
| 1409 | } | - |
| 1410 | | - |
| 1411 | QWidget::changeEvent(e); | - |
| 1412 | } | - |
| 1413 | | - |
| 1414 | | - |
| 1415 | | - |
| 1416 | | - |
| 1417 | bool QMenuBar::event(QEvent *e) | - |
| 1418 | { | - |
| 1419 | Q_D(QMenuBar); | - |
| 1420 | switch (e->type()) { | - |
| 1421 | case QEvent::KeyPress: { | - |
| 1422 | QKeyEvent *ke = (QKeyEvent*)e; | - |
| 1423 | #if 0 | - |
| 1424 | if(!d->keyboardState) { | - |
| 1425 | d->setCurrentAction(0); | - |
| 1426 | return ; | - |
| 1427 | } | - |
| 1428 | #endif | - |
| 1429 | if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) { | - |
| 1430 | keyPressEvent(ke); | - |
| 1431 | return true; | - |
| 1432 | } | - |
| 1433 | | - |
| 1434 | } break; | - |
| 1435 | #ifndef QT_NO_SHORTCUT | - |
| 1436 | case QEvent::Shortcut: { | - |
| 1437 | QShortcutEvent *se = static_cast<QShortcutEvent *>(e); | - |
| 1438 | int shortcutId = se->shortcutId(); | - |
| 1439 | for(int j = 0; j < d->shortcutIndexMap.size(); ++j) { | - |
| 1440 | if (shortcutId == d->shortcutIndexMap.value(j)) | - |
| 1441 | d->_q_internalShortcutActivated(j); | - |
| 1442 | } | - |
| 1443 | } break; | - |
| 1444 | #endif | - |
| 1445 | case QEvent::Show: | - |
| 1446 | d->_q_updateLayout(); | - |
| 1447 | break; | - |
| 1448 | case QEvent::ShortcutOverride: { | - |
| 1449 | QKeyEvent *kev = static_cast<QKeyEvent*>(e); | - |
| 1450 | | - |
| 1451 | if (kev->matches(QKeySequence::Cancel) && d->currentAction) { | - |
| 1452 | e->accept(); | - |
| 1453 | return true; | - |
| 1454 | } | - |
| 1455 | } | - |
| 1456 | break; | - |
| 1457 | | - |
| 1458 | | - |
| 1459 | #ifndef QT_NO_WHATSTHIS | - |
| 1460 | case QEvent::QueryWhatsThis: | - |
| 1461 | e->setAccepted(d->whatsThis.size()); | - |
| 1462 | if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) { | - |
| 1463 | if (action->whatsThis().size() || action->menu()) | - |
| 1464 | e->accept(); | - |
| 1465 | } | - |
| 1466 | return true; | - |
| 1467 | #endif | - |
| 1468 | case QEvent::LayoutDirectionChange: | - |
| 1469 | d->_q_updateLayout(); | - |
| 1470 | break; | - |
| 1471 | default: | - |
| 1472 | break; | - |
| 1473 | } | - |
| 1474 | return QWidget::event(e); | - |
| 1475 | } | - |
| 1476 | | - |
| 1477 | | - |
| 1478 | | - |
| 1479 | | - |
| 1480 | bool QMenuBar::eventFilter(QObject *object, QEvent *event) | - |
| 1481 | { | - |
| 1482 | Q_D(QMenuBar); | - |
| 1483 | if (object && (event->type() == QEvent::ParentChange)) | - |
| 1484 | d->handleReparent(); | - |
| 1485 | | - |
| 1486 | if (object == d->leftWidget || object == d->rightWidget) { | - |
| 1487 | switch (event->type()) { | - |
| 1488 | case QEvent::ShowToParent: | - |
| 1489 | case QEvent::HideToParent: | - |
| 1490 | d->_q_updateLayout(); | - |
| 1491 | break; | - |
| 1492 | default: | - |
| 1493 | break; | - |
| 1494 | } | - |
| 1495 | } | - |
| 1496 | | - |
| 1497 | if (style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this)) { | - |
| 1498 | if (d->altPressed) { | - |
| 1499 | switch (event->type()) { | - |
| 1500 | case QEvent::KeyPress: | - |
| 1501 | case QEvent::KeyRelease: | - |
| 1502 | { | - |
| 1503 | QKeyEvent *kev = static_cast<QKeyEvent*>(event); | - |
| 1504 | if (kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta) { | - |
| 1505 | if (event->type() == QEvent::KeyPress) | - |
| 1506 | break; | - |
| 1507 | d->setKeyboardMode(!d->keyboardState); | - |
| 1508 | } | - |
| 1509 | } | - |
| 1510 | | - |
| 1511 | case QEvent::MouseButtonPress: | - |
| 1512 | case QEvent::MouseButtonRelease: | - |
| 1513 | case QEvent::MouseMove: | - |
| 1514 | case QEvent::FocusIn: | - |
| 1515 | case QEvent::FocusOut: | - |
| 1516 | case QEvent::ActivationChange: | - |
| 1517 | d->altPressed = false; | - |
| 1518 | qApp->removeEventFilter(this); | - |
| 1519 | break; | - |
| 1520 | default: | - |
| 1521 | break; | - |
| 1522 | } | - |
| 1523 | } else if (isVisible()) { | - |
| 1524 | if (event->type() == QEvent::ShortcutOverride) { | - |
| 1525 | QKeyEvent *kev = static_cast<QKeyEvent*>(event); | - |
| 1526 | if ((kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta) | - |
| 1527 | && kev->modifiers() == Qt::AltModifier) { | - |
| 1528 | d->altPressed = true; | - |
| 1529 | qApp->installEventFilter(this); | - |
| 1530 | } | - |
| 1531 | } | - |
| 1532 | } | - |
| 1533 | } | - |
| 1534 | | - |
| 1535 | return false; | - |
| 1536 | } | - |
| 1537 | | - |
| 1538 | | - |
| 1539 | | - |
| 1540 | | - |
| 1541 | | - |
| 1542 | | - |
| 1543 | | - |
| 1544 | QAction *QMenuBar::actionAt(const QPoint &pt) const | - |
| 1545 | { | - |
| 1546 | Q_D(const QMenuBar); | - |
| 1547 | return d->actionAt(pt); | - |
| 1548 | } | - |
| 1549 | | - |
| 1550 | | - |
| 1551 | | - |
| 1552 | | - |
| 1553 | | - |
| 1554 | | - |
| 1555 | QRect QMenuBar::actionGeometry(QAction *act) const | - |
| 1556 | { | - |
| 1557 | Q_D(const QMenuBar); | - |
| 1558 | return d->actionRect(act); | - |
| 1559 | } | - |
| 1560 | | - |
| 1561 | | - |
| 1562 | | - |
| 1563 | | - |
| 1564 | QSize QMenuBar::minimumSizeHint() const | - |
| 1565 | { | - |
| 1566 | Q_D(const QMenuBar); | - |
| 1567 | const bool as_gui_menubar = !isNativeMenuBar(); | - |
| 1568 | | - |
| 1569 | ensurePolished(); | - |
| 1570 | QSize ret(0, 0); | - |
| 1571 | const_cast<QMenuBarPrivate*>(d)->updateGeometries(); | - |
| 1572 | const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); | - |
| 1573 | const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); | - |
| 1574 | int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); | - |
| 1575 | int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); | - |
| 1576 | if(as_gui_menubar) { | - |
| 1577 | int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); | - |
| 1578 | d->calcActionRects(w - (2 * fw), 0); | - |
| 1579 | for (int i = 0; ret.isNull() && i < d->actions.count(); ++i) | - |
| 1580 | ret = d->actionRects.at(i).size(); | - |
| 1581 | if (!d->extension->isHidden()) | - |
| 1582 | ret += QSize(d->extension->sizeHint().width(), 0); | - |
| 1583 | ret += QSize(2*fw + hmargin, 2*fw + vmargin); | - |
| 1584 | } | - |
| 1585 | int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; | - |
| 1586 | if(d->leftWidget) { | - |
| 1587 | QSize sz = d->leftWidget->minimumSizeHint(); | - |
| 1588 | ret.setWidth(ret.width() + sz.width()); | - |
| 1589 | if(sz.height() + margin > ret.height()) | - |
| 1590 | ret.setHeight(sz.height() + margin); | - |
| 1591 | } | - |
| 1592 | if(d->rightWidget) { | - |
| 1593 | QSize sz = d->rightWidget->minimumSizeHint(); | - |
| 1594 | ret.setWidth(ret.width() + sz.width()); | - |
| 1595 | if(sz.height() + margin > ret.height()) | - |
| 1596 | ret.setHeight(sz.height() + margin); | - |
| 1597 | } | - |
| 1598 | if(as_gui_menubar) { | - |
| 1599 | QStyleOptionMenuItem opt; | - |
| 1600 | opt.rect = rect(); | - |
| 1601 | opt.menuRect = rect(); | - |
| 1602 | opt.state = QStyle::State_None; | - |
| 1603 | opt.menuItemType = QStyleOptionMenuItem::Normal; | - |
| 1604 | opt.checkType = QStyleOptionMenuItem::NotCheckable; | - |
| 1605 | opt.palette = palette(); | - |
| 1606 | return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, | - |
| 1607 | ret.expandedTo(QApplication::globalStrut()), | - |
| 1608 | this)); | - |
| 1609 | } | - |
| 1610 | return ret; | - |
| 1611 | } | - |
| 1612 | | - |
| 1613 | | - |
| 1614 | | - |
| 1615 | | - |
| 1616 | QSize QMenuBar::sizeHint() const | - |
| 1617 | { | - |
| 1618 | Q_D(const QMenuBar); | - |
| 1619 | const bool as_gui_menubar = !isNativeMenuBar(); | - |
| 1620 | | - |
| 1621 | ensurePolished(); | - |
| 1622 | QSize ret(0, 0); | - |
| 1623 | const_cast<QMenuBarPrivate*>(d)->updateGeometries(); | - |
| 1624 | const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); | - |
| 1625 | const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); | - |
| 1626 | int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); | - |
| 1627 | int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); | - |
| 1628 | if(as_gui_menubar) { | - |
| 1629 | const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); | - |
| 1630 | d->calcActionRects(w - (2 * fw), 0); | - |
| 1631 | for (int i = 0; i < d->actionRects.count(); ++i) { | - |
| 1632 | const QRect &actionRect = d->actionRects.at(i); | - |
| 1633 | ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height())); | - |
| 1634 | } | - |
| 1635 | | - |
| 1636 | | - |
| 1637 | ret += QSize(fw + hmargin, fw + vmargin); | - |
| 1638 | } | - |
| 1639 | int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; | - |
| 1640 | if(d->leftWidget) { | - |
| 1641 | QSize sz = d->leftWidget->sizeHint(); | - |
| 1642 | sz.rheight() += margin; | - |
| 1643 | ret = ret.expandedTo(sz); | - |
| 1644 | } | - |
| 1645 | if(d->rightWidget) { | - |
| 1646 | QSize sz = d->rightWidget->sizeHint(); | - |
| 1647 | ret.setWidth(ret.width() + sz.width()); | - |
| 1648 | if(sz.height() + margin > ret.height()) | - |
| 1649 | ret.setHeight(sz.height() + margin); | - |
| 1650 | } | - |
| 1651 | if(as_gui_menubar) { | - |
| 1652 | QStyleOptionMenuItem opt; | - |
| 1653 | opt.rect = rect(); | - |
| 1654 | opt.menuRect = rect(); | - |
| 1655 | opt.state = QStyle::State_None; | - |
| 1656 | opt.menuItemType = QStyleOptionMenuItem::Normal; | - |
| 1657 | opt.checkType = QStyleOptionMenuItem::NotCheckable; | - |
| 1658 | opt.palette = palette(); | - |
| 1659 | return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt, | - |
| 1660 | ret.expandedTo(QApplication::globalStrut()), | - |
| 1661 | this)); | - |
| 1662 | } | - |
| 1663 | return ret; | - |
| 1664 | } | - |
| 1665 | | - |
| 1666 | | - |
| 1667 | | - |
| 1668 | | - |
| 1669 | int QMenuBar::heightForWidth(int) const | - |
| 1670 | { | - |
| 1671 | Q_D(const QMenuBar); | - |
| 1672 | const bool as_gui_menubar = !isNativeMenuBar(); | - |
| 1673 | | - |
| 1674 | const_cast<QMenuBarPrivate*>(d)->updateGeometries(); | - |
| 1675 | int height = 0; | - |
| 1676 | const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); | - |
| 1677 | int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); | - |
| 1678 | int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); | - |
| 1679 | if(as_gui_menubar) { | - |
| 1680 | for (int i = 0; i < d->actionRects.count(); ++i) | - |
| 1681 | height = qMax(height, d->actionRects.at(i).height()); | - |
| 1682 | if (height) | - |
| 1683 | height += spaceBelowMenuBar; | - |
| 1684 | height += 2*fw; | - |
| 1685 | height += 2*vmargin; | - |
| 1686 | } | - |
| 1687 | int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; | - |
| 1688 | if(d->leftWidget) | - |
| 1689 | height = qMax(d->leftWidget->sizeHint().height() + margin, height); | - |
| 1690 | if(d->rightWidget) | - |
| 1691 | height = qMax(d->rightWidget->sizeHint().height() + margin, height); | - |
| 1692 | if(as_gui_menubar) { | - |
| 1693 | QStyleOptionMenuItem opt; | - |
| 1694 | opt.init(this); | - |
| 1695 | opt.menuRect = rect(); | - |
| 1696 | opt.state = QStyle::State_None; | - |
| 1697 | opt.menuItemType = QStyleOptionMenuItem::Normal; | - |
| 1698 | opt.checkType = QStyleOptionMenuItem::NotCheckable; | - |
| 1699 | return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); | - |
| 1700 | } | - |
| 1701 | return height; | - |
| 1702 | } | - |
| 1703 | | - |
| 1704 | | - |
| 1705 | | - |
| 1706 | | - |
| 1707 | void QMenuBarPrivate::_q_internalShortcutActivated(int id) | - |
| 1708 | { | - |
| 1709 | Q_Q(QMenuBar); | - |
| 1710 | QAction *act = actions.at(id); | - |
| 1711 | setCurrentAction(act, true, true); | - |
| 1712 | if (act && !act->menu()) { | - |
| 1713 | activateAction(act, QAction::Trigger); | - |
| 1714 | | - |
| 1715 | autoReleaseTimer.start(100, q); | - |
| 1716 | } else if (act && q->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, q)) { | - |
| 1717 | | - |
| 1718 | setKeyboardMode(true); | - |
| 1719 | } | - |
| 1720 | } | - |
| 1721 | | - |
| 1722 | void QMenuBarPrivate::_q_updateLayout() | - |
| 1723 | { | - |
| 1724 | Q_Q(QMenuBar); | - |
| 1725 | itemsDirty = true; | - |
| 1726 | if (q->isVisible()) { | - |
| 1727 | updateGeometries(); | - |
| 1728 | q->update(); | - |
| 1729 | } | - |
| 1730 | } | - |
| 1731 | | - |
| 1732 | | - |
| 1733 | | - |
| 1734 | | - |
| 1735 | | - |
| 1736 | | - |
| 1737 | | - |
| 1738 | | - |
| 1739 | | - |
| 1740 | | - |
| 1741 | | - |
| 1742 | | - |
| 1743 | | - |
| 1744 | | - |
| 1745 | void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner) | - |
| 1746 | { | - |
| 1747 | Q_D(QMenuBar); | - |
| 1748 | switch (corner) { | - |
| 1749 | case Qt::TopLeftCorner: | - |
| 1750 | if (d->leftWidget) | - |
| 1751 | d->leftWidget->removeEventFilter(this); | - |
| 1752 | d->leftWidget = w; | - |
| 1753 | break; | - |
| 1754 | case Qt::TopRightCorner: | - |
| 1755 | if (d->rightWidget) | - |
| 1756 | d->rightWidget->removeEventFilter(this); | - |
| 1757 | d->rightWidget = w; | - |
| 1758 | break; | - |
| 1759 | default: | - |
| 1760 | qWarning("QMenuBar::setCornerWidget: Only TopLeftCorner and TopRightCorner are supported"); | - |
| 1761 | return; | - |
| 1762 | } | - |
| 1763 | | - |
| 1764 | if (w) { | - |
| 1765 | w->setParent(this); | - |
| 1766 | w->installEventFilter(this); | - |
| 1767 | } | - |
| 1768 | | - |
| 1769 | d->_q_updateLayout(); | - |
| 1770 | } | - |
| 1771 | | - |
| 1772 | | - |
| 1773 | | - |
| 1774 | | - |
| 1775 | | - |
| 1776 | | - |
| 1777 | | - |
| 1778 | | - |
| 1779 | QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const | - |
| 1780 | { | - |
| 1781 | Q_D(const QMenuBar); | - |
| 1782 | QWidget *w = 0; | - |
| 1783 | switch(corner) { | - |
| 1784 | case Qt::TopLeftCorner: | - |
| 1785 | w = d->leftWidget; | - |
| 1786 | break; | - |
| 1787 | case Qt::TopRightCorner: | - |
| 1788 | w = d->rightWidget; | - |
| 1789 | break; | - |
| 1790 | default: | - |
| 1791 | qWarning("QMenuBar::cornerWidget: Only TopLeftCorner and TopRightCorner are supported"); | - |
| 1792 | break; | - |
| 1793 | } | - |
| 1794 | | - |
| 1795 | return w; | - |
| 1796 | } | - |
| 1797 | | - |
| 1798 | | - |
| 1799 | | - |
| 1800 | | - |
| 1801 | | - |
| 1802 | | - |
| 1803 | | - |
| 1804 | | - |
| 1805 | | - |
| 1806 | | - |
| 1807 | | - |
| 1808 | | - |
| 1809 | | - |
| 1810 | | - |
| 1811 | | - |
| 1812 | | - |
| 1813 | | - |
| 1814 | | - |
| 1815 | void QMenuBar::setNativeMenuBar(bool nativeMenuBar) | - |
| 1816 | { | - |
| 1817 | Q_D(QMenuBar); | - |
| 1818 | if (nativeMenuBar != bool(d->platformMenuBar)) { | - |
| 1819 | if (!nativeMenuBar) { | - |
| 1820 | delete d->platformMenuBar; | - |
| 1821 | d->platformMenuBar = 0; | - |
| 1822 | } else { | - |
| 1823 | if (!d->platformMenuBar) | - |
| 1824 | d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); | - |
| 1825 | } | - |
| 1826 | | - |
| 1827 | updateGeometry(); | - |
| 1828 | if (!nativeMenuBar && parentWidget()) | - |
| 1829 | setVisible(true); | - |
| 1830 | } | - |
| 1831 | } | - |
| 1832 | | - |
| 1833 | bool QMenuBar::isNativeMenuBar() const | - |
| 1834 | { | - |
| 1835 | Q_D(const QMenuBar); | - |
| 1836 | return bool(d->platformMenuBar); | - |
| 1837 | } | - |
| 1838 | | - |
| 1839 | | - |
| 1840 | | - |
| 1841 | | - |
| 1842 | QPlatformMenuBar *QMenuBar::platformMenuBar() | - |
| 1843 | { | - |
| 1844 | Q_D(const QMenuBar); | - |
| 1845 | return d->platformMenuBar; | - |
| 1846 | } | - |
| 1847 | | - |
| 1848 | | - |
| 1849 | | - |
| 1850 | | - |
| 1851 | | - |
| 1852 | | - |
| 1853 | | - |
| 1854 | | - |
| 1855 | | - |
| 1856 | | - |
| 1857 | | - |
| 1858 | | - |
| 1859 | | - |
| 1860 | | - |
| 1861 | | - |
| 1862 | #ifdef Q_OS_WINCE | - |
| 1863 | void QMenuBar::setDefaultAction(QAction *act) | - |
| 1864 | { | - |
| 1865 | Q_D(QMenuBar); | - |
| 1866 | if (d->defaultAction == act) | - |
| 1867 | return; | - |
| 1868 | if (qt_wince_is_mobile()) | - |
| 1869 | if (d->defaultAction) { | - |
| 1870 | disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); | - |
| 1871 | disconnect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); | - |
| 1872 | } | - |
| 1873 | d->defaultAction = act; | - |
| 1874 | if (qt_wince_is_mobile()) | - |
| 1875 | if (d->defaultAction) { | - |
| 1876 | connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); | - |
| 1877 | connect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); | - |
| 1878 | } | - |
| 1879 | if (d->wce_menubar) { | - |
| 1880 | d->wce_menubar->rebuild(); | - |
| 1881 | } | - |
| 1882 | } | - |
| 1883 | | - |
| 1884 | | - |
| 1885 | | - |
| 1886 | | - |
| 1887 | | - |
| 1888 | | - |
| 1889 | | - |
| 1890 | | - |
| 1891 | QAction *QMenuBar::defaultAction() const | - |
| 1892 | { | - |
| 1893 | return d_func()->defaultAction; | - |
| 1894 | } | - |
| 1895 | #endif | - |
| 1896 | | - |
| 1897 | | - |
| 1898 | | - |
| 1899 | | - |
| 1900 | | - |
| 1901 | | - |
| 1902 | | - |
| 1903 | | - |
| 1904 | | - |
| 1905 | | - |
| 1906 | | - |
| 1907 | | - |
| 1908 | | - |
| 1909 | | - |
| 1910 | | - |
| 1911 | | - |
| 1912 | | - |
| 1913 | | - |
| 1914 | | - |
| 1915 | | - |
| 1916 | | - |
| 1917 | | - |
| 1918 | | - |
| 1919 | | - |
| 1920 | | - |
| 1921 | | - |
| 1922 | | - |
| 1923 | | - |
| 1924 | | - |
| 1925 | | - |
| 1926 | | - |
| 1927 | | - |
| 1928 | QT_END_NAMESPACE | - |
| 1929 | | - |
| 1930 | #include <moc_qmenubar.cpp> | - |
| 1931 | | - |
| 1932 | #endif // QT_NO_MENUBAR | - |
| | |