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

📄 q3action.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*!    \property Q3Action::on    \brief whether a toggle action is on    This property is always on (true) for command actions and    \l{Q3ActionGroup}s; setOn() has no effect on them. For action's    where isToggleAction() is true, this property's default value is    off (false).    \sa toggleAction*/void Q3Action::setOn(bool enable){    if (!isToggleAction()) {        if (enable)            qWarning("Q3Action::%s() (%s) Only toggle actions "                      "can be switched", "setOn", objectName().toLocal8Bit().data());        return;    }    if (enable == (bool)d->on)        return;    d->on = enable;    d->update(Q3ActionPrivate::State);    emit toggled(enable);}bool Q3Action::isOn() const{    return d->on;}/*!    \property Q3Action::enabled    \brief whether the action is enabled    Disabled actions can't be chosen by the user. They don't disappear    from the menu/tool bar but are displayed in a way which indicates    that they are unavailable, e.g. they might be displayed grayed    out.    What's this? help on disabled actions is still available provided    the \l Q3Action::whatsThis property is set.*/void Q3Action::setEnabled(bool enable){    d->forceDisabled = !enable;    if ((bool)d->enabled == enable)        return;    d->enabled = enable;    d->update(Q3ActionPrivate::State);}bool Q3Action::isEnabled() const{    return d->enabled;}/*!    Disables the action if \a disable is true; otherwise    enables the action.    See the \l enabled documentation for more information.*/void Q3Action::setDisabled(bool disable){    setEnabled(!disable);}/*!    \property Q3Action::visible    \brief whether the action can be seen (e.g. in menus and toolbars)    If \e visible is true the action can be seen (e.g. in menus and    toolbars) and chosen by the user; if \e visible is false the    action cannot be seen or chosen by the user.    Actions which are not visible are \e not grayed out; they do not    appear at all.*/void Q3Action::setVisible(bool visible){    d->forceInvisible = !visible;    if ((bool)d->visible == visible)        return;    d->visible = visible;    d->update(Q3ActionPrivate::Visibility);}/*    Returns true if the action is visible (e.g. in menus and    toolbars); otherwise returns false.*/bool Q3Action::isVisible() const{    return d->visible;}/*! \internal*/void Q3Action::internalActivation(){    if (isToggleAction())        setOn(!isOn());    emit activated();}/*! \internal*/void Q3Action::toolButtonToggled(bool on){    if (!isToggleAction())        return;    setOn(on);}/*!    Adds this action to widget \a w.    Currently actions may be added to Q3ToolBar and Q3PopupMenu widgets.    An action added to a tool bar is automatically displayed as a tool    button; an action added to a pop up menu appears as a menu option.    addTo() returns true if the action was added successfully and    false otherwise. (If \a w is not a Q3ToolBar or Q3PopupMenu the    action will not be added and false will be returned.)    \sa removeFrom()*/bool Q3Action::addTo(QWidget* w){#ifndef QT_NO_TOOLBAR    if (::qobject_cast<Q3ToolBar*>(w)) {        if (objectName() == QLatin1String("qt_separator_action")) {            ((Q3ToolBar*)w)->addSeparator();        } else {            QString bname = objectName() + QLatin1String("_action_button");            QToolButton* btn = new QToolButton((Q3ToolBar*) w);            btn->setObjectName(bname);            addedTo(btn, w);            btn->setToggleButton(d->toggleaction);            d->toolbuttons.append(btn);            if (d->icon)                btn->setIconSet(*d->icon);            d->update(Q3ActionPrivate::State | Q3ActionPrivate::Visibility | Q3ActionPrivate::EverythingElse) ;            connect(btn, SIGNAL(clicked()), this, SIGNAL(activated()));            connect(btn, SIGNAL(toggled(bool)), this, SLOT(toolButtonToggled(bool)));            connect(btn, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));        }    } else#endif    if (qobject_cast<Q3PopupMenu*>(w)) {        Q3ActionPrivate::MenuItem* mi = new Q3ActionPrivate::MenuItem;        mi->popup = (Q3PopupMenu*) w;        QIcon* dicon = d->icon;        if (objectName() == QLatin1String("qt_separator_action"))            mi->id = ((Q3PopupMenu*)w)->insertSeparator();        else if (dicon)            mi->id = mi->popup->insertItem(*dicon, QString::fromLatin1(""));        else            mi->id = mi->popup->insertItem(QString::fromLatin1(""));        addedTo(mi->popup->indexOf(mi->id), mi->popup);        mi->popup->connectItem(mi->id, this, SLOT(internalActivation()));        d->menuitems.append(mi);        d->update(Q3ActionPrivate::State | Q3ActionPrivate::Visibility | Q3ActionPrivate::EverythingElse);        connect(mi->popup, SIGNAL(highlighted(int)), this, SLOT(menuStatusText(int)));        connect(mi->popup, SIGNAL(aboutToHide()), this, SLOT(clearStatusText()));        connect(mi->popup, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));    // Makes only sense when called by Q3ActionGroup::addTo    } else if (qobject_cast<QComboBox*>(w)) {        Q3ActionPrivate::ComboItem *ci = new Q3ActionPrivate::ComboItem;        ci->combo = (QComboBox*)w;        connect(ci->combo, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));        ci->id = ci->combo->count();        if (objectName() == QLatin1String("qt_separator_action")) {            if (d->icon)                ci->combo->insertItem(d->icon->pixmap(), text());            else                ci->combo->insertItem(text());        } else {            ci->id = -1;        }        d->comboitems.append(ci);        d->update(Q3ActionPrivate::State | Q3ActionPrivate::EverythingElse);    } else if(qobject_cast<QMenu*>(w)) {        Q3ActionPrivate::Action4Item *act = new Q3ActionPrivate::Action4Item;        if(!act->action) { //static            act->action = new QAction(this);            if (objectName() == QLatin1String("qt_separator_action"))                act->action->setSeparator(true);        }        act->widget = w;        act->widget->addAction(act->action);        d->action4items.append(act);        d->update(Q3ActionPrivate::State | Q3ActionPrivate::EverythingElse);    } else {        qWarning("Q3Action::addTo(), unknown object");        return false;    }    return true;}/*!    This function is called from the addTo() function when it has    created a widget (\a actionWidget) for the action in the \a    container.*/void Q3Action::addedTo(QWidget *actionWidget, QWidget *container){    Q_UNUSED(actionWidget);    Q_UNUSED(container);}/*!    \overload    This function is called from the addTo() function when it has    created a menu item at the index position \a index in the popup    menu \a menu.*/void Q3Action::addedTo(int index, Q3PopupMenu *menu){    Q_UNUSED(index);    Q_UNUSED(menu);}/*!    Sets the status message to \a text*/void Q3Action::showStatusText(const QString& text){#ifndef QT_NO_STATUSBAR    // find out whether we are clearing the status bar by the popup that actually set the text    static Q3PopupMenu *lastmenu = 0;    QObject *s = (QObject*)sender();    if (s) {        Q3PopupMenu *menu = qobject_cast<Q3PopupMenu*>(s);        if (menu && text.size())            lastmenu = menu;        else if (menu && text.isEmpty()) {            if (lastmenu && menu != lastmenu)                return;            lastmenu = 0;        }    }    QObject* par = parent();    QObject* lpar = 0;    QStatusBar *bar = 0;    while (par && !bar) {        lpar = par;        bar = (QStatusBar*)par->child(0, "QStatusBar", false);        par = par->parent();    }    if (!bar && lpar) {        QObjectList l = lpar->queryList("QStatusBar");        if (l.isEmpty())            return;        // #### hopefully the last one is the one of the mainwindow...        bar = static_cast<QStatusBar*>(l.at(l.size()-1));    }    if (bar) {        if (text.isEmpty())            bar->clearMessage();        else            bar->showMessage(text);    }#endif}/*!    Sets the status message to the menu item's status text, or to the    tooltip, if there is no status text.*/void Q3Action::menuStatusText(int id){    static int lastId = 0;    QString text;    QList<Q3ActionPrivate::MenuItem*>::Iterator it(d->menuitems.begin());    while (it != d->menuitems.end()) {        if ((*it)->id == id) {            text = statusTip();            break;        }        ++it;    }    if (!text.isEmpty())        showStatusText(text);    else if (id != lastId)        clearStatusText();    lastId = id;}/*!    Clears the status text.*/void Q3Action::clearStatusText(){    if (!statusTip().isEmpty())        showStatusText(QString());}/*!    Removes the action from widget \a w.    Returns true if the action was removed successfully; otherwise    returns false.    \sa addTo()*/bool Q3Action::removeFrom(QWidget* w){#ifndef QT_NO_TOOLBAR    if (::qobject_cast<Q3ToolBar*>(w)) {        QList<QToolButton*>::Iterator it(d->toolbuttons.begin());        QToolButton* btn;        while (it != d->toolbuttons.end()) {            btn = *it;            ++it;            if (btn->parentWidget() == w) {                d->toolbuttons.removeAll(btn);                disconnect(btn, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));                delete btn;                // no need to disconnect from status bar            }        }    } else#endif    if (::qobject_cast<Q3PopupMenu*>(w)) {        QList<Q3ActionPrivate::MenuItem*>::Iterator it(d->menuitems.begin());        Q3ActionPrivate::MenuItem* mi;        while (it != d->menuitems.end()) {            mi = *it;            ++it;            if (mi->popup == w) {                disconnect(mi->popup, SIGNAL(highlighted(int)), this, SLOT(menuStatusText(int)));                disconnect(mi->popup, SIGNAL(aboutToHide()), this, SLOT(clearStatusText()));                disconnect(mi->popup, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));                mi->popup->removeItem(mi->id);                d->menuitems.removeAll(mi);                delete mi;            }        }    } else if (::qobject_cast<QComboBox*>(w)) {        QList<Q3ActionPrivate::ComboItem*>::Iterator it(d->comboitems.begin());        Q3ActionPrivate::ComboItem *ci;        while (it != d->comboitems.end()) {            ci = *it;            ++it;            if (ci->combo == w) {                disconnect(ci->combo, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));                d->comboitems.removeAll(ci);                delete ci;            }        }    } else if (::qobject_cast<QMenu*>(w)) {        QList<Q3ActionPrivate::Action4Item*>::Iterator it(d->action4items.begin());        Q3ActionPrivate::Action4Item *a4i;        while (it != d->action4items.end()) {            a4i = *it;            ++it;            if (a4i->widget == w) {                a4i->widget->removeAction(a4i->action);                d->action4items.removeAll(a4i);                delete a4i;            }        }    } else {        qWarning("Q3Action::removeFrom(), unknown object");        return false;    }    return true;}/*!  \internal*/void Q3Action::objectDestroyed(){    const QObject* obj = sender();    Q3ActionPrivate::MenuItem* mi;    for (int i = 0; i < d->menuitems.size();) {        mi = d->menuitems.at(i);        ++i;        if (mi->popup == obj) {            d->menuitems.removeAll(mi);            delete mi;        }    }    Q3ActionPrivate::ComboItem *ci;    QList<Q3ActionPrivate::ComboItem*>::Iterator it2(d->comboitems.begin());    while (it2 != d->comboitems.end()) {        ci = *it2;        ++it2;        if (ci->combo == obj) {            d->comboitems.removeAll(ci);            delete ci;        }    }    d->toolbuttons.removeAll((QToolButton *)obj);}/*!    \fn void Q3Action::activated()    This signal is emitted when an action is activated by the user,    e.g. when the user clicks a menu option or a toolbar button or    presses an action's accelerator key combination.    Connect to this signal for command actions. Connect to the    toggled() signal for toggle actions.*//*!    \fn void Q3Action::toggled(bool on)    This signal is emitted when a toggle action changes state; command    actions and \l{Q3ActionGroup}s don't emit toggled().    The \a on argument denotes the new state: If \a on is true the    toggle action is switched on, and if \a on is false the toggle    action is switched off.    To trigger a user command depending on whether a toggle action has    been switched on or off connect it to a slot that takes a bool to    indicate the state.    \sa activated() setToggleAction() setOn()*/void Q3ActionGroupPrivate::update(const Q3ActionGroup* that){

⌨️ 快捷键说明

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