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

📄 qdialogbuttonbox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        buttonLayout->addStretch();    QList<QAbstractButton *> acceptRoleList = buttonLists[AcceptRole];    while (*currentLayout != EOL) {        int role = (*currentLayout & ~Reverse);        bool reverse = (*currentLayout & Reverse);        switch (role) {        case Stretch:            if (!center)                buttonLayout->addStretch();            break;        case AcceptRole: {            if (acceptRoleList.isEmpty())                break;            // Only the first one            QAbstractButton *button = acceptRoleList.first();            buttonLayout->addWidget(button);            button->show();        }            break;        case AlternateRole:            {                if (acceptRoleList.size() < 2)                    break;                QList<QAbstractButton *> list = acceptRoleList;                list.removeFirst();                addButtonsToLayout(list, reverse);            }            break;        case DestructiveRole:            {                const QList<QAbstractButton *> &list = buttonLists[role];                /*                    Mac: Insert a gap on the left of the destructive                    buttons to ensure that they don't get too close to                    the help and action buttons (but only if there are                    some buttons to the left of the destructive buttons                    (and the stretch, whence buttonLayout->count() > 1                    and not 0)).                */                if (tmpPolicy == QDialogButtonBox::MacLayout                        && !list.isEmpty() && buttonLayout->count() > 1)                    buttonLayout->addSpacing(MacGap);                addButtonsToLayout(list, reverse);                /*                    Insert a gap between the destructive buttons and the                    accept and reject buttons.                */                if (tmpPolicy == QDialogButtonBox::MacLayout && !list.isEmpty())                    buttonLayout->addSpacing(MacGap);            }            break;        case RejectRole:        case ActionRole:        case HelpRole:        case YesRole:        case NoRole:        case ApplyRole:        case ResetRole:            addButtonsToLayout(buttonLists[role], reverse);        }        ++currentLayout;    }    QWidget *lastWidget = 0;    q->setFocusProxy(0);    for (int i = 0; i < buttonLayout->count(); ++i) {        QLayoutItem *item = buttonLayout->itemAt(i);        if (QWidget *widget = item->widget()) {            if (lastWidget)                QWidget::setTabOrder(lastWidget, widget);            else                q->setFocusProxy(widget);            lastWidget = widget;        }    }    if (center)        buttonLayout->addStretch();}QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardButton sbutton,                                                   bool doLayout){    Q_Q(QDialogButtonBox);    const char *buttonText = 0;    int icon = 0;    switch (sbutton) {    case QDialogButtonBox::Ok:        icon = QStyle::SP_DialogOkButton;        break;    case QDialogButtonBox::Save:        icon = QStyle::SP_DialogSaveButton;        break;    case QDialogButtonBox::Open:        icon = QStyle::SP_DialogOpenButton;        break;    case QDialogButtonBox::Cancel:        icon = QStyle::SP_DialogCancelButton;        break;    case QDialogButtonBox::Close:        icon = QStyle::SP_DialogCloseButton;        break;    case QDialogButtonBox::Apply:        icon = QStyle::SP_DialogApplyButton;        break;    case QDialogButtonBox::Reset:        icon = QStyle::SP_DialogResetButton;        break;    case QDialogButtonBox::Help:        icon = QStyle::SP_DialogHelpButton;        break;    case QDialogButtonBox::Discard:        icon = QStyle::SP_DialogDiscardButton;        break;    case QDialogButtonBox::Yes:        icon = QStyle::SP_DialogYesButton;        break;    case QDialogButtonBox::No:        icon = QStyle::SP_DialogNoButton;        break;    case QDialogButtonBox::YesToAll:    case QDialogButtonBox::NoToAll:    case QDialogButtonBox::SaveAll:    case QDialogButtonBox::Abort:    case QDialogButtonBox::Retry:    case QDialogButtonBox::Ignore:    case QDialogButtonBox::RestoreDefaults:        break;    case QDialogButtonBox::NoButton:        return 0;        ;    }    buttonText = standardButtonText(sbutton);    QPushButton *button = new QPushButton(QDialogButtonBox::tr(buttonText), q);    if (q->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q) && icon != 0)        button->setIcon(q->style()->standardIcon(QStyle::StandardPixmap(icon), 0, q));    standardButtonHash.insert(button, sbutton);    addButton(button, roleFor(sbutton), doLayout);    return button;}void QDialogButtonBoxPrivate::addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role,                                        bool doLayout){    Q_Q(QDialogButtonBox);    QObject::connect(button, SIGNAL(clicked()), q, SLOT(_q_handleButtonClicked()));    QObject::connect(button, SIGNAL(destroyed()), q, SLOT(_q_handleButtonDestroyed()));    buttonLists[role].append(button);    if (doLayout)        layoutButtons();}void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons){    uint i = QDialogButtonBox::FirstButton;    while (i <= QDialogButtonBox::LastButton) {        if (i & buttons) {            createButton(QDialogButtonBox::StandardButton(i), false);        }        i = i << 1;    }    layoutButtons();}const char *QDialogButtonBoxPrivate::standardButtonText(QDialogButtonBox::StandardButton sbutton) const{    const char *buttonText = 0;    switch (sbutton) {    case QDialogButtonBox::Ok:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "OK");        break;    case QDialogButtonBox::Save:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Save");        break;    case QDialogButtonBox::Open:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Open");        break;    case QDialogButtonBox::Cancel:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Cancel");        break;    case QDialogButtonBox::Close:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Close");        break;    case QDialogButtonBox::Apply:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Apply");        break;    case QDialogButtonBox::Reset:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Reset");        break;    case QDialogButtonBox::Help:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Help");        break;    case QDialogButtonBox::Discard:        if (layoutPolicy == QDialogButtonBox::MacLayout)            buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Don't Save");        else if (layoutPolicy == QDialogButtonBox::GnomeLayout)            buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Close without Saving");        else            buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Discard");        break;    case QDialogButtonBox::Yes:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&Yes");        break;    case QDialogButtonBox::YesToAll:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Yes to &All");        break;    case QDialogButtonBox::No:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&No");        break;    case QDialogButtonBox::NoToAll:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "N&o to All");        break;    case QDialogButtonBox::SaveAll:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Save All");        break;    case QDialogButtonBox::Abort:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Abort");        break;    case QDialogButtonBox::Retry:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Retry");        break;    case QDialogButtonBox::Ignore:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Ignore");        break;    case QDialogButtonBox::RestoreDefaults:        buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Restore Defaults");        break;    case QDialogButtonBox::NoButton:        ;    } // switch    return buttonText;}void QDialogButtonBoxPrivate::retranslateStrings(){    const char *buttonText = 0;    QHash<QPushButton *, QDialogButtonBox::StandardButton>::iterator it =  standardButtonHash.begin();    while (it != standardButtonHash.end()) {        buttonText = standardButtonText(it.value());        if (buttonText) {            QPushButton *button = it.key();            button->setText(QDialogButtonBox::tr(buttonText));        }        ++it;    }}/*!    Constructs an empty, horizontal button box with the given \a parent.    \sa orientation, addButton()*/QDialogButtonBox::QDialogButtonBox(QWidget *parent)    : QWidget(*new QDialogButtonBoxPrivate(Qt::Horizontal), parent, 0){    d_func()->initLayout();}/*!    Constructs an empty button box with the given \a orientation and \a parent.    \sa orientation, addButton()*/QDialogButtonBox::QDialogButtonBox(Qt::Orientation orientation, QWidget *parent)    : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0){    d_func()->initLayout();}/*!    Constructs a button box with the given \a orientation and \a parent, containing    the standard buttons specified by \a buttons.    \sa orientation, addButton()*/QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation,                                   QWidget *parent)    : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0){    d_func()->initLayout();    d_func()->createStandardButtons(buttons);}/*!    Destroys the button box.*/QDialogButtonBox::~QDialogButtonBox(){}/*!    \enum QDialogButtonBox::ButtonRole    \enum QMessageBox::ButtonRole    This enum describes the roles that can be used to describe buttons in    the button box. Combinations of these roles are as flags used to    describe different aspects of their behavior.    \value InvalidRole The button is invalid.    \value AcceptRole Clicking the button causes the dialog to be accepted           (e.g. OK).    \value RejectRole Clicking the button causes the dialog to be rejected           (e.g. Cancel).    \value DestructiveRole Clicking the button causes a destructive change           (e.g. for Discarding Changes) and closes the dialog.    \value ActionRole Clicking the button causes changes to the elements within           the dialog, without closing the dialog.    \value HelpRole The button can be clicked to request help.    \value YesRole The button is a "Yes"-like button.    \value NoRole The button is a "No"-like button.    \value ApplyRole The button applies current changes.    \value ResetRole The button resets the dialog's fields to default values.    \omitvalue NRoles    \sa StandardButton*//*!    \enum QDialogButtonBox::StandardButton    These enums describe flags for standard buttons. Each button has a    defined \l ButtonRole.    \value Ok An "OK" button defined with the \l AcceptRole.    \value Open A "Open" button defined with the \l AcceptRole.    \value Save A "Save" button defined with the \l AcceptRole.    \value Cancel A "Cancel" button defined with the \l RejectRole.    \value Close A "Close" button defined with the \l RejectRole.    \value Discard A "Discard" or "Don't Save" button, depending on the platform,                    defined with the \l DestructiveRole.    \value Apply An "Apply" button defined with the \l ApplyRole.    \value Reset A "Reset" button defined with the \l ResetRole.    \value RestoreDefaults A "Restore Defaults" button defined with the \l ResetRole.    \value Help A "Help" button defined with the \l HelpRole.    \value SaveAll A "Save All" button defined with the \l AcceptRole.    \value Yes A "Yes" button defined with the \l YesRole.    \value YesToAll A "Yes to All" button defined with the \l YesRole.    \value No A "No" button defined with the \l NoRole.    \value NoToAll A "No to All" button defined with the \l NoRole.    \value Abort An "Abort" button defined with the \l RejectRole.    \value Retry A "Retry" button defined with the \l AcceptRole.    \value Ignore An "Ignore" button defined with the \l AcceptRole.    \value NoButton An invalid button.    \omitvalue FirstButton    \omitvalue LastButton    \sa ButtonRole, standardButtons*//*!    \enum QDialogButtonBox::ButtonLayout    This enum describes the layout policy to be used when arranging the buttons    contained in the button box.    \value WinLayout Use a policy appropriate for applications on Windows.    \value MacLayout Use a policy appropriate for applications on Mac OS X.    \value KdeLayout Use a policy appropriate for applications on KDE.    \value GnomeLayout Use a policy appropriate for applications on GNOME.

⌨️ 快捷键说明

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