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/graphicsview/qgraphicswidget_p.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**
     
    6767    focusNext = focusPrev = q;
    6868    focusPolicy = Qt::NoFocus;
     69
     70    adjustWindowFlags(&wFlags);
     71    windowFlags = wFlags;
     72
    6973    q->setParentItem(parentItem);
    7074    q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType));
     
    7276
    7377    resolveLayoutDirection();
    74 
    75     if (!parentItem)
    76         adjustWindowFlags(&wFlags);
    77     windowFlags = wFlags;
    7878    q->unsetWindowFrameMargins();
    79 }
     79    q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
     80    q->setFlag(QGraphicsItem::ItemSendsGeometryChanges);
     81}
     82
    8083qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const
    8184{
     
    9093}
    9194
    92 void QGraphicsWidgetPrivate::getLayoutItemMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
    93 {
    94     if (left)
    95         *left = leftLayoutItemMargin;
    96     if (top)
    97         *top = topLayoutItemMargin;
    98     if (right)
    99         *right = rightLayoutItemMargin;
    100     if (bottom)
    101         *bottom = bottomLayoutItemMargin;
    102 }
    103 
    104 void QGraphicsWidgetPrivate::setLayoutItemMargins(qreal left, qreal top, qreal right, qreal bottom)
    105 {
    106     if (leftLayoutItemMargin == left
    107         && topLayoutItemMargin == top
    108         && rightLayoutItemMargin == right
    109         && bottomLayoutItemMargin == bottom)
    110         return;
    111 
    112     Q_Q(QGraphicsWidget);
    113     leftLayoutItemMargin = left;
    114     topLayoutItemMargin = top;
    115     rightLayoutItemMargin = right;
    116     bottomLayoutItemMargin = bottom;
    117     q->updateGeometry();
    118 }
    119 
    120 void QGraphicsWidgetPrivate::setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt)
    121 {
    122     Q_Q(QGraphicsWidget);
    123     QStyleOption myOpt;
    124     if (!opt) {
    125         q->initStyleOption(&myOpt);
    126         myOpt.rect.setRect(0, 0, 32768, 32768);     // arbitrary
    127         opt = &myOpt;
    128     }
    129 
    130     QRect liRect = q->style()->subElementRect(element, opt, /* q */ 0);
    131     if (liRect.isValid()) {
    132         leftLayoutItemMargin = (opt->rect.left() - liRect.left());
    133         topLayoutItemMargin = (opt->rect.top() - liRect.top());
    134         rightLayoutItemMargin = (liRect.right() - opt->rect.right());
    135         bottomLayoutItemMargin = (liRect.bottom() - opt->rect.bottom());
    136     } else {
    137         leftLayoutItemMargin = 0;
    138         topLayoutItemMargin = 0;
    139         rightLayoutItemMargin = 0;
    140         bottomLayoutItemMargin = 0;
    141     }
     95/*!
     96    \internal
     97*/
     98QGraphicsWidgetPrivate::~QGraphicsWidgetPrivate()
     99{
     100    // Remove any lazily allocated data
     101    delete[] margins;
     102    delete[] windowFrameMargins;
     103    delete windowData;
     104}
     105
     106/*!
     107    \internal
     108
     109     Ensures that margins is allocated.
     110     This function must be called before any dereferencing.
     111*/
     112void QGraphicsWidgetPrivate::ensureMargins() const
     113{
     114    if (!margins) {
     115        margins = new qreal[4];
     116        for (int i = 0; i < 4; ++i)
     117            margins[i] = 0;
     118    }
     119}
     120
     121/*!
     122    \internal
     123
     124     Ensures that windowFrameMargins is allocated.
     125     This function must be called before any dereferencing.
     126*/
     127void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const
     128{
     129    if (!windowFrameMargins) {
     130        windowFrameMargins = new qreal[4];
     131        for (int i = 0; i < 4; ++i)
     132            windowFrameMargins[i] = 0;
     133    }
     134}
     135
     136/*!
     137    \internal
     138
     139     Ensures that windowData is allocated.
     140     This function must be called before any dereferencing.
     141*/
     142void QGraphicsWidgetPrivate::ensureWindowData()
     143{
     144    if (!windowData)
     145        windowData = new WindowData;
    142146}
    143147
     
    298302{
    299303    Q_Q(QGraphicsWidget);
     304    ensureWindowData();
    300305    q->initStyleOption(option);
    301306    option->rect.setHeight(titleBarHeight(*option));
    302307    option->titleBarFlags = windowFlags;
    303308    option->subControls = QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarSysMenu;
    304     option->activeSubControls = hoveredSubControl;
     309    option->activeSubControls = windowData->hoveredSubControl;
    305310    bool isActive = q->isActiveWindow();
    306311    if (isActive) {
     
    314319    QFont windowTitleFont = QApplication::font("QWorkspaceTitleBar");
    315320    QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, 0);
    316     option->text = QFontMetrics(windowTitleFont).elidedText(windowTitle, Qt::ElideRight, textRect.width());
     321    option->text = QFontMetrics(windowTitleFont).elidedText(
     322        windowData->windowTitle, Qt::ElideRight, textRect.width());
    317323}
    318324
     
    342348{
    343349    Q_Q(QGraphicsWidget);
    344     if (grabbedSection != Qt::NoSection) {
    345         if (grabbedSection == Qt::TitleBarArea) {
    346             buttonSunken = false;
     350    ensureWindowData();
     351    if (windowData->grabbedSection != Qt::NoSection) {
     352        if (windowData->grabbedSection == Qt::TitleBarArea) {
     353            windowData->buttonSunken = false;
    347354            QStyleOptionTitleBar bar;
    348355            initStyleOptionTitleBar(&bar);
     
    352359            bar.rect.setHeight(q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &bar));
    353360            QPointF pos = event->pos();
    354             pos.rx() += leftWindowFrameMargin;
    355             pos.ry() += topWindowFrameMargin;
     361            if (windowFrameMargins) {
     362                pos.rx() += windowFrameMargins[Left];
     363                pos.ry() += windowFrameMargins[Top];
     364            }
    356365            bar.subControls = QStyle::SC_TitleBarCloseButton;
    357366            if (q->style()->subControlRect(QStyle::CC_TitleBar, &bar,
     
    362371        }
    363372        if (!(static_cast<QGraphicsSceneMouseEvent *>(event)->buttons()))
    364             grabbedSection = Qt::NoSection;
     373            windowData->grabbedSection = Qt::NoSection;
    365374        event->accept();
    366375    }
     
    373382        return;
    374383
    375     startGeometry = q->geometry();
    376     grabbedSection = q->windowFrameSectionAt(event->pos());
    377     switch (grabbedSection) {
    378     case Qt::LeftSection:
    379     case Qt::TopLeftSection:
    380         mouseDelta = event->pos() - q->rect().topLeft();
    381         break;
    382     case Qt::TopSection:
    383     case Qt::TopRightSection:
    384         mouseDelta = event->pos() - q->rect().topRight();
    385         break;
    386     case Qt::RightSection:
    387     case Qt::BottomRightSection:
    388         mouseDelta = event->pos() - q->rect().bottomRight();
    389         break;
    390     case Qt::BottomSection:
    391     case Qt::BottomLeftSection:
    392         mouseDelta = event->pos() - q->rect().bottomLeft();
    393         break;
    394     case Qt::TitleBarArea:
    395         if (hoveredSubControl == QStyle::SC_TitleBarCloseButton) {
    396             buttonSunken = true;
    397             q->update();
    398         }
    399         break;
    400     case Qt::NoSection:
    401         break;
    402     }
    403     event->setAccepted(grabbedSection != Qt::NoSection);
     384    ensureWindowData();
     385    windowData->startGeometry = q->geometry();
     386    windowData->grabbedSection = q->windowFrameSectionAt(event->pos());
     387    ensureWindowData();
     388    if (windowData->grabbedSection == Qt::TitleBarArea
     389        && windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton) {
     390        windowData->buttonSunken = true;
     391        q->update();
     392    }
     393    event->setAccepted(windowData->grabbedSection != Qt::NoSection);
     394}
     395
     396/*!
     397  Used to calculate the
     398  Precondition:
     399  \a widget should support either hfw or wfh
     400
     401  If \a heightForWidth is set to false, this function will query the width for height
     402  instead. \a width will then be interpreted as height, \a minh and \a maxh will be interpreted
     403  as minimum width and maximum width.
     404 */
     405static qreal minimumHeightForWidth(qreal width, qreal minh, qreal maxh,
     406                                   const QGraphicsWidget *widget,
     407                                   bool heightForWidth = true)
     408{
     409    qreal minimumHeightForWidth = -1;
     410    const QSizePolicy sp = widget->layout() ? widget->layout()->sizePolicy() : widget->sizePolicy();
     411    const bool hasHFW = sp.hasHeightForWidth();
     412    if (hasHFW == heightForWidth) {
     413        minimumHeightForWidth = hasHFW
     414                                ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(width, -1)).height()
     415                                : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, width)).width();    //"width" is here height!
     416    } else {
     417        // widthForHeight
     418        const qreal constraint = width;
     419        while (maxh - minh > 0.1) {
     420            qreal middle = minh + (maxh - minh)/2;
     421            // ### really bad, if we are a widget with a layout it will call
     422            // layout->effectiveSizeHint(Qt::MiniumumSize), which again will call
     423            // sizeHint three times because of how the cache works
     424            qreal hfw = hasHFW
     425                        ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(middle, -1)).height()
     426                        : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, middle)).width();
     427            if (hfw > constraint) {
     428                minh = middle;
     429            } else if (hfw <= constraint) {
     430                maxh = middle;
     431            }
     432        }
     433        minimumHeightForWidth = maxh;
     434    }
     435    return minimumHeightForWidth;
     436}
     437
     438static qreal minimumWidthForHeight(qreal height, qreal minw, qreal maxw,
     439                                   const QGraphicsWidget *widget)
     440{
     441    return minimumHeightForWidth(height, minw, maxw, widget, false);
     442}
     443
     444static QSizeF closestAcceptableSize(const QSizeF &proposed,
     445                                    const QGraphicsWidget *widget)
     446{
     447    const QSizeF current = widget->size();
     448
     449    qreal minw = proposed.width();
     450    qreal maxw = current.width();
     451    qreal minh = proposed.height();
     452    qreal maxh = current.height();
     453
     454    qreal middlew = maxw;
     455    qreal middleh = maxh;
     456    qreal min_hfw;
     457    min_hfw = minimumHeightForWidth(maxw, minh, maxh, widget);
     458
     459    do {
     460        if (maxw - minw < 0.1) {
     461            // we still havent found anything, cut off binary search
     462            minw = maxw;
     463            minh = maxh;
     464        }
     465        middlew = minw + (maxw - minw)/2.0;
     466        middleh = minh + (maxh - minh)/2.0;
     467
     468        min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget);
     469
     470        if (min_hfw > middleh) {
     471            minw = middlew;
     472            minh = middleh;
     473        } else if (min_hfw <= middleh) {
     474            maxw = middlew;
     475            maxh = middleh;
     476        }
     477    } while (maxw != minw);
     478
     479    min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget);
     480
     481    QSizeF result;
     482    if (min_hfw < maxh) {
     483        result = QSizeF(middlew, min_hfw);
     484    } else {
     485        // Needed because of the cut-off we do above.
     486        result = QSizeF(minimumWidthForHeight(maxh, proposed.width(), current.width(), widget), maxh);
     487    }
     488    return result;
    404489}
    405490
    406491static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry,
    407492                                              QRectF *rect, Qt::WindowFrameSection section,
    408                                               const QSizeF &min, const QSizeF &max)
    409 {
    410     int height;
    411     int width;
     493                                              const QSizeF &min, const QSizeF &max,
     494                                              const QGraphicsWidget *widget)
     495{
     496    const QRectF proposedRect = *rect;
     497    qreal width = qBound(min.width(), proposedRect.width(), max.width());
     498    qreal height = qBound(min.height(), proposedRect.height(), max.height());
     499
     500    QSizePolicy sp = widget->sizePolicy();
     501    if (const QGraphicsLayout *l = widget->layout()) {
     502        sp = l->sizePolicy();
     503    }
     504    const bool hasHFW = sp.hasHeightForWidth(); // || sp.hasWidthForHeight();
     505
     506    const bool widthChanged = proposedRect.width() < widget->size().width();
     507    const bool heightChanged = proposedRect.height() < widget->size().height();
     508
     509    if (hasHFW) {
     510        if (widthChanged || heightChanged) {
     511            const qreal minh = min.height();
     512            const qreal maxh = max.height();
     513            const qreal proposedHFW = minimumHeightForWidth(width, minh, maxh, widget);
     514            if (proposedHFW > proposedRect.height()) {
     515                QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget);
     516                width = effectiveSize.width();
     517                height = effectiveSize.height();
     518            }
     519        }
     520    }
     521
    412522    switch (section) {
    413523    case Qt::LeftSection:
    414         width = qRound(qBound(min.width(), rect->width(), max.width()));
    415         rect->setRect(startGeometry.right() - width, startGeometry.top(),
    416                       width, startGeometry.height());
     524        rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
     525                      qRound(width), startGeometry.height());
    417526        break;
    418527    case Qt::TopLeftSection:
    419         width = qRound(qBound(min.width(), rect->width(), max.width()));
    420         height = qRound(qBound(min.height(), rect->height(), max.height()));
    421         rect->setRect(startGeometry.right() - width, startGeometry.bottom() - height,
    422                       width, height);
     528        rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height),
     529                      qRound(width), qRound(height));
    423530        break;
    424531    case Qt::TopSection:
    425         height = qRound(qBound(min.height(), rect->height(), max.height()));
    426         rect->setRect(startGeometry.left(), startGeometry.bottom() - height,
    427                       startGeometry.width(), height);
     532        rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height),
     533                      startGeometry.width(), qRound(height));
    428534        break;
    429535    case Qt::TopRightSection:
    430         height = qRound(qBound(min.height(), rect->height(), max.height()));
    431         rect->setTop(rect->bottom() - height);
    432         rect->setWidth(qBound(min.width(), rect->width(), max.width()));
     536        rect->setTop(rect->bottom() - qRound(height));
     537        rect->setWidth(qRound(width));
    433538        break;
    434539    case Qt::RightSection:
    435         rect->setWidth(qBound(min.width(), rect->width(), max.width()));
     540        rect->setWidth(qRound(width));
    436541        break;
    437542    case Qt::BottomRightSection:
    438         rect->setWidth(qBound(min.width(), rect->width(), max.width()));
    439         rect->setHeight(qBound(min.height(), rect->height(), max.height()));
     543        rect->setWidth(qRound(width));
     544        rect->setHeight(qRound(height));
    440545        break;
    441546    case Qt::BottomSection:
    442         rect->setHeight(qBound(min.height(), rect->height(), max.height()));
     547        rect->setHeight(qRound(height));
    443548        break;
    444549    case Qt::BottomLeftSection:
    445         height = qRound(qBound(min.height(), rect->height(), max.height()));
    446         width = qRound(qBound(min.width(), rect->width(), max.width()));
    447         rect->setRect(startGeometry.right() - width, startGeometry.top(),
    448                       width, height);
     550        rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
     551                      qRound(width), qRound(height));
    449552        break;
    450553    default:
     
    456559{
    457560    Q_Q(QGraphicsWidget);
    458     if (!(event->buttons() & Qt::LeftButton) || hoveredSubControl != QStyle::SC_TitleBarLabel)
     561    ensureWindowData();
     562    if (!(event->buttons() & Qt::LeftButton) || windowData->hoveredSubControl != QStyle::SC_TitleBarLabel)
    459563        return;
    460564
     
    465569
    466570    QRectF newGeometry;
    467     switch (grabbedSection) {
     571    switch (windowData->grabbedSection) {
    468572    case Qt::LeftSection:
    469         newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()),
    470                              startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
     573        newGeometry = QRectF(windowData->startGeometry.topLeft()
     574                             + QPointF(parentXDelta.dx(), parentXDelta.dy()),
     575                             windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
    471576        break;
    472577    case Qt::TopLeftSection:
    473         newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()),
    474                              startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
     578        newGeometry = QRectF(windowData->startGeometry.topLeft()
     579                             + QPointF(parentDelta.dx(), parentDelta.dy()),
     580                             windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
    475581        break;
    476582    case Qt::TopSection:
    477         newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()),
    478                              startGeometry.size() - QSizeF(0, delta.dy()));
     583        newGeometry = QRectF(windowData->startGeometry.topLeft()
     584                             + QPointF(parentYDelta.dx(), parentYDelta.dy()),
     585                             windowData->startGeometry.size() - QSizeF(0, delta.dy()));
    479586        break;
    480587    case Qt::TopRightSection:
    481         newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()),
    482                              startGeometry.size() - QSizeF(-delta.dx(), delta.dy()));
     588        newGeometry = QRectF(windowData->startGeometry.topLeft()
     589                             + QPointF(parentYDelta.dx(), parentYDelta.dy()),
     590                             windowData->startGeometry.size() - QSizeF(-delta.dx(), delta.dy()));
    483591        break;
    484592    case Qt::RightSection:
    485         newGeometry = QRectF(startGeometry.topLeft(),
    486                              startGeometry.size() + QSizeF(delta.dx(), 0));
     593        newGeometry = QRectF(windowData->startGeometry.topLeft(),
     594                             windowData->startGeometry.size() + QSizeF(delta.dx(), 0));
    487595        break;
    488596    case Qt::BottomRightSection:
    489         newGeometry = QRectF(startGeometry.topLeft(),
    490                              startGeometry.size() + QSizeF(delta.dx(), delta.dy()));
     597        newGeometry = QRectF(windowData->startGeometry.topLeft(),
     598                             windowData->startGeometry.size() + QSizeF(delta.dx(), delta.dy()));
    491599        break;
    492600    case Qt::BottomSection:
    493         newGeometry = QRectF(startGeometry.topLeft(),
    494                              startGeometry.size() + QSizeF(0, delta.dy()));
     601        newGeometry = QRectF(windowData->startGeometry.topLeft(),
     602                             windowData->startGeometry.size() + QSizeF(0, delta.dy()));
    495603        break;
    496604    case Qt::BottomLeftSection:
    497         newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()),
    498                              startGeometry.size() - QSizeF(delta.dx(), -delta.dy()));
     605        newGeometry = QRectF(windowData->startGeometry.topLeft()
     606                             + QPointF(parentXDelta.dx(), parentXDelta.dy()),
     607                             windowData->startGeometry.size() - QSizeF(delta.dx(), -delta.dy()));
    499608        break;
    500609    case Qt::TitleBarArea:
    501         newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()),
    502                              startGeometry.size());
     610        newGeometry = QRectF(windowData->startGeometry.topLeft()
     611                             + QPointF(parentDelta.dx(), parentDelta.dy()),
     612                             windowData->startGeometry.size());
    503613        break;
    504614    case Qt::NoSection:
     
    506616    }
    507617
    508     if (grabbedSection != Qt::NoSection) {
    509         _q_boundGeometryToSizeConstraints(startGeometry, &newGeometry, grabbedSection,
     618    if (windowData->grabbedSection != Qt::NoSection) {
     619        _q_boundGeometryToSizeConstraints(windowData->startGeometry, &newGeometry,
     620                                          windowData->grabbedSection,
    510621                                          q->effectiveSizeHint(Qt::MinimumSize),
    511                                           q->effectiveSizeHint(Qt::MaximumSize));
     622                                          q->effectiveSizeHint(Qt::MaximumSize),
     623                                          q);
    512624        q->setGeometry(newGeometry);
    513625    }
     
    520632        return;
    521633
     634    ensureWindowData();
     635
    522636    if (q->rect().contains(event->pos())) {
    523         if (buttonMouseOver || hoveredSubControl != QStyle::SC_None)
     637        if (windowData->buttonMouseOver || windowData->hoveredSubControl != QStyle::SC_None)
    524638            windowFrameHoverLeaveEvent(event);
    525639        return;
    526640    }
    527641
    528     bool wasMouseOver = buttonMouseOver;
    529     QRect oldButtonRect = buttonRect;
    530     buttonRect = QRect();
    531     buttonMouseOver = false;
     642    bool wasMouseOver = windowData->buttonMouseOver;
     643    QRect oldButtonRect = windowData->buttonRect;
     644    windowData->buttonRect = QRect();
     645    windowData->buttonMouseOver = false;
    532646    QPointF pos = event->pos();
    533647    QStyleOptionTitleBar bar;
    534648    // make sure that the coordinates (rect and pos) we send to the style are positive.
    535     pos.rx() += leftWindowFrameMargin;
    536     pos.ry() += topWindowFrameMargin;
     649    if (windowFrameMargins) {
     650        pos.rx() += windowFrameMargins[Left];
     651        pos.ry() += windowFrameMargins[Top];
     652    }
    537653    initStyleOptionTitleBar(&bar);
    538654    bar.rect = q->windowFrameRect().toRect();
     
    560676            break;
    561677        case Qt::TitleBarArea:
    562             buttonRect = q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0);
     678            windowData->buttonRect = q->style()->subControlRect(
     679                QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0);
    563680#ifdef Q_WS_MAC
    564681            // On mac we should hover if we are in the 'area' of the buttons
    565             buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0);
    566             buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0);
     682            windowData->buttonRect |= q->style()->subControlRect(
     683                QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0);
     684            windowData->buttonRect |= q->style()->subControlRect(
     685                QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0);
    567686#endif
    568             if (buttonRect.contains(pos.toPoint()))
    569                 buttonMouseOver = true;
     687            if (windowData->buttonRect.contains(pos.toPoint()))
     688                windowData->buttonMouseOver = true;
    570689            event->ignore();
    571690            break;
     
    579698#endif
    580699    // update buttons if we hover over them
    581     hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);
    582     if (hoveredSubControl != QStyle::SC_TitleBarCloseButton)
    583         hoveredSubControl = QStyle::SC_TitleBarLabel;
    584 
    585     if (buttonMouseOver != wasMouseOver) {
     700    windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);
     701    if (windowData->hoveredSubControl != QStyle::SC_TitleBarCloseButton)
     702        windowData->hoveredSubControl = QStyle::SC_TitleBarLabel;
     703
     704    if (windowData->buttonMouseOver != wasMouseOver) {
    586705        if (!oldButtonRect.isNull())
    587706            q->update(QRectF(oldButtonRect).translated(q->windowFrameRect().topLeft()));
    588         if (!buttonRect.isNull())
    589             q->update(QRectF(buttonRect).translated(q->windowFrameRect().topLeft()));
     707        if (!windowData->buttonRect.isNull())
     708            q->update(QRectF(windowData->buttonRect).translated(q->windowFrameRect().topLeft()));
    590709    }
    591710}
     
    601720#endif
    602721
     722        ensureWindowData();
     723
    603724        bool needsUpdate = false;
    604         if (hoveredSubControl == QStyle::SC_TitleBarCloseButton || buttonMouseOver)
     725        if (windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton
     726            || windowData->buttonMouseOver)
    605727            needsUpdate = true;
    606728
    607729        // update the hover state (of buttons etc...)
    608         hoveredSubControl = QStyle::SC_None;
    609         buttonMouseOver = false;
    610         buttonRect = QRect();
     730        windowData->hoveredSubControl = QStyle::SC_None;
     731        windowData->buttonMouseOver = false;
     732        windowData->buttonRect = QRect();
    611733        if (needsUpdate)
    612             q->update(buttonRect);
     734            q->update(windowData->buttonRect);
    613735    }
    614736}
     
    617739{
    618740    return (windowFlags & Qt::Window) && (windowFlags & Qt::WindowTitleHint);
    619 }
    620 
    621 /*!
    622     \internal
    623 */
    624 void QGraphicsWidgetPrivate::setFocusWidget()
    625 {
    626     // Update focus child chain.
    627     QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
    628     QGraphicsWidget *parent = widget;
    629     bool hidden = !visible;
    630     do {
    631         parent->d_func()->focusChild = widget;
    632     } while (!parent->isWindow() && (parent = parent->parentWidget()) && (!hidden || !parent->d_func()->visible));
    633 }
    634 
    635 /*!
    636     \internal
    637 */
    638 void QGraphicsWidgetPrivate::clearFocusWidget()
    639 {
    640     // Reset focus child chain.
    641     QGraphicsWidget *parent = static_cast<QGraphicsWidget *>(q_ptr);
    642     do {
    643         if (parent->d_func()->focusChild != q_ptr)
    644             break;
    645         parent->d_func()->focusChild = 0;
    646     } while (!parent->isWindow() && (parent = parent->parentWidget()));
    647741}
    648742
     
    650744 * is called after a reparent has taken place to fix up the focus chain(s)
    651745 */
    652 void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *newScene)
     746void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene)
    653747{
    654748    Q_Q(QGraphicsWidget);
     
    663757    QGraphicsWidget *firstOld = 0;
    664758    bool wasPreviousNew = true;
    665 
    666     if (focusChild) {
    667         // Ensure that the current focus child doesn't leave pointers around
    668         // before reparenting.
    669         focusChild->clearFocus();
    670     }
    671759   
    672760    while (w != q) {
     
    702790    if (newParent)
    703791        newScene = newParent->scene();
    704     QGraphicsScene *oldScene = q->scene();
     792
    705793    if (oldScene && newScene != oldScene)
    706794        oldScene->d_func()->tabFocusFirst = firstOld;
Note: See TracChangeset for help on using the changeset viewer.