Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qdialogbuttonbox.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4747#include <QtGui/qapplication.h>
    4848#include <QtGui/private/qwidget_p.h>
     49#include <QtGui/qaction.h>
    4950
    5051#include "qdialogbuttonbox.h"
     52
     53#ifdef QT_SOFTKEYS_ENABLED
     54#include <QtGui/qaction.h>
     55#endif
     56
    5157
    5258QT_BEGIN_NAMESPACE
     
    5864    layout that is appropriate to the current widget style.
    5965
    60     \ingroup application
    61     \mainclass
     66    \ingroup dialog-classes
     67
    6268
    6369    Dialogs and message boxes typically present buttons in a layout that
     
    255261};
    256262
     263class QDialogButtonEnabledProxy : public QObject
     264{
     265public:
     266    QDialogButtonEnabledProxy(QObject *parent, QWidget *src, QAction *trg) : QObject(parent), source(src), target(trg)
     267    {
     268        source->installEventFilter(this);
     269        target->setEnabled(source->isEnabled());
     270    }
     271    ~QDialogButtonEnabledProxy()
     272    {
     273        source->removeEventFilter(this);
     274    }
     275    bool eventFilter(QObject *object, QEvent *event)
     276    {
     277        if (object == source && event->type() == QEvent::EnabledChange) {
     278            target->setEnabled(source->isEnabled());
     279        }
     280        return false;
     281    };
     282private:
     283    QWidget *source;
     284    QAction *target;
     285};
     286
     287
    257288class QDialogButtonBoxPrivate : public QWidgetPrivate
    258289{
     
    264295    QList<QAbstractButton *> buttonLists[QDialogButtonBox::NRoles];
    265296    QHash<QPushButton *, QDialogButtonBox::StandardButton> standardButtonHash;
     297#ifdef QT_SOFTKEYS_ENABLED
     298    QHash<QAbstractButton *, QAction *> softKeyActions;
     299#endif
    266300
    267301    Qt::Orientation orientation;
     
    283317    void retranslateStrings();
    284318    const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const;
     319#ifdef QT_SOFTKEYS_ENABLED
     320    QAction *createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role);
     321#endif
    285322};
    286323
     
    305342    }
    306343
    307         int left, top, right, bottom;
     344    int left, top, right, bottom;
    308345    setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem);
    309         getLayoutItemMargins(&left, &top, &right, &bottom);
     346    getLayoutItemMargins(&left, &top, &right, &bottom);
    310347    buttonLayout->setContentsMargins(-left, -top, -right, -bottom);
    311348
     
    346383{
    347384    Q_Q(QDialogButtonBox);
    348     const int MacGap = 36 - 8;  // 8 is the default gap between a widget and a spacer item
     385    const int MacGap = 36 - 8;    // 8 is the default gap between a widget and a spacer item
    349386
    350387    for (int i = buttonLayout->count() - 1; i >= 0; --i) {
     
    537574    QObject::connect(button, SIGNAL(destroyed()), q, SLOT(_q_handleButtonDestroyed()));
    538575    buttonLists[role].append(button);
     576#ifdef QT_SOFTKEYS_ENABLED
     577    QAction *action = createSoftKey(button, role);
     578    softKeyActions.insert(button, action);
     579    new QDialogButtonEnabledProxy(action, button, action);
     580#endif
    539581    if (doLayout)
    540582        layoutButtons();
    541583}
     584
     585#ifdef QT_SOFTKEYS_ENABLED
     586QAction* QDialogButtonBoxPrivate::createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role)
     587{
     588    Q_Q(QDialogButtonBox);
     589    QAction::SoftKeyRole softkeyRole;
     590
     591    QAction *action = new QAction(button->text(), button);
     592
     593    switch (role) {
     594    case ApplyRole:
     595    case AcceptRole:
     596    case YesRole:
     597    case ActionRole:
     598    case HelpRole:
     599        softkeyRole = QAction::PositiveSoftKey;
     600        break;
     601    case RejectRole:
     602    case DestructiveRole:
     603    case NoRole:
     604    case ResetRole:
     605        softkeyRole = QAction::NegativeSoftKey;
     606        break;
     607    default:
     608        break;
     609    }
     610    QObject::connect(action, SIGNAL(triggered()), button, SIGNAL(clicked()));
     611    action->setSoftKeyRole(softkeyRole);
     612
     613
     614    QWidget *dialog = 0;
     615    QWidget *p = q;
     616    while (p && !p->isWindow()) {
     617        p = p->parentWidget();
     618        if ((dialog = qobject_cast<QDialog *>(p)))
     619            break;
     620    }
     621
     622    if (dialog) {
     623        dialog->addAction(action);
     624    } else {
     625        q->addAction(action);
     626    }
     627
     628    return action;
     629}
     630#endif
    542631
    543632void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons)
     
    632721            QPushButton *button = it.key();
    633722            button->setText(QDialogButtonBox::tr(buttonText));
     723#ifdef QT_SOFTKEYS_ENABLED
     724            QAction *action = softKeyActions.value(button, 0);
     725            if (action)
     726                action->setText(button->text());
     727#endif
    634728        }
    635729        ++it;
     
    824918{
    825919    Q_D(QDialogButtonBox);
     920#ifdef QT_SOFTKEYS_ENABLED
     921    // Delete softkey actions as they have the buttons as parents
     922    qDeleteAll(d->softKeyActions.values());
     923    d->softKeyActions.clear();
     924#endif
    826925    // Remove the created standard buttons, they should be in the other lists, which will
    827926    // do the deletion
     
    9011000        }
    9021001    }
     1002#ifdef QT_SOFTKEYS_ENABLED
     1003    QAction *action = d->softKeyActions.value(button, 0);
     1004    if (action) {
     1005        d->softKeyActions.remove(button);
     1006        delete action;
     1007    }
     1008#endif
    9031009    if (!d->internalRemove)
    9041010        button->setParent(0);
     
    9691075{
    9701076    Q_D(QDialogButtonBox);
     1077#ifdef QT_SOFTKEYS_ENABLED
     1078    // Delete softkey actions since they have the buttons as parents
     1079    qDeleteAll(d->softKeyActions.values());
     1080    d->softKeyActions.clear();
     1081#endif
    9711082    // Clear out all the old standard buttons, then recreate them.
    9721083    qDeleteAll(d->standardButtonHash.keys());
     
    11261237        if (!hasDefault && firstAcceptButton)
    11271238            firstAcceptButton->setDefault(true);
     1239#ifdef QT_SOFTKEYS_ENABLED
     1240        if (dialog)
     1241            setFixedSize(0,0);
     1242#endif
    11281243    }else if (event->type() == QEvent::LanguageChange) {
    11291244        d->retranslateStrings();
    11301245    }
     1246#ifdef QT_SOFTKEYS_ENABLED
     1247    else if (event->type() == QEvent::ParentChange) {
     1248        QWidget *dialog = 0;
     1249        QWidget *p = this;
     1250        while (p && !p->isWindow()) {
     1251            p = p->parentWidget();
     1252            if ((dialog = qobject_cast<QDialog *>(p)))
     1253                break;
     1254        }
     1255
     1256        // If the parent changes, then move the softkeys
     1257        for (QHash<QAbstractButton *, QAction *>::const_iterator it = d->softKeyActions.constBegin();
     1258            it != d->softKeyActions.constEnd(); ++it) {
     1259            QAction *current = it.value();
     1260            QList<QWidget *> widgets = current->associatedWidgets();
     1261            foreach (QWidget *w, widgets)
     1262                w->removeAction(current);
     1263            if (dialog)
     1264                dialog->addAction(current);
     1265            else
     1266                addAction(current);
     1267        }
     1268    }
     1269#endif
    11311270
    11321271    return QWidget::event(event);
Note: See TracChangeset for help on using the changeset viewer.