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/qwizard.cpp

    r651 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)
     
    219219      topLevelMarginBottom(-1), childMarginLeft(-1), childMarginRight(-1),
    220220      childMarginTop(-1), childMarginBottom(-1), hspacing(-1), vspacing(-1),
    221           wizStyle(QWizard::ClassicStyle), header(false), watermark(false), title(false),
    222           subTitle(false), extension(false) {}
     221      wizStyle(QWizard::ClassicStyle), header(false), watermark(false), title(false),
     222      subTitle(false), extension(false), sideWidget(false) {}
    223223
    224224    int topLevelMarginLeft;
     
    239239    bool subTitle;
    240240    bool extension;
     241    bool sideWidget;
    241242
    242243    bool operator==(const QWizardLayoutInfo &other);
     
    262263           && title == other.title
    263264           && subTitle == other.subTitle
    264            && extension == other.extension;
     265           && extension == other.extension
     266           && sideWidget == other.sideWidget;
    265267}
    266268
     
    426428};
    427429
     430class QWatermarkLabel : public QLabel
     431{
     432public:
     433    QWatermarkLabel(QWidget *parent, QWidget *sideWidget) : QLabel(parent), m_sideWidget(sideWidget) {
     434        m_layout = new QVBoxLayout(this);
     435        if (m_sideWidget)
     436            m_layout->addWidget(m_sideWidget);
     437    }
     438
     439    QSize minimumSizeHint() const {
     440        if (!pixmap() && !pixmap()->isNull())
     441            return pixmap()->size();
     442        return QFrame::minimumSizeHint();
     443    }
     444
     445    void setSideWidget(QWidget *widget) {
     446        if (m_sideWidget == widget)
     447            return;
     448        if (m_sideWidget) {
     449            m_layout->removeWidget(m_sideWidget);
     450            m_sideWidget->hide();
     451        }
     452        m_sideWidget = widget;
     453        if (m_sideWidget)
     454            m_layout->addWidget(m_sideWidget);
     455    }
     456    QWidget *sideWidget() const {
     457        return m_sideWidget;
     458    }
     459private:
     460    QVBoxLayout *m_layout;
     461    QWidget *m_sideWidget;
     462};
     463
    428464class QWizardPagePrivate : public QWidgetPrivate
    429465{
     
    502538    inline QWizardPrivate()
    503539        : start(-1)
     540        , startSetByUser(false)
    504541        , current(-1)
    505542        , canContinue(false)
     
    514551        , headerWidget(0)
    515552        , watermarkLabel(0)
     553        , sideWidget(0)
    516554        , titleLabel(0)
    517555        , subTitleLabel(0)
     
    582620    QSet<int> initialized; // ### remove and move bit to QWizardPage?
    583621    int start;
     622    bool startSetByUser;
    584623    int current;
    585624    bool canContinue;
     
    613652    QWidget *placeholderWidget2;
    614653    QWizardHeader *headerWidget;
    615     QLabel *watermarkLabel;
     654    QWatermarkLabel *watermarkLabel;
     655    QWidget *sideWidget;
    616656    QFrame *pageFrame;
    617657    QLabel *titleLabel;
     
    908948    info.header = (info.wizStyle == QWizard::ClassicStyle || info.wizStyle == QWizard::ModernStyle)
    909949        && !(opts & QWizard::IgnoreSubTitles) && !subTitleText.isEmpty();
     950    info.sideWidget = sideWidget;
    910951    info.watermark = (info.wizStyle != QWizard::MacStyle) && (info.wizStyle != QWizard::AeroStyle)
    911952        && !watermarkPixmap.isNull();
    912953    info.title = !info.header && !titleText.isEmpty();
    913954    info.subTitle = !(opts & QWizard::IgnoreSubTitles) && !info.header && !subTitleText.isEmpty();
    914     info.extension = info.watermark && (opts & QWizard::ExtendedWatermarkPixmap);
     955    info.extension = (info.watermark || info.sideWidget) && (opts & QWizard::ExtendedWatermarkPixmap);
    915956
    916957    return info;
     
    955996    if (mac) {
    956997        numColumns = 3;
    957     } else if (info.watermark) {
     998    } else if (info.watermark || info.sideWidget) {
    958999        numColumns = 2;
    9591000    } else {
     
    10971138    }
    10981139
    1099     if (info.watermark && !watermarkLabel) {
    1100         watermarkLabel = new QLabel(antiFlickerWidget);
     1140    if ((info.watermark || info.sideWidget) && !watermarkLabel) {
     1141        watermarkLabel = new QWatermarkLabel(antiFlickerWidget, sideWidget);
    11011142        watermarkLabel->setBackgroundRole(QPalette::Base);
    11021143        watermarkLabel->setMinimumHeight(1);
     
    11741215    mainLayout->addLayout(buttonLayout, row++, buttonStartColumn, 1, buttonNumColumns);
    11751216
    1176     if (info.watermark) {
     1217    if (info.watermark || info.sideWidget) {
    11771218        if (info.extension)
    11781219            watermarkEndRow = row;
     
    11941235        bottomRuler->setVisible(classic || modern);
    11951236    if (watermarkLabel)
    1196         watermarkLabel->setVisible(info.watermark);
     1237        watermarkLabel->setVisible(info.watermark || info.sideWidget);
    11971238
    11981239    layoutInfo = info;
     
    12341275    }
    12351276
    1236     if (info.watermark) {
    1237         Q_ASSERT(page);
    1238         watermarkLabel->setPixmap(page->pixmap(QWizard::WatermarkPixmap));
    1239     }
     1277    if (info.watermark || info.sideWidget) {
     1278        QPixmap pix;
     1279        if (info.watermark) {
     1280            if (page)
     1281                pix = page->pixmap(QWizard::WatermarkPixmap);
     1282            else
     1283                pix = q->pixmap(QWizard::WatermarkPixmap);
     1284        }
     1285        watermarkLabel->setPixmap(pix); // in case there is no watermark and we show the side widget we need to clear the watermark
     1286    }
     1287
    12401288    if (info.title) {
    12411289        Q_ASSERT(page);
     
    12681316        maximumSize.setWidth(headerWidget->maximumWidth());
    12691317    }
    1270     if (info.watermark) {
     1318    if (info.watermark && !info.sideWidget) {
    12711319        minimumSize.setHeight(mainLayout->totalSizeHint().height());
    12721320        maximumSize.setHeight(mainLayout->totalSizeHint().height());
     
    21502198    QWizard so far.
    21512199
    2152     \sa setPage(), page()
     2200    \sa setPage(), page(), pageAdded()
    21532201*/
    21542202int QWizard::addPage(QWizardPage *page)
     
    21672215    Adds the given \a page to the wizard with the given \a id.
    21682216
    2169     \sa addPage(), page()
     2217    \note Adding a page may influence the value of the startId property
     2218    in case it was not set explicitly.
     2219
     2220    \sa addPage(), page(), pageAdded()
    21702221*/
    21712222void QWizard::setPage(int theid, QWizardPage *page)
     
    22112262    page->hide();
    22122263    d->pageVBoxLayout->setEnabled(pageVBoxLayoutEnabled);
     2264
     2265    if (!d->startSetByUser && d->pageMap.constBegin().key() == theid)
     2266        d->start = theid;
     2267    emit pageAdded(theid);
    22132268}
    22142269
    22152270/*!
    22162271    Removes the page with the given \a id. cleanupPage() will be called if necessary.
     2272
     2273    \note Removing a page may influence the value of the startId property.
     2274
    22172275    \since 4.5
    2218     \sa addPage(), setPage()
     2276    \sa addPage(), setPage(), pageRemoved(), startId()
    22192277*/
    22202278void QWizard::removePage(int id)
     
    22242282    QWizardPage *removedPage = 0;
    22252283
    2226     if (d->start == id)
    2227         d->start = -1;
     2284    // update startItem accordingly
     2285    if (d->pageMap.count() > 0) { // only if we have any pages
     2286        if (d->start == id) {
     2287            const int firstId = d->pageMap.constBegin().key();
     2288            if (firstId == id) {
     2289                if (d->pageMap.count() > 1)
     2290                    d->start = (++d->pageMap.constBegin()).key(); // secondId
     2291                else
     2292                    d->start = -1; // removing the last page
     2293            } else { // startSetByUser has to be "true" here
     2294                d->start = firstId;
     2295            }
     2296            d->startSetByUser = false;
     2297        }
     2298    }
     2299
     2300    if (d->pageMap.contains(id))
     2301        emit pageRemoved(id);
    22282302
    22292303    if (!d->history.contains(id)) {
     
    23352409{
    23362410    Q_D(QWizard);
    2337     if (!d->pageMap.contains(theid)) {
    2338         qWarning("QWizard::setStartId: Invalid page ID %d", theid);
     2411    int newStart = theid;
     2412    if (theid == -1)
     2413        newStart = d->pageMap.count() ? d->pageMap.constBegin().key() : -1;
     2414
     2415    if (d->start == newStart) {
     2416        d->startSetByUser = theid != -1;
    23392417        return;
    23402418    }
    2341     d->start = theid;
     2419
     2420    if (!d->pageMap.contains(newStart)) {
     2421        qWarning("QWizard::setStartId: Invalid page ID %d", newStart);
     2422        return;
     2423    }
     2424    d->start = newStart;
     2425    d->startSetByUser = theid != -1;
    23422426}
    23432427
     
    23452429{
    23462430    Q_D(const QWizard);
    2347     if (d->start != -1)
    2348         return d->start;
    2349     if (!d->pageMap.isEmpty())
    2350         return d->pageMap.constBegin().key();
    2351     return -1;
     2431    return d->start;
    23522432}
    23532433
     
    28262906
    28272907/*!
     2908    \since 4.7
     2909
     2910    Sets the given \a widget to be shown on the left side of the wizard.
     2911    For styles which use the WatermarkPixmap (ClassicStyle and ModernStyle)
     2912    the side widget is displayed on top of the watermark, for other styles
     2913    or when the watermark is not provided the side widget is displayed
     2914    on the left side of the wizard.
     2915
     2916    Passing 0 shows no side widget.
     2917
     2918    When the \a widget is not 0 the wizard reparents it.
     2919
     2920    Any previous side widget is hidden.
     2921
     2922    You may call setSideWidget() with the same widget at different
     2923    times.
     2924
     2925    All widgets set here will be deleted by the wizard when it is
     2926    destroyed unless you separately reparent the widget after setting
     2927    some other side widget (or 0).
     2928
     2929    By default, no side widget is present.
     2930*/
     2931void QWizard::setSideWidget(QWidget *widget)
     2932{
     2933    Q_D(QWizard);
     2934
     2935    d->sideWidget = widget;
     2936    if (d->watermarkLabel) {
     2937        d->watermarkLabel->setSideWidget(widget);
     2938        d->updateLayout();
     2939    }
     2940}
     2941
     2942/*!
     2943    \since 4.7
     2944
     2945    Returns the widget on the left side of the wizard or 0.
     2946
     2947    By default, no side widget is present.
     2948*/
     2949QWidget *QWizard::sideWidget() const
     2950{
     2951    Q_D(const QWizard);
     2952
     2953    return d->sideWidget;
     2954}
     2955
     2956/*!
    28282957    \reimp
    28292958*/
     
    28763005
    28773006    \sa currentId(), currentPage()
     3007*/
     3008
     3009/*!
     3010    \fn void QWizard::pageAdded(int id)
     3011
     3012    \since 4.7
     3013
     3014    This signal is emitted whenever a page is added to the
     3015    wizard. The page's \a id is passed as parameter.
     3016
     3017    \sa addPage(), setPage(), startId()
     3018*/
     3019
     3020/*!
     3021    \fn void QWizard::pageRemoved(int id)
     3022
     3023    \since 4.7
     3024
     3025    This signal is emitted whenever a page is removed from the
     3026    wizard. The page's \a id is passed as parameter.
     3027
     3028    \sa removePage(), startId()
    28783029*/
    28793030
Note: See TracChangeset for help on using the changeset viewer.