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.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**
     
    7575    items in a QGraphicsScene.
    7676    \since 4.4
    77     \ingroup multimedia
    7877    \ingroup graphicsview-api
    7978
     
    171170
    172171/*!
    173     \property QGraphicsWidget::enabled
    174     \brief whether the item is enabled or not
    175 
    176     This property is declared in QGraphicsItem.
    177 
    178     By default, this property is true.
    179 
    180     \sa QGraphicsItem::isEnabled(), QGraphicsItem::setEnabled()
    181 */
    182 
    183 /*!
    184     \property QGraphicsWidget::visible
    185     \brief whether the item is visible or not
    186 
    187     This property is declared in QGraphicsItem.
    188 
    189     By default, this property is true.
    190 
    191     \sa QGraphicsItem::isVisible(), QGraphicsItem::setVisible(), show(),
    192     hide()
    193 */
    194 
    195 /*!
    196     \property QGraphicsWidget::opacity
    197     \brief the opacity of the widget
    198 */   
    199 
    200 /*!
    201     \property QGraphicsWidget::pos
    202     \brief the position of the widget
    203 */   
    204 
    205 /*!
    206172    Constructs a QGraphicsWidget instance. The optional \a parent argument is
    207173    passed to QGraphicsItem's constructor. The optional \a wFlags argument
     
    210176*/
    211177QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
    212     : QGraphicsItem(*new QGraphicsWidgetPrivate, 0, 0), QGraphicsLayoutItem(0, false)
     178    : QGraphicsObject(*new QGraphicsWidgetPrivate, 0, 0), QGraphicsLayoutItem(0, false)
    213179{
    214180    Q_D(QGraphicsWidget);
     
    222188*/
    223189QGraphicsWidget::QGraphicsWidget(QGraphicsWidgetPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene, Qt::WindowFlags wFlags)
    224     : QGraphicsItem(dd, 0, scene), QGraphicsLayoutItem(0, false)
     190    : QGraphicsObject(dd, 0, scene), QGraphicsLayoutItem(0, false)
    225191{
    226192    Q_D(QGraphicsWidget);
     
    292258    //we check if we have a layout previously
    293259    if (d->layout) {
    294         delete d->layout;
     260        QGraphicsLayout *temp = d->layout;
    295261        foreach (QGraphicsItem * item, childItems()) {
    296262            // In case of a custom layout which doesn't remove and delete items, we ensure that
     
    303269            }
    304270        }
     271        d->layout = 0;
     272        delete temp;
    305273    }
    306274
     
    351319
    352320/*!
     321    \property QGraphicsWidget::sizePolicy
     322    \brief the size policy for the widget
     323    \sa sizePolicy(), setSizePolicy(), QWidget::sizePolicy()
     324*/
     325
     326/*!
    353327    \property QGraphicsWidget::geometry
    354328    \brief the geometry of the widget
     
    367341{
    368342    QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func();
    369     QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr;
     343    QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr.data();
    370344    QRectF newGeom;
    371345    QPointF oldPos = d->geom.topLeft();
     
    380354        // setPos triggers ItemPositionChange, which can adjust position
    381355        wd->inSetGeometry = 1;
    382         wd->setPosHelper(newGeom.topLeft());
     356        setPos(newGeom.topLeft());
    383357        wd->inSetGeometry = 0;
    384358        newGeom.moveTopLeft(pos());
     
    441415
    442416/*!
     417    \property QGraphicsWidget::minimumSize
     418    \brief the minimum size of the widget
     419
     420    \sa setMinimumSize(), minimumSize(), preferredSize, maximumSize
     421*/
     422
     423/*!
     424    \property QGraphicsWidget::preferredSize
     425    \brief the preferred size of the widget
     426
     427    \sa setPreferredSize(), preferredSize(), minimumSize, maximumSize
     428*/
     429
     430/*!
     431    \property QGraphicsWidget::maximumSize
     432    \brief the maximum size of the widget
     433
     434    \sa setMaximumSize(), maximumSize(), minimumSize, preferredSize
     435*/
     436
     437/*!
    443438    Sets the widget's contents margins to \a left, \a top, \a right and \a
    444439    bottom.
     
    460455    Q_D(QGraphicsWidget);
    461456
    462     if (left == d->leftMargin
    463         && top == d->topMargin
    464         && right == d->rightMargin
    465         && bottom == d->bottomMargin) {
     457    if (!d->margins && left == 0 && top == 0 && right == 0 && bottom == 0)
    466458        return;
    467     }
    468 
    469     d->leftMargin = left;
    470     d->topMargin = top;
    471     d->rightMargin = right;
    472     d->bottomMargin = bottom;
     459    d->ensureMargins();
     460    if (left == d->margins[d->Left]
     461        && top == d->margins[d->Top]
     462        && right == d->margins[d->Right]
     463        && bottom == d->margins[d->Bottom])
     464        return;
     465
     466    d->margins[d->Left] = left;
     467    d->margins[d->Top] = top;
     468    d->margins[d->Right] = right;
     469    d->margins[d->Bottom] = bottom;
    473470
    474471    if (QGraphicsLayout *l = d->layout)
     
    491488{
    492489    Q_D(const QGraphicsWidget);
     490    if (left || top || right || bottom)
     491        d->ensureMargins();
    493492    if (left)
    494         *left = d->leftMargin;
     493        *left = d->margins[d->Left];
    495494    if (top)
    496         *top = d->topMargin;
     495        *top = d->margins[d->Top];
    497496    if (right)
    498         *right = d->rightMargin;
     497        *right = d->margins[d->Right];
    499498    if (bottom)
    500         *bottom = d->bottomMargin;
     499        *bottom = d->margins[d->Bottom];
    501500}
    502501
     
    514513{
    515514    Q_D(QGraphicsWidget);
    516     bool unchanged = left == d->leftWindowFrameMargin && top == d->topWindowFrameMargin
    517                      && right == d->rightWindowFrameMargin && bottom == d->bottomWindowFrameMargin;
     515
     516    if (!d->windowFrameMargins && left == 0 && top == 0 && right == 0 && bottom == 0)
     517        return;
     518    d->ensureWindowFrameMargins();
     519    bool unchanged =
     520        d->windowFrameMargins[d->Left] == left
     521        && d->windowFrameMargins[d->Top] == top
     522        && d->windowFrameMargins[d->Right] == right
     523        && d->windowFrameMargins[d->Bottom] == bottom;
    518524    if (d->setWindowFrameMargins && unchanged)
    519525        return;
    520526    if (!unchanged)
    521527        prepareGeometryChange();
    522     d->leftWindowFrameMargin = left;
    523     d->topWindowFrameMargin = top;
    524     d->rightWindowFrameMargin = right;
    525     d->bottomWindowFrameMargin = bottom;
     528    d->windowFrameMargins[d->Left] = left;
     529    d->windowFrameMargins[d->Top] = top;
     530    d->windowFrameMargins[d->Right] = right;
     531    d->windowFrameMargins[d->Bottom] = bottom;
    526532    d->setWindowFrameMargins = true;
    527533}
     
    537543{
    538544    Q_D(const QGraphicsWidget);
     545    if (left || top || right || bottom)
     546        d->ensureWindowFrameMargins();
    539547    if (left)
    540         *left = d->leftWindowFrameMargin;
     548        *left = d->windowFrameMargins[d->Left];
    541549    if (top)
    542         *top = d->topWindowFrameMargin;
     550        *top = d->windowFrameMargins[d->Top];
    543551    if (right)
    544         *right = d->rightWindowFrameMargin;
     552        *right = d->windowFrameMargins[d->Right];
    545553    if (bottom)
    546         *bottom = d->bottomWindowFrameMargin;
     554        *bottom = d->windowFrameMargins[d->Bottom];
    547555}
    548556
     
    578586{
    579587    Q_D(const QGraphicsWidget);
    580     return geometry().adjusted(-d->leftWindowFrameMargin, -d->topWindowFrameMargin,
    581                                d->rightWindowFrameMargin, d->bottomWindowFrameMargin);
     588    return d->windowFrameMargins
     589        ? geometry().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
     590                              d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
     591        : geometry();
    582592}
    583593
     
    590600{
    591601    Q_D(const QGraphicsWidget);
    592     return rect().adjusted(-d->leftWindowFrameMargin, -d->topWindowFrameMargin,
    593                            d->rightWindowFrameMargin, d->bottomWindowFrameMargin);
     602    return d->windowFrameMargins
     603        ? rect().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
     604                          d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
     605        : rect();
    594606}
    595607
     
    699711    QSizeF sh;
    700712    if (d->layout) {
    701         sh = d->layout->effectiveSizeHint(which, constraint);
    702         sh += QSizeF(d->leftMargin + d->rightMargin, d->topMargin + d->bottomMargin);
     713        QSizeF marginSize(0,0);
     714        if (d->margins) {
     715            marginSize = QSizeF(d->margins[d->Left] + d->margins[d->Right],
     716                         d->margins[d->Top] + d->margins[d->Bottom]);
     717        }
     718        sh = d->layout->effectiveSizeHint(which, constraint - marginSize);
     719        sh += marginSize;
    703720    } else {
    704721        switch (which) {
     
    9851002    very important that subclasses call the base implementation.
    9861003
    987     For example, QGraphicsWidget uses ItemVisibleChange to deliver \l Show and
    988     \l Hide events, ItemPositionHasChanged to deliver \l Move events, and
    989     ItemParentChange both to deliver \l ParentChange events, and for managing
    990     the focus chain.
    991 
    992     \sa propertyChange()
     1004    \a change specifies the type of change, and \a value is the new value.
     1005
     1006    For example, QGraphicsWidget uses ItemVisibleChange to deliver
     1007    \l{QEvent::Show} {Show} and \l{QEvent::Hide}{Hide} events,
     1008    ItemPositionHasChanged to deliver \l{QEvent::Move}{Move} events,
     1009    and ItemParentChange both to deliver \l{QEvent::ParentChange}
     1010    {ParentChange} events, and for managing the focus chain.
     1011
     1012    QGraphicsWidget enables the ItemSendsGeometryChanges flag by default in
     1013    order to track position changes.
     1014
     1015    \sa QGraphicsItem::itemChange()
    9931016*/
    9941017QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &value)
     
    10321055    case ItemParentChange: {
    10331056        QGraphicsItem *parent = qVariantValue<QGraphicsItem *>(value);
    1034         d->fixFocusChainBeforeReparenting((parent && parent->isWidget()) ? static_cast<QGraphicsWidget *>(parent) : 0);
     1057        d->fixFocusChainBeforeReparenting((parent && parent->isWidget()) ? static_cast<QGraphicsWidget *>(parent) : 0, scene());
    10351058
    10361059        // Deliver ParentAboutToChange.
     
    10401063    }
    10411064    case ItemParentHasChanged: {
    1042         // reset window type on parent change in order to automagically remove decorations etc.
    1043         Qt::WindowFlags wflags = d->windowFlags & ~Qt::WindowType_Mask;
    1044         d->adjustWindowFlags(&wflags);
    1045         setWindowFlags(wflags);
    10461065        // Deliver ParentChange.
    10471066        QEvent event(QEvent::ParentChange);
     
    11081127bool QGraphicsWidget::sceneEvent(QEvent *event)
    11091128{
    1110     return QCoreApplication::sendEvent(this, event) || QGraphicsItem::sceneEvent(event);
     1129    return QGraphicsItem::sceneEvent(event);
    11111130}
    11121131
     
    11321151        break;
    11331152    case QEvent::GraphicsSceneMouseMove:
    1134         if (d->grabbedSection != Qt::NoSection) {
     1153        d->ensureWindowData();
     1154        if (d->windowData->grabbedSection != Qt::NoSection) {
    11351155            d->windowFrameMouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
    11361156            event->accept();
     
    11871207    const qreal cornerMargin = 20;
    11881208    //### Not sure of this one, it should be the same value for all edges.
    1189     const qreal windowFrameWidth = d->leftWindowFrameMargin;
     1209    const qreal windowFrameWidth = d->windowFrameMargins
     1210        ? d->windowFrameMargins[d->Left] : 0;
    11901211
    11911212    Qt::WindowFrameSection s = Qt::NoSection;
     
    12131234    if (s == Qt::NoSection) {
    12141235        QRectF r1 = r;
    1215         r1.setHeight(d->topWindowFrameMargin);
     1236        r1.setHeight(d->windowFrameMargins
     1237                     ? d->windowFrameMargins[d->Top] : 0);
    12161238        if (r1.contains(pos))
    12171239            s = Qt::TitleBarArea;
     
    12231245    \reimp
    12241246
    1225     QGraphicsWidget handles the following events:
     1247    Handles the \a event.  QGraphicsWidget handles the following
     1248    events:
    12261249
    12271250    \table   \o Event                 \o Usage
     
    12791302        polishEvent();
    12801303        d->polished = true;
    1281         d->updateFont(d->font);
     1304        if (!d->font.isCopyOf(QApplication::font()))
     1305            d->updateFont(d->font);
    12821306        break;
    12831307    case QEvent::WindowActivate:
    12841308    case QEvent::WindowDeactivate:
    12851309        update();
    1286         foreach (QGraphicsItem *child, childItems()) {
    1287             if (child->isWidget())
    1288                 QApplication::sendEvent(static_cast<QGraphicsWidget *>(child), event);
    1289         }
    12901310        break;
    12911311        // Taken from QWidget::event
     
    13211341    case QEvent::GraphicsSceneMouseRelease:
    13221342    case QEvent::GraphicsSceneMouseDoubleClick:
    1323         if (d->hasDecoration() && d->grabbedSection != Qt::NoSection)
     1343        d->ensureWindowData();
     1344        if (d->hasDecoration() && d->windowData->grabbedSection != Qt::NoSection)
    13241345            return windowFrameEvent(event);
    13251346        break;
     
    13581379        // ### Don't unset if the margins are explicitly set.
    13591380        unsetWindowFrameMargins();
     1381        if (d->layout)
     1382            d->layout->invalidate();
    13601383    case QEvent::FontChange:
    13611384        update();
     
    15961619/*!
    15971620    Returns the widgets window type.
     1621
     1622    \sa windowFlags(), isWindow(), isPanel()
    15981623*/
    15991624Qt::WindowType QGraphicsWidget::windowType() const
     
    16111636
    16121637    By default, this property contains no window flags.
     1638
     1639    Windows are panels. If you set the Qt::Window flag, the ItemIsPanel flag
     1640    will be set automatically. If you clear the Qt::Window flag, the
     1641    ItemIsPanel flag is also cleared. Note that the ItemIsPanel flag can be
     1642    set independently of Qt::Window.
     1643
     1644    \sa isWindow(), isPanel()
    16131645*/
    16141646Qt::WindowFlags QGraphicsWidget::windowFlags() const
     
    16241656    bool wasPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
    16251657
     1658    d->adjustWindowFlags(&wFlags);
    16261659    d->windowFlags = wFlags;
    16271660    if (!d->setWindowFrameMargins)
    16281661        unsetWindowFrameMargins();
     1662
     1663    setFlag(ItemIsPanel, d->windowFlags & Qt::Window);
    16291664
    16301665    bool isPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
     
    16361671            d->scene->d_func()->addPopup(this);
    16371672    }
     1673
     1674    if (d->scene && d->scene->d_func()->allItemsIgnoreHoverEvents && d->hasDecoration()) {
     1675        d->scene->d_func()->allItemsIgnoreHoverEvents = false;
     1676        d->scene->d_func()->enableMouseTrackingOnViews();
     1677    }
    16381678}
    16391679
     
    16461686    currently has input focus, or that itself has input focus.
    16471687
    1648     \sa QGraphicsScene::activeWindow(), QGraphicsScene::setActiveWindow()
     1688    \sa QGraphicsScene::activeWindow(), QGraphicsScene::setActiveWindow(), isActive()
    16491689*/
    16501690bool QGraphicsWidget::isActiveWindow() const
    16511691{
    1652     Q_D(const QGraphicsWidget);
    1653     if (!d->scene)
    1654         return false;
    1655     const QGraphicsWidget *w = window();
    1656     return (!w && d->scene->d_func()->activationRefCount) || (w && d->scene->activeWindow() == w);
     1692    return isActive();
    16571693}
    16581694
     
    16631699    This property is only used for windows.
    16641700
    1665     By default, if no title has been set, this property contains an empty string.
     1701    By default, if no title has been set, this property contains an
     1702    empty string.
    16661703*/
    16671704void QGraphicsWidget::setWindowTitle(const QString &title)
    16681705{
    16691706    Q_D(QGraphicsWidget);
    1670     d->windowTitle = title;
     1707    d->ensureWindowData();
     1708    d->windowData->windowTitle = title;
    16711709}
    16721710QString QGraphicsWidget::windowTitle() const
    16731711{
    16741712    Q_D(const QGraphicsWidget);
    1675     return d->windowTitle;
     1713    return d->windowData ? d->windowData->windowTitle : QString();
    16761714}
    16771715
     
    17151753    If this widget, a child or descendant of this widget currently has input
    17161754    focus, this function will return a pointer to that widget. If
    1717     no descendant has input focus, 0 is returned.
    1718 
    1719     \sa QWidget::focusWidget()
     1755    no descendant widget has input focus, 0 is returned.
     1756
     1757    \sa QGraphicsItem::focusItem(), QWidget::focusWidget()
    17201758*/
    17211759QGraphicsWidget *QGraphicsWidget::focusWidget() const
    17221760{
    17231761    Q_D(const QGraphicsWidget);
    1724     return d->focusChild;
    1725 }
    1726 
     1762    if (d->subFocusItem && d->subFocusItem->d_ptr->isWidget)
     1763        return static_cast<QGraphicsWidget *>(d->subFocusItem);
     1764    return 0;
     1765}
    17271766
    17281767#ifndef QT_NO_SHORTCUT
     
    18881927    d->actions.insert(pos, action);
    18891928
    1890     QActionPrivate *apriv = action->d_func();
    1891     apriv->graphicsWidgets.append(this);
     1929    if (index == -1) {
     1930        QActionPrivate *apriv = action->d_func();
     1931        apriv->graphicsWidgets.append(this);
     1932    }
    18921933
    18931934    QActionEvent e(QEvent::ActionAdded, action, before);
     
    21092150    bar.QStyleOption::operator=(*option);
    21102151    d->initStyleOptionTitleBar(&bar);   // this clear flags in bar.state
    2111     if (d->buttonMouseOver)
     2152    d->ensureWindowData();
     2153    if (d->windowData->buttonMouseOver)
    21122154        bar.state |= QStyle::State_MouseOver;
    21132155    else
    21142156        bar.state &= ~QStyle::State_MouseOver;
    2115     if (d->buttonSunken)
     2157    if (d->windowData->buttonSunken)
    21162158        bar.state |= QStyle::State_Sunken;
    21172159    else
     
    22482290/*!
    22492291    \fn const QObjectList &QGraphicsWidget::children() const
     2292    \internal
    22502293
    22512294    This function returns the same value as QObject::children(). It's
     
    22682311            break;
    22692312        }
    2270         qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? "1" : "0") << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);
     2313        qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? '1' : '0') << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);
    22712314        if (visited.contains(next)) {
    22722315            qWarning("Already visited this node. However, I expected to dump until I found myself.");
Note: See TracChangeset for help on using the changeset viewer.