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/qgraphicsscene_p.h

    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**
     
    4848//
    4949// This file is not part of the Qt API.  It exists for the convenience
    50 // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp.  This header
    51 // file may change from version to version without notice, or even be removed.
     50// of other Qt classes.  This header file may change from version to
     51// version without notice, or even be removed.
    5252//
    5353// We mean it.
     
    5858#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
    5959
    60 #include "qgraphicsscene_bsp_p.h"
     60#include "qgraphicssceneevent.h"
     61#include "qgraphicsview.h"
     62#include "qgraphicsview_p.h"
    6163#include "qgraphicsitem_p.h"
    6264
     
    6971#include <QtGui/qpalette.h>
    7072#include <QtGui/qstyle.h>
     73#include <QtGui/qstyleoption.h>
    7174
    7275QT_BEGIN_NAMESPACE
    7376
     77class QGraphicsSceneIndex;
    7478class QGraphicsView;
    7579class QGraphicsWidget;
    7680
    77 class QGraphicsScenePrivate : public QObjectPrivate
     81class Q_AUTOTEST_EXPORT QGraphicsScenePrivate : public QObjectPrivate
    7882{
    7983    Q_DECLARE_PUBLIC(QGraphicsScene)
     
    8286    void init();
    8387
    84     quint32 changedSignalMask;
     88    static QGraphicsScenePrivate *get(QGraphicsScene *q);
     89
     90    static int changedSignalIndex;
    8591
    8692    QGraphicsScene::ItemIndexMethod indexMethod;
    87     int bspTreeDepth;
    88 
    89     QList<QGraphicsItem *> estimateItemsInRect(const QRectF &rect) const;
    90     void addToIndex(QGraphicsItem *item);
    91     void removeFromIndex(QGraphicsItem *item);
    92     void resetIndex();
    93 
    94     QGraphicsSceneBspTree bspTree;
    95     void _q_updateIndex();
     93    QGraphicsSceneIndex *index;
     94
    9695    int lastItemCount;
    9796
    9897    QRectF sceneRect;
    9998    bool hasSceneRect;
     99    bool dirtyGrowingItemsBoundingRect;
    100100    QRectF growingItemsBoundingRect;
    101     QRectF largestUntransformableItem;
    102101
    103102    void _q_emitUpdated();
     
    105104    bool updateAll;
    106105    bool calledEmitUpdated;
     106    bool processDirtyItemsEmitted;
    107107
    108108    QPainterPath selectionArea;
    109109    int selectionChanging;
    110110    QSet<QGraphicsItem *> selectedItems;
    111     QList<QGraphicsItem *> unindexedItems;
    112     QList<QGraphicsItem *> indexedItems;
    113     QList<QGraphicsItem *> dirtyItems;
    114     QList<QGraphicsItem *> pendingUpdateItems;
    115     QList<QGraphicsItem *> unpolishedItems;
     111    QSet<QGraphicsItem *> unpolishedItems;
     112    QList<QGraphicsItem *> topLevelItems;
     113    bool needSortTopLevelItems;
     114    bool unpolishedItemsModified;
     115    bool holesInTopLevelSiblingIndex;
     116    bool topLevelSequentialOrdering;
     117
    116118    QMap<QGraphicsItem *, QPointF> movingItemsInitialPositions;
     119    void registerTopLevelItem(QGraphicsItem *item);
     120    void unregisterTopLevelItem(QGraphicsItem *item);
    117121    void _q_updateLater();
    118122    void _q_polishItems();
    119123
    120     void _q_resetDirtyItems();
    121     void resetDirtyItemsLater();
    122     bool dirtyItemResetPending;
    123 
    124     QList<int> freeItemIndexes;
    125     bool regenerateIndex;
    126 
    127     bool purgePending;
    128     void _q_removeItemLater(QGraphicsItem *item);
    129     QSet<QGraphicsItem *> removedItems;
    130     void purgeRemovedItems();
     124    void _q_processDirtyItems();
     125
     126    QSet<QGraphicsItem *> scenePosItems;
     127    bool scenePosDescendantsUpdatePending;
     128    void setScenePosItemEnabled(QGraphicsItem *item, bool enabled);
     129    void registerScenePosItem(QGraphicsItem *item);
     130    void unregisterScenePosItem(QGraphicsItem *item);
     131    void _q_updateScenePosDescendants();
     132
     133    void removeItemHelper(QGraphicsItem *item);
    131134
    132135    QBrush backgroundBrush;
    133136    QBrush foregroundBrush;
    134 
    135     int indexTimerId;
    136     bool restartIndexTimer;
    137     void startIndexTimer();
    138137
    139138    bool stickyFocus;
     
    142141    QGraphicsItem *lastFocusItem;
    143142    QGraphicsWidget *tabFocusFirst;
    144     QGraphicsWidget *activeWindow;
     143    QGraphicsItem *activePanel;
     144    QGraphicsItem *lastActivePanel;
    145145    int activationRefCount;
     146    int childExplicitActivation;
     147    void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent);
     148    void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason);
    146149
    147150    QList<QGraphicsWidget *> popupWidgets;
     
    160163    void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false);
    161164    void clearKeyboardGrabber();
    162    
     165
    163166    QGraphicsItem *dragDropItem;
    164167    QGraphicsWidget *enterWidget;
     
    166169    QList<QGraphicsItem *> cachedItemsUnderMouse;
    167170    QList<QGraphicsItem *> hoverItems;
     171    QPointF lastSceneMousePos;
     172    bool allItemsIgnoreHoverEvents;
     173    bool allItemsUseDefaultCursor;
     174    void enableMouseTrackingOnViews();
    168175    QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownPos;
    169176    QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownScenePos;
     
    172179                                           const QPointF &scenePos,
    173180                                           QWidget *widget) const;
    174     static bool itemCollidesWithPath(QGraphicsItem *item, const QPainterPath &path, Qt::ItemSelectionMode mode);
    175181    void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event);
    176182
    177183    QList<QGraphicsView *> views;
     184    void addView(QGraphicsView *view);
     185    void removeView(QGraphicsView *view);
     186
    178187    bool painterStateProtection;
    179188
     
    181190    void installSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
    182191    void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
     192    bool filterDescendantEvent(QGraphicsItem *item, QEvent *event);
    183193    bool filterEvent(QGraphicsItem *item, QEvent *event);
    184194    bool sendEvent(QGraphicsItem *item, QEvent *event);
     
    198208    QGraphicsWidget *windowForItem(const QGraphicsItem *item) const;
    199209
    200     QList<QGraphicsItem *> items_helper(const QPointF &pos) const;
    201     QList<QGraphicsItem *> items_helper(const QRectF &rect,
    202                                         Qt::ItemSelectionMode mode,
    203                                         Qt::SortOrder order) const;
    204     QList<QGraphicsItem *> items_helper(const QPolygonF &rect,
    205                                         Qt::ItemSelectionMode mode,
    206                                         Qt::SortOrder order) const;
    207     QList<QGraphicsItem *> items_helper(const QPainterPath &rect,
    208                                         Qt::ItemSelectionMode mode,
    209                                         Qt::SortOrder order) const;
    210     void childItems_helper(QList<QGraphicsItem *> *items,
    211                            const QGraphicsItem *parent,
    212                            const QPointF &pos) const;
    213     void childItems_helper(QList<QGraphicsItem *> *items,
    214                            const QGraphicsItem *parent,
    215                            const QRectF &rect,
    216                            Qt::ItemSelectionMode mode) const;
    217     void childItems_helper(QList<QGraphicsItem *> *items,
    218                            const QGraphicsItem *parent,
    219                            const QPolygonF &polygon,
    220                            Qt::ItemSelectionMode mode) const;
    221     void childItems_helper(QList<QGraphicsItem *> *items,
    222                            const QGraphicsItem *parent,
    223                            const QPainterPath &path,
    224                            Qt::ItemSelectionMode mode) const;
    225 
    226     bool sortCacheEnabled;
    227     bool updatingSortCache;
    228     void invalidateSortCache();
    229     static void climbTree(QGraphicsItem *item, int *stackingOrder);
    230     void _q_updateSortCache();
    231 
    232     static bool closestItemFirst_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2);
    233     static bool closestItemLast_withoutCache(const QGraphicsItem *item1, const QGraphicsItem *item2);
    234 
    235     static inline bool closestItemFirst_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
    236     {
    237         return item1->d_ptr->globalStackingOrder < item2->d_ptr->globalStackingOrder;
    238     }
    239     static inline bool closestItemLast_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
    240     {
    241         return item1->d_ptr->globalStackingOrder >= item2->d_ptr->globalStackingOrder;
    242     }
    243 
    244     static void sortItems(QList<QGraphicsItem *> *itemList, Qt::SortOrder order, bool cached);
     210    bool sortCacheEnabled; // for compatibility
    245211
    246212    void drawItemHelper(QGraphicsItem *item, QPainter *painter,
    247213                        const QStyleOptionGraphicsItem *option, QWidget *widget,
    248214                        bool painterStateProtection);
    249    
     215
     216    void drawItems(QPainter *painter, const QTransform *const viewTransform,
     217                   QRegion *exposedRegion, QWidget *widget);
     218
     219    void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const,
     220                              QRegion *exposedRegion, QWidget *widget, qreal parentOpacity = qreal(1.0),
     221                              const QTransform *const effectTransform = 0);
     222    void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const,
     223              QRegion *, QWidget *, qreal, const QTransform *const, bool, bool);
     224
     225    void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false,
     226                   bool force = false, bool ignoreOpacity = false, bool removingItemFromScene = false);
     227    void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false,
     228                                    qreal parentOpacity = qreal(1.0));
     229
     230    inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false)
     231    {
     232        Q_ASSERT(item);
     233        item->d_ptr->dirty = 0;
     234        item->d_ptr->paintedViewBoundingRectsNeedRepaint = 0;
     235        item->d_ptr->geometryChanged = 0;
     236        if (!item->d_ptr->dirtyChildren)
     237            recursive = false;
     238        item->d_ptr->dirtyChildren = 0;
     239        item->d_ptr->needsRepaint = QRectF();
     240        item->d_ptr->allChildrenDirty = 0;
     241        item->d_ptr->fullUpdatePending = 0;
     242        item->d_ptr->ignoreVisible = 0;
     243        item->d_ptr->ignoreOpacity = 0;
     244#ifndef QT_NO_GRAPHICSEFFECT
     245        QGraphicsEffect::ChangeFlags flags;
     246        if (item->d_ptr->notifyBoundingRectChanged) {
     247            flags |= QGraphicsEffect::SourceBoundingRectChanged;
     248            item->d_ptr->notifyBoundingRectChanged = 0;
     249        }
     250        if (item->d_ptr->notifyInvalidated) {
     251            flags |= QGraphicsEffect::SourceInvalidated;
     252            item->d_ptr->notifyInvalidated = 0;
     253        }
     254#endif //QT_NO_GRAPHICSEFFECT
     255        if (recursive) {
     256            for (int i = 0; i < item->d_ptr->children.size(); ++i)
     257                resetDirtyItem(item->d_ptr->children.at(i), recursive);
     258        }
     259#ifndef QT_NO_GRAPHICSEFFECT
     260        if (flags && item->d_ptr->graphicsEffect)
     261            item->d_ptr->graphicsEffect->sourceChanged(flags);
     262#endif //QT_NO_GRAPHICSEFFECT
     263    }
     264
     265    inline void ensureSortedTopLevelItems()
     266    {
     267        if (needSortTopLevelItems) {
     268            qSort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf);
     269            topLevelSequentialOrdering = false;
     270            needSortTopLevelItems = false;
     271        }
     272    }
     273
     274    void ensureSequentialTopLevelSiblingIndexes();
     275
    250276    QStyle *style;
    251277    QFont font;
     
    258284    void updatePalette(const QPalette &palette);
    259285
    260     mutable QVector<QTransform> sceneTransformCache;
    261     mutable QBitArray validTransforms;
    262     mutable QVector<int> freeSceneTransformSlots;
     286    QStyleOptionGraphicsItem styleOptionTmp;
     287
     288    QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints;
     289    QMap<int, QGraphicsItem *> itemForTouchPointId;
     290    static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
     291    int findClosestTouchPointId(const QPointF &scenePos);
     292    void touchEventHandler(QTouchEvent *touchEvent);
     293    bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
     294    bool allItemsIgnoreTouchEvents;
     295    void enableTouchEventsOnViews();
     296
     297    QHash<QGesture *, QGraphicsObject *> gestureTargets;
     298    void gestureEventHandler(QGestureEvent *event);
     299    void getGestureTargets(const QSet<QGesture *> &gestures, QWidget *viewport,
     300                           QMap<Qt::GestureType, QGesture *> *conflictedGestures,
     301                           QList<QList<QGraphicsObject *> > *conflictedItems,
     302                           QHash<QGesture *, QGraphicsObject *> *normalGestures);
     303    void cancelGesturesForChildren(QGesture *original, QWidget *viewport);
     304
     305    void updateInputMethodSensitivityInViews();
     306
     307    QList<QGraphicsItem *> modalPanels;
     308    void enterModal(QGraphicsItem *item,
     309                    QGraphicsItem::PanelModality panelModality = QGraphicsItem::NonModal);
     310    void leaveModal(QGraphicsItem *item);
    263311};
    264312
     313// QRectF::intersects() returns false always if either the source or target
     314// rectangle's width or height are 0. This works around that problem.
     315static inline void _q_adjustRect(QRectF *rect)
     316{
     317    Q_ASSERT(rect);
     318    if (!rect->width())
     319        rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
     320    if (!rect->height())
     321        rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001));
     322}
     323
     324static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
     325{
     326    Q_ASSERT(item);
     327    QRectF boundingRect(item->boundingRect());
     328    _q_adjustRect(&boundingRect);
     329    return boundingRect;
     330}
     331
     332static inline QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
     333{
     334    Q_ASSERT(item);
     335    QRectF boundingRect(QGraphicsItemPrivate::get(item)->effectiveBoundingRect());
     336    _q_adjustRect(&boundingRect);
     337    return boundingRect;
     338}
     339
    265340QT_END_NAMESPACE
    266341
Note: See TracChangeset for help on using the changeset viewer.