Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/dialogs/qmessagebox.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    9797#ifndef QT_NO_CONTEXTMENU
    9898            QMenu *menu = createStandardContextMenu();
    99             menu->exec(e->globalPos());
    100             delete menu;
     99            menu->setAttribute(Qt::WA_DeleteOnClose);
     100            menu->popup(e->globalPos());
    101101#else
    102102            Q_UNUSED(e);
     
    123123    void setText(const QString &text) { textEdit->setPlainText(text); }
    124124    QString text() const { return textEdit->toPlainText(); }
    125     QString label(DetailButtonLabel label)
    126         { return label == ShowLabel ? QMessageBox::tr("Show Details...")
    127                                     : QMessageBox::tr("Hide Details..."); }
    128125private:
    129126    TextEdit *textEdit;
    130127};
    131128#endif // QT_NO_TEXTEDIT
     129
     130class DetailButton : public QPushButton
     131{
     132public:
     133    DetailButton(QWidget *parent) : QPushButton(label(ShowLabel), parent)
     134    {
     135        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     136    }
     137
     138    QString label(DetailButtonLabel label) const
     139    { return label == ShowLabel ? QMessageBox::tr("Show Details...") : QMessageBox::tr("Hide Details..."); }
     140
     141    void setLabel(DetailButtonLabel lbl)
     142    { setText(label(lbl)); }
     143
     144    QSize sizeHint() const
     145    {
     146        ensurePolished();
     147        QStyleOptionButton opt;
     148        initStyleOption(&opt);
     149        const QFontMetrics fm = fontMetrics();
     150        opt.text = label(ShowLabel);
     151        QSize sz = fm.size(Qt::TextShowMnemonic, opt.text);
     152        QSize ret = style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this).
     153                      expandedTo(QApplication::globalStrut());
     154        opt.text = label(HideLabel);
     155        sz = fm.size(Qt::TextShowMnemonic, opt.text);
     156        ret.expandedTo(style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this).
     157                      expandedTo(QApplication::globalStrut()));
     158        return ret;
     159    }
     160};
     161
    132162
    133163class QMessageBoxPrivate : public QDialogPrivate
     
    186216    QPushButton *defaultButton;
    187217    QAbstractButton *clickedButton;
    188     QPushButton *detailsButton;
     218    DetailButton *detailsButton;
    189219#ifndef QT_NO_TEXTEDIT
    190220    QMessageBoxDetailsText *detailsText;
     
    436466#ifndef QT_NO_TEXTEDIT
    437467    if (detailsButton && detailsText && button == detailsButton) {
    438         detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
     468        detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel);
    439469        detailsText->setHidden(!detailsText->isHidden());
    440470        updateSize();
     
    747777    arguments are passed to the QDialog constructor.
    748778
    749     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    750     {application modal} dialog box. If \a parent is a widget, the
    751     message box is \l{Qt::WindowModal} {window modal} relative to \a
    752     parent.
     779    The message box is an \l{Qt::ApplicationModal} {application modal}
     780    dialog box.
    753781
    754782    On Mac OS X, if \a parent is not 0 and you want your message box
     
    15201548    {escape button} is returned.
    15211549
    1522     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    1523     {application modal} dialog box. If \a parent is a widget, the
    1524     message box is \l{Qt::WindowModal} {window modal} relative to \a
    1525     parent.
     1550    The message box is an \l{Qt::ApplicationModal} {application modal}
     1551    dialog box.
    15261552
    15271553    \sa question(), warning(), critical()
     
    15501576    {escape button} is returned.
    15511577
    1552     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    1553     {application modal} dialog box. If \a parent is a widget, the
    1554     message box is \l{Qt::WindowModal} {window modal} relative to \a
    1555     parent.
     1578    The message box is an \l{Qt::ApplicationModal} {application modal}
     1579    dialog box.
    15561580
    15571581    \sa information(), warning(), critical()
     
    15781602    {escape button} is returned.
    15791603
    1580     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    1581     {application modal} dialog box. If \a parent is a widget, the
    1582     message box is \l{Qt::WindowModal} {window modal} relative to \a
    1583     parent.
     1604    The message box is an \l{Qt::ApplicationModal} {application modal}
     1605    dialog box.
    15841606
    15851607    \sa question(), information(), critical()
     
    16061628    {escape button} is returned.
    16071629
    1608     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    1609     {application modal} dialog box. If \a parent is a widget, the
    1610     message box is \l{Qt::WindowModal} {window modal} relative to \a
    1611     parent.
     1630    The message box is an \l{Qt::ApplicationModal} {application modal}
     1631    dialog box.
    16121632
    16131633  \warning Do not delete \a parent during the execution of the dialog.
     
    16411661    The about box has a single button labelled "OK". On Mac OS X, the
    16421662    about box is popped up as a modeless window; on other platforms,
    1643     it is currently a window modal.
     1663    it is currently application modal.
    16441664
    16451665    \sa QWidget::windowIcon(), QApplication::activeWindow()
     
    16941714
    16951715    On Mac OS X, the about box is popped up as a modeless window; on
    1696     other platforms, it is currently window modal.
     1716    other platforms, it is currently application modal.
    16971717
    16981718    \sa QApplication::aboutQt()
     
    17421762        "<p>Please see <a href=\"http://qt.nokia.com/products/licensing\">qt.nokia.com/products/licensing</a> "
    17431763        "for an overview of Qt licensing.</p>"
    1744         "<p>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).</p>"
     1764        "<p>Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).</p>"
    17451765        "<p>Qt is a Nokia product. See <a href=\"http://qt.nokia.com/\">qt.nokia.com</a> "
    17461766        "for more information.</p>"
     
    19061926#ifndef QT_NO_TEXTEDIT
    19071927    if (detailsButton)
    1908         detailsButton->setText(detailsText->isHidden() ? detailsText->label(HideLabel) : detailsText->label(ShowLabel));
     1928        detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel);
    19091929#endif
    19101930}
     
    19541974    \snippet doc/src/snippets/dialogs/dialogs.cpp 2
    19551975
    1956     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    1957     {application modal} dialog box. If \a parent is a widget, the
    1958     message box is \l{Qt::WindowModal} {window modal} relative to \a
    1959     parent.
     1976    The message box is an \l{Qt::ApplicationModal} {application modal}
     1977    dialog box.
    19601978
    19611979    The \a parent and \a f arguments are passed to
     
    20062024    of the button that was clicked.
    20072025
    2008     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2009     {application modal} dialog box. If \a parent is a widget, the
    2010     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2011     parent.
     2026    The message box is an \l{Qt::ApplicationModal} {application modal}
     2027    dialog box.
    20122028
    20132029  \warning Do not delete \a parent during the execution of the dialog.
     
    20442060    the relevant button.
    20452061
    2046     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2047     {application modal} dialog box. If \a parent is a widget, the
    2048     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2049     parent.
     2062    The message box is an \l{Qt::ApplicationModal} {application modal}
     2063    dialog box.
    20502064
    20512065  \warning Do not delete \a parent during the execution of the dialog.
     
    20962110    of the button that was clicked.
    20972111
    2098     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2099     {application modal} dialog box. If \a parent is a widget, the
    2100     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2101     parent.
     2112    The message box is an \l{Qt::ApplicationModal} {application modal}
     2113    dialog box.
    21022114
    21032115  \warning Do not delete \a parent during the execution of the dialog.
     
    21342146    the relevant button.
    21352147
    2136     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2137     {application modal} dialog box. If \a parent is a widget, the
    2138     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2139     parent.
     2148    The message box is an \l{Qt::ApplicationModal} {application modal}
     2149    dialog box.
    21402150
    21412151  \warning Do not delete \a parent during the execution of the dialog.
     
    21862196    of the button that was clicked.
    21872197
    2188     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2189     {application modal} dialog box. If \a parent is a widget, the
    2190     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2191     parent.
     2198    The message box is an \l{Qt::ApplicationModal} {application modal}
     2199    dialog box.
    21922200
    21932201  \warning Do not delete \a parent during the execution of the dialog.
     
    22242232    the relevant button.
    22252233
    2226     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2227     {application modal} dialog box. If \a parent is a widget, the
    2228     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2229     parent.
     2234    The message box is an \l{Qt::ApplicationModal} {application modal}
     2235    dialog box.
    22302236
    22312237  \warning Do not delete \a parent during the execution of the dialog.
     
    22752281    of the button that was clicked.
    22762282
    2277     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2278     {application modal} dialog box. If \a parent is a widget, the
    2279     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2280     parent.
     2283    The message box is an \l{Qt::ApplicationModal} {application modal}
     2284    dialog box.
    22812285
    22822286  \warning Do not delete \a parent during the execution of the dialog.
     
    23142318    the relevant button.
    23152319
    2316     If \a parent is 0, the message box is an \l{Qt::ApplicationModal}
    2317     {application modal} dialog box. If \a parent is a widget, the
    2318     message box is \l{Qt::WindowModal} {window modal} relative to \a
    2319     parent.
     2320    The message box is an \l{Qt::ApplicationModal} {application modal}
     2321    dialog box.
    23202322
    23212323  \warning Do not delete \a parent during the execution of the dialog.
     
    24142416        d->detailsText->hide();
    24152417    }
    2416     if (!d->detailsButton) {
    2417         d->detailsButton = new QPushButton(d->detailsText->label(ShowLabel), this);
    2418         QPushButton hideDetails(d->detailsText->label(HideLabel));
    2419         d->detailsButton->setFixedSize(d->detailsButton->sizeHint().expandedTo(hideDetails.sizeHint()));
    2420     }
     2418    if (!d->detailsButton)
     2419        d->detailsButton = new DetailButton(this);
    24212420    d->detailsText->setText(text);
    24222421}
Note: See TracChangeset for help on using the changeset viewer.