⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmenubar.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#if 0        if(!d->keyboardState) { //all keypresses..            d->setCurrentAction(0);            return ;        }#endif        if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {            keyPressEvent(ke);            return true;        }    } break;#ifndef QT_NO_SHORTCUT    case QEvent::Shortcut: {        QShortcutEvent *se = static_cast<QShortcutEvent *>(e);        int shortcutId = se->shortcutId();        for(int j = 0; j < d->shortcutIndexMap.size(); ++j) {            if (shortcutId == d->shortcutIndexMap.value(j))                d->_q_internalShortcutActivated(j);        }    } break;#endif    case QEvent::Show:#ifdef QT3_SUPPORT        if(QWidget *p = parentWidget()) {            // If itemsDirty == true, updateGeometries sends the MenubarUpdated event.            if (!d->itemsDirty) {                QMenubarUpdatedEvent menubarUpdated(this);                QApplication::sendEvent(p, &menubarUpdated);            }        }#endif        d->updateGeometries();    break;#ifdef QT3_SUPPORT    case QEvent::Hide: {        if(QWidget *p = parentWidget()) {            QMenubarUpdatedEvent menubarUpdated(this);            QApplication::sendEvent(p, &menubarUpdated);        }    } break;#endif#ifndef QT_NO_WHATSTHIS    case QEvent::QueryWhatsThis:        e->setAccepted(d->whatsThis.size());        if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) {            if (action->whatsThis().size() || action->menu())                e->accept();        }        return true;#endif    case QEvent::LayoutDirectionChange:        d->_q_updateLayout();        break;    default:        break;    }    return QWidget::event(e);}/*!  \reimp*/bool QMenuBar::eventFilter(QObject *object, QEvent *event){    Q_D(QMenuBar);    if (object == parent() && object) {#ifdef QT3_SUPPORT        if (d->doAutoResize && event->type() == QEvent::Resize) {            QResizeEvent *e = (QResizeEvent *)event;            int w = e->size().width();            setGeometry(0, y(), w, heightForWidth(w));            return false;        }#endif        if (event->type() == QEvent::ParentChange) //GrandparentChange            d->handleReparent();    }    if (object == d->leftWidget || object == d->rightWidget) {        switch (event->type()) {        case QEvent::ShowToParent:        case QEvent::HideToParent:            d->_q_updateLayout();            break;        default:            break;        }    }    if (style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this)) {        if (d->altPressed) {            switch (event->type()) {            case QEvent::KeyPress:            case QEvent::KeyRelease:            {                QKeyEvent *kev = static_cast<QKeyEvent*>(event);                if (kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta) {                    if (event->type() == QEvent::KeyPress) // Alt-press does not interest us, we have the shortcut-override event                        break;                    d->setKeyboardMode(!d->keyboardState);                }            }            // fall through            case QEvent::MouseButtonPress:            case QEvent::FocusIn:            case QEvent::FocusOut:            case QEvent::ActivationChange:                d->altPressed = false;                qApp->removeEventFilter(this);                break;            default:                break;            }        } else if (isVisible()) {            if (event->type() == QEvent::ShortcutOverride) {                QKeyEvent *kev = static_cast<QKeyEvent*>(event);                if ((kev->key() == Qt::Key_Alt || kev->key() == Qt::Key_Meta)                    && kev->modifiers() == Qt::AltModifier) {                    d->altPressed = true;                    qApp->installEventFilter(this);                }            }        }    }    return false;}/*!  \internal  Return the item at \a pt, or 0 if there is no item there or if it is  a separator item.*/QAction *QMenuBar::actionAt(const QPoint &pt) const{    Q_D(const QMenuBar);    return d->actionAt(pt);}/*!  \internal  Returns the geometry of action \a act.*/QRect QMenuBar::actionGeometry(QAction *act) const{    Q_D(const QMenuBar);    return d->actionRect(act);}/*!  \reimp*/QSize QMenuBar::minimumSizeHint() const{    Q_D(const QMenuBar);#ifdef Q_WS_MAC    const bool as_gui_menubar = !d->mac_menubar;#else    const bool as_gui_menubar = true;#endif    ensurePolished();    QSize ret(0, 0);    const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this);    const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);    int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);    int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);    if(as_gui_menubar) {        QMap<QAction*, QRect> actionRects;        QList<QAction*> actionList;        int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();        d->calcActionRects(w - (2 * fw), 0, actionRects, actionList);        if (d->actionList.count() > 0) {            ret = d->actionRect(d->actionList.at(0)).size();            if (!d->extension->isHidden())                ret += QSize(d->extension->sizeHint().width(), 0);        }        ret += QSize(2*fw + hmargin, 2*fw + vmargin);    }    int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;    if(d->leftWidget) {        QSize sz = d->leftWidget->minimumSizeHint();        ret.setWidth(ret.width() + sz.width());        if(sz.height() + margin > ret.height())            ret.setHeight(sz.height() + margin);    }    if(d->rightWidget) {        QSize sz = d->rightWidget->minimumSizeHint();        ret.setWidth(ret.width() + sz.width());        if(sz.height() + margin > ret.height())            ret.setHeight(sz.height() + margin);    }    if(as_gui_menubar) {        QStyleOptionMenuItem opt;        opt.rect = rect();        opt.menuRect = rect();        opt.state = QStyle::State_None;        opt.menuItemType = QStyleOptionMenuItem::Normal;        opt.checkType = QStyleOptionMenuItem::NotCheckable;        opt.palette = palette();        return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,                                         ret.expandedTo(QApplication::globalStrut()),                                         this));    }    return ret;}/*!  \reimp*/QSize QMenuBar::sizeHint() const{    Q_D(const QMenuBar);#ifdef Q_WS_MAC    const bool as_gui_menubar = !d->mac_menubar;#else    const bool as_gui_menubar = true;#endif    ensurePolished();    QSize ret(0, 0);    const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this);    const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);    int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);    int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);    if(as_gui_menubar) {        QMap<QAction*, QRect> actionRects;        QList<QAction*> actionList;        const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();        d->calcActionRects(w - (2 * fw), 0, actionRects, actionList);        for (QMap<QAction*, QRect>::const_iterator i = actionRects.constBegin();             i != actionRects.constEnd(); ++i) {            QRect actionRect(i.value());            if(actionRect.x() + actionRect.width() > ret.width())                ret.setWidth(actionRect.x() + actionRect.width());            if(actionRect.y() + actionRect.height() > ret.height())                ret.setHeight(actionRect.y() + actionRect.height());        }        ret += QSize(2*fw + 2*hmargin, 2*fw + 2*vmargin);    }    int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;    if(d->leftWidget) {        QSize sz = d->leftWidget->sizeHint();        ret.setWidth(ret.width() + sz.width());        if(sz.height() + margin > ret.height())            ret.setHeight(sz.height() + margin);    }    if(d->rightWidget) {        QSize sz = d->rightWidget->sizeHint();        ret.setWidth(ret.width() + sz.width());        if(sz.height() + margin > ret.height())            ret.setHeight(sz.height() + margin);    }    if(as_gui_menubar) {        QStyleOptionMenuItem opt;        opt.rect = rect();        opt.menuRect = rect();        opt.state = QStyle::State_None;        opt.menuItemType = QStyleOptionMenuItem::Normal;        opt.checkType = QStyleOptionMenuItem::NotCheckable;        opt.palette = palette();        return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,                                         ret.expandedTo(QApplication::globalStrut()),                                         this));    }    return ret;}/*!  \reimp*/int QMenuBar::heightForWidth(int) const{    Q_D(const QMenuBar);#ifdef Q_WS_MAC    const bool as_gui_menubar = !d->mac_menubar;#else    const bool as_gui_menubar = true;#endif    int height = 0;    const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);    int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);    int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);    if(as_gui_menubar) {        if (d->actionList.count()) {            // assume all actionrects have the same height            height = d->actionRect(d->actionList.first()).height();            height += spaceBelowMenuBar;        }        height += 2*fw;        height += 2*vmargin;    }    int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;    if(d->leftWidget)        height = qMax(d->leftWidget->sizeHint().height() + margin, height);    if(d->rightWidget)        height = qMax(d->rightWidget->sizeHint().height() + margin, height);    if(as_gui_menubar) {        QStyleOptionMenuItem opt;        opt.init(this);        opt.menuRect = rect();        opt.state = QStyle::State_None;        opt.menuItemType = QStyleOptionMenuItem::Normal;        opt.checkType = QStyleOptionMenuItem::NotCheckable;        return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); //not pretty..    }    return height;}/*!  \internal*/void QMenuBarPrivate::_q_internalShortcutActivated(int id){    QAction *act = actionList.at(id);    setCurrentAction(act, true, true);}void QMenuBarPrivate::_q_updateLayout(){    Q_Q(QMenuBar);    itemsDirty = true;    if (q->isVisible()) {        updateGeometries();        q->update();    }}/*!  \internal  This sets widget \a w to be shown directly on the left of the first or  the right of the last menu item, depending on \a corner.*/void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner){    Q_D(QMenuBar);    switch (corner) {    case Qt::TopLeftCorner:        if (d->leftWidget)            d->leftWidget->removeEventFilter(this);        d->leftWidget = w;        break;    case Qt::TopRightCorner:        if (d->rightWidget)            d->rightWidget->removeEventFilter(this);        d->rightWidget = w;        break;    default:        qWarning("QMenuBar::setCornerWidget: Only TopLeftCorner and TopRightCorner are supported");        return;    }    if (w) {        w->setParent(this);        w->installEventFilter(this);    }    d->_q_updateLayout();}/*!  \internal  Returns the widget in the left of the first or the right of the last menu  item, depending on \a corner.*/QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const{    Q_D(const QMenuBar);    QWidget *w = 0;    switch(corner) {    case Qt::TopLeftCorner:        w = d->leftWidget;        break;    case Qt::TopRightCorner:        w = d->rightWidget;        break;    default:        qWarning("QMenuBar::cornerWidget: Only TopLeftCorner and TopRightCorner are supported");        break;    }    return w;}/*!    \fn void QMenuBar::triggered(QAction *action)    This signal is emitted when an action in a menu belonging to this menubar    is triggered as a result of a mouse click; \a action is the action that    caused the signal to be emitted.    Normally, you connect each menu action to a single slot using    QAction::triggered(), but sometimes you will want to connect    several items to a single slot (most often if the user selects    from an array). This signal is useful in such cases.    \sa hovered(), QAction::triggered()*//*!    \fn void QMenuBar::hovered(QAction *action)    This signal is emitted when a menu action is highlighted; \a action    is the action that caused the event to be sent.    Often this is used to update status information.    \sa triggered(), QAction::hovered()*/#ifdef QT3_SUPPORT/*!    Use style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, this)    instead.*/int QMenuBar::frameWidth() const{    return style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);}int QMenuBar::insertAny(const QIcon *icon, const QString *text, const QObject *receiver, const char *member,                        const QKeySequence *shortcut, const QMenu *popup, int id, int index){    QAction *act = popup ? popup->menuAction() : new QAction(this);    if(id != -1)        static_cast<QMenuItem*>(act)->setId(id);    if(icon)        act->setIcon(*icon);    if(text)        act->setText(*text);    if(shortcut)        act->setShortcut(*shortcut);    if(receiver && member)        QObject::connect(act, SIGNAL(triggered(bool)), receiver, member);    if(index == -1 || index >= actions().count())

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -